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 @@ -19,7 +19,6 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once
#include <sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.h>

#include <sofa/core/visual/VisualParams.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ int CCDTightInclusionIntersection::computeIntersection(Line& e1, Line& e2, Outpu
SReal outputTolerance = 0.0;


const auto result = ticcd::edgeEdgeCCD(
// the returned boolean is not tested here: computeIntersection is only called on pairs for which
// testIntersection already reported a collision. The call is kept for its outputs: toi and outputTolerance.
[[maybe_unused]] const auto result = ticcd::edgeEdgeCCD(
Line1ABegin, Line2ABegin, Line1BBegin, Line2BBegin,
Line1AEnd, Line2AEnd, Line1BEnd, Line2BEnd,
err,maxSeparation, toi,d_tolerance.getValue(), tmax, d_maxIterations.getValue(), outputTolerance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ void TriangleOctreeCollisionModel::computeBoundingTree(int maxDepth)
}
}

void TriangleOctreeCollisionModel::computeContinuousBoundingTree(SReal/* dt*/, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth)
void TriangleOctreeCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth)
{
SOFA_UNUSED(dt);
SOFA_UNUSED(continuousIntersectionFlag);

computeBoundingTree(maxDepth);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void BuiltConstraintSolver::addRegularization(linearalgebra::BaseMatrix& W, cons
//Now for all vector of the null space basis, we look at the indices where the coefficient
//is greater than 1% of the norm of the vector, this is the constraints that
//belong to the null space and thus have other one that are antagonists
for(int i=nullSpaceBegin; (i != -1) && (i<problemSize); ++i)
for(int i=nullSpaceBegin; (i != -1) && (i < static_cast<int>(problemSize)); ++i)
{
for(size_t j=0; j<problemSize; j++)
nullSpaceIndicator[j] = nullSpaceIndicator[j] || fabs(svd.matrixV().col(i)(j)) > d_svdSingularVectorNullSpaceCriteriaFactor.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ImprovedJacobiConstraintSolver::ImprovedJacobiConstraintSolver()

void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal timeout)
{
SOFA_UNUSED(timeout);

SCOPED_TIMER_VARNAME(gaussSeidelTimer, "ImprovedJacobiConstraintSolver");


Expand All @@ -63,7 +65,7 @@ void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem

std::copy_n(dfree, dimension, d);

for(unsigned i=0; i< dimension; ++i)
for(int i=0; i< dimension; ++i)
{
force[i] = 0;
}
Expand Down Expand Up @@ -128,7 +130,7 @@ void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem

for(unsigned l=j; l<j+nb; ++l )
{
for(unsigned k=0; k<dimension; ++k)
for(int k=0; k<dimension; ++k)
{
d[l] += w[l][k] * deltaF[k];
}
Expand All @@ -153,7 +155,7 @@ void ImprovedJacobiConstraintSolver::doSolve(GenericConstraintProblem * problem
SReal cstError = 0.0;
for(unsigned l=j; l<j+nb; ++l )
{
for(unsigned k=0; k<dimension; ++k)
for(int k=0; k<dimension; ++k)
{
cstError += pow(w[l][k] * deltaF[k],2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace sofa::component::constraint::lagrangian::solver

void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal timeout)
{
SOFA_UNUSED(timeout);

SCOPED_TIMER_VARNAME(unbuiltGaussSeidelTimer, "NonsmoothNonlinearConjugateGradient");

const int dimension = problem->getDimension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ PreconditionedConjugateResidual::PreconditionedConjugateResidual()

void PreconditionedConjugateResidual::doSolve(GenericConstraintProblem * problem , SReal timeout)
{
SOFA_UNUSED(timeout);

SCOPED_TIMER_VARNAME(gaussSeidelTimer, "PreconditionedConjugateResidual");

if (!problem)
Expand Down Expand Up @@ -73,18 +75,18 @@ void PreconditionedConjugateResidual::doSolve(GenericConstraintProblem * problem
// ===== BEGIN Initialization =====
// Initialize the state (matrices/vectors) and apply the Jacobi preconditioner on left and right to keep symmetry
// This implies that the solution will be P^{-1}*x and thus should be corrected after solving.
for(unsigned j=0; j< dimension; ++j)
for(int j=0; j< dimension; ++j)
{
const SReal invWjj = 1.0/sqrt(W[j][j]);
for(unsigned k=0; k< dimension; ++k)
for(int k=0; k< dimension; ++k)
{
const SReal invWkk = 1.0/sqrt(W[k][k]);

MW[j][k] = W[j][k] * invWjj * invWkk;
}
}

for(unsigned j=0; j< dimension; ++j)
for(int j=0; j< dimension; ++j)
{
const SReal invWjj = 1.0/sqrt(W[j][j]);
r[j] = -dfree[j] * invWjj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ bool BoxROI<DataTypes>::isPointInAlignedBox(const typename DataTypes::CPos& p, c
{
static_assert(std::is_same_v<typename DataTypes::CPos::size_type, typename type::Vec6::size_type>);

for (typename type::Vec6::size_type i = 0; i < DataTypes::spatial_dimensions; ++i)
/// An axis-aligned box is stored as a Vec6 gathering the min corner (indices [0,2]) and the max
/// corner (indices [3,5]): it cannot describe more than 3 dimensions. Higher dimensions of the
/// tested point are therefore ignored.
static constexpr typename type::Vec6::size_type nbTestedDimensions =
DataTypes::spatial_dimensions < 3 ? DataTypes::spatial_dimensions : 3;

for (typename type::Vec6::size_type i = 0; i < nbTestedDimensions; ++i)
{
if (p[i] < box[i] || p[i] > box[i + 3])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void MeshSampler<DataTypes>::farthestPointSampling(VD& distances,VI& voronoi,con

while(ind.size()<nbc)
{
Real dmax=0; ID imax;
Real dmax=0; ID imax=0;
for (unsigned int i=0; i<distances.size(); i++) if(distances[i]>dmax) {dmax=distances[i]; imax=(ID)i;}
if(dmax==0) break;
else ind.push_back(imax);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ bool XMLVTKReader::loadUnstructuredGrid(tinyxml2::XMLHandle datasetFormatHandle)

BaseVTKReader::BaseVTKDataIO* XMLVTKReader::parsePolysIndices(tinyxml2::XMLElement* element, BaseVTKReader::VTKDataIO<int>* vtkIO_elemtypes, BaseVTKDataIO* offsetElement)
{
SOFA_UNUSED(offsetElement);

const char* typeStrTemp;
typeStrTemp = element->Attribute("type");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <sofa/component/io/mesh/STLExporter.h>

#include <cstring>
#include <fstream>

#include <sofa/core/ObjectFactory.h>
Expand Down Expand Up @@ -260,7 +261,8 @@ bool STLExporter::writeSTLBinary(bool autonumbering)
{
buffer[i]='\0';
}
strncpy(buffer, "Exported from Sofa", 18);
// the 80-byte header is not required to be null-terminated: copy the text without its trailing nul
std::memcpy(buffer, "Exported from Sofa", 18);

/* Number of d_facets */
const unsigned int nbt = vecTri.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ SkinningMapping<TIn, TOut>::SkinningMapping ()
, d_initPos (initData (&d_initPos, "initPos", "initial child coordinates in the world reference frame." ) )
, d_nbRef (initData (&d_nbRef, "nbRef", "Number of primitives influencing each point." ) )
, d_index (initData (&d_index, "indices", "parent indices for each child." ) )
, d_computeWeightsFromPosition (initData (&d_computeWeightsFromPosition, false, "computeWeightsFromPosition", "By default, the weights are computed w.r.t the rest positions of the input model. Set to true to compute them from the position instead." ) )
, d_weight (initData (&d_weight, "weight", "influence weights of the Dofs." ) )
, d_showFromIndex (initData (&d_showFromIndex, ( unsigned int ) 0, "showFromIndex", "Displayed From Index." ) )
, d_computeWeightsFromPosition (initData (&d_computeWeightsFromPosition, false, "computeWeightsFromPosition", "By default, the weights are computed w.r.t the rest positions of the input model. Set to true to compute them from the position instead." ) )
, d_showWeights (initData (&d_showWeights, false, "showWeights", "Show influence." ) )
{
type::vector<unsigned int> defaultNbRef;
Expand Down
3 changes: 2 additions & 1 deletion Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ void FEMMass<TDataTypes, TElementType>::buildMassMatrix(
const auto columnId = m_globalMassMatrix.colsIndex[xj];
const auto& value = m_globalMassMatrix.colsValue[xj];

for (typename GlobalMassMatrixType::Index d = 0; d < spatial_dimensions; ++d)
const auto nbDoFs = static_cast<typename GlobalMassMatrixType::Index>(spatial_dimensions);
for (typename GlobalMassMatrixType::Index d = 0; d < nbDoFs; ++d)
{
matrices->add(rowId * spatial_dimensions + d, columnId * spatial_dimensions + d, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class NodalMassDensity : public sofa::core::BaseNodalProperty<Scalar>
template<class T>
static bool canCreate(T* obj, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg)
{
SOFA_UNUSED(obj);

if (const auto* state = context->getMechanicalState())
{
static const auto scalarType = defaulttype::DataTypeInfo<Scalar>::name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ void BaseElementLinearFEMForceField<DataTypes, ElementType>::precomputeElementSt
if (!this->mstate)
return;

const auto youngModulusAccessor = sofa::helper::ReadAccessor(this->d_youngModulus);
const auto poissonRatioAccessor = sofa::helper::ReadAccessor(this->d_poissonRatio);
// accessors are only there to make sure both Data are up-to-date before they are read
// concurrently through getYoungModulusInElement/getPoissonRatioInElement
[[maybe_unused]] const auto youngModulusAccessor = sofa::helper::ReadAccessor(this->d_youngModulus);
[[maybe_unused]] const auto poissonRatioAccessor = sofa::helper::ReadAccessor(this->d_poissonRatio);

auto restPositionAccessor = this->mstate->readRestPositions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void CorotationalFEMForceField<DataTypes, ElementType>::init()

if (!this->isComponentStateInvalid())
{
const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
// makes sure the element sequence is available in the topology container
[[maybe_unused]] const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
}

if (!this->isComponentStateInvalid())
Expand All @@ -74,6 +75,10 @@ void CorotationalFEMForceField<DataTypes, ElementType>::beforeElementForce(
const sofa::core::MechanicalParams* mparams, sofa::type::vector<ElementGradient>& f,
const sofa::VecCoord_t<DataTypes>& x)
{
SOFA_UNUSED(mparams);
SOFA_UNUSED(f);
SOFA_UNUSED(x);

const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
m_rotations.resize(elements.size(), RotationMatrix::Identity());
}
Expand All @@ -83,6 +88,8 @@ void CorotationalFEMForceField<DataTypes, ElementType>::computeElementsForces(
const sofa::simulation::Range<std::size_t>& range, const sofa::core::MechanicalParams* mparams,
sofa::type::vector<ElementGradient>& elementForces, const sofa::VecCoord_t<DataTypes>& nodePositions)
{
SOFA_UNUSED(mparams);

static constexpr auto DIM = trait::spatial_dimensions;
const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
auto restPositionAccessor = this->mstate->readRestPositions();
Expand Down Expand Up @@ -134,6 +141,8 @@ void CorotationalFEMForceField<DataTypes, ElementType>::computeElementsForcesDer
sofa::type::vector<ElementGradient>& elementForcesDeriv,
const sofa::VecDeriv_t<DataTypes>& nodeDx)
{
SOFA_UNUSED(mparams);

const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness);

Expand Down Expand Up @@ -206,6 +215,8 @@ SReal CorotationalFEMForceField<DataTypes, ElementType>::getPotentialEnergy(
const sofa::core::MechanicalParams*,
const sofa::DataVecCoord_t<DataTypes>& x) const
{
SOFA_UNUSED(x);

return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ class FEMForceField :

virtual void beforeElementForce(const sofa::core::MechanicalParams* mparams,
sofa::type::vector<ElementGradient>& f,
const sofa::VecCoord_t<DataTypes>& x) {}
const sofa::VecCoord_t<DataTypes>& x)
{
SOFA_UNUSED(mparams);
SOFA_UNUSED(f);
SOFA_UNUSED(x);
}

virtual void computeElementsForces(
const sofa::simulation::Range<std::size_t>& range,
Expand All @@ -106,7 +111,10 @@ class FEMForceField :
sofa::type::vector<ElementGradient>& df,
const sofa::VecDeriv_t<DataTypes>& dx);

virtual void beforeElementForceDeriv(const sofa::core::MechanicalParams* mparams) {}
virtual void beforeElementForceDeriv(const sofa::core::MechanicalParams* mparams)
{
SOFA_UNUSED(mparams);
}

virtual void computeElementsForcesDeriv(
const sofa::simulation::Range<std::size_t>& range,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void LinearSmallStrainFEMForceField<DataTypes, ElementType>::computeElementsForc
sofa::type::vector<ElementGradient>& elementForces,
const sofa::VecCoord_t<DataTypes>& nodePositions)
{
SOFA_UNUSED(mparams);

const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
auto restPositionAccessor = this->mstate->readRestPositions();
auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness);
Expand Down Expand Up @@ -78,6 +80,8 @@ void LinearSmallStrainFEMForceField<DataTypes, ElementType>::computeElementsForc
sofa::type::vector<ElementGradient>& elementForcesDeriv,
const sofa::VecDeriv_t<DataTypes>& nodeDx)
{
SOFA_UNUSED(mparams);

const auto& elements = trait::FiniteElement::getElementSequence(*this->l_topology);
auto elementStiffness = sofa::helper::getReadAccessor(this->d_elementStiffness);

Expand Down Expand Up @@ -145,6 +149,8 @@ SReal LinearSmallStrainFEMForceField<DataTypes, ElementType>::getPotentialEnergy
const sofa::core::MechanicalParams*,
const sofa::DataVecCoord_t<DataTypes>& x) const
{
SOFA_UNUSED(x);

return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,23 +1339,23 @@ void TetrahedronFEMForceField<DataTypes>::init()
if (!((i%nx)&1))
{
// swap all points on the X edges
for (const auto [v0, v1] : sofa::geometry::Hexahedron::xEdges)
for (const auto& [v0, v1] : sofa::geometry::Hexahedron::xEdges)
{
std::swap(c[v0], c[v1]);
}
}
if (((i/nx)%ny)&1)
{
// swap all points on the Y edges
for (const auto [v0, v1] : sofa::geometry::Hexahedron::yEdges)
for (const auto& [v0, v1] : sofa::geometry::Hexahedron::yEdges)
{
std::swap(c[v0], c[v1]);
}
}
if ((i/(nx*ny))&1)
{
// swap all points on the Z edges
for (const auto [v0, v1] : sofa::geometry::Hexahedron::zEdges)
for (const auto& [v0, v1] : sofa::geometry::Hexahedron::zEdges)
{
std::swap(c[v0], c[v1]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct IdentityRotation
template<class RotationMatrix, class NotUsed1, class NotUsed2>
void computeRotation(RotationMatrix& rotationMatrix, const RotationMatrix& initialRotationMatrix, const NotUsed1&, const NotUsed2&)
{
SOFA_UNUSED(initialRotationMatrix);

rotationMatrix.identity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
******************************************************************************/
#pragma once

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

namespace sofa::component::solidmechanics::fem::elastic
Expand Down Expand Up @@ -65,7 +65,7 @@ struct RotationMethodsContainer

static constexpr auto NumberOfMethods = std::variant_size_v<decltype(m_rotationComputer)>;

explicit RotationMethodsContainer(sofa::core::objectmodel::BaseObject* parent)
explicit RotationMethodsContainer(sofa::core::objectmodel::BaseComponent* parent)
: d_rotationMethod(parent->initData(&d_rotationMethod, "rotationMethod", ("The method used to compute the element rotations.\n" + RotationMethodsItems::dataDescription()).c_str()))
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ class Ogden: public HyperelasticMaterial<DataTypes>
const Real alpha1 = param.parameterArray[1];
const Real k0 = param.parameterArray[2];

// trace of C^(alpha1/2)
const Real aBy2 = alpha1/static_cast<Real>(2);

// Siso = dWiso/dlambda*dlambda/dC + dWiso/dF*dF/dC
const MatrixSym S_isochoric = m_CaBy2Minus1 * m_FJ * mu1 / alpha1
-m_invC * m_FJ * mu1 / (static_cast<Real>(3)*alpha1) * m_trCaBy2;
Expand All @@ -149,7 +146,6 @@ class Ogden: public HyperelasticMaterial<DataTypes>
{
this->precomputeVariables(sinfo, param);

const MatrixSym& C = sinfo->deformationTensor;
const Real mu1 = param.parameterArray[0];
const Real alpha1 = param.parameterArray[1];
const Real k0 = param.parameterArray[2];
Expand Down
Loading
Loading