Simbody  3.4 (development)
ParticleConSurfaceSystem.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_PARTICLECONSURFACESYSTEM_H_
00002 #define SimTK_SIMBODY_PARTICLECONSURFACESYSTEM_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                       Simbody(tm): SimTKmath                               *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2012 Stanford University and the Authors.           *
00013  * Authors: Ian Stavness, Michael Sherman                                     *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00027 
00036 #include "simmath/internal/BicubicSurface.h" // XXX compiler needed this
00037 #include "simmath/internal/ContactGeometry.h"
00038 #include "SimTKcommon.h"
00039 #include "SimTKcommon/internal/SystemGuts.h"
00040 
00041 namespace SimTK {
00042 
00043 class ParticleConSurfaceSystem;
00044 class ParticleConSurfaceSystemGuts: public System::Guts {
00045     friend class ParticleConSurfaceSystem;
00046 
00047     // TOPOLOGY STATE
00048     SubsystemIndex subsysIndex;
00049 
00050     // TOPOLOGY CACHE
00051 //    mutable DiscreteVariableIndex massIndex, lengthIndex, gravityIndex;
00052     DiscreteVariableIndex geodesicIndex, geometryIndex;
00053     mutable QIndex q0;
00054     mutable UIndex u0;
00055     mutable QErrIndex qerr0;
00056     mutable UErrIndex uerr0;
00057     mutable UDotErrIndex udoterr0;
00058     mutable EventTriggerByStageIndex event0;
00059 
00060 public:
00061     ParticleConSurfaceSystemGuts(const ContactGeometryImpl& geom)
00062     : Guts(), geom(geom) {
00063         // Index types set themselves invalid on construction.
00064     }
00065 
00066     inline const ParticleConSurfaceSystem& getParticleConSurfaceSystem() const;
00067     
00068     SubsystemIndex getSubsysIndex() const {
00069         return subsysIndex;
00070     }
00071 
00072     /*virtual*/ParticleConSurfaceSystemGuts* cloneImpl() const {return new ParticleConSurfaceSystemGuts(*this);}
00073 
00075         // Implementation of continuous DynamicSystem virtuals //
00077 
00078     /*virtual*/int realizeTopologyImpl(State&) const;
00079     /*virtual*/int realizeModelImpl(State&) const;
00080     /*virtual*/int realizeInstanceImpl(const State&) const;
00081     /*virtual*/int realizePositionImpl(const State&) const;
00082     /*virtual*/int realizeVelocityImpl(const State&) const;
00083     /*virtual*/int realizeDynamicsImpl(const State&) const;
00084     /*virtual*/int realizeAccelerationImpl(const State&) const;
00085 
00086     // qdot==u here so these are just copies
00087     /*virtual*/void multiplyByNImpl(const State& state, const Vector& u, 
00088                                  Vector& dq) const {dq=u;}
00089     /*virtual*/void multiplyByNTransposeImpl(const State& state, const Vector& fq, 
00090                                           Vector& fu) const {fu=fq;}
00091     /*virtual*/void multiplyByNPInvImpl(const State& state, const Vector& dq, 
00092                                      Vector& u) const {u=dq;}
00093     /*virtual*/void multiplyByNPInvTransposeImpl(const State& state, const Vector& fu, 
00094                                               Vector& fq) const {fq=fu;}
00095 
00096     // No prescribed motion.
00097     /*virtual*/bool prescribeQImpl(State&) const {return false;}
00098     /*virtual*/bool prescribeUImpl(State&) const {return false;}
00099 
00100     // No constraints.
00101     /*virtual*/void projectQImpl(State&, Vector& qErrEst,
00102              const ProjectOptions& options, ProjectResults& results) const;
00103     /*virtual*/void projectUImpl(State&, Vector& uErrEst,
00104              const ProjectOptions& options, ProjectResults& results) const;
00105 private:
00106     const ContactGeometryImpl& geom;
00107 }; // class ParticleConSurfaceSystemGuts
00108 
00109 
00110 
00111 class ParticleConSurfaceSystem: public System {
00112 public:
00113     ParticleConSurfaceSystem(const ContactGeometryImpl& geom) : System()
00114     { 
00115         adoptSystemGuts(new ParticleConSurfaceSystemGuts(geom));
00116         DefaultSystemSubsystem defsub(*this);
00117         updGuts().subsysIndex = defsub.getMySubsystemIndex();
00118 
00119         setHasTimeAdvancedEvents(false);
00120     }
00121 
00122     const ParticleConSurfaceSystemGuts& getGuts() const {
00123         return SimTK_DYNAMIC_CAST_DEBUG<const ParticleConSurfaceSystemGuts&>
00124                                                             (getSystemGuts());
00125     }
00126 
00127     ParticleConSurfaceSystemGuts& updGuts() {
00128         return SimTK_DYNAMIC_CAST_DEBUG<ParticleConSurfaceSystemGuts&>
00129                                                             (updSystemGuts());
00130     }
00131 
00132     void setDefaultTimeAndState(Real t, const Vector& q, const Vector& u) {
00133         const ParticleConSurfaceSystemGuts& guts = getGuts();
00134         updDefaultState().updU(guts.subsysIndex) = u;
00135         updDefaultState().updQ(guts.subsysIndex) = q;
00136         updDefaultState().updTime() = t;
00137     }
00138 
00139 
00140 }; // class ParticleConSurfaceSystem
00141 
00142 
00143 inline const ParticleConSurfaceSystem& ParticleConSurfaceSystemGuts::
00144 getParticleConSurfaceSystem() const {
00145     return static_cast<const ParticleConSurfaceSystem&>(getSystem());
00146 }
00147 
00148 
00149 } // namespace SimTK
00150 
00151 #endif /*SimTK_SIMBODY_PARTICLECONSURFACESYSTEM_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines