/usr/include/sofa/component/mastersolver/MasterContactSolver.h is in libsofa1-dev 1.0~beta4-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | /******************************************************************************
* 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 *
******************************************************************************/
#ifndef SOFA_COMPONENT_ODESOLVER_MASTERCONTACTSOLVER_H
#define SOFA_COMPONENT_ODESOLVER_MASTERCONTACTSOLVER_H
#include <sofa/core/componentmodel/behavior/OdeSolver.h>
#include <sofa/simulation/common/MasterSolverImpl.h>
#include <sofa/simulation/common/Node.h>
#include <sofa/simulation/common/MechanicalVisitor.h>
#include <sofa/core/componentmodel/behavior/BaseConstraintCorrection.h>
#include <sofa/core/componentmodel/behavior/OdeSolver.h>
#include <sofa/component/odesolver/OdeSolverImpl.h>
#include <sofa/component/linearsolver/FullMatrix.h>
#include <sofa/component/linearsolver/SparseMatrix.h>
#include <sofa/helper/set.h>
namespace sofa
{
namespace component
{
namespace odesolver
{
using namespace sofa::defaulttype;
using namespace sofa::component::linearsolver;
using namespace helper::system::thread;
class SOFA_COMPONENT_MASTERSOLVER_API LCP
{
public:
int maxConst;
LPtrFullMatrix<double> W;
FullVector<double> dFree, f;
double tol;
int numItMax;
unsigned int nbConst;
bool useInitialF;
double mu;
int dim;
private:
bool lok;
public:
LCP(unsigned int maxConstraint);
~LCP();
void reset(void);
//LCP& operator=(LCP& lcp);
inline double** getW(void) {return W.lptr();};
inline double& getMu(void) { return mu;};
inline double* getDfree(void) {return dFree.ptr();};
inline int getDfreeSize(void) {return dFree.size();};
inline double getTolerance(void) {return tol;};
inline void setTol(double t) {tol = t;};
inline double getMaxIter(void) {return numItMax;};
inline double* getF(void) {return f.ptr();};
inline bool useInitialGuess(void) {return useInitialF;};
inline unsigned int getNbConst(void) {return nbConst;};
inline void setNbConst(unsigned int nbC) {nbConst = nbC;};
inline unsigned int getMaxConst(void) {return maxConst;};
inline bool isLocked(void) {return false;};
inline void lock(void) {lok = true;};
inline void unlock(void) {lok = false;};
inline void wait(void) {while(lok) ; } //infinite loop?
};
class SOFA_COMPONENT_MASTERSOLVER_API MechanicalResetContactForceVisitor : public simulation::MechanicalVisitor
{
public:
VecId force;
MechanicalResetContactForceVisitor()
{
}
virtual Result fwdMechanicalState(simulation::Node* node, core::componentmodel::behavior::BaseMechanicalState* ms)
{
ctime_t t0 = begin(node, ms);
ms->resetContactForce();
end(node, ms, t0);
return RESULT_CONTINUE;
}
virtual Result fwdMappedMechanicalState(simulation::Node* node, core::componentmodel::behavior::BaseMechanicalState* ms)
{
ctime_t t0 = begin(node, ms);
ms->resetForce();
end(node, ms, t0);
return RESULT_CONTINUE;
}
#ifdef DUMP_VISITOR_INFO
void setReadWriteVectors()
{
}
#endif
};
/* ACTION 2 : Apply the Contact Forces on mechanical models & Compute displacements */
class SOFA_COMPONENT_MASTERSOLVER_API MechanicalApplyContactForceVisitor : public simulation::MechanicalVisitor
{
public:
VecId force;
MechanicalApplyContactForceVisitor(double *f):_f(f)
{
}
virtual Result fwdMechanicalState(simulation::Node* node, core::componentmodel::behavior::BaseMechanicalState* ms)
{
ctime_t t0 = begin(node, ms);
ms->applyContactForce(_f);
end(node, ms, t0);
return RESULT_CONTINUE;
}
virtual Result fwdMappedMechanicalState(simulation::Node* node, core::componentmodel::behavior::BaseMechanicalState* ms)
{
ctime_t t0 = begin(node, ms);
ms->applyContactForce(_f);
end(node, ms, t0);
return RESULT_CONTINUE;
}
#ifdef DUMP_VISITOR_INFO
void setReadWriteVectors()
{
}
#endif
private:
double *_f; // vector of contact forces from lcp //
// to be multiplied by constraint direction in mechanical models //
};
/* ACTION 3 : gets the vector of constraint values */
/* ACTION 3 : gets the vector of constraint values */
class SOFA_COMPONENT_MASTERSOLVER_API MechanicalGetConstraintValueVisitor : public simulation::MechanicalVisitor
{
public:
MechanicalGetConstraintValueVisitor(BaseVector *v): _v(v) // , _numContacts(numContacts)
{
#ifdef DUMP_VISITOR_INFO
setReadWriteVectors();
#endif
}
virtual Result fwdConstraint(simulation::Node* node, core::componentmodel::behavior::BaseConstraint* c)
{
//sout << c->getName()<<"->getConstraintValue()"<<sendl;
ctime_t t0 = begin(node, c);
c->getConstraintValue(_v /*, _numContacts*/);
end(node, c, t0);
return RESULT_CONTINUE;
}
#ifdef DUMP_VISITOR_INFO
void setReadWriteVectors()
{
}
#endif
private:
BaseVector* _v; // vector for constraint values
// unsigned int &_numContacts; // we need an offset to fill the vector _v if differents contact class are created
};
class SOFA_COMPONENT_MASTERSOLVER_API MechanicalGetContactIDVisitor : public simulation::MechanicalVisitor
{
public:
MechanicalGetContactIDVisitor(long *id, unsigned int offset = 0)
: _id(id),_offset(offset)
{
#ifdef DUMP_VISITOR_INFO
setReadWriteVectors();
#endif
}
virtual Result fwdConstraint(simulation::Node* node, core::componentmodel::behavior::BaseConstraint* c)
{
ctime_t t0 = begin(node, c);
c->getConstraintId(_id, _offset);
end(node, c, t0);
return RESULT_CONTINUE;
}
#ifdef DUMP_VISITOR_INFO
void setReadWriteVectors()
{
}
#endif
private:
long *_id;
unsigned int _offset;
};
class SOFA_COMPONENT_MASTERSOLVER_API MasterContactSolver : public sofa::simulation::MasterSolverImpl//, public sofa::component::odesolver::OdeSolverImpl
{
public:
// for unbuilt lcp
// typedef Mat<3,3,double> Mat3x3;
typedef std::vector<core::componentmodel::behavior::BaseConstraintCorrection*> list_cc;
typedef std::vector<list_cc> VecListcc;
Data<bool> displayTime;
Data<bool> initial_guess;
Data<bool> build_lcp;
Data < double > tol;
Data < int > maxIt;
Data < double > mu;
Data < helper::set<int> > constraintGroups;
MasterContactSolver();
// virtual const char* getTypeName() const { return "MasterSolver"; }
void step (double dt);
//virtual void propagatePositionAndVelocity(double t, VecId x, VecId v);
virtual void init();
LCP* getLCP(void) {return (lcp == &lcp1) ? &lcp2 : &lcp1;};
private:
std::vector<core::componentmodel::behavior::BaseConstraintCorrection*> constraintCorrections;
void computeInitialGuess();
void keepContactForcesValue();
unsigned int _numConstraints;
double _mu;
/// for built lcp ///
void build_LCP();
LCP lcp1, lcp2;
LPtrFullMatrix<double> *_W;
LCP* lcp;
/// common built-unbuilt
simulation::Node *context;
FullVector<double> *_dFree, *_result;
///
/// for unbuilt lcp ///
void build_problem_info();
int gaussseidel_unbuilt(double *dfree, double *f);
SparseMatrix<double> *_Wdiag;
//std::vector<helper::LocalBlock33 *> _Wdiag;
std::vector<core::componentmodel::behavior::BaseConstraintCorrection*> _cclist_elem1;
std::vector<core::componentmodel::behavior::BaseConstraintCorrection*> _cclist_elem2;
typedef struct {
Vector3 n;
Vector3 t;
Vector3 s;
Vector3 F;
long id;
} contactBuf;
contactBuf *_PreviousContactList;
unsigned int _numPreviousContact;
long *_cont_id_list;
};
} // namespace odesolver
} // namespace component
} // namespace sofa
#endif
|