16 #ifndef SURGSIM_MATH_UNITTESTS_MOCKOBJECT_H 17 #define SURGSIM_MATH_UNITTESTS_MOCKOBJECT_H 20 #include "SurgSim/Math/OdeEquation.h" 21 #include "SurgSim/Math/OdeSolver.h" 22 #include "SurgSim/Math/OdeState.h" 48 m_viscosity(viscosity),
49 m_gravity(0.0, -9.81, 0.0)
55 this->m_initialState = std::make_shared<MassPointState>();
65 SURGSIM_ASSERT(m_odeSolver) <<
"Ode solver not initialized, it should have been initialized on wake-up";
70 Math::zeroRow(condition, &bTemp);
72 auto solution = m_odeSolver->getLinearSolver()->solve(bTemp);
75 Math::zeroRow(condition, &solution);
80 void setOdeSolver(std::shared_ptr<SurgSim::Math::OdeSolver> solver)
87 double m_mass, m_viscosity;
93 m_f = m_mass * m_gravity - m_viscosity * state.
getVelocities();
120 m_f = m_mass * m_gravity - m_viscosity * state.
getVelocities();
154 m_gravityForce.setZero();
155 m_gravityForce.segment<3>(3) =
Vector3d(0.0, 0.01 * -9.81, 0.0);
156 m_gravityForce.segment<3>(6) =
Vector3d(0.0, 0.01 * -9.81, 0.0);
158 this->m_initialState = std::make_shared<MassPointsStateForStatic>();
161 const Vector& getExternalForces()
const 163 return m_gravityForce;
168 SURGSIM_ASSERT(m_odeSolver) <<
"Ode solver not initialized, it should have been initialized on wake-up";
173 Math::zeroRow(condition, &bTemp);
175 auto solution = m_odeSolver->getLinearSolver()->solve(bTemp);
178 Math::zeroRow(condition, &solution);
183 void setOdeSolver(std::shared_ptr<SurgSim::Math::OdeSolver> solver)
185 m_odeSolver = solver;
194 m_f = -m_K * (state.
getPositions() - m_initialState->getPositions());
197 m_f += m_gravityForce;
228 typedef Eigen::Triplet<double> T;
229 std::vector<T> tripletList;
230 tripletList.reserve(39);
233 for (
int counter = 0; counter < 3; ++counter)
235 tripletList.push_back(T(counter, counter, 1.0));
238 for (
int row = 3; row < 9; ++row)
241 tripletList.push_back(T(row, row, 8.0));
244 for (
int col = 3; col < 9; ++col)
246 tripletList.push_back(T(row, col, 2.0));
249 m_K.setFromTriplets(tripletList.begin(), tripletList.end());
262 std::shared_ptr<SurgSim::Math::OdeSolver> m_odeSolver;
277 this->m_initialState = std::make_shared<MassPointState>();
282 SURGSIM_ASSERT(m_odeSolver) <<
"Ode solver not initialized, it should have been initialized on wake-up";
287 Math::zeroRow(condition, &bTemp);
289 auto solution = m_odeSolver->getLinearSolver()->solve(bTemp);
292 Math::zeroRow(condition, &solution);
297 void setOdeSolver(std::shared_ptr<SurgSim::Math::OdeSolver> solver)
299 m_odeSolver = solver;
321 m_K.resize(static_cast<Eigen::Index>(state.
getNumDof()), static_cast<Eigen::Index>(state.
getNumDof()));
336 std::shared_ptr<SurgSim::Math::OdeSolver> m_odeSolver;
343 #endif // SURGSIM_MATH_UNITTESTS_MOCKOBJECT_H Definition: MockObject.h:41
MassPointsForStatic()
Constructor.
Definition: MockObject.h:144
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void computeF(const OdeState &state) override
Evaluation of the RHS function for a given state.
Definition: MockObject.h:189
SurgSim::Math::Vector & getVelocities()
Retrieves all degrees of freedom's velocity (non-const version)
Definition: OdeState.cpp:100
void computeFMDK(const OdeState &state) override
Evaluation of , , and .
Definition: MockObject.h:326
void computeM(const OdeState &state) override
Evaluation of the LHS matrix for a given state.
Definition: MockObject.h:200
void computeFMDK(const OdeState &state) override
Evaluation of , , and .
Definition: MockObject.h:113
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
Ode equation of 2nd order of the form with for initial conditions and a set of boundary conditions...
Definition: OdeEquation.h:54
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
void computeM(const OdeState &state) override
Evaluation of the LHS matrix for a given state.
Definition: MockObject.h:96
Definition: MockObject.h:30
void computeD(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:205
Definition: MockObject.h:140
OdeComplexNonLinear()
Constructor.
Definition: MockObject.h:271
void computeK(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:210
void computeF(const OdeState &state) override
Evaluation of the RHS function for a given state.
Definition: MockObject.h:303
size_t getNumDof() const
Retrieves the number of degrees of freedom.
Definition: OdeState.cpp:70
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
void computeF(const OdeState &state) override
Evaluation of the RHS function for a given state.
Definition: MockObject.h:91
void computeK(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:108
State class for static resolution It contains 3 nodes with 3 dofs each, with positions (0 0 0) (1 0 0...
Definition: MockObject.h:128
Matrix applyCompliance(const OdeState &state, const Matrix &b) override
Calculate the product where is the compliance matrix with boundary conditions applied.
Definition: MockObject.h:63
void computeM(const OdeState &state) override
Evaluation of the LHS matrix for a given state.
Definition: MockObject.h:309
const std::vector< size_t > & getBoundaryConditions() const
Retrieves all boundary conditions.
Definition: OdeState.cpp:149
std::shared_ptr< SurgSim::Math::OdeSolver > m_odeSolver
Ode solver (its type depends on the numerical integration scheme)
Definition: MockObject.h:86
MassPoint(double viscosity=0.0)
Constructor.
Definition: MockObject.h:46
Class for the complex non-linear ODE a = x.v^2.
Definition: MockObject.h:267
virtual void setNumDof(size_t numDofPerNode, size_t numNodes)
Allocates the state for a given number of degrees of freedom.
Definition: OdeState.cpp:55
OdeState()
Default constructor.
Definition: OdeState.cpp:27
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
Matrix applyCompliance(const OdeState &state, const Matrix &b) override
Calculate the product where is the compliance matrix with boundary conditions applied.
Definition: MockObject.h:280
SurgSim::Math::Vector & getPositions()
Retrieves all degrees of freedom's position (non-const version)
Definition: OdeState.cpp:85
void computeD(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:102
Matrix applyCompliance(const OdeState &state, const Matrix &b) override
Calculate the product where is the compliance matrix with boundary conditions applied.
Definition: MockObject.h:166
void computeD(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:314
void computeK(const OdeState &state) override
Evaluation of for a given state.
Definition: MockObject.h:319
void computeFMDK(const OdeState &state) override
Evaluation of , , and .
Definition: MockObject.h:252