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
@@ -0,0 +1,60 @@
/******************************************************************************
* SofaPython3 plugin *
* (c) 2021 CNRS, University of Lille, INRIA *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#include <pybind11/pybind11.h>

#include <SofaPython3/SofaDeformable/Binding_LameParameters.h>
#include <sofa/component/solidmechanics/fem/elastic/impl/LameParameters.h>

namespace sofapython3
{

void moduleAddLameParameters(pybind11::module &m)
{
using namespace sofa::component::solidmechanics::fem::elastic;

m.def(
"toLameParameters2D",
[](SReal youngModulus, SReal poissonRatio) {
LameLambda<SReal> lambda{0};
LameMu<SReal> mu{0};
toLameParameters<2>(YoungModulus<SReal>(youngModulus),
PoissonRatio<SReal>(poissonRatio), lambda, mu);
return std::make_pair(mu.get(), lambda.get());
},
pybind11::arg("youngModulus"), pybind11::arg("poissonRatio"),
"Converts Young's modulus and Poisson's ratio to Lamé parameters (mu, "
"lambda) for 2D.");

m.def(
"toLameParameters3D",
[](SReal youngModulus, SReal poissonRatio) {
LameLambda<SReal> lambda{0};
LameMu<SReal> mu{0};
toLameParameters<3>(YoungModulus<SReal>(youngModulus),
PoissonRatio<SReal>(poissonRatio), lambda, mu);
return std::make_pair(mu.get(), lambda.get());
},
pybind11::arg("youngModulus"), pybind11::arg("poissonRatio"),
"Converts Young's modulus and Poisson's ratio to Lamé parameters (mu, "
"lambda) for 3D.");
}

} // namespace sofapython3
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2021 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#pragma once

#include <pybind11/pybind11.h>

namespace sofapython3
{

void moduleAddLameParameters(pybind11::module& m);

} // namespace sofapython3
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
project(Bindings.Modules.SofaDeformable)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Module_SofaDeformable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LameParameters.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Binding_SpringForceField.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Module_SofaDeformable.cpp
)

set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LameParameters.h
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring.h
${CMAKE_CURRENT_SOURCE_DIR}/Binding_LinearSpring_doc.h
${CMAKE_CURRENT_SOURCE_DIR}/Binding_SpringForceField.h
Expand All @@ -18,6 +20,7 @@ if (NOT TARGET SofaPython3::Plugin)
endif()

sofa_find_package(Sofa.Component.SolidMechanics.Spring REQUIRED)
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
Expand All @@ -26,6 +29,6 @@ SP3_add_python_module(
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS Sofa.Component.SolidMechanics.Spring SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
DEPENDS Sofa.Component.SolidMechanics.Spring Sofa.Component.SolidMechanics.FEM.Elastic SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core

)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <pybind11/pybind11.h>
#include <SofaPython3/SofaDeformable/Binding_LinearSpring.h>
#include <SofaPython3/SofaDeformable/Binding_SpringForceField.h>
#include <SofaPython3/SofaDeformable/Binding_LameParameters.h>


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

moduleAddLinearSpring(m);
moduleAddSpringForceField(m);
moduleAddLameParameters(m);
}

} // namespace sofapython3
Loading