Skip to content

Commit f38462b

Browse files
authored
Cleaning of AdaptiveBeamForceFieldAndMass (sofa-framework#187)
* use link instead of raw pointers * use SingleStateAccessor (+ some minor cleanings) * clean code
1 parent aba5969 commit f38462b

File tree

2 files changed

+185
-187
lines changed

2 files changed

+185
-187
lines changed

src/BeamAdapter/component/forcefield/AdaptiveBeamForceFieldAndMass.h

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@
3232
//
3333
#pragma once
3434

35-
//////////////////////// Inclusion of headers...from wider to narrower/closer //////////////////////
35+
#include <BeamAdapter/config.h>
36+
37+
#include <sofa/type/Transform.h>
38+
#include <sofa/type/SpatialVector.h>
3639
#include <sofa/core/behavior/ForceField.h>
3740
#include <sofa/core/behavior/Mass.h>
38-
#include <BeamAdapter/config.h>
3941
#include <BeamAdapter/component/BaseBeamInterpolation.h>
4042
#include <BeamAdapter/component/engine/WireRestShape.h>
4143

4244

4345
namespace beamadapter
4446
{
4547

46-
using sofa::core::behavior::MultiMatrixAccessor;
47-
using sofa::core::visual::VisualParams;
48-
using sofa::core::MechanicalParams;
49-
5048
/*!
5149
* \class AdaptiveBeamForceFieldAndMass
5250
* @brief AdaptiveBeamForceFieldAndMass Class
@@ -77,8 +75,8 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>
7775
using Vec6NoInit = sofa::type::VecNoInit<6, Real>;
7876
using Matrix6x6 = sofa::type::Mat<6, 6, Real>;
7977
using Matrix6x6NoInit = sofa::type::MatNoInit<6, 6, Real>;
80-
using Transform = typename sofa::defaulttype::SolidTypes<Real>::Transform;
81-
using SpatialVector = typename sofa::defaulttype::SolidTypes<Real>::SpatialVector;
78+
using Transform = sofa::type::Transform<Real>;
79+
using SpatialVector = sofa::type::SpatialVector<Real>;
8280

8381
using BInterpolation = BaseBeamInterpolation<DataTypes>;
8482
using core::behavior::Mass<DataTypes>::mstate;
@@ -89,8 +87,8 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>
8987
* \class BeamLocalMatrices
9088
* @brief BeamLocalMatrices Class
9189
*/
92-
class BeamLocalMatrices{
93-
90+
class BeamLocalMatrices
91+
{
9492
public:
9593
BeamLocalMatrices() = default;
9694

@@ -114,37 +112,37 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>
114112
/////////////////////////////////////
115113
void init() override ;
116114
void reinit() override ;
117-
void draw(const VisualParams* vparams) override ;
115+
void draw(const sofa::core::visual::VisualParams* vparams) override ;
118116

119117

120118
/////////////////////////////////////
121119
/// Mass Interface
122120
/////////////////////////////////////
123-
void addMDx(const MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override;
124-
void addMToMatrix(const MechanicalParams *mparams, const MultiMatrixAccessor* matrix) override;
125-
void addMBKToMatrix(const MechanicalParams* mparams, const MultiMatrixAccessor* matrix) override;
121+
void addMDx(const sofa::core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override;
122+
void addMToMatrix(const sofa::core::MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
123+
void addMBKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
126124

127125
void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override;
128126
void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
129127
void buildDampingMatrix(core::behavior::DampingMatrix* matrices) override;
130128

131129
//TODO(dmarchal 2017-05-17) So what do we do ? For who is this message intended for ? How can we make this code "more" manageable.
132-
void accFromF(const MechanicalParams* mparams, DataVecDeriv& , const DataVecDeriv& ) override
130+
void accFromF(const sofa::core::MechanicalParams* mparams, DataVecDeriv& , const DataVecDeriv& ) override
133131
{
134132
SOFA_UNUSED(mparams);
135133
msg_error()<<"accFromF can not be implemented easily: It necessitates a solver because M^-1 is not available";
136134
}
137135

138136
//TODO(dmarchal 2017-05-17) So what do we do ? For who is this message intended for ? How can we make this code "more" manageable.
139-
SReal getKineticEnergy(const MechanicalParams* mparams, const DataVecDeriv& ) const override ///< vMv/2 using dof->getV()
137+
SReal getKineticEnergy(const sofa::core::MechanicalParams* mparams, const DataVecDeriv& ) const override ///< vMv/2 using dof->getV()
140138
{
141139
SOFA_UNUSED(mparams);
142140
msg_error() << "getKineticEnergy not yet implemented";
143141
return 0;
144142
}
145143

146144
//TODO(dmarchal 2017-05-17) So what do we do ? For who is this message intended for ? How can we make this code "more" manageable.
147-
void addGravityToV(const MechanicalParams* mparams, DataVecDeriv& ) override
145+
void addGravityToV(const sofa::core::MechanicalParams* mparams, DataVecDeriv& ) override
148146
{
149147
SOFA_UNUSED(mparams);
150148
msg_error() << "addGravityToV not implemented yet";
@@ -155,24 +153,24 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>
155153
/////////////////////////////////////
156154
/// ForceField Interface
157155
/////////////////////////////////////
158-
void addForce(const MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override;
156+
void addForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override;
159157

160-
void addDForce(const MechanicalParams* mparams, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override;
158+
void addDForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override;
161159

162160
//TODO(dmarchal 2017-05-17) So what do we do ? For who is this message intended for ? How can we make this code "more" manageable.
163-
SReal getPotentialEnergy(const MechanicalParams* mparams, const DataVecCoord& )const override
161+
SReal getPotentialEnergy(const sofa::core::MechanicalParams* mparams, const DataVecCoord& )const override
164162
{
165163
SOFA_UNUSED(mparams);
166164
msg_error()<<"getPotentialEnergy not yet implemented";
167165
return 0_sreal;
168166
}
169167

170168
using sofa::core::behavior::ForceField<DataTypes>::addKToMatrix;
171-
void addKToMatrix(const MechanicalParams* mparams,
172-
const MultiMatrixAccessor* matrix) override;
169+
void addKToMatrix(const sofa::core::MechanicalParams* mparams,
170+
const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
173171

174-
void computeStiffness(int beam, BeamLocalMatrices& beamLocalMatrices);
175-
void computeMass(int beam, BeamLocalMatrices& beamMatrices);
172+
void computeStiffness(const sofa::Index beamID, BeamLocalMatrices& beamLocalMatrices);
173+
void computeMass(const sofa::Index beamID, BeamLocalMatrices& beamMatrices);
176174

177175
Data<bool> d_computeMass; ///< if false, only compute the stiff elastic model
178176
Real m_defaultMassDensity;
@@ -183,16 +181,16 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>
183181
protected :
184182
SingleLink<AdaptiveBeamForceFieldAndMass<DataTypes>, BInterpolation, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_interpolation;
185183

186-
void applyMassLarge( VecDeriv& df, int bIndex, Index nd0Id, Index nd1Id, SReal factor);
187-
void applyStiffnessLarge( VecDeriv& df, const VecDeriv& dx, int beam, Index nd0Id, Index nd1Id, SReal factor );
184+
void applyMassLarge( VecDeriv& df, const sofa::Index beamID, const sofa::Index nd0Id, const sofa::Index nd1Id, const SReal factor);
185+
void applyStiffnessLarge( VecDeriv& df, const VecDeriv& dx, const sofa::Index beamID, const sofa::Index nd0Id, const sofa::Index nd1Id, const SReal factor );
188186
void computeGravityVector();
189187

190188
private:
191189
type::vector<BeamLocalMatrices> m_localBeamMatrices;
192190
Vec6 m_gravity;
193191

194-
void drawElement(const VisualParams* vparams, int beam,
195-
Transform &global_H0_local, Transform &global_H1_local) ;
192+
void drawElement(const sofa::core::visual::VisualParams* vparams, const sofa::Index beamID,
193+
const Transform &global_H0_local, const Transform &global_H1_local) ;
196194
};
197195

198196
/// Instantiate the templates so that they are not instiated in each translation unit (see )

0 commit comments

Comments
 (0)