Skip to content

Commit 558d955

Browse files
authored
Merge branch 'master' into consolemessagehandler
2 parents b1957f9 + f3642d9 commit 558d955

31 files changed

Lines changed: 402 additions & 159 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ For newcomers in the community, we regularly identify issues easy to tackle and
7373

7474
### Rules
7575

76+
- While **artificial intelligence** tools may assist in drafting code contributions, such contributions must address a real issue encountered by a human developer or a feature needed by end users for their specific use case. The contributor must actively participate in the development process from start to finish, ensuring no contribution is fully automated.
7677
- Description must explain the **issue solved** or the **feature added**, and this must be reported in the **[CHANGELOG.md](https://github.com/sofa-framework/sofa/blob/master/CHANGELOG.md)** file.
7778
- Code must follow **[our guidelines](https://github.com/sofa-framework/sofa/blob/master/GUIDELINES.md)**.
7879
- Commit must build **successfully** on Jenkins for all steps (compilation + tests + examples).
@@ -159,4 +160,4 @@ By making a contribution to this project, I certify that:
159160

160161
# Annual development cycle
161162

162-
<center><figure><img src="https://www.sofa-framework.org/wp-content/uploads/2023/04/SOFA-contribution-process.png" alt="Annual dev cycle" style="width:75%"><figcaption align = "center"><b>A year of development within the SOFA community: dev meeting and events</b></figcaption></figure></center>
163+
<center><figure><img src="https://www.sofa-framework.org/wp-content/uploads/2023/04/SOFA-contribution-process.png" alt="Annual dev cycle" style="width:75%"><figcaption align = "center"><b>A year of development within the SOFA community: dev meeting and events</b></figcaption></figure></center>

Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,10 @@ void FreeMotionAnimationLoop::init()
132132
}
133133
}
134134

135-
auto* taskScheduler = sofa::simulation::MainTaskSchedulerFactory::createInRegistry();
136-
assert(taskScheduler != nullptr);
135+
137136
if (d_parallelCollisionDetectionAndFreeMotion.getValue() || d_parallelODESolving.getValue())
138137
{
139-
if (taskScheduler->getThreadCount() < 1)
140-
{
141-
taskScheduler->init(0);
142-
msg_info() << "Task scheduler initialized on " << taskScheduler->getThreadCount() << " threads";
143-
}
144-
else
145-
{
146-
msg_info() << "Task scheduler already initialized on " << taskScheduler->getThreadCount() << " threads";
147-
}
138+
initTaskScheduler();
148139
}
149140

150141
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
@@ -348,9 +339,6 @@ void FreeMotionAnimationLoop::computeFreeMotionAndCollisionDetection(const sofa:
348339
{
349340
SCOPED_TIMER("FreeMotion+CollisionDetection");
350341

351-
auto* taskScheduler = sofa::simulation::MainTaskSchedulerFactory::createInRegistry();
352-
assert(taskScheduler != nullptr);
353-
354342
preCollisionComputation(params);
355343

356344
{
@@ -368,7 +356,7 @@ void FreeMotionAnimationLoop::computeFreeMotionAndCollisionDetection(const sofa:
368356
}
369357

370358
sofa::simulation::CpuTask::Status freeMotionTaskStatus;
371-
taskScheduler->addTask(freeMotionTaskStatus, [&]() { computeFreeMotion(params, cparams, dt, pos, freePos, freeVel, mop); });
359+
m_taskScheduler->addTask(freeMotionTaskStatus, [&]() { computeFreeMotion(params, cparams, dt, pos, freePos, freeVel, mop); });
372360

373361
{
374362
SCOPED_TIMER("CollisionDetection");
@@ -379,7 +367,7 @@ void FreeMotionAnimationLoop::computeFreeMotionAndCollisionDetection(const sofa:
379367

380368
{
381369
SCOPED_TIMER("WaitFreeMotion");
382-
taskScheduler->workUntilDone(&freeMotionTaskStatus);
370+
m_taskScheduler->workUntilDone(&freeMotionTaskStatus);
383371
}
384372

385373
{

Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <sofa/simulation/CollisionAnimationLoop.h>
2626
#include <sofa/core/MultiVecId.h>
27+
#include <sofa/simulation/task/TaskSchedulerUser.h>
2728

2829
namespace sofa::core::behavior
2930
{
@@ -33,7 +34,8 @@ namespace sofa::core::behavior
3334
namespace sofa::component::animationloop
3435
{
3536

36-
class SOFA_COMPONENT_ANIMATIONLOOP_API FreeMotionAnimationLoop : public sofa::simulation::CollisionAnimationLoop
37+
class SOFA_COMPONENT_ANIMATIONLOOP_API FreeMotionAnimationLoop : public sofa::simulation::CollisionAnimationLoop,
38+
public sofa::simulation::TaskSchedulerUser
3739
{
3840
public:
3941
SOFA_CLASS(FreeMotionAnimationLoop, sofa::simulation::CollisionAnimationLoop);

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class StopperLagrangianConstraint : public core::behavior::LagrangianConstraint<
109109

110110

111111
public:
112-
void init() override;
113112
void buildConstraintMatrix(const core::ConstraintParams* cParams, DataMatrixDeriv &c_d, unsigned int &cIndex, const DataVecCoord &x) override;
114113
void getConstraintViolation(const core::ConstraintParams* cParams, linearalgebra::BaseVector *resV, const DataVecCoord &x, const DataVecDeriv &v) override;
115114

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/StopperLagrangianConstraint.inl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ StopperLagrangianConstraint<DataTypes>::StopperLagrangianConstraint(MechanicalSt
3737
{
3838
}
3939

40-
template<class DataTypes>
41-
void StopperLagrangianConstraint<DataTypes>::init()
42-
{
43-
this->mstate = dynamic_cast<MechanicalState*>(this->getContext()->getMechanicalState());
44-
45-
helper::WriteAccessor<Data<VecCoord> > xData = *this->mstate->write(core::vec_id::write_access::position);
46-
VecCoord& x = xData.wref();
47-
if (x[d_index.getValue()].x() < d_min.getValue())
48-
x[d_index.getValue()].x() = (Real) d_min.getValue();
49-
if (x[d_index.getValue()].x() > d_max.getValue())
50-
x[d_index.getValue()].x() = (Real) d_max.getValue();
51-
}
52-
5340
template<class DataTypes>
5441
void StopperLagrangianConstraint<DataTypes>::buildConstraintMatrix(const core::ConstraintParams* /*cParams*/, DataMatrixDeriv &c_d, unsigned int &cIndex, const DataVecCoord &/*x*/)
5542
{

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void BuiltConstraintSolver::init()
4242
Inherit1::init();
4343
if(d_multithreading.getValue())
4444
{
45-
simulation::MainTaskSchedulerFactory::createInRegistry()->init();
45+
initTaskScheduler();
4646
}
4747
}
4848

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma once
2323

2424
#include <sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h>
25+
#include <sofa/simulation/task/TaskSchedulerUser.h>
2526

2627
namespace sofa::component::constraint::lagrangian::solver
2728
{
@@ -32,7 +33,8 @@ namespace sofa::component::constraint::lagrangian::solver
3233
* This component is purely virtual because doSolve is not defined and needs to be defined in the
3334
* inherited class
3435
*/
35-
class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API BuiltConstraintSolver : public GenericConstraintSolver
36+
class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API BuiltConstraintSolver : public GenericConstraintSolver,
37+
public sofa::simulation::TaskSchedulerUser
3638
{
3739

3840
public:

Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <sofa/simulation/MechanicalVisitor.h>
2626
#include <sofa/simulation/MechanicalOperations.h>
2727
#include <sofa/simulation/VectorOperations.h>
28+
#include <sofa/simulation/task/TaskSchedulerUser.h>
2829
#include <sofa/core/behavior/LinearSolver.h>
2930
#include <sofa/component/linearsolver/iterative/GraphScatteredTypes.h>
3031
#include <sofa/linearalgebra/FullVector.h>
@@ -44,6 +45,7 @@
4445
#include <sofa/core/behavior/DefaultMultiMatrixAccessor.h>
4546
#endif // SOFA_CORE_ENABLE_CRSMULTIMATRIXACCESSOR
4647

48+
4749
namespace sofa::component::linearsolver
4850
{
4951

@@ -174,7 +176,8 @@ template<class Matrix, class Vector, class ThreadManager = NoThreadManager>
174176
class MatrixLinearSolver;
175177

176178
template<class Matrix, class Vector>
177-
class MatrixLinearSolver<Matrix,Vector,NoThreadManager> : public BaseMatrixLinearSolver<Matrix, Vector>
179+
class MatrixLinearSolver<Matrix,Vector,NoThreadManager> : public BaseMatrixLinearSolver<Matrix, Vector>,
180+
public simulation::TaskSchedulerUser
178181
{
179182
public:
180183
SOFA_ABSTRACT_CLASS(SOFA_TEMPLATE3(MatrixLinearSolver,Matrix,Vector,NoThreadManager), SOFA_TEMPLATE2(BaseMatrixLinearSolver,Matrix,Vector));

Sofa/Component/LinearSolver/Iterative/src/sofa/component/linearsolver/iterative/MatrixLinearSolver.inl

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,7 @@ MatrixLinearSolver<Matrix,Vector>::MatrixLinearSolver()
6262
SOFA_UNUSED(tracker);
6363
if (d_parallelInverseProduct.getValue())
6464
{
65-
simulation::TaskScheduler* taskScheduler = simulation::MainTaskSchedulerFactory::createInRegistry();
66-
assert(taskScheduler);
67-
68-
if (taskScheduler->getThreadCount() < 1)
69-
{
70-
taskScheduler->init(0);
71-
msg_info() << "Task scheduler initialized on " << taskScheduler->getThreadCount() << " threads";
72-
}
73-
else
74-
{
75-
msg_info() << "Task scheduler already initialized on " << taskScheduler->getThreadCount() << " threads";
76-
}
65+
initTaskScheduler();
7766
}
7867
return this->d_componentState.getValue();
7968
},

Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ void MeshTopology::init()
518518

519519
const auto hexahedra = sofa::helper::getReadAccessor(d_seqHexahedra);
520520
const auto tetrahedra = sofa::helper::getReadAccessor(d_seqTetrahedra);
521+
const auto prisms = sofa::helper::getReadAccessor(d_seqPrisms);
522+
const auto pyramids = sofa::helper::getReadAccessor(d_seqPyramids);
521523
const auto quads = sofa::helper::getReadAccessor(d_seqQuads);
522524
const auto triangles = sofa::helper::getReadAccessor(d_seqTriangles);
523525
const auto edges = sofa::helper::getReadAccessor(d_seqEdges);
@@ -527,6 +529,10 @@ void MeshTopology::init()
527529
m_upperElementType = geometry::ElementType::HEXAHEDRON;
528530
else if (!tetrahedra.empty())
529531
m_upperElementType = sofa::geometry::ElementType::TETRAHEDRON;
532+
else if (!prisms.empty())
533+
m_upperElementType = sofa::geometry::ElementType::PRISM;
534+
else if (!pyramids.empty())
535+
m_upperElementType = sofa::geometry::ElementType::PYRAMID;
530536
else if (!quads.empty())
531537
m_upperElementType = sofa::geometry::ElementType::QUAD;
532538
else if (!triangles.empty())
@@ -545,28 +551,13 @@ void MeshTopology::init()
545551
// compute the number of points, if the topology is charged from the scene or if it was loaded from a MeshLoader without any points data.
546552
if (nbPoints==0)
547553
{
548-
unsigned int n = 0;
549-
const auto countPoints = [&n](const auto& seqElements)
550-
{
551-
for (const auto& element : seqElements)
552-
{
553-
for (const auto pointId : element)
554-
{
555-
if (n <= pointId)
556-
{
557-
n = 1 + pointId;
558-
}
559-
}
560-
}
561-
};
562-
563-
countPoints(edges);
564-
countPoints(triangles);
565-
countPoints(quads);
566-
countPoints(tetrahedra);
567-
countPoints(hexahedra);
568-
569-
nbPoints = n;
554+
nbPoints = std::max(nbPoints, countPoints(edges));
555+
nbPoints = std::max(nbPoints, countPoints(triangles));
556+
nbPoints = std::max(nbPoints, countPoints(quads));
557+
nbPoints = std::max(nbPoints, countPoints(tetrahedra));
558+
nbPoints = std::max(nbPoints, countPoints(hexahedra));
559+
nbPoints = std::max(nbPoints, countPoints(prisms));
560+
nbPoints = std::max(nbPoints, countPoints(pyramids));
570561
}
571562

572563

@@ -694,55 +685,58 @@ void MeshTopology::addPoint(SReal px, SReal py, SReal pz)
694685

695686
void MeshTopology::addEdge( Index a, Index b )
696687
{
697-
d_seqEdges.beginEdit()->push_back(Edge(a, b));
698-
d_seqEdges.endEdit();
699-
if (a >= nbPoints) nbPoints = a+1;
700-
if (b >= nbPoints) nbPoints = b+1;
688+
const Edge addedElement { a, b };
689+
auto seqElements = helper::getWriteOnlyAccessor(d_seqEdges);
690+
seqElements.push_back(addedElement);
691+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
701692
}
702693

703694
void MeshTopology::addTriangle( Index a, Index b, Index c )
704695
{
705-
d_seqTriangles.beginEdit()->push_back(Triangle(a, b, c) );
706-
d_seqTriangles.endEdit();
707-
if (a >= nbPoints) nbPoints = a+1;
708-
if (b >= nbPoints) nbPoints = b+1;
709-
if (c >= nbPoints) nbPoints = c+1;
696+
const Triangle addedElement { a, b, c };
697+
auto seqElements = helper::getWriteOnlyAccessor(d_seqTriangles);
698+
seqElements.push_back(addedElement);
699+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
710700
}
711701

712702
void MeshTopology::addQuad(Index a, Index b, Index c, Index d)
713703
{
714-
d_seqQuads.beginEdit()->push_back(Quad(a, b, c, d));
715-
d_seqQuads.endEdit();
716-
if (a >= nbPoints) nbPoints = a+1;
717-
if (b >= nbPoints) nbPoints = b+1;
718-
if (c >= nbPoints) nbPoints = c+1;
719-
if (d >= nbPoints) nbPoints = d+1;
704+
const Quad addedElement { a, b, c, d };
705+
auto seqElements = helper::getWriteOnlyAccessor(d_seqQuads);
706+
seqElements.push_back(addedElement);
707+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
720708
}
721709

722710
void MeshTopology::addTetra( Index a, Index b, Index c, Index d )
723711
{
724-
d_seqTetrahedra.beginEdit()->push_back(Tetra(a, b, c, d) );
725-
d_seqTetrahedra.endEdit();
726-
if (a >= nbPoints) nbPoints = a+1;
727-
if (b >= nbPoints) nbPoints = b+1;
728-
if (c >= nbPoints) nbPoints = c+1;
729-
if (d >= nbPoints) nbPoints = d+1;
712+
const Tetrahedron addedElement { a, b, c, d };
713+
auto seqElements = helper::getWriteOnlyAccessor(d_seqTetrahedra);
714+
seqElements.push_back(addedElement);
715+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
730716
}
731717

732718
void MeshTopology::addHexa(Index p1, Index p2, Index p3, Index p4, Index p5, Index p6, Index p7, Index p8)
733719
{
720+
const Hexahedron addedElement { p1, p2, p3, p4, p5, p6, p7, p8 };
721+
auto seqElements = helper::getWriteOnlyAccessor(d_seqHexahedra);
722+
seqElements.push_back(addedElement);
723+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
724+
}
734725

735-
d_seqHexahedra.beginEdit()->push_back(Hexa(p1, p2, p3, p4, p5, p6, p7, p8));
726+
void MeshTopology::addPrism(Index a, Index b, Index c, Index d, Index e, Index f)
727+
{
728+
const Prism addedElement { a, b, c, d, e, f };
729+
auto seqElements = helper::getWriteOnlyAccessor(d_seqPrisms);
730+
seqElements.push_back(addedElement);
731+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
732+
}
736733

737-
d_seqHexahedra.endEdit();
738-
if (p1 >= nbPoints) nbPoints = p1+1;
739-
if (p2 >= nbPoints) nbPoints = p2+1;
740-
if (p3 >= nbPoints) nbPoints = p3+1;
741-
if (p4 >= nbPoints) nbPoints = p4+1;
742-
if (p5 >= nbPoints) nbPoints = p5+1;
743-
if (p6 >= nbPoints) nbPoints = p6+1;
744-
if (p7 >= nbPoints) nbPoints = p7+1;
745-
if (p8 >= nbPoints) nbPoints = p8+1;
734+
void MeshTopology::addPyramid(Index a, Index b, Index c, Index d, Index e)
735+
{
736+
const Pyramid addedElement { a, b, c, d, e };
737+
auto seqElements = helper::getWriteOnlyAccessor(d_seqPyramids);
738+
seqElements.push_back(addedElement);
739+
nbPoints = std::max(nbPoints, countPoints(std::array{addedElement}));
746740
}
747741

748742
void MeshTopology::addUV(SReal u, SReal v)

0 commit comments

Comments
 (0)