#include <ForceFieldTestCreation.h>
Helper for writing ForceField tests. The constructor creates a root node and adds it a State and a ForceField (of the parameter type of this template class). Pointers to node, state and force are available. Deriving the ForceField test from this class makes it easy to write: just call function run_test with positions, velocities and the corresponding expected forces. This function automatically checks not only the forces (function addForce), but also the stiffness (methods addDForce and addKToMatrix), using finite differences. More...
Helper for writing ForceField tests. The constructor creates a root node and adds it a State and a ForceField (of the parameter type of this template class). Pointers to node, state and force are available. Deriving the ForceField test from this class makes it easy to write: just call function run_test with positions, velocities and the corresponding expected forces. This function automatically checks not only the forces (function addForce), but also the stiffness (methods addDForce and addKToMatrix), using finite differences.
Public Attributes | |
Scene elements | |
{ | |
DOF::SPtr | dof |
ForceField::SPtr | force |
simulation::Node::SPtr | node |
Precision and control parameters | |
} { | |
SReal | errorMax |
tolerance in precision test. The actual value is this one times the epsilon of the Real numbers (typically float or double) More... | |
SReal | errorFactorPotentialEnergy |
The test for potential energy is successful if the (infinite norm of the) difference is less than errorFactorPotentialEnergy * errorMax *epsilon (default = 1) More... | |
std::pair< Real, Real > | deltaRange |
Minimum/Maximum amplitudes of the random perturbation used to check the stiffness using finite differences. More... | |
bool | checkStiffness |
If false, stops the test after checking the force, without checking the stiffness. Default value is true. More... | |
bool | debug |
Public Attributes inherited from sofa::testing::BaseTest | |
sofa::testing::MessageAsTestFailure | m_fatal |
sofa::testing::MessageAsTestFailure | m_error |
Tested API | |
{ | |
unsigned char | flags |
static const unsigned char | TEST_POTENTIAL_ENERGY = 1 |
testing getPotentialEnergy function. The tests will only work with conservative forces (if dissipative forces such as viscosity or damping are computed, the test is wrong) More... | |
static const unsigned char | TEST_ALL = UCHAR_MAX |
testing everything More... | |
ForceField_test () | |
} More... | |
ForceField_test (std::string filename) | |
void | run_test (const VecCoord &x, const VecDeriv &v, const VecDeriv &ef, bool initScene=true) |
Given positions and velocities, checks that the expected forces are obtained, and that a small change of positions generates the corresponding change of forces. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from sofa::testing::BaseTest | |
static int | seed = (unsigned int)time(nullptr) |
Seed value. More... | |
Public Member Functions inherited from sofa::testing::BaseSimulationTest | |
BaseSimulationTest () | |
bool | importPlugin (const std::string &name) |
Public Member Functions inherited from sofa::testing::BaseTest | |
BaseTest () | |
Initialize Sofa and the random number generator. More... | |
~BaseTest () override | |
virtual void | onSetUp () |
virtual void | onTearDown () |
Public Member Functions inherited from sofa::testing::NumericTest< _ForceFieldType::DataTypes::Real > | |
NumericTest () | |
Real | vectorMaxDiff (const Container1 &c1, const Container2 &c2) |
Return the maximum difference between two containers. Issues a failure if sizes are different. More... | |
Real | vectorMaxAbs (const Container &c) |
Return the maximum absolute value of a container. More... | |
Static Public Member Functions inherited from sofa::testing::NumericTest< _ForceFieldType::DataTypes::Real > | |
static Real | matrixMaxDiff (const Matrix1 &m1, const Matrix2 &m2) |
return the maximum difference between corresponding entries, or the infinity if the matrices have different sizes More... | |
static Real | matrixMaxDiff (const sofa::type::Mat< M, N, Real > &m1, const Matrix2 &m2) |
Return the maximum difference between corresponding entries, or the infinity if the matrices have different sizes. More... | |
static Real | epsilon () |
the smallest real number More... | |
static Real | infinity () |
Infinity. More... | |
static bool | isSmall (Real r, Real ratio=1.) |
true if the magnitude of r is less than ratio*epsilon More... | |
static Real | vectorMaxDiff (const sofa::type::Vec< N, Real > &m1, const Vector2 &m2) |
return the maximum difference between corresponding entries, or the infinity if the vectors have different sizes More... | |
static Real | vectorMaxDiff (const sofa::type::Vec< N, Real > &m1, const sofa::type::Vec< N, Real > &m2) |
return the maximum difference between corresponding entries More... | |
Static Protected Member Functions inherited from sofa::testing::NumericTest< _ForceFieldType::DataTypes::Real > | |
static float | norm (float a) |
static double | norm (double a) |
static Real | norm (T a) |
bool sofa::ForceField_test< _ForceFieldType >::checkStiffness |
If false, stops the test after checking the force, without checking the stiffness. Default value is true.
bool sofa::ForceField_test< _ForceFieldType >::debug |
Print debug messages. Default is false.
std::pair<Real,Real> sofa::ForceField_test< _ForceFieldType >::deltaRange |
Minimum/Maximum amplitudes of the random perturbation used to check the stiffness using finite differences.
DOF::SPtr sofa::ForceField_test< _ForceFieldType >::dof |
SReal sofa::ForceField_test< _ForceFieldType >::errorFactorPotentialEnergy |
The test for potential energy is successful if the (infinite norm of the) difference is less than errorFactorPotentialEnergy * errorMax *epsilon (default = 1)
SReal sofa::ForceField_test< _ForceFieldType >::errorMax |
tolerance in precision test. The actual value is this one times the epsilon of the Real numbers (typically float or double)
unsigned char sofa::ForceField_test< _ForceFieldType >::flags |
testing options. (all by default). To be used with precaution.
ForceField::SPtr sofa::ForceField_test< _ForceFieldType >::force |
simulation::Node::SPtr sofa::ForceField_test< _ForceFieldType >::node |
|
static |
testing everything
|
static |
testing getPotentialEnergy function. The tests will only work with conservative forces (if dissipative forces such as viscosity or damping are computed, the test is wrong)
|
inline |
}
Create a scene with a node, a state and a forcefield.;
|
inline |
Create a scene from a xml file.
|
inline |
Given positions and velocities, checks that the expected forces are obtained, and that a small change of positions generates the corresponding change of forces.
x | positions |
v | velocities |
ef | expected forces This function first checks that the expected forces are obtained. Then, it checks getPotentialEnergy. And then, it checks the stiffness, unless member checkStiffness is set to false. A new position is created using a small random change, and the new force is computed. The change of potential energy is compared to the dot product between displacement and force. The change of force is compared to the change computed by function addDForce, and to the product of the position change with the stiffness matrix. |