Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include <sofa/core/ObjectFactory.h>

#include <sofa/core/behavior/BaseConstraint.h> ///< ConstraintResolution.
#include <sofa/core/behavior/BaseLagrangianConstraint.h> ///< ConstraintResolution.

#include <sofa/helper/AdvancedTimer.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ class PenalityContactForceField : public core::behavior::PairInteractionForceFie

void addDForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& data_df1, DataVecDeriv& data_df2, const DataVecDeriv& data_dx1, const DataVecDeriv& data_dx2) override;

void addKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
void doAddKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;

void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;

void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final;
void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final;

SReal getPotentialEnergy(const sofa::core::MechanicalParams*, const DataVecCoord&, const DataVecCoord& ) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void PenalityContactForceField<DataTypes>::addDForce(const sofa::core::Mechanica
}

template <class DataTypes>
void PenalityContactForceField<DataTypes>::addKToMatrix(const sofa::core::MechanicalParams* mparams,
void PenalityContactForceField<DataTypes>::doAddKToMatrix(const sofa::core::MechanicalParams* mparams,
const sofa::core::behavior::MultiMatrixAccessor* matrix)
{
static constexpr auto N = DataTypes::spatial_dimensions;
Expand Down Expand Up @@ -200,7 +200,7 @@ void PenalityContactForceField<DataTypes>::addKToMatrix(const sofa::core::Mechan
}

template <class DataTypes>
void PenalityContactForceField<DataTypes>::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix)
void PenalityContactForceField<DataTypes>::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix)
{
const type::vector<Contact>& cc = contacts.getValue();

Expand Down Expand Up @@ -257,7 +257,7 @@ void PenalityContactForceField<DataTypes>::buildStiffnessMatrix(core::behavior::
}

template <class DataTypes>
void PenalityContactForceField<DataTypes>::buildDampingMatrix(core::behavior::DampingMatrix*)
void PenalityContactForceField<DataTypes>::doBuildDampingMatrix(core::behavior::DampingMatrix*)
{
// No damping in this ForceField
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class BaseContactLagrangianConstraint : public core::behavior::PairInteractionCo
typedef typename Coord::value_type Real;
typedef typename core::behavior::MechanicalState<DataTypes> MechanicalState;

typedef core::behavior::BaseConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseConstraint::PersistentID PersistentID;
typedef core::behavior::BaseConstraint::ConstCoord ConstCoord;

typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseConstraint::VecConstArea VecConstArea;
typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID;
typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord;

typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea;

typedef core::objectmodel::Data<VecCoord> DataVecCoord;
typedef core::objectmodel::Data<VecDeriv> DataVecDeriv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <sofa/component/constraint/lagrangian/model/config.h>

#include <sofa/type/Mat.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/core/behavior/ConstraintResolution.h>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace sofa::component::constraint::lagrangian::model

/// These 'using' are in a per-file namespace so they will not leak
/// and polluate the standard namespace.
using sofa::core::behavior::BaseConstraint ;
using sofa::core::behavior::BaseLagrangianConstraint ;
using sofa::core::behavior::ConstraintResolution ;
using sofa::core::behavior::PairInteractionConstraint ;
using sofa::core::ConstraintParams ;
Expand Down Expand Up @@ -81,7 +81,7 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint<DataTypes
typedef typename DataTypes::MatrixDeriv::RowIterator MatrixDerivRowIterator;

typedef core::behavior::MechanicalState<DataTypes> MechanicalState;
typedef BaseConstraint::PersistentID PersistentID;
typedef BaseLagrangianConstraint::PersistentID PersistentID;

typedef Data<VecCoord> DataVecCoord;
typedef Data<VecDeriv> DataVecDeriv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
#include <sofa/core/behavior/BaseConstraintCorrection.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/helper/map.h>

#include <sofa/simulation/CpuTask.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void LCPConstraintSolver::computeInitialGuess()
for (const ConstraintBlockInfo& info : constraintBlockInfo)
{
if (!info.hasId) continue;
std::map<core::behavior::BaseConstraint*, ConstraintBlockBuf>::const_iterator previt = _previousConstraints.find(info.parent);
std::map<core::behavior::BaseLagrangianConstraint*, ConstraintBlockBuf>::const_iterator previt = _previousConstraints.find(info.parent);
if (previt == _previousConstraints.end()) continue;
const ConstraintBlockBuf& buf = previt->second;
const int c0 = info.const0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
#include <sofa/core/behavior/BaseConstraintCorrection.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

#include <sofa/simulation/MechanicalVisitor.h>
#include <sofa/simulation/fwd.h>
Expand Down Expand Up @@ -147,17 +147,17 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
std::vector<core::behavior::BaseConstraintCorrection*> _cclist_elem1;
std::vector<core::behavior::BaseConstraintCorrection*> _cclist_elem2;

typedef core::behavior::BaseConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseConstraint::PersistentID PersistentID;
typedef core::behavior::BaseConstraint::ConstCoord ConstCoord;
typedef core::behavior::BaseConstraint::ConstDeriv ConstDeriv;
typedef core::behavior::BaseConstraint::ConstArea ConstArea;
typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID;
typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord;
typedef core::behavior::BaseLagrangianConstraint::ConstDeriv ConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::ConstArea ConstArea;

typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseConstraint::VecConstArea VecConstArea;
typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea;

class ConstraintBlockBuf
{
Expand All @@ -166,7 +166,7 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint
};

std::map<core::behavior::BaseConstraint*, ConstraintBlockBuf> _previousConstraints;
std::map<core::behavior::BaseLagrangianConstraint*, ConstraintBlockBuf> _previousConstraints;
type::vector< SReal > _previousForces;

type::vector< VecConstraintBlockInfo > hierarchy_constraintBlockInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.h>
#include <sofa/core/ConstraintParams.h>

Expand All @@ -35,7 +35,7 @@ ConstraintStoreLambdaVisitor::ConstraintStoreLambdaVisitor(const sofa::core::Con

simulation::Visitor::Result ConstraintStoreLambdaVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet)
{
if (core::behavior::BaseConstraint *c = dynamic_cast<core::behavior::BaseConstraint*>(cSet) )
if (core::behavior::BaseLagrangianConstraint *c = dynamic_cast<core::behavior::BaseLagrangianConstraint*>(cSet) )
{
const ctime_t t0 = begin(node, c);
c->storeLambda(m_cParams, m_cParams->lambda(), m_lambda);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.h>
#include <sofa/core/behavior/BaseConstraintSet.h>
#include <sofa/core/ConstraintParams.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

namespace sofa::component::constraint::lagrangian::solver
{
Expand All @@ -39,7 +39,7 @@ MechanicalGetConstraintResolutionVisitor::MechanicalGetConstraintResolutionVisit

MechanicalGetConstraintResolutionVisitor::Result MechanicalGetConstraintResolutionVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet)
{
if (core::behavior::BaseConstraint *c=cSet->toBaseConstraint())
if (core::behavior::BaseLagrangianConstraint *c=cSet->toBaseLagrangianConstraint())
{
const ctime_t t0 = begin(node, c);
c->getConstraintResolution(cparams, _res, _offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class TetrahedronDiffusionFEMForceField : public core::behavior::ForceField<Data
/// Forcefield functions for Matrix system. Adding derivate force to global forcefield vector.
void addDForce(const sofa::core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, DataVecDeriv& dF , const DataVecDeriv& dX) override;
/// Forcefield functions for Matrix system. Adding derivate force to global forcefield vector. (direct solver)
void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override;

void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {}
void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {}

/// Return Potential energy of the mesh.
SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& x) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,17 @@ void TetrahedronDiffusionFEMForceField<DataTypes>::addDForce(const sofa::core::M


template <class DataTypes>
void TetrahedronDiffusionFEMForceField<DataTypes>::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix)
void TetrahedronDiffusionFEMForceField<DataTypes>::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFactor, unsigned int &offset)
{
SCOPED_TIMER("addKToMatrix");
const auto N = defaulttype::DataTypeInfo<Deriv>::size();
sofa::core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate);
sofa::linearalgebra::BaseMatrix* mat = r.matrix;

if((sofa::Size)(mat->colSize()) != (m_topology->getNbPoints()*N) || (sofa::Size)(mat->rowSize()) != (m_topology->getNbPoints()*N))
if((sofa::Size)(matrix->colSize()) != (m_topology->getNbPoints()*N) || (sofa::Size)(matrix->rowSize()) != (m_topology->getNbPoints()*N))
{
msg_error()<<"Wrong size of the input Matrix: need resize in addKToMatrix function.";
mat->resize(m_topology->getNbPoints()*N,m_topology->getNbPoints()*N);
matrix->resize(m_topology->getNbPoints()*N,m_topology->getNbPoints()*N);
}

Real kFactor = mparams->kFactor();
unsigned int &offset = r.offset;

sofa::Index v0,v1;

const auto& edges = m_topology->getEdges();
Expand All @@ -381,15 +376,15 @@ void TetrahedronDiffusionFEMForceField<DataTypes>::addKToMatrix(const core::Mech
v0 = edges[i][0];
v1 = edges[i][1];

mat->add(offset+N*v1, offset+N*v0, -kFactor * edgeDiffusionCoefficient[i]);
mat->add(offset+N*v0, offset+N*v1, -kFactor * edgeDiffusionCoefficient[i]);
mat->add(offset+N*v0, offset+N*v0, kFactor * edgeDiffusionCoefficient[i]);
mat->add(offset+N*v1, offset+N*v1, kFactor * edgeDiffusionCoefficient[i]);
matrix->add(offset+N*v1, offset+N*v0, -kFactor * edgeDiffusionCoefficient[i]);
matrix->add(offset+N*v0, offset+N*v1, -kFactor * edgeDiffusionCoefficient[i]);
matrix->add(offset+N*v0, offset+N*v0, kFactor * edgeDiffusionCoefficient[i]);
matrix->add(offset+N*v1, offset+N*v1, kFactor * edgeDiffusionCoefficient[i]);
}
}

template <class DataTypes>
void TetrahedronDiffusionFEMForceField<DataTypes>::buildStiffnessMatrix(
void TetrahedronDiffusionFEMForceField<DataTypes>::doBuildStiffnessMatrix(
core::behavior::StiffnessMatrix* matrix)
{
constexpr auto N = DataTypes::deriv_total_size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class BaseROI : public core::DataEngine
void draw(const core::visual::VisualParams* vparams) final;
void computeBBox(const core::ExecParams* params, bool onlyVisible) final;

virtual void roiInit() {};
virtual bool roiDoUpdate() { return true; };
virtual void roiDraw(const core::visual::VisualParams*) {};
virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {};
virtual void roiInit() {}
virtual bool roiDoUpdate() { return true; }
virtual void roiDraw(const core::visual::VisualParams*) {}
virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {}

public:
//Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ MeshBoundaryROI::MeshBoundaryROI(): Inherit1()

void MeshBoundaryROI::init()
{
Inherit1::init();

if (!d_triangles.isSet() || !d_quads.isSet() )
{
msg_info(this) << "No topology given. Searching for a BaseMeshTopology in the current context.\n";
core::topology::BaseMeshTopology* topology = nullptr;
this->getContext()->get(topology, core::objectmodel::BaseContext::Local);

if (topology)
{
if (!d_triangles.isSet())
{
if (core::BaseData* tparent = topology->findData("triangles"))
{
d_triangles.setParent(tparent);
d_triangles.setReadOnly(true);
}
}
if (!d_quads.isSet())
{
if (core::BaseData* tparent = topology->findData("quads"))
{
d_quads.setParent(tparent);
d_quads.setReadOnly(true);
}
}
}
}

if (!d_triangles.isSet() && !d_quads.isSet())
{
msg_warning() << "No topology given. No mesh to process.\n";
}

setDirtyValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ template<class DataTypes>
public:
SOFA_CLASS(BuggyForceField, sofa::core::behavior::ForceField<DataTypes>);

void buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override
void doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override
{
auto dfdx = matrix->getForceDerivativeIn(this->mstate).withRespectToPositionsIn(this->mstate);
dfdx(10, 20) += 0.;
Expand Down
10 changes: 5 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>

/// Add Mass contribution to global Matrix assembling
void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override;
void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override;
void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {}
void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {}
void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override;
void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {}
void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {}

SReal getElementMass(sofa::Index index) const override;
void getElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const override;
SReal doGetElementMass(sofa::Index index) const override;
void doGetElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const override;

bool isDiagonal() const override {return true;}

Expand Down
6 changes: 3 additions & 3 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void DiagonalMass<DataTypes, GeometricalTypes>::addMToMatrix(sofa::linearalgebra
}

template <class DataTypes, class GeometricalTypes>
void DiagonalMass<DataTypes, GeometricalTypes>::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices)
void DiagonalMass<DataTypes, GeometricalTypes>::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices)
{
const MassVector &masses= d_vertexMass.getValue();
static constexpr auto N = Deriv::total_size;
Expand All @@ -642,15 +642,15 @@ void DiagonalMass<DataTypes, GeometricalTypes>::buildMassMatrix(sofa::core::beha


template <class DataTypes, class GeometricalTypes>
SReal DiagonalMass<DataTypes, GeometricalTypes>::getElementMass(sofa::Index index) const
SReal DiagonalMass<DataTypes, GeometricalTypes>::doGetElementMass(sofa::Index index) const
{
return SReal(d_vertexMass.getValue()[index]);
}


//TODO: special case for Rigid Mass
template <class DataTypes, class GeometricalTypes>
void DiagonalMass<DataTypes, GeometricalTypes>::getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const
void DiagonalMass<DataTypes, GeometricalTypes>::doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const
{
static const linearalgebra::BaseMatrix::Index dimension = linearalgebra::BaseMatrix::Index(defaulttype::DataTypeInfo<Deriv>::size());
if (m->rowSize() != dimension || m->colSize() != dimension) m->resize(dimension,dimension);
Expand Down
Loading