Skip to content
Merged
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 @@ -189,28 +189,13 @@ class HexahedralFEMForceField : virtual public core::behavior::ForceField<DataTy
/// container that stotes all requires information for each hexahedron
topology::HexahedronData<sofa::type::vector<HexahedronInformation> > hexahedronInfo;

class HFFHexahedronHandler : public topology::TopologyDataHandler<core::topology::BaseMeshTopology::Hexahedron,sofa::type::vector<HexahedronInformation> >
{
public:
typedef typename HexahedralFEMForceField<DataTypes>::HexahedronInformation HexahedronInformation;

HFFHexahedronHandler(HexahedralFEMForceField<DataTypes>* ff, topology::HexahedronData<sofa::type::vector<HexahedronInformation> >* data )
:topology::TopologyDataHandler<core::topology::BaseMeshTopology::Hexahedron,sofa::type::vector<HexahedronInformation> >(data)
,ff(ff)
{
}

void applyCreateFunction(Index, HexahedronInformation &t, const core::topology::BaseMeshTopology::Hexahedron &,
const sofa::type::vector<Index> &, const sofa::type::vector<double> &);
protected:
HexahedralFEMForceField<DataTypes>* ff;
};


/** Method to create @sa HexahedronInformation when a new hexahedron is created.
* Will be set as creation callback in the HexahedronData @sa hexahedronInfo
*/
void createHexahedronInformation(Index, HexahedronInformation& t, const core::topology::BaseMeshTopology::Hexahedron&,
const sofa::type::vector<Index>&, const sofa::type::vector<double>&);

protected:
HFFHexahedronHandler* hexahedronHandler;

topology::HexahedronSetTopologyContainer* _topology;

type::Mat<8,3,int> _coef; ///< coef of each vertices to compute the strain stress matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,12 @@
namespace sofa::component::forcefield
{

template< class DataTypes>
void HexahedralFEMForceField<DataTypes>::HFFHexahedronHandler::applyCreateFunction(Index hexahedronIndex,
HexahedronInformation &,
const core::topology::BaseMeshTopology::Hexahedron &,
const sofa::type::vector<Index> &,
const sofa::type::vector<double> &)
{
if (ff)
{
switch(ff->method)
{
case LARGE :
ff->initLarge(hexahedronIndex);

break;
case POLAR :
ff->initPolar(hexahedronIndex);
break;
}
}
}

template <class DataTypes>
HexahedralFEMForceField<DataTypes>::HexahedralFEMForceField()
: f_method(initData(&f_method,std::string("large"),"method","\"large\" or \"polar\" displacements"))
, f_poissonRatio(initData(&f_poissonRatio,(Real)0.45f,"poissonRatio",""))
, f_youngModulus(initData(&f_youngModulus,(Real)5000,"youngModulus",""))
, hexahedronInfo(initData(&hexahedronInfo, "hexahedronInfo", "Internal hexahedron data"))
, hexahedronHandler(nullptr)
{

_coef[0][0]= -1; _coef[0][1]= -1; _coef[0][2]= -1;
Expand All @@ -90,16 +67,14 @@ HexahedralFEMForceField<DataTypes>::HexahedralFEMForceField()
_coef[6][0]= 1; _coef[6][1]= 1; _coef[6][2]= 1;
_coef[7][0]= -1; _coef[7][1]= 1; _coef[7][2]= 1;

hexahedronHandler = new HFFHexahedronHandler(this,&hexahedronInfo);

f_poissonRatio.setRequired(true);
f_youngModulus.setRequired(true);
}

template <class DataTypes>
HexahedralFEMForceField<DataTypes>::~HexahedralFEMForceField()
{
if(hexahedronHandler) delete hexahedronHandler;

}


Expand Down Expand Up @@ -137,14 +112,38 @@ void HexahedralFEMForceField<DataTypes>::reinit()

for (size_t i=0; i<_topology->getNbHexahedra(); ++i)
{
hexahedronHandler->applyCreateFunction(i,hexahedronInf[i],
_topology->getHexahedron(i), (const std::vector< Index > )0,
(const std::vector< double >)0);
createHexahedronInformation(i,hexahedronInf[i],
_topology->getHexahedron(i), (const std::vector< Index > )0,
(const std::vector< double >)0);
}
hexahedronInfo.createTopologyHandler(_topology,hexahedronHandler);
hexahedronInfo.createTopologyHandler(_topology);
hexahedronInfo.setCreationCallback([this](Index hexahedronIndex, HexahedronInformation& hexaInfo,
const core::topology::BaseMeshTopology::Hexahedron& hexa,
const sofa::type::vector< Index >& ancestors,
const sofa::type::vector< double >& coefs)
{
createHexahedronInformation(hexahedronIndex, hexaInfo, hexa, ancestors, coefs);
});
hexahedronInfo.endEdit();
}

template< class DataTypes>
void HexahedralFEMForceField<DataTypes>::createHexahedronInformation(Index hexahedronIndex, HexahedronInformation&,
const core::topology::BaseMeshTopology::Hexahedron&,
const sofa::type::vector<Index>&,
const sofa::type::vector<double>&)
{
switch (method)
{
case LARGE:
initLarge(hexahedronIndex);

break;
case POLAR:
initPolar(hexahedronIndex);
break;
}
}

template<class DataTypes>
void HexahedralFEMForceField<DataTypes>::addForce (const core::MechanicalParams* /*mparams*/, DataVecDeriv& f, const DataVecCoord& p, const DataVecDeriv& /*v*/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,7 @@ class TetrahedralCorotationalFEMForceField : public core::behavior::ForceField<D
SReal m_potentialEnergy;

sofa::core::topology::BaseMeshTopology* _topology;
public:
class SOFA_SOFAGENERALSIMPLEFEM_API TetrahedronHandler : public topology::TopologyDataHandler<core::topology::BaseMeshTopology::Tetrahedron, sofa::type::vector<TetrahedronInformation> >
{
public :
typedef typename TetrahedralCorotationalFEMForceField<DataTypes>::TetrahedronInformation TetrahedronInformation;
using Index = sofa::Index;
TetrahedronHandler(TetrahedralCorotationalFEMForceField<DataTypes>* ff,
topology::TetrahedronData<sofa::type::vector<TetrahedronInformation> >* data)
:topology::TopologyDataHandler<core::topology::BaseMeshTopology::Tetrahedron, sofa::type::vector<TetrahedronInformation> >(data)
,ff(ff)
{

}

void applyCreateFunction(Index, TetrahedronInformation &t, const core::topology::BaseMeshTopology::Tetrahedron &,
const sofa::type::vector<Index> &,
const sofa::type::vector<double> &);

protected:
TetrahedralCorotationalFEMForceField<DataTypes>* ff;

};
public:
int method;
Data<std::string> f_method; ///< the computation method of the displacements
Expand All @@ -179,7 +158,6 @@ class TetrahedralCorotationalFEMForceField : public core::behavior::ForceField<D
SingleLink<TetrahedralCorotationalFEMForceField<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
protected:
TetrahedralCorotationalFEMForceField();
TetrahedronHandler* tetrahedronHandler;

/// Pointer to the topology container. Will be set by link @sa l_topology
sofa::core::topology::BaseMeshTopology* m_topology;
Expand Down Expand Up @@ -224,6 +202,13 @@ class TetrahedralCorotationalFEMForceField : public core::behavior::ForceField<D


protected:
/** Method to create @sa TetrahedronInformation when a new tetrahedron is created.
* Will be set as creation callback in the TetrahedronData @sa tetrahedronInfo
*/
void createTetrahedronInformation(Index tetrahedronIndex, TetrahedronInformation& tInfo,
const core::topology::BaseMeshTopology::Tetrahedron& tetra,
const sofa::type::vector<Index>& ancestors,
const sofa::type::vector<double>& coefs);

void computeStrainDisplacement( StrainDisplacementTransposed &J, Coord a, Coord b, Coord c, Coord d );
Real peudo_determinant_for_coef ( const type::Mat<2, 3, Real>& M );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,33 @@ namespace sofa::component::forcefield
{

template< class DataTypes>
void TetrahedralCorotationalFEMForceField<DataTypes>::TetrahedronHandler::applyCreateFunction(Index tetrahedronIndex,
TetrahedronInformation &,
const core::topology::BaseMeshTopology::Tetrahedron &,
const sofa::type::vector<Index> &,
const sofa::type::vector<double> &)
void TetrahedralCorotationalFEMForceField<DataTypes>::createTetrahedronInformation(Index tetrahedronIndex, TetrahedronInformation& tInfo,
const core::topology::BaseMeshTopology::Tetrahedron& tetra,
const sofa::type::vector<Index>& ancestors,
const sofa::type::vector<double>& coefs)
{
const core::topology::BaseMeshTopology::Tetrahedron t=this->m_topology->getTetrahedron(tetrahedronIndex);
Index a = t[0];
Index b = t[1];
Index c = t[2];
Index d = t[3];

if (ff)
switch(method)
{
case SMALL :
computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
initSmall(tetrahedronIndex,a,b,c,d);
break;
case LARGE :
computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
initLarge(tetrahedronIndex,a,b,c,d);

const core::topology::BaseMeshTopology::Tetrahedron t=ff->m_topology->getTetrahedron(tetrahedronIndex);
Index a = t[0];
Index b = t[1];
Index c = t[2];
Index d = t[3];

switch(ff->method)
{
case SMALL :
ff->computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
ff->initSmall(tetrahedronIndex,a,b,c,d);
break;
case LARGE :
ff->computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
ff->initLarge(tetrahedronIndex,a,b,c,d);

break;
case POLAR :
ff->computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
ff->initPolar(tetrahedronIndex,a,b,c,d);
break;
}
break;
case POLAR :
computeMaterialStiffness(tetrahedronIndex,a,b,c,d);
initPolar(tetrahedronIndex,a,b,c,d);
break;
}

}

template< class DataTypes>
Expand All @@ -86,11 +79,9 @@ TetrahedralCorotationalFEMForceField<DataTypes>::TetrahedralCorotationalFEMForce
, drawColor3(initData(&drawColor3,sofa::type::RGBAColor(0.0f,1.0f,1.0f,1.0f),"drawColor3"," draw color for faces 3"))
, drawColor4(initData(&drawColor4,sofa::type::RGBAColor(0.5f,1.0f,1.0f,1.0f),"drawColor4"," draw color for faces 4"))
, l_topology(initLink("topology", "link to the topology container"))
, tetrahedronHandler(nullptr)
{
this->addAlias(&_assembling, "assembling");
_poissonRatio.setWidget("poissonRatio");
tetrahedronHandler = new TetrahedronHandler(this,&tetrahedronInfo);

_poissonRatio.setRequired(true);
_youngModulus.setRequired(true);
Expand Down Expand Up @@ -143,12 +134,20 @@ void TetrahedralCorotationalFEMForceField<DataTypes>::reinit()

for (std::size_t i=0; i<m_topology->getNbTetrahedra(); ++i)
{
tetrahedronHandler->applyCreateFunction(i, tetrahedronInf[i],
createTetrahedronInformation(i, tetrahedronInf[i],
m_topology->getTetrahedron(i), (const std::vector< Index > )0,
(const std::vector< double >)0);
}

tetrahedronInfo.createTopologyHandler(m_topology,tetrahedronHandler);
tetrahedronInfo.createTopologyHandler(m_topology);
tetrahedronInfo.setCreationCallback([this](Index tetrahedronIndex, TetrahedronInformation& tInfo,
const core::topology::BaseMeshTopology::Tetrahedron& tetra,
const sofa::type::vector<Index>& ancestors,
const sofa::type::vector<double>& coefs)
{
createTetrahedronInformation(tetrahedronIndex, tInfo, tetra, ancestors, coefs);
});

tetrahedronInfo.endEdit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,22 @@ class TriangularFEMForceFieldOptim : public core::behavior::ForceField<DataTypes
topology::PointData<VecVertexInfo> d_vertexInfo; ///< Internal point data
topology::EdgeData<VecEdgeInfo> d_edgeInfo; ///< Internal edge data

/** Method to create @sa TriangleInfo when a new triangle is created.
* Will be set as creation callback in the TriangleData @sa d_triangleInfo
*/
void createTriangleInfo(Index triangleIndex, TriangleInfo&,
const Triangle& t,
const sofa::type::vector< Index >&,
const sofa::type::vector< double >&);

/** Method to create @sa TriangleState when a new triangle is created.
* Will be set as creation callback in the TriangleData @sa d_triangleState
*/
void createTriangleState(Index triangleIndex, TriangleState&,
const Triangle& t,
const sofa::type::vector< Index > &,
const sofa::type::vector< double > &);

class TFEMFFOTriangleInfoHandler : public topology::TopologyDataHandler<Triangle,VecTriangleInfo >
{
public:
TFEMFFOTriangleInfoHandler(TriangularFEMForceFieldOptim<DataTypes>* _ff, topology::TriangleData<VecTriangleInfo >* _data) : topology::TopologyDataHandler<Triangle, VecTriangleInfo >(_data), ff(_ff) {}

void applyCreateFunction(Index triangleIndex, TriangleInfo& ,
const Triangle & t,
const sofa::type::vector< Index > &,
const sofa::type::vector< double > &);

protected:
TriangularFEMForceFieldOptim<DataTypes>* ff;
};
void initTriangleInfo(Index triangleIndex, TriangleInfo& ti, const Triangle t, const VecCoord& x0);
void initTriangleState(Index triangleIndex, TriangleState& ti, const Triangle t, const VecCoord& x);

Expand All @@ -256,20 +258,6 @@ class TriangularFEMForceFieldOptim : public core::behavior::ForceField<DataTypes
computeTriangleRotation(result,x0[t[0]], x0[t[1]], x0[t[2]]);
}

class TFEMFFOTriangleStateHandler : public topology::TopologyDataHandler<Triangle,VecTriangleState >
{
public:
TFEMFFOTriangleStateHandler(TriangularFEMForceFieldOptim<DataTypes>* _ff, topology::TriangleData<VecTriangleState >* _data) : topology::TopologyDataHandler<Triangle, VecTriangleState >(_data), ff(_ff) {}

void applyCreateFunction(Index triangleIndex, TriangleState& ,
const Triangle & t,
const sofa::type::vector< Index > &,
const sofa::type::vector< double > &);

protected:
TriangularFEMForceFieldOptim<DataTypes>* ff;
};

template<class MatrixWriter>
void addKToMatrixT(const core::MechanicalParams* mparams, MatrixWriter m);

Expand All @@ -289,10 +277,6 @@ class TriangularFEMForceFieldOptim : public core::behavior::ForceField<DataTypes
Data<bool> d_showStressVector; ///< Flag activating rendering of stress directions within each triangle
Data<Real> d_showStressMaxValue; ///< Max value for rendering of stress values


TFEMFFOTriangleInfoHandler* triangleInfoHandler;
TFEMFFOTriangleStateHandler* triangleStateHandler;

/// Link to be set to the topology container in the component graph.
SingleLink<TriangularFEMForceFieldOptim<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

Expand Down
Loading