/// After simulation compare the positions of points to the theoretical positions. bool runTest(double /*convergenceAccuracy*/) { // Init simulation sofa::simulation::getSimulation()->init(this->root.get()); // xin typename InDOFs::ReadVecCoord x = this->inDofs->readPositions(); InVecCoord xin(x.size()); copyFromData(xin,x); // xout typename OutDOFs::ReadVecCoord xelasticityDofs = this->outDofs->readPositions(); OutVecCoord xout(xelasticityDofs.size()); copyFromData(xout,xelasticityDofs); // Apply affine transform to each dof InVecCoord parentNew(xin.size()); this->applyAffineTransform(xin,parentNew); // Expected children positions: rotation from affine constraint OutVecCoord expectedChildCoords(xout.size()); for(size_t i=0;i<xout.size();++i) { OutFrame &f = expectedChildCoords[i].getF(); f = testedRotation; } // run the mapping test return Inherited::runTest(xin,xout,parentNew,expectedChildCoords); }
/// After simulation compare the positions of deformation gradients to the theoretical positions. bool runTest(double convergenceAccuracy) { // Init simulation sofa::simulation::getSimulation()->init(this->root.get()); // Get dofs positions typename InDOFs::ReadVecCoord x = this->inDofs->readPositions(); // xin InVecCoord xin(x.size()); copyFromData(xin,x); // xout typename OutDOFs::ReadVecCoord xelasticityDofs = this->outDofs->readPositions(); OutVecCoord xout(xelasticityDofs.size()); copyFromData(xout,xelasticityDofs); // Initialize parameters to test convergence size_t numNodes = xin.size(); InVecCoord xPrev(numNodes); InVecCoord dx(numNodes); bool hasConverged = true; for (size_t i=0; i<numNodes; i++) { xPrev[i] = CPos(0,0,0); } // Animate do { hasConverged = true; sofa::simulation::getSimulation()->animate(this->root.get(),0.05); typename InDOFs::ReadVecCoord xCurrent = this->inDofs->readPositions(); // Compute dx for (size_t i=0; i<xCurrent.size(); i++) { // Translation dx[i].getCenter() = xCurrent[i].getCenter()-xPrev[i].getCenter(); //Rotation dx[i].getOrientation() = xCurrent[i].getOrientation().inverse()*xPrev[i].getOrientation(); // Test convergence if(dx[i].norm()>convergenceAccuracy) hasConverged = false; } // xprev = xCurrent for (size_t i=0; i<numNodes; i++) { xPrev[i]=xCurrent[i]; } } while(!hasConverged); // not converged // Parent new : Get simulated positions typename InDOFs::WriteVecCoord xinNew = this->inDofs->writePositions(); // New position of parents InVecCoord parentNew(xinNew.size()); for(size_t i=0; i<xinNew.size();++i) { parentNew[i] = xinNew[i]; } // Expected children positions: rotation from affine constraint typename OutDOFs::WriteVecCoord xoutNew = this->outDofs->writePositions(); OutVecCoord expectedChildCoords(xoutNew.size()); for(size_t i=0;i<xoutNew.size();++i) { OutFrame &f = expectedChildCoords[i].getF(); f = testedRotation; } // run the mapping test return Inherited::runTest(xin,xout,parentNew,expectedChildCoords); }