Skip to content

Commit 6357d53

Browse files
committed
add binding to convert elastic parameters to Lamé's parameters
1 parent e6fb484 commit 6357d53

4 files changed

Lines changed: 97 additions & 2 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
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+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
21+
#include <pybind11/pybind11.h>
22+
23+
#include <SofaPython3/SofaDeformable/Binding_LameParameters.h>
24+
#include <sofa/component/solidmechanics/fem/elastic/impl/LameParameters.h>
25+
26+
namespace sofapython3
27+
{
28+
29+
void moduleAddLameParameters(pybind11::module &m)
30+
{
31+
using namespace sofa::component::solidmechanics::fem::elastic;
32+
33+
m.def(
34+
"toLameParameters2D",
35+
[](SReal youngModulus, SReal poissonRatio) {
36+
LameLambda<SReal> lambda{0};
37+
LameMu<SReal> mu{0};
38+
toLameParameters<2>(YoungModulus<SReal>(youngModulus),
39+
PoissonRatio<SReal>(poissonRatio), lambda, mu);
40+
return std::make_pair(mu.get(), lambda.get());
41+
},
42+
pybind11::arg("youngModulus"), pybind11::arg("poissonRatio"),
43+
"Converts Young's modulus and Poisson's ratio to Lamé parameters (mu, "
44+
"lambda) for 2D.");
45+
46+
m.def(
47+
"toLameParameters3D",
48+
[](SReal youngModulus, SReal poissonRatio) {
49+
LameLambda<SReal> lambda{0};
50+
LameMu<SReal> mu{0};
51+
toLameParameters<3>(YoungModulus<SReal>(youngModulus),
52+
PoissonRatio<SReal>(poissonRatio), lambda, mu);
53+
return std::make_pair(mu.get(), lambda.get());
54+
},
55+
pybind11::arg("youngModulus"), pybind11::arg("poissonRatio"),
56+
"Converts Young's modulus and Poisson's ratio to Lamé parameters (mu, "
57+
"lambda) for 3D.");
58+
}
59+
60+
} // namespace sofapython3
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2021 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+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
21+
#pragma once
22+
23+
#include <pybind11/pybind11.h>
24+
25+
namespace sofapython3
26+
{
27+
28+
void moduleAddLameParameters(pybind11::module& m);
29+
30+
} // namespace sofapython3

bindings/Modules/src/SofaPython3/SofaDeformable/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
project(Bindings.Modules.SofaDeformable)
22

33
set(SOURCE_FILES
4-
${CMAKE_CURRENT_SOURCE_DIR}/Module_SofaDeformable.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LameParameters.cpp
55
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring.cpp
66
${CMAKE_CURRENT_SOURCE_DIR}/Binding_SpringForceField.cpp
7+
${CMAKE_CURRENT_SOURCE_DIR}/Module_SofaDeformable.cpp
78
)
89

910
set(HEADER_FILES
11+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LameParameters.h
1012
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring.h
1113
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring_doc.h
1214
${CMAKE_CURRENT_SOURCE_DIR}/Binding_SpringForceField.h
@@ -18,6 +20,7 @@ if (NOT TARGET SofaPython3::Plugin)
1820
endif()
1921

2022
sofa_find_package(Sofa.Component.SolidMechanics.Spring REQUIRED)
23+
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic REQUIRED)
2124

2225
SP3_add_python_module(
2326
TARGET ${PROJECT_NAME}
@@ -26,6 +29,6 @@ SP3_add_python_module(
2629
DESTINATION Sofa
2730
SOURCES ${SOURCE_FILES}
2831
HEADERS ${HEADER_FILES}
29-
DEPENDS Sofa.Component.SolidMechanics.Spring SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
32+
DEPENDS Sofa.Component.SolidMechanics.Spring Sofa.Component.SolidMechanics.FEM.Elastic SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
3033

3134
)

bindings/Modules/src/SofaPython3/SofaDeformable/Module_SofaDeformable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <pybind11/pybind11.h>
2222
#include <SofaPython3/SofaDeformable/Binding_LinearSpring.h>
2323
#include <SofaPython3/SofaDeformable/Binding_SpringForceField.h>
24+
#include <SofaPython3/SofaDeformable/Binding_LameParameters.h>
2425

2526

2627
namespace py { using namespace pybind11; }
@@ -34,6 +35,7 @@ PYBIND11_MODULE(SofaDeformable, m)
3435

3536
moduleAddLinearSpring(m);
3637
moduleAddSpringForceField(m);
38+
moduleAddLameParameters(m);
3739
}
3840

3941
} // namespace sofapython3

0 commit comments

Comments
 (0)