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

[SofaMiscForceField] Fix MeshMatrixMass duplicate Data parameters #2192

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -64,13 +64,13 @@ using namespace sofa::gpu::cuda;
template<>
void MeshMatrixMass<CudaVec3fTypes, float>::copyVertexMass()
{
helper::vector<MassType>& vertexInf = *(d_vertexMassInfo.beginEdit());
helper::vector<MassType>& vertexInf = *(d_vertexMass.beginEdit());
data.vMass.resize(m_topology->getNbPoints());

for (int i=0; i<this->m_topology->getNbPoints(); ++i)
data.vMass[i] = (float) vertexInf[i];

d_vertexMassInfo.endEdit();
d_vertexMass.endEdit();
}

template<>
Expand Down Expand Up @@ -113,13 +113,13 @@ void MeshMatrixMass<CudaVec3fTypes, float>::accFromF(const core::MechanicalParam
template<>
void MeshMatrixMass<CudaVec2fTypes, float>::copyVertexMass()
{
helper::vector<MassType>& vertexInf = *(d_vertexMassInfo.beginEdit());
helper::vector<MassType>& vertexInf = *(d_vertexMass.beginEdit());
data.vMass.resize(m_topology->getNbPoints());

for (int i=0; i<this->m_topology->getNbPoints(); ++i)
data.vMass[i] = (float) vertexInf[i];

d_vertexMassInfo.endEdit();
d_vertexMass.endEdit();
}

template<>
Expand Down Expand Up @@ -162,13 +162,13 @@ void MeshMatrixMass<CudaVec2fTypes, float>::accFromF(const core::MechanicalParam
template<>
void MeshMatrixMass<CudaVec1fTypes, float>::copyVertexMass()
{
helper::vector<MassType>& vertexInf = *(d_vertexMassInfo.beginEdit());
helper::vector<MassType>& vertexInf = *(d_vertexMass.beginEdit());
data.vMass.resize(m_topology->getNbPoints());

for (int i=0; i<this->m_topology->getNbPoints(); ++i)
data.vMass[i] = (float) vertexInf[i];

d_vertexMassInfo.endEdit();
d_vertexMass.endEdit();
}

template<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MeshMatrixMass_test : public Sofa_test<>
void check(MassType expectedTotalMass, const VecMass& expectedMass)
{
// Check that the mass vector has the right size.
ASSERT_EQ(mstate->x.getValue().size(), mass->d_vertexMassInfo.getValue().size());
ASSERT_EQ(mstate->x.getValue().size(), mass->d_vertexMass.getValue().size());
// Safety check...
ASSERT_EQ(mstate->x.getValue().size(), expectedMass.size());

Expand All @@ -120,7 +120,7 @@ class MeshMatrixMass_test : public Sofa_test<>

// Check the mass at each index.
for (size_t i = 0 ; i < mstate->x.getValue().size() ; i++)
EXPECT_FLOAT_EQ(expectedMass[i], mass->d_vertexMassInfo.getValue()[i]);
EXPECT_FLOAT_EQ(expectedMass[i], mass->d_vertexMass.getValue()[i]);
}

void runTest(VecCoord positions, BaseObject::SPtr topologyContainer, BaseObject::SPtr geometryAlgorithms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ using namespace sofa::defaulttype;
template <>
Vector6 MeshMatrixMass<Vec3Types, double>::getMomentum ( const core::MechanicalParams*, const DataVecCoord& vx, const DataVecDeriv& vv ) const
{
const MassVector &vertexMass= d_vertexMassInfo.getValue();
const MassVector &edgeMass= d_edgeMassInfo.getValue();
const MassVector &vertexMass= d_vertexMass.getValue();
const MassVector &edgeMass= d_edgeMass.getValue();

helper::ReadAccessor< DataVecCoord > x = vx;
helper::ReadAccessor< DataVecDeriv > v = vv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ class MeshMatrixMass : public core::behavior::Mass<DataTypes>

/// @name Data of mass information
/// @{
/// Mass stored on vertices
Data< sofa::helper::vector< Real > > d_vertexMass;
/// Mass density of the object
Data< sofa::helper::vector< Real > > d_massDensity;
/// Total mass of the object
Expand All @@ -96,12 +94,9 @@ class MeshMatrixMass : public core::behavior::Mass<DataTypes>


/// Values of the particles masses stored on vertices
topology::PointData<helper::vector<MassType> > d_vertexMassInfo;
topology::PointData<helper::vector<MassType> > d_vertexMass;
/// Values of the particles masses stored on edges
topology::EdgeData<helper::vector<MassType> > d_edgeMassInfo;

/// to display the center of gravity of the system
Data< sofa::helper::vector< Real > > d_edgeMass;
topology::EdgeData<helper::vector<MassType> > d_edgeMass;

/// if true, the mass of every element is computed based on the rest position rather than the position
Data< bool > d_computeMassOnRest;
Expand Down Expand Up @@ -162,7 +157,7 @@ class MeshMatrixMass : public core::behavior::Mass<DataTypes>
}

int getMassCount() {
return d_vertexMassInfo.getValue().size();
return d_vertexMass.getValue().size();
}

/// Print key mass informations (totalMass, vertexMass and massDensity)
Expand Down
Loading