EulerKaapiSolver.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <sofa/component/odesolver/EulerKaapiSolver.h>
00026 #include <sofa/core/ObjectFactory.h>
00027 #include <math.h>
00028 #include <iostream>
00029 #include <sofa/simulation/common/MechanicalKaapiAction.h>
00030 #include <sofa/simulation/common/MechanicalVPrintAction.h>
00031
00032
00033 using
00034 std::cerr;
00035 using
00036 std::endl;
00037 using namespace sofa::simulation::tree;
00038 using namespace sofa::simulation;
00039
00040
00041 namespace
00042 sofa
00043 {
00044
00045 namespace
00046 component
00047 {
00048
00049 namespace
00050 odesolver
00051 {
00052
00053 using namespace
00054 sofa::defaulttype;
00055 using namespace
00056 core::componentmodel::behavior;
00057
00058 int
00059 EulerKaapiSolverClass =
00060 core::RegisterObject ("A simple explicit time integrator with kaapi").
00061 add < EulerKaapiSolver > ().addAlias ("EulerKaapi");
00062
00063 SOFA_DECL_CLASS (EulerKaapi);
00064
00065 EulerKaapiSolver::EulerKaapiSolver ():
00066 symplectic (dataField
00067 (&symplectic, true, "symplectic",
00068 "If true, the velocities are updated before the velocities and the method is symplectic (more robust). If false, the positions are updated before the velocities (standard Euler, less robust)."))
00069 {
00070 }
00071
00072
00073
00074 EulerKaapiSolver::VecId EulerKaapiSolver::v_alloc(VecId::Type t)
00075 {
00076 VecId v(t, vectors[t].alloc());
00077 MechanicalVAllocAction(v).execute( getContext() );
00078 return v;
00079 }
00080 void EulerKaapiSolver::v_clear(VecId v)
00081 {
00082 MechanicalVOpAction(v).execute( getContext() );
00083 }
00084
00085 void EulerKaapiSolver::v_free(VecId v)
00086 {
00087 if (vectors[v.type].free(v.index))
00088 MechanicalVFreeAction(v).execute( getContext() );
00089 }
00090
00091
00092
00093 void EulerKaapiSolver::v_peq(VecId v, VecId a, double f)
00094 {
00095 std::cout<<"ve peque"<<std::endl;
00096 MechanicalVOpAction(v,v,a,f).execute( getContext() );
00097 }
00098
00099 void EulerKaapiSolver::projectResponse(VecId dx, double **W)
00100 {
00101 MechanicalApplyConstraintsAction(dx, W).execute( getContext() );
00102 }
00103
00104
00105
00106 void EulerKaapiSolver::accFromF(VecId a, VecId f)
00107 {
00108 MechanicalAccFromFAction(a,f).execute( getContext() );
00109 }
00110
00111 void EulerKaapiSolver::propagatePositionAndVelocity(double t, VecId x, VecId v)
00112 {
00113 MechanicalPropagatePositionAndVelocityAction(t,x,v).execute( getContext() );
00114 }
00115
00116 void EulerKaapiSolver::computeForce(VecId result)
00117 {
00118 MechanicalResetForceAction(result).execute( getContext() );
00119 finish();
00120 MechanicalComputeForceAction(result).execute( getContext() );
00121 }
00122
00123
00124 void EulerKaapiSolver::computeAcc (double t, VecId a, VecId x, VecId v)
00125 {
00126 MultiVector
00127 f (this, VecId::force ());
00128 std::cout<<"kaapi solver"<<std::endl;
00129 propagatePositionAndVelocity (t, x, v);
00130 computeForce (f);
00131 if (this->f_printLog.getValue () == true)
00132 {
00133 cerr << "OdeSolver::computeAcc, f = " << f << endl;
00134 }
00135
00136 accFromF (a, f);
00137 projectResponse (a);
00138 }
00139
00140 void
00141 EulerKaapiSolver::solve (double dt)
00142 {
00143
00144 OdeSolver *
00145 group = this;
00146 MultiVector
00147 pos (group, VecId::position ());
00148 MultiVector
00149 vel (group, VecId::velocity ());
00150 MultiVector
00151 acc (group, VecId::dx ());
00152 bool
00153 printLog = 1;
00154
00155
00156 if (printLog)
00157 {
00158 cerr << "EulerKaapiSolver, dt = " << dt << endl;
00159 cerr << "EulerKaapiSolver, initial x = " << pos << endl;
00160 cerr << "EulerKaapiSolver, initial v = " << vel << endl;
00161 }
00162
00163 computeAcc (getTime (), acc, pos, vel);
00164
00165
00166 if (symplectic.getValue ())
00167 {
00168 vel.peq (acc, dt);
00169 pos.peq (vel, dt);
00170 }
00171 else
00172 {
00173 pos.peq (vel, dt);
00174 vel.peq (acc, dt);
00175 }
00176
00177 if (printLog)
00178 {
00179 cerr << "EulerKaapiSolver, acceleration = " << acc << endl;
00180 cerr << "EulerKaapiSolver, final x = " << pos << endl;
00181 cerr << "EulerKaapiSolver, final v = " << vel << endl;
00182 }
00183 }
00184
00185 }
00186
00187 }
00188
00189 }