Base class for the Mapping tests, with helpers to automatically test applyJ, applyJT, applyDJT and getJs using finite differences.
More...
template<class _Mapping>
struct sofa::mapping_test::Mapping_test< _Mapping >
Base class for the Mapping tests, with helpers to automatically test applyJ, applyJT, applyDJT and getJs using finite differences.
Specific test cases can be created using a derived class instantiated on the mapping class to test, and calling function runTest( const VecCoord_t<In>& parentInit, const VecCoord_t<Out>& childInit, const VecCoord_t<In> parentNew, const VecCoord_t<Out> expectedChildNew);
This function compares the actual output positions with the expected ones, then automatically tests the methods related to the Jacobian using finite differences.
- A small change of the input positions dxIn is randomly chosen and added to the current position. The same is set as velocity.
- mapping->apply is called, and the difference dXout between the new output positions and the previous positions is computed
- to validate mapping->applyJ, dXin is converted to input velocity vIn and mapping->applyJ is called. dXout and the output velocity vOut must be the same (up to linear approximations errors, thus we apply a very small change of position).
- to validate mapping->getJs, we use it to get the Jacobian, then we check that J.vIn = vOut
- to validate mapping->applyJT, we apply it after setting the child force fc=vOut, then we check that parent force fp = J^T.fc
- to validate mapping->applyDJT, we set the child force, and we compare the parent force before and after a small displacement
The magnitude of the small random changes applied in finite differences is between deltaRange.first*epsilon and deltaRange.second*epsilon, and a failure is issued if the error is greater than errorMax*epsilon, where epsilon=std::numeric_limits<Real>::epsilon() is 1.19209e-07 for float and 2.22045e-16 for double.
- Author
- François Faure
- Date
- 2013
|
virtual Deriv_t< Out > | difference (const Coord_t< Out > &a, const Coord_t< Out > &b) |
|
virtual VecDeriv_t< Out > | difference (const VecDeriv_t< Out > &a, const VecDeriv_t< Out > &b) |
|
virtual VecDeriv_t< Out > | preTreatment (const VecDeriv_t< Out > &f) |
|
void | checkComparisonThreshold () |
|
void | warnMissingTests () const |
|
bool | testMappingPositionVelocity (const VecCoord_t< In > &parentInit, const VecCoord_t< Out > &childInit, const VecCoord_t< In > &parentNew, const VecCoord_t< Out > &expectedChildNew, const Real_t< In > errorThreshold, core::MechanicalParams mparams) |
|
template<class DataTypes > |
VecDeriv_t< DataTypes > | generateRandomVecDeriv (const std::size_t size, const Real_t< DataTypes > minMagnitude, const Real_t< DataTypes > maxMagnitude) |
|
void | computeForceInFromForceOut (core::MechanicalParams mparams, VecDeriv_t< In > &forceIn, const VecDeriv_t< Out > &forceOut) |
|
void | computeVelocityOutFromVelocityIn (core::MechanicalParams mparams, VecDeriv_t< Out > &velocityOut, const VecDeriv_t< In > &velocityIn) |
|
const VecDeriv_t< In > & | applyDJT (core::MechanicalParams mparams, bool updateK) |
|
bool | checkApplyDJT (const VecDeriv_t< In > &dfp, const VecDeriv_t< In > &fp12, Real_t< In > errorThreshold, bool updateK) |
|
VecCoord_t< In > | computePerturbedPositions (const std::size_t sizeIn, const VecDeriv_t< In > velocityIn) |
|
bool | checkJacobianMatrixTranspose (EigenSparseMatrix *jacobianMatrix, const VecDeriv_t< Out > &forceOut, const VecDeriv_t< In > &expectedForceIn, Real_t< In > errorThreshold) |
|
bool | checkJacobianMatrix (EigenSparseMatrix *jacobianMatrix, const VecDeriv_t< In > &velocityIn, const VecDeriv_t< Out > &expectedVelocityOut, Real_t< In > errorThreshold) |
|
bool | testApplyJonPosition (core::MechanicalParams mparams, const VecCoord_t< Out > &positionOut, const VecDeriv_t< Out > &expectedVelocityOut, Real_t< In > errorThreshold) |
|
VecDeriv_t< In > | computeForceChange (core::MechanicalParams mparams, const std::size_t sizeIn, VecDeriv_t< Out > forceOut, VecDeriv_t< In > forceIn) |
|
bool | testGetK (const std::size_t &sizeIn, const VecDeriv_t< In > &velocityIn, const VecDeriv_t< In > &forceChange, Real_t< In > errorThreshold) |
|
bool | testBuildGeometricStiffnessMatrix (std::size_t sizeIn, const VecDeriv_t< In > &velocityIn, const VecDeriv_t< In > &forceChange, Real_t< In > errorThreshold) |
|
|
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...
|
|
template<class _Mapping >
Test the mapping using the given values and small changes. Return true in case of success, if all errors are below maxError*epsilon. The mapping is initialized using the two first parameters, then a new parent position is applied, and the new child position is compared with the expected one. Additionally, the Jacobian-related methods are tested using finite differences.
The initialization values can used when the mapping is an embedding, e.g. to attach a mesh to a rigid object we compute the local coordinates of the vertices based on their world coordinates and the frame coordinates. In other cases, such as mapping from pairs of points to distances, no initialization values are necessary, an one can use the same values as for testing, i.e. runTest( xp, expected_xc, xp, expected_xc).
- Parameters
-
parentInit | initial parent position |
childInit | initial child position |
parentNew | new parent position |
expectedChildNew | expected position of the child corresponding to the new parent position |