1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
*******************************************************************************
* SOFA :: Modules *
* *
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/simulation/common/AnimateVisitor.h>
#include <sofa/simulation/common/MechanicalVisitor.h>
#include <sofa/simulation/common/CollisionVisitor.h>
//#include "MechanicalIntegration.h"
namespace sofa
{
namespace simulation
{
void AnimateVisitor::processMasterSolver(simulation::Node*, core::componentmodel::behavior::MasterSolver* obj)
{
obj->step(getDt());
}
void AnimateVisitor::processBehaviorModel(simulation::Node*, core::BehaviorModel* obj)
{
obj->updatePosition(getDt());
}
void AnimateVisitor::fwdInteractionForceField(simulation::Node*, core::componentmodel::behavior::InteractionForceField* obj)
{
obj->addForce();
}
void AnimateVisitor::processCollisionPipeline(simulation::Node* node, core::componentmodel::collision::Pipeline*)
{
CollisionVisitor act;
node->execute(&act);
}
void AnimateVisitor::processOdeSolver(simulation::Node* /*node*/, core::componentmodel::behavior::OdeSolver* solver)
{
/* MechanicalIntegrationVisitor act(getDt());
node->execute(&act);*/
cerr<<"AnimateVisitor::processOdeSolver "<<solver->getName()<<endl;
solver->solve(getDt());
}
Visitor::Result AnimateVisitor::processNodeTopDown(simulation::Node* node)
{
//cerr<<"AnimateVisitor::process Node "<<node->getName()<<endl;
if (!node->is_activated.getValue()) return Visitor::RESULT_PRUNE;
if (dt == 0) setDt(node->getDt());
// for_each(this, node, node->behaviorModel, &AnimateVisitor::processBehaviorModel);
if (node->masterSolver != NULL)
{
ctime_t t0 = begin(node, node->masterSolver);
processMasterSolver(node, node->masterSolver);
end(node, node->masterSolver, t0);
return RESULT_PRUNE;
}
if (node->collisionPipeline != NULL)
{
//ctime_t t0 = begin(node, node->collisionPipeline);
processCollisionPipeline(node, node->collisionPipeline);
//end(node, node->collisionPipeline, t0);
}
/* if (node->solver != NULL)
{
ctime_t t0 = begin(node, node->solver);
processOdeSolver(node, node->solver);
end(node, node->solver, t0);
return RESULT_PRUNE;
}*/
if (!node->solver.empty() )
{
double nextTime = node->getTime() + dt;
MechanicalBeginIntegrationVisitor beginVisitor(dt);
node->execute(&beginVisitor);
for( unsigned i=0; i<node->solver.size(); i++ ){
ctime_t t0 = begin(node, node->solver[i]);
//cerr<<"AnimateVisitor::processNodeTpDown solver "<<node->solver[i]->getName()<<endl;
node->solver[i]->solve(getDt());
end(node, node->solver[i], t0);
}
MechanicalPropagatePositionAndVelocityVisitor(nextTime,core::componentmodel::behavior::OdeSolver::VecId::position(),core::componentmodel::behavior::OdeSolver::VecId::velocity()).execute( node );
MechanicalEndIntegrationVisitor endVisitor(dt);
node->execute(&endVisitor);
return RESULT_PRUNE;
}
/*
if (node->mechanicalModel != NULL)
{
std::cerr << "Graph Error: MechanicalState without solver." << std::endl;
return RESULT_PRUNE;
}
*/
{
// process InteractionForceFields
for_each(this, node, node->interactionForceField, &AnimateVisitor::fwdInteractionForceField);
return RESULT_CONTINUE;
}
}
// void AnimateVisitor::processNodeBottomUp(simulation::Node* node)
// {
// node->setTime( node->getTime() + node->getDt() );
// }
} // namespace simulation
} // namespace sofa
|