16 #ifndef SURGSIM_PHYSICS_UNITTESTS_MOCKOBJECTS_H 17 #define SURGSIM_PHYSICS_UNITTESTS_MOCKOBJECTS_H 19 #include "SurgSim/Collision/Representation.h" 20 #include "SurgSim/Framework/ObjectFactory.h" 21 #include "SurgSim/Framework/Macros.h" 23 #include "SurgSim/Math/OdeSolver.h" 24 #include "SurgSim/Math/OdeState.h" 27 #include "SurgSim/Physics/Constraint.h" 28 #include "SurgSim/Physics/ConstraintImplementation.h" 29 #include "SurgSim/Physics/Computation.h" 31 #include "SurgSim/Physics/Fem1DRepresentation.h" 32 #include "SurgSim/Physics/Fem2DRepresentation.h" 33 #include "SurgSim/Physics/Fem3DCorotationalTetrahedronRepresentation.h" 34 #include "SurgSim/Physics/Fem3DRepresentation.h" 35 #include "SurgSim/Physics/FemElement.h" 36 #include "SurgSim/Physics/FemPlyReaderDelegate.h" 37 #include "SurgSim/Physics/FemRepresentation.h" 38 #include "SurgSim/Physics/FixedRepresentation.h" 39 #include "SurgSim/Physics/LinearSpring.h" 40 #include "SurgSim/Physics/Localization.h" 41 #include "SurgSim/Physics/Mass.h" 42 #include "SurgSim/Physics/MassSpringLocalization.h" 43 #include "SurgSim/Physics/MassSpringRepresentation.h" 44 #include "SurgSim/Physics/Representation.h" 45 #include "SurgSim/Physics/RigidRepresentation.h" 46 #include "SurgSim/Physics/VirtualToolCoupler.h" 66 int m_postUpdateCount;
81 void update(
double dt)
override;
87 int getPreUpdateCount()
const;
89 int getUpdateCount()
const;
91 int getPostUpdateCount()
const;
127 setRepresentation(representation);
132 void setLocalNode(
size_t nodeID)
137 const size_t& getLocalNode()
const 142 bool isValidRepresentation(std::shared_ptr<Representation> representation)
override 144 std::shared_ptr<DeformableRepresentation> defRepresentation =
148 return (defRepresentation !=
nullptr || representation ==
nullptr);
154 std::shared_ptr<DeformableRepresentation> defRepresentation =
157 SURGSIM_ASSERT(defRepresentation !=
nullptr) <<
"Deformable Representation is null, it was probably not" <<
159 SURGSIM_ASSERT((0.0 <= time) && (time <= 1.0)) <<
"Time must be between 0.0 and 1.0 inclusive";
164 return SurgSim::Math::interpolate(previousPoint, currentPoint, time);
169 std::shared_ptr<DeformableRepresentation> defRepresentation =
172 SURGSIM_ASSERT(defRepresentation !=
nullptr) <<
"Deformable Representation is null, it was probably not" <<
174 SURGSIM_ASSERT((0.0 <= time) && (time <= 1.0)) <<
"Time must be between 0.0 and 1.0 inclusive";
177 const SurgSim::Math::Vector3d& previousVelocity = defRepresentation->getPreviousState()->getVelocity(m_nodeID);
179 return SurgSim::Math::interpolate(previousVelocity, currentVelocity, time);
183 std::shared_ptr<Localization> doCopy()
const override 185 auto localization = std::make_shared<MockDeformableLocalization>(getRepresentation());
186 localization->setLocalNode(getLocalNode());
200 void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
206 void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
208 void computeF(
const OdeState& state)
override;
209 void computeM(
const OdeState& state)
override;
210 void computeD(
const OdeState& state)
override;
211 void computeK(
const OdeState& state)
override;
212 void computeFMDK(
const OdeState& state)
override;
220 void addNode(
size_t nodeId);
222 void addForce(
const OdeState& state, Vector* F,
double scale = 1.0)
override;
223 void addDamping(
const OdeState& state, SparseMatrix* D,
double scale = 1.0)
override;
225 double scale = 1.0)
override;
227 void addFDK(
const OdeState& state, Vector* f, SparseMatrix* D, SparseMatrix* K)
override;
228 void addMatVec(
const OdeState& state,
double alphaD,
double alphaK,
const Vector& x, Vector* F)
override;
232 SparseMatrix m_D, m_K;
244 size_t numNodes, std::vector<size_t> nodeBoundaryConditions,
246 double rayleighDampingMass,
double rayleighDampingStiffness,
247 double springStiffness,
double springDamping,
248 SurgSim::Math::IntegrationScheme integrationScheme);
252 const Vector3d& getGravityVector()
const;
256 return m_externalGeneralizedForce;
260 return m_externalGeneralizedStiffness;
264 return m_externalGeneralizedDamping;
274 explicit MockFemElement(std::shared_ptr<FemElementStructs::FemElementParameter> elementData);
276 void addNode(
size_t nodeId);
278 double getVolume(
const OdeState& state)
const override;
279 Vector computeCartesianCoordinate(
const OdeState& state,
const Vector& barycentricCoordinate)
const override;
288 void initializeMembers();
289 void doUpdateFMDK(
const Math::OdeState& state,
int options)
override;
290 bool m_isInitialized;
304 void setInitialState(std::shared_ptr<SurgSim::Math::OdeState> initialState)
override;
306 void loadFem(
const std::string& filename)
override;
308 void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
312 std::shared_ptr<FemPlyReaderDelegate> getDelegate();
314 const std::vector<double>& getMassPerNode()
const;
318 bool hasSetInitialStateBeenCalled();
324 void transformState(std::shared_ptr<OdeState> state,
const RigidTransform3d& transform)
override;
327 bool m_setInitialStateCalled;
345 bool doInitialize()
override;
347 double getMassPerNode(
size_t nodeId);
355 double getMassPerNode(
size_t nodeId);
373 SurgSim::Physics::ConstraintType getConstraintType()
const override;
376 size_t doGetNumDof()
const override;
378 void doBuild(
double dt,
380 const std::shared_ptr<Localization>& localization,
382 size_t indexOfRepresentation,
383 size_t indexOfConstraint,
384 ConstraintSideSign sign)
override;
393 SurgSim::Physics::ConstraintType getConstraintType()
const override;
396 size_t doGetNumDof()
const override;
398 void doBuild(
double dt,
400 const std::shared_ptr<Localization>& localization,
402 size_t indexOfRepresentation,
403 size_t indexOfConstraint,
404 ConstraintSideSign sign)
override;
407 template <
class Base>
431 std::shared_ptr<Localization> doCopy()
const override;
437 SurgSim::Physics::ConstraintType getConstraintType()
const override;
440 size_t doGetNumDof()
const override;
442 virtual void doBuild(
double dt,
444 const std::shared_ptr<Localization>& localization,
446 size_t indexOfRepresentation,
447 size_t indexOfConstraint,
448 ConstraintSideSign sign);
471 inline std::shared_ptr<Constraint> makeMockConstraint(std::shared_ptr<MockRepresentation> firstRepresentation,
472 std::shared_ptr<MockRepresentation> secondRepresentation)
477 if (firstRepresentation->getConstraintImplementation(type) ==
nullptr)
480 std::make_shared<MockConstraintImplementation>());
483 return std::make_shared<Constraint>(type, std::make_shared<ConstraintData>(),
484 firstRepresentation, Location(),
485 secondRepresentation, Location());
496 int getShapeType()
const override;
497 std::shared_ptr<Math::Shape> getShape()
const override;
498 void update(
const double& dt)
override;
501 int getNumberOfTimesUpdateCalled()
const;
505 int m_numberOfTimesUpdateCalled;
516 std::shared_ptr<PhysicsManagerState> doUpdate(
const double& dt,
517 const std::shared_ptr<PhysicsManagerState>& state)
override;
523 #endif // SURGSIM_PHYSICS_UNITTESTS_MOCKOBJECTS_H Definition: MockObjects.h:434
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Finite Element Model 2D is a fem built with 2D FemElement.
Definition: Fem2DRepresentation.h:52
Definition: MockObjects.h:367
A description of a physical mixed LCP system to be solved.
Definition: MlcpPhysicsProblem.h:43
Finite Element Model 1D is a fem built with 1D FemElement.
Definition: Fem1DRepresentation.h:54
Finite Element Model (a.k.a FEM) is a deformable model (a set of nodes connected by FemElement)...
Definition: FemRepresentation.h:46
void beforeUpdate(double dt) override
Preprocessing done before the update call.
Definition: MockObjects.cpp:40
Definition: MockObjects.h:235
The Representation class defines the base class for all physics objects.
Definition: Representation.h:53
A Location defines a local position w.r.t.
Definition: Location.h:39
Definition: MockObjects.h:270
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
static ConstraintImplementationFactory & getFactory()
Definition: ConstraintImplementation.cpp:34
Definition: MockObjects.h:387
The FixedRepresentation class represents a physics entity without any motion nor compliance against w...
Definition: FixedRepresentation.h:35
void afterUpdate(double dt) override
Postprocessing done after the update call.
Definition: MockObjects.cpp:50
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
Base class for all CosntraintData Derived classes should be specific to a given constraint.
Definition: ConstraintData.h:27
Definition: MockObjects.h:330
Base class for all Fem Element (1D, 2D, 3D) It handles the node ids to which it is connected and requ...
Definition: FemElement.h:45
Definition: MockObjects.h:96
std::shared_ptr< Localization > createLocalization(const SurgSim::DataStructures::Location &location) override
Computes a localized coordinate w.r.t this representation, given a Location object.
Definition: MockObjects.cpp:70
The RigidRepresentation class defines the dynamic rigid body representation Note that the rigid repre...
Definition: RigidRepresentation.h:42
Definition: MockObjects.h:350
Definition: MockObjects.h:415
bool initialize(const std::weak_ptr< Runtime > &runtime)
Initialize this component, this needs to be called before wakeUp() can be called. ...
Definition: Component.cpp:77
Definition: MockObjects.h:215
Definition: MockObjects.h:340
MassSpring model is a deformable model (a set of masses connected by springs).
Definition: MassSpringRepresentation.h:45
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:42
The RigidState class describes a state (position and velocity information).
Definition: RigidState.h:31
Definition: MockObjects.h:508
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
void addImplementation(std::type_index typeIndex, std::shared_ptr< ConstraintImplementation > implementation)
Add an implementation to the internal directory.
Definition: ConstraintImplementationFactory.cpp:105
Base class for all constraint implementations. A ConstraintImplementation defines 1 side of a constra...
Definition: ConstraintImplementation.h:42
A collection of NamedData objects.
Definition: DataGroup.h:68
Definitions of small fixed-size square matrix types.
Co-rotational Tetrahedron Finite Element Model 3D is a fem built with co-rotational tetrahedron 3D Fe...
Definition: Fem3DCorotationalTetrahedronRepresentation.h:38
Definition: MockObjects.h:358
Definitions of small fixed-size vector types.
void update(double dt) override
Update the representation state to the current time step.
Definition: MockObjects.cpp:45
Definition: MockObjects.h:107
bool isInitialized() const
Definition: Component.cpp:72
Encapsulates a calculation over a selection of objects, needs to be subclassed to be used...
Definition: Computation.h:32
The type of collision detection.
Definition: Representation.h:60
Base class for all solvers of ode equation of order 2 of the form .
Definition: OdeSolver.h:78
Definition: MockObjects.h:294
Definition: MockObjects.h:61
Class to represent a mock collision representation to test if update gets called from the Computation...
Definition: MockObjects.h:489
SurgSim::Physics::ConstraintType getConstraintType() const override
Gets the constraint type for this ConstraintImplementation.
Definition: MockObjects.cpp:580
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
This class localize a point on a representation (representation specific)
Definition: Localization.h:39
Definition: MockObjects.h:408