Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[all] Sofa defrost sprint week2 #884

Merged
merged 8 commits into from
Jan 21, 2019
1 change: 1 addition & 0 deletions SofaKernel/framework/sofa/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ set(SOURCE_FILES
State.cpp
behavior/BaseAnimationLoop.cpp
behavior/BaseConstraint.cpp
behavior/BaseConstraintCorrection.cpp
behavior/BaseConstraintSet.cpp
behavior/BaseForceField.cpp
behavior/BaseInteractionForceField.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, development version *
* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/core/behavior/BaseConstraintCorrection.h>

namespace sofa
{

namespace core
{

namespace behavior
{

BaseConstraintCorrection::BaseConstraintCorrection(){}
BaseConstraintCorrection::~BaseConstraintCorrection(){}

void BaseConstraintCorrection::rebuildSystem(double /*massFactor*/, double /*forceFactor*/){}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment: use SOFA_UNUSED instead of commenting out variable names


void BaseConstraintCorrection::getComplianceWithConstraintMerge(defaulttype::BaseMatrix* /*Wmerged*/, std::vector<int> & /*constraint_merge*/)
{
msg_warning() << "getComplianceWithConstraintMerge is not implemented yet " ;
}

void BaseConstraintCorrection::computeResidual(const core::ExecParams* /*params*/, defaulttype::BaseVector * /*lambda*/)
{
dmsg_warning() << "ComputeResidual is not implemented in " << this->getName() ;
}

void BaseConstraintCorrection::getBlockDiagonalCompliance(defaulttype::BaseMatrix* /*W*/, int /*begin*/,int /*end*/)
{
dmsg_warning() << "getBlockDiagonalCompliance(defaulttype::BaseMatrix* W) is not implemented in " << this->getTypeName() ;
}

bool BaseConstraintCorrection::hasConstraintNumber(int /*index*/) {return true;}
void BaseConstraintCorrection::resetForUnbuiltResolution(double * /*f*/, std::list<unsigned int>& /*renumbering*/) {}
void BaseConstraintCorrection::addConstraintDisplacement(double * /*d*/, int /*begin*/, int /*end*/) {}
void BaseConstraintCorrection::setConstraintDForce(double * /*df*/, int /*begin*/, int /*end*/, bool /*update*/) {} // f += df


} // namespace behavior

} // namespace core

} // namespace sofa

58 changes: 18 additions & 40 deletions SofaKernel/framework/sofa/core/behavior/BaseConstraintCorrection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define SOFA_CORE_BEHAVIOR_BASECONSTRAINTCORRECTION_H

#include <sofa/core/objectmodel/BaseObject.h>

#include <sofa/core/ConstraintParams.h>

namespace sofa
Expand Down Expand Up @@ -51,24 +50,14 @@ class ConstraintSolver;
/**
* \brief Component computing constraint forces within a simulated body using the compliance method.
*/
class BaseConstraintCorrection : public virtual objectmodel::BaseObject
class SOFA_CORE_API BaseConstraintCorrection : public virtual objectmodel::BaseObject
{
public:
SOFA_ABSTRACT_CLASS(BaseConstraintCorrection, objectmodel::BaseObject);
protected:
BaseConstraintCorrection() {};
virtual ~BaseConstraintCorrection() {}

private:
BaseConstraintCorrection(const BaseConstraintCorrection& n) ;
BaseConstraintCorrection& operator=(const BaseConstraintCorrection& n) ;

virtual bool isActive() { return this->getContext()->isActive(); }

public:

virtual bool isActive() { return this->getContext()->isActive(); }

/// @name Compliance Matrix API
/// @name Compliance Matrix API
/// @{

virtual void addComplianceInConstraintSpace(const ConstraintParams *, defaulttype::BaseMatrix* W) = 0;
Expand All @@ -77,10 +66,7 @@ class BaseConstraintCorrection : public virtual objectmodel::BaseObject
virtual void getComplianceMatrix(defaulttype::BaseMatrix* m) const = 0;

/// For multigrid approach => constraints are merged
virtual void getComplianceWithConstraintMerge(defaulttype::BaseMatrix* /*Wmerged*/, std::vector<int> & /*constraint_merge*/)
{
sout << "getComplianceWithConstraintMerge is not implemented yet " << sendl;
}
virtual void getComplianceWithConstraintMerge(defaulttype::BaseMatrix* /*Wmerged*/, std::vector<int> & /*constraint_merge*/);

/// @}

Expand All @@ -102,7 +88,6 @@ class BaseConstraintCorrection : public virtual objectmodel::BaseObject
/// @param lambda is the constraint space force vector
virtual void computeMotionCorrectionFromLambda(const core::ConstraintParams* cparams, core::MultiVecDerivId dx, const defaulttype::BaseVector * lambda) = 0;


/// Compute motion correction from the constraint resolution (LCP) calculated force
///
/// @param cparams
Expand Down Expand Up @@ -137,43 +122,36 @@ class BaseConstraintCorrection : public virtual objectmodel::BaseObject

/// Rebuild the system using a mass and force factor
/// Experimental API used to investigate convergence issues.
virtual void rebuildSystem(double /*massFactor*/, double /*forceFactor*/){}
virtual void rebuildSystem(double /*massFactor*/, double /*forceFactor*/);

/// Compute the residual in the newton iterations due to the constraints forces
/// i.e. compute Vecid::force() += J^t lambda
/// the result is accumulated in Vecid::force()
virtual void computeResidual(const core::ExecParams* /*params*/, defaulttype::BaseVector * /*lambda*/)
{
dmsg_error() << "ComputeResidual is not implemented in " << this->getName() ;
}
virtual void computeResidual(const core::ExecParams* /*params*/, defaulttype::BaseVector * /*lambda*/) ;

/// @name Deprecated API
/// @{

virtual void applyContactForce(const defaulttype::BaseVector *f) = 0;

virtual void resetContactForce() = 0;

/// @}


/// @name Unbuilt constraint system during resolution
/// @{
virtual bool hasConstraintNumber(int /*index*/);
virtual void resetForUnbuiltResolution(double * /*f*/, std::list<unsigned int>& /*renumbering*/);
virtual void addConstraintDisplacement(double * /*d*/, int /*begin*/, int /*end*/);
virtual void setConstraintDForce(double * /*df*/, int /*begin*/, int /*end*/, bool /*update*/); // f += df
virtual void getBlockDiagonalCompliance(defaulttype::BaseMatrix* /*W*/, int /*begin*/,int /*end*/);
/// @}

virtual bool hasConstraintNumber(int /*index*/) {return true;}

virtual void resetForUnbuiltResolution(double * /*f*/, std::list<unsigned int>& /*renumbering*/) {}

virtual void addConstraintDisplacement(double * /*d*/, int /*begin*/, int /*end*/) {}

virtual void setConstraintDForce(double * /*df*/, int /*begin*/, int /*end*/, bool /*update*/) {} // f += df
protected:
BaseConstraintCorrection();
virtual ~BaseConstraintCorrection() override;

virtual void getBlockDiagonalCompliance(defaulttype::BaseMatrix* /*W*/, int /*begin*/,int /*end*/)
{
sout << "warning : getBlockDiagonalCompliance(defaulttype::BaseMatrix* W) is not implemented in " << this->getTypeName() << sendl;
}
private:
BaseConstraintCorrection(const BaseConstraintCorrection& n) ;
BaseConstraintCorrection& operator=(const BaseConstraintCorrection& n) ;

/// @}
};

} // namespace behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SOFA_CORE_API BaseInteractionConstraint : public BaseConstraint

protected:
BaseInteractionConstraint() {}
virtual ~BaseInteractionConstraint(){}
virtual ~BaseInteractionConstraint()override {}

private:
BaseInteractionConstraint(const BaseInteractionConstraint& n) ;
Expand Down
2 changes: 1 addition & 1 deletion SofaKernel/framework/sofa/core/behavior/BaseLMConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class SOFA_CORE_API BaseLMConstraint: public BaseConstraintSet

protected:
BaseLMConstraint();
virtual ~BaseLMConstraint() override {}

~BaseLMConstraint() {}
public:

/// Called by MechanicalWriteLMConstaint: The Object will compute the constraints present in the current state, and create the ConstraintGroup related.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ extern template class SOFA_CORE_API ConstraintCorrection< sofa::defaulttype::Vec
extern template class SOFA_CORE_API ConstraintCorrection< sofa::defaulttype::Vec1Types >;
extern template class SOFA_CORE_API ConstraintCorrection< sofa::defaulttype::Rigid3Types >;


#endif

} // namespace behavior
Expand Down
6 changes: 1 addition & 5 deletions SofaKernel/framework/sofa/core/behavior/ForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ void ForceField<DataTypes>::addBToMatrix(const MechanicalParams* mparams, const
template<class DataTypes>
void ForceField<DataTypes>::addBToMatrix(sofa::defaulttype::BaseMatrix * /*mat*/, SReal /*bFact*/, unsigned int &/*offset*/)
{
// static int i=0;
// if (i < 10) {
// serr << "addBToMatrix not implemented." << sendl;
// i++;
// }

}

template<class DataTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,84 +96,6 @@ void PairInteractionForceField<DataTypes>::addDForce(const MechanicalParams* mpa
serr<<"PairInteractionForceField<DataTypes>::addDForce(const MechanicalParams* /*mparams*/, MultiVecDerivId /*fId*/ ), mstate missing"<<sendl;
}

/*
template<class DataTypes>
void PairInteractionForceField<DataTypes>::addForce(const MechanicalParams* mparams, DataVecDeriv& f1, DataVecDeriv& f2, const DataVecCoord& x1, const DataVecCoord& x2, const DataVecDeriv& v1, const DataVecDeriv& v2 )
{
addForce( *f1.beginEdit(mparams) , *f2.beginEdit(mparams),
x1.getValue(mparams) , x2.getValue(mparams) ,
v1.getValue(mparams) , v2.getValue(mparams) );
f1.endEdit(mparams); f2.endEdit(mparams);
}
template<class DataTypes>
void PairInteractionForceField<DataTypes>::addForce(VecDeriv& , VecDeriv& , const VecCoord& , const VecCoord& , const VecDeriv& , const VecDeriv& )
{
serr << "ERROR("<<getClassName()<<"): addForce not implemented." << sendl;
}
*/


/*
template<class DataTypes>
void PairInteractionForceField<DataTypes>::addDForce(const MechanicalParams* mparams, DataVecDeriv& df1, DataVecDeriv& df2, const DataVecDeriv& dx1, const DataVecDeriv& dx2)
{
addDForce(*df1.beginEdit(mparams), *df2.beginEdit(mparams), dx1.getValue(mparams), dx2.getValue(mparams),mparams->kFactor(),mparams->bFactor());
df1.endEdit(mparams); df2.endEdit(mparams);
}
template<class DataTypes>
void PairInteractionForceField<DataTypes>::addDForce(VecDeriv& df1, VecDeriv& df2, const VecDeriv& dx1, const VecDeriv& dx2, SReal kFactor, SReal)
{
if (kFactor == 1.0)
addDForce(df1, df2, dx1, dx2);
else if (kFactor != 0.0)
{
VecDerivId vtmp1(VecDerivId::V_FIRST_DYNAMIC_INDEX);
mstate1->vAvail(vtmp1);
mstate1->vAlloc(vtmp1);
VecDerivId vdx1(0);
/// @TODO: Add a better way to get the current VecId of dx
for (vdx1.index=0;vdx1.index<vtmp1.index;++vdx1.index)
if (&mstate1->read(VecDerivId(vdx1))->getValue() == &dx1)
break;
VecDeriv* dx1scaled = mstate1->write(vtmp1)->beginEdit();
dx1scaled->resize(dx1.size());
mstate1->vOp(vtmp1,VecId::null(),vdx1,kFactor);
//sout << "dx1 = "<<dx1<<sendl;
//sout << "dx1*"<<kFactor<<" = "<<dx1scaled<<sendl;
VecDerivId vtmp2(VecDerivId::V_FIRST_DYNAMIC_INDEX);
mstate2->vAvail(vtmp2);
mstate2->vAlloc(vtmp2);
VecDerivId vdx2(0);
/// @TODO: Add a better way to get the current VecId of dx
for (vdx2.index=0;vdx2.index<vtmp2.index;++vdx2.index)

if (&mstate2->read(VecDerivId(vdx2))->getValue() == &dx2)
break;
VecDeriv* dx2scaled = mstate2->write(vtmp2)->beginEdit();
dx2scaled->resize(dx2.size());
mstate2->vOp(vtmp2,VecId::null(),vdx2,kFactor);
//sout << "dx2 = "<<dx2<<sendl;
//sout << "dx2*"<<kFactor<<" = "<<dx2scaled<<sendl;

addDForce(df1, df2, *dx1scaled, *dx2scaled);

mstate1->write(vtmp1)->endEdit();
mstate2->write(vtmp2)->endEdit();

mstate1->vFree(vtmp1);
mstate2->vFree(vtmp2);
}
}
template<class DataTypes>
void PairInteractionForceField<DataTypes>::addDForce(VecDeriv& , VecDeriv&, const VecDeriv&, const VecDeriv& )
{
serr << "ERROR("<<getClassName()<<"): addDForce not implemented." << sendl;
}

*/



template<class DataTypes>
SReal PairInteractionForceField<DataTypes>::getPotentialEnergy(const MechanicalParams* mparams) const
{
Expand All @@ -182,21 +104,6 @@ SReal PairInteractionForceField<DataTypes>::getPotentialEnergy(const MechanicalP
else return 0.0;
}

/*
template<class DataTypes>
SReal PairInteractionForceField<DataTypes>::getPotentialEnergy(const MechanicalParams* mparams, const DataVecCoord& x1, const DataVecCoord& x2 ) const
{
return getPotentialEnergy( x1.getValue(mparams) , x2.getValue(mparams) );
}
template<class DataTypes>
SReal PairInteractionForceField<DataTypes>::getPotentialEnergy(const VecCoord& , const VecCoord& ) const
{
serr << "ERROR("<<getClassName()<<"): getPotentialEnergy(const VecCoord1& , const VecCoord2&) not implemented." << sendl;
return 0.0;
}
*/


template<class DataTypes>
void PairInteractionForceField<DataTypes>::updateForceMask()
{
Expand All @@ -206,12 +113,6 @@ void PairInteractionForceField<DataTypes>::updateForceMask()
mstate2->forceMask.assign( mstate2->getSize(), true );
}







} // namespace behavior

} // namespace core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,10 @@ void ProjectiveConstraintSet<DataTypes>::projectJacobianMatrix(const MechanicalP
template<class DataTypes>
void ProjectiveConstraintSet<DataTypes>::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId)
{
// serr << "ProjectiveConstraintSet<DataTypes>::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) " << this->getName() << sendl;

if (!isActive())
return;
if (mstate)
{
// serr << "ProjectiveConstraintSet<DataTypes>::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) " << this->getName() << " has mstate " << sendl;

projectResponse(mparams, *dxId[mstate.get(mparams)].write());
}
else serr << "ProjectiveConstraintSet<DataTypes>::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId), no mstate for " << this->getName() << sendl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean: replacing serr with msg_*

Expand Down
1 change: 0 additions & 1 deletion SofaKernel/framework/sofa/defaulttype/SolidTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class SOFA_DEFAULTTYPE_API SolidTypes
return SpatialVector( lineVec *a, freeVec * a);
}

//template<class Real2>
SpatialVector& operator *= ( Real a )
{
lineVec *=a;
Expand Down
Loading