Skip to content

Commit d82852d

Browse files
alxbilgerfredroy
andauthored
[Simulation] Move MappingGraph class from Sofa.Component.LinearSystem to Sofa.Simulation.Core (#5991)
* move MappingGraph class from Sofa.Component.LinearSystem to Sofa.Simulation.Core * try to fix compilation * Fix incorrect method call in MatrixProjectionMethod --------- Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
1 parent 600bf8f commit d82852d

13 files changed

Lines changed: 81 additions & 34 deletions

File tree

Sofa/Component/LinearSystem/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ set(HEADER_FILES
1717
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/LinearSystemData.h
1818
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MappedMassMatrixObserver.h
1919
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MappedMassMatrixObserver.inl
20-
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MappingGraph.h
2120
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MatrixFreeSystem.h
2221
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MatrixLinearSystem.h
2322
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MatrixLinearSystem.inl
@@ -46,7 +45,6 @@ set(SOURCE_FILES
4645
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/ConstantSparsityPatternSystem.cpp
4746
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/ConstantSparsityProjectionMethod.cpp
4847
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MappedMassMatrixObserver.cpp
49-
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MappingGraph.cpp
5048
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MatrixLinearSystem.cpp
5149
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/MatrixProjectionMethod.cpp
5250
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/TypedMatrixLinearSystem.cpp
@@ -55,11 +53,21 @@ set(SOURCE_FILES
5553
${SOFACOMPONENTLINEARSOLVERLINEARSYSTEM_SOURCE_DIR}/visitors/DispatchFromGlobalVectorToLocalVectorVisitor.cpp
5654
)
5755

56+
set(DEPRECATED_DIR "compat/sofa/component/linearsystem")
57+
set(DEPRECATED_HEADER_FILES
58+
${DEPRECATED_DIR}/MappingGraph.h
59+
)
60+
5861
sofa_find_package(Sofa.Simulation.Core REQUIRED)
5962

6063
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
6164
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core Sofa.LinearAlgebra)
6265

66+
target_include_directories(${PROJECT_NAME} PUBLIC
67+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compat>
68+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}_compat>
69+
)
70+
6371
sofa_create_package_with_targets(
6472
PACKAGE_NAME ${PROJECT_NAME}
6573
PACKAGE_VERSION ${Sofa_VERSION}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#pragma once
23+
24+
#include <sofa/config.h>
25+
#include <sofa/simulation/MappingGraph.h>
26+
SOFA_HEADER_DEPRECATED("v26.06", "v26.12", "sofa/simulation/MappingGraph.h")
27+
28+
namespace sofa::component::linearsystem
29+
{
30+
using MappingGraph = sofa::simulation::MappingGraph;
31+
}

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixLinearSystem.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ inline sofa::type::vector<core::behavior::BaseMechanicalState*> retrieveAssociat
239239

240240
inline sofa::type::vector<core::behavior::BaseMechanicalState*> retrieveAssociatedMechanicalState(BaseMapping* component)
241241
{
242-
type::vector<BaseMechanicalState*> mstates = component->getMechFrom();
242+
type::vector<core::behavior::BaseMechanicalState*> mstates = component->getMechFrom();
243243

244244
//remove duplicates: it may happen for MultiMappings
245245
std::sort( mstates.begin(), mstates.end() );

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ class MatrixProjectionMethod : public BaseMatrixProjectionMethod<TMatrix>
6161
linearalgebra::BaseMatrix* globalMatrix) override;
6262

6363
/// Given a Mechanical State and its matrix, identifies the nodes affected by the matrix
64-
std::vector<unsigned int> identifyAffectedDoFs(BaseMechanicalState* mstate, TMatrix* crs);
64+
std::vector<unsigned int> identifyAffectedDoFs(core::behavior::BaseMechanicalState* mstate, TMatrix* crs);
6565

6666
/**
6767
* Build the jacobian matrices of mappings from a mapped state to its top most parents (in the
6868
* sense of mappings)
6969
*/
70-
MappingJacobians<TMatrix> computeJacobiansFrom(BaseMechanicalState* mstate, const core::MechanicalParams* mparams, const MappingGraph& mappingGraph, TMatrix* crs);
70+
simulation::MappingJacobians<TMatrix> computeJacobiansFrom(core::behavior::BaseMechanicalState* mstate, const core::MechanicalParams* mparams, const MappingGraph& mappingGraph, TMatrix* crs);
7171

7272
core::objectmodel::BaseContext* getSolveContext();
7373

@@ -87,7 +87,7 @@ class MatrixProjectionMethod : public BaseMatrixProjectionMethod<TMatrix>
8787
void addMappedMatrixToGlobalMatrixEigen(
8888
sofa::type::fixed_array<core::behavior::BaseMechanicalState*, 2> mstatePair,
8989
TMatrix* mappedMatrix,
90-
sofa::type::fixed_array<MappingJacobians<TMatrix>, 2> jacobians,
90+
sofa::type::fixed_array<simulation::MappingJacobians<TMatrix>, 2> jacobians,
9191
const MappingGraph& mappingGraph,
9292
linearalgebra::BaseMatrix* globalMatrix);
9393

@@ -100,7 +100,7 @@ class MatrixProjectionMethod : public BaseMatrixProjectionMethod<TMatrix>
100100

101101
Data<bool> d_areJacobiansConstant; ///< True if mapping jacobians are considered constant over time. They are computed only the first time.
102102

103-
std::optional<sofa::type::fixed_array<MappingJacobians<TMatrix>, 2>> m_mappingJacobians;
103+
std::optional<sofa::type::fixed_array<simulation::MappingJacobians<TMatrix>, 2>> m_mappingJacobians;
104104
};
105105

106106
#if !defined(SOFA_COMPONENT_LINEARSYSTEM_EIGENMATRIXMAPPING_CPP)

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MatrixProjectionMethod.inl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sofa/component/linearsystem/MatrixProjectionMethod.h>
2424
#include <sofa/component/linearsystem/BaseMatrixProjectionMethod.inl>
2525
#include <sofa/core/BaseMapping.h>
26+
#include <sofa/core/behavior/BaseMechanicalState.h>
2627
#include <sofa/core/ConstraintParams.h>
2728
#include <sofa/core/MechanicalParams.h>
2829
#include <sofa/simulation/mechanicalvisitor/MechanicalResetConstraintVisitor.h>
@@ -70,7 +71,7 @@ template <class TMatrix>
7071
void MatrixProjectionMethod<TMatrix>::addMappedMatrixToGlobalMatrixEigen(
7172
sofa::type::fixed_array<core::behavior::BaseMechanicalState*, 2> mstatePair,
7273
TMatrix* mappedMatrix,
73-
sofa::type::fixed_array<MappingJacobians<TMatrix>, 2> jacobians,
74+
sofa::type::fixed_array<simulation::MappingJacobians<TMatrix>, 2> jacobians,
7475
const MappingGraph& mappingGraph, linearalgebra::BaseMatrix* globalMatrix)
7576
{
7677
if (!mappedMatrix)
@@ -125,17 +126,17 @@ void MatrixProjectionMethod<TMatrix>::addMappedMatrixToGlobalMatrixEigen(
125126
// nb rows of J[0] = size of first mechanical state
126127
msg_error_when(sofa::Size(J[0]->rows()) != mstatePair[0]->getMatrixSize(), "MatrixMapping")
127128
<< "[J0] Incompatible matrix size [rows] " << J[0]->rows() << " " << mstatePair[0]->getMatrixSize();
128-
msg_error_when(sofa::Size(J[0]->cols()) != a->BaseMechanicalState::getMatrixSize(), "MatrixMapping")
129-
<< "[J0] Incompatible matrix size [cols] " << J[0]->cols() << " " << a->BaseMechanicalState::getMatrixSize();
129+
msg_error_when(sofa::Size(J[0]->cols()) != a->getMatrixSize(), "MatrixMapping")
130+
<< "[J0] Incompatible matrix size [cols] " << J[0]->cols() << " " << a->getMatrixSize();
130131
}
131132

132133
if (J[1])
133134
{
134135
// nb rows of J[1] = size of second mechanical state
135136
msg_error_when(sofa::Size(J[1]->rows()) != mstatePair[1]->getMatrixSize(), "MatrixMapping")
136137
<< "[J1] Incompatible matrix size [rows] " << J[1]->rows() << " " << mstatePair[1]->getMatrixSize();
137-
msg_error_when(sofa::Size(J[1]->cols()) != b->BaseMechanicalState::getMatrixSize(), "MatrixMapping")
138-
<< "[J1] Incompatible matrix size [cols] " << J[1]->cols() << " " << b->BaseMechanicalState::getMatrixSize();
138+
msg_error_when(sofa::Size(J[1]->cols()) != b->getMatrixSize(), "MatrixMapping")
139+
<< "[J1] Incompatible matrix size [cols] " << J[1]->cols() << " " << b->getMatrixSize();
139140
}
140141

141142
Eigen::SparseMatrix<Block, Eigen::RowMajor> JT_K_J;
@@ -206,14 +207,14 @@ void MatrixProjectionMethod<TMatrix>::computeMatrixJacobians(const core::Mechani
206207
{
207208
if (!m_mappingJacobians.has_value() || !d_areJacobiansConstant.getValue())
208209
{
209-
const MappingJacobians<TMatrix> J0 = computeJacobiansFrom(
210+
const simulation::MappingJacobians<TMatrix> J0 = computeJacobiansFrom(
210211
this->l_mechanicalStates[0], mparams, mappingGraph, matrixToProject);
211212

212-
const MappingJacobians<TMatrix> J1 =
213+
const simulation::MappingJacobians<TMatrix> J1 =
213214
(this->l_mechanicalStates[0] == this->l_mechanicalStates[1]) ?
214215
J0 : computeJacobiansFrom(this->l_mechanicalStates[1], mparams, mappingGraph, matrixToProject);
215216

216-
m_mappingJacobians.emplace(sofa::type::fixed_array<MappingJacobians<TMatrix>, 2>({J0, J1}));
217+
m_mappingJacobians.emplace(sofa::type::fixed_array<simulation::MappingJacobians<TMatrix>, 2>({J0, J1}));
217218
}
218219
}
219220

@@ -237,7 +238,7 @@ void MatrixProjectionMethod<TMatrix>::projectMatrixToGlobalMatrix(const core::Me
237238

238239
template <class TMatrix>
239240
std::vector<unsigned> MatrixProjectionMethod<TMatrix>::identifyAffectedDoFs(
240-
BaseMechanicalState* mstate, TMatrix* crs)
241+
core::behavior::BaseMechanicalState* mstate, TMatrix* crs)
241242
{
242243
const auto blockSize = mstate->getMatrixBlockSize();
243244
std::set<unsigned int> setAffectedDoFs;
@@ -262,13 +263,13 @@ std::vector<unsigned> MatrixProjectionMethod<TMatrix>::identifyAffectedDoFs(
262263
}
263264

264265
template <class TMatrix>
265-
MappingJacobians<TMatrix> MatrixProjectionMethod<TMatrix>::computeJacobiansFrom(
266-
BaseMechanicalState* mstate, const core::MechanicalParams* mparams,
266+
simulation::MappingJacobians<TMatrix> MatrixProjectionMethod<TMatrix>::computeJacobiansFrom(
267+
core::behavior::BaseMechanicalState* mstate, const core::MechanicalParams* mparams,
267268
const MappingGraph& mappingGraph, TMatrix* crs)
268269
{
269270
core::ConstraintParams cparams(*mparams);
270271

271-
MappingJacobians<TMatrix> jacobians(*mstate);
272+
simulation::MappingJacobians<TMatrix> jacobians(*mstate);
272273

273274
if (!mappingGraph.hasAnyMappingInput(mstate))
274275
{

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/visitors/AssembleGlobalVectorFromLocalVectorVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
******************************************************************************/
2222
#pragma once
2323

24+
#include <sofa/component/linearsystem/config.h>
2425
#include <sofa/simulation/BaseMechanicalVisitor.h>
2526
#include <sofa/component/linearsystem/MappingGraph.h>
2627

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/visitors/DispatchFromGlobalVectorToLocalVectorVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
******************************************************************************/
2222
#pragma once
2323

24+
#include <sofa/component/linearsystem/config.h>
2425
#include <sofa/simulation/BaseMechanicalVisitor.h>
2526
#include <sofa/component/linearsystem/MappingGraph.h>
2627

Sofa/Component/LinearSystem/tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ project(Sofa.Component.LinearSystem_test)
44

55
set(SOURCE_FILES
66
MatrixLinearSystem_test.cpp
7-
MappingGraph_test.cpp
87
)
98

109
add_executable(${PROJECT_NAME} ${SOURCE_FILES})

Sofa/framework/Simulation/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(HEADER_FILES
6666
${SRC_ROOT}/SceneCheck.h
6767
${SRC_ROOT}/SceneCheckRegistry.h
6868
${SRC_ROOT}/SceneCheckMainRegistry.h
69+
${SRC_ROOT}/MappingGraph.h
6970

7071
${SRC_ROOT}/events/BuildConstraintSystemEndEvent.h
7172
${SRC_ROOT}/events/SimulationInitDoneEvent.h
@@ -168,6 +169,7 @@ set(SOURCE_FILES
168169
${SRC_ROOT}/InitVisitor.cpp
169170
${SRC_ROOT}/IntegrateBeginEvent.cpp
170171
${SRC_ROOT}/IntegrateEndEvent.cpp
172+
${SRC_ROOT}/MappingGraph.cpp
171173
${SRC_ROOT}/MechanicalOperations.cpp
172174
${SRC_ROOT}/MechanicalVPrintVisitor.cpp
173175
${SRC_ROOT}/MechanicalVisitor.cpp

Sofa/Component/LinearSystem/src/sofa/component/linearsystem/MappingGraph.cpp renamed to Sofa/framework/Simulation/Core/src/sofa/simulation/MappingGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* *
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
22-
#include <sofa/component/linearsystem/MappingGraph.h>
22+
#include <sofa/simulation/MappingGraph.h>
2323

2424
#include <sofa/core/BaseMapping.h>
2525
#include <sofa/core/behavior/BaseForceField.h>
@@ -30,7 +30,7 @@
3030
#include <sofa/simulation/mechanicalvisitor/MechanicalAccumulateJacobian.h>
3131
#include <sofa/simulation/mechanicalvisitor/MechanicalResetConstraintVisitor.h>
3232

33-
namespace sofa::component::linearsystem
33+
namespace sofa::simulation
3434
{
3535

3636
core::objectmodel::BaseContext* MappingGraph::getRootNode() const

0 commit comments

Comments
 (0)