Skip to content

Commit db667ba

Browse files
authored
Merge pull request #7 from gismo/pybind11
Binding shell assembler and material matrices to Python
2 parents 1e7dc7a + 5ef166d commit db667ba

16 files changed

+647
-3
lines changed

examples/example_shell3D.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ int main(int argc, char *argv[])
107107
gsInfo << "Patches: "<< mp.nPatches() <<", degree: "<< dbasis.minCwiseDegree() <<"\n";
108108
gsInfo << dbasis.basis(0)<<"\n";
109109

110+
110111
//! [Set boundary conditions]
111112
gsBoundaryConditions<> bc;
112113
bc.setGeoMap(mp);
@@ -136,9 +137,9 @@ int main(int argc, char *argv[])
136137
bc.addCondition(boundary::west, condition_type::dirichlet, 0, 0 ,false,i);
137138
}
138139

139-
pressure = -1;
140+
// pressure = -1;
140141
refPoint<<0.5,0.5;
141-
// tmp << 0,0,-1;
142+
tmp << 0,0,-1;
142143

143144
}
144145
else if (testCase == 1)

gsKLShell.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <gsCore/gsTemplateTools.h>
2+
3+
#include <gsKLShell/gsMaterialMatrixBase.h>
4+
#include <gsKLShell/gsMaterialMatrixBaseDim.h>
5+
6+
#include <gsKLShell/gsMaterialMatrixLinear.h>
7+
#include <gsKLShell/gsMaterialMatrix.h>
8+
9+
#include <gsKLShell/gsThinShellAssembler.h>
10+
11+
12+
namespace gismo
13+
{
14+
15+
#ifdef GISMO_BUILD_PYBIND11
16+
17+
namespace py = pybind11;
18+
19+
void pybind11_init_gsKLShell(py::module &m)
20+
{
21+
gismo::pybind11_init_gsMaterialMatrixBase( m );
22+
23+
gismo::pybind11_init_gsMaterialMatrixBaseDim2( m );
24+
gismo::pybind11_init_gsMaterialMatrixBaseDim3( m );
25+
26+
gismo::pybind11_init_gsMaterialMatrixLinear2( m );
27+
gismo::pybind11_init_gsMaterialMatrixLinear3( m );
28+
29+
gismo::pybind11_init_gsMaterialMatrixNH2i( m );
30+
gismo::pybind11_init_gsMaterialMatrixNH2c( m );
31+
32+
gismo::pybind11_init_gsMaterialMatrixNH3i( m );
33+
gismo::pybind11_init_gsMaterialMatrixNH3c( m );
34+
35+
gismo::pybind11_init_gsMaterialMatrixMR2i( m );
36+
gismo::pybind11_init_gsMaterialMatrixMR2c( m );
37+
38+
gismo::pybind11_init_gsMaterialMatrixMR3i( m );
39+
gismo::pybind11_init_gsMaterialMatrixMR3c( m );
40+
41+
gismo::pybind11_init_gsMaterialMatrixOG2i( m );
42+
gismo::pybind11_init_gsMaterialMatrixOG2c( m );
43+
44+
gismo::pybind11_init_gsMaterialMatrixOG3i( m );
45+
gismo::pybind11_init_gsMaterialMatrixOG3c( m );
46+
47+
gismo::pybind11_init_gsThinShellAssemblerBase( m );
48+
49+
gismo::pybind11_init_gsThinShellAssembler2( m );
50+
gismo::pybind11_init_gsThinShellAssembler3( m );
51+
gismo::pybind11_init_gsThinShellAssembler3nb( m );
52+
}
53+
54+
#endif
55+
}
56+

gsMaterialMatrix.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,31 @@ class gsMaterialMatrix : public gsMaterialMatrixBaseDim<dim,T>
11941194
}
11951195
};
11961196

1197+
#ifdef GISMO_BUILD_PYBIND11
1198+
1199+
/**
1200+
* @brief Initializes the Python wrapper for the class: gsMaterialMatrixLinear
1201+
*/
1202+
void pybind11_init_gsMaterialMatrixNH2i(pybind11::module &m);
1203+
void pybind11_init_gsMaterialMatrixNH2c(pybind11::module &m);
1204+
1205+
void pybind11_init_gsMaterialMatrixNH3i(pybind11::module &m);
1206+
void pybind11_init_gsMaterialMatrixNH3c(pybind11::module &m);
1207+
1208+
void pybind11_init_gsMaterialMatrixMR2i(pybind11::module &m);
1209+
void pybind11_init_gsMaterialMatrixMR2c(pybind11::module &m);
1210+
1211+
void pybind11_init_gsMaterialMatrixMR3i(pybind11::module &m);
1212+
void pybind11_init_gsMaterialMatrixMR3c(pybind11::module &m);
1213+
1214+
void pybind11_init_gsMaterialMatrixOG2i(pybind11::module &m);
1215+
void pybind11_init_gsMaterialMatrixOG2c(pybind11::module &m);
1216+
1217+
void pybind11_init_gsMaterialMatrixOG3i(pybind11::module &m);
1218+
void pybind11_init_gsMaterialMatrixOG3c(pybind11::module &m);
1219+
1220+
#endif // GISMO_BUILD_PYBIND11
1221+
11971222
} // namespace
11981223

11991224

gsMaterialMatrix2dComp_.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,44 @@ namespace gismo
2424

2525
// OG
2626
CLASS_TEMPLATE_INST gsMaterialMatrix<2,real_t,34,true>;
27+
28+
#ifdef GISMO_BUILD_PYBIND11
29+
30+
namespace py = pybind11;
31+
32+
void pybind11_init_gsMaterialMatrixNH2c(py::module &m)
33+
{
34+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
35+
using Class = gsMaterialMatrix<2,real_t,11,true>;
36+
py::class_<Class,Base>(m, "gsMaterialNH2c")
37+
38+
// Constructors
39+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
40+
;
41+
}
42+
43+
void pybind11_init_gsMaterialMatrixMR2c(py::module &m)
44+
{
45+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
46+
using Class = gsMaterialMatrix<2,real_t,13,true>;
47+
py::class_<Class,Base>(m, "gsMaterialMR2c")
48+
49+
// Constructors
50+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
51+
;
52+
}
53+
54+
void pybind11_init_gsMaterialMatrixOG2c(py::module &m)
55+
{
56+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
57+
using Class = gsMaterialMatrix<2,real_t,34,true>;
58+
py::class_<Class,Base>(m, "gsMaterialOG2c")
59+
60+
// Constructors
61+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
62+
;
63+
}
64+
65+
#endif
2766
}
2867

gsMaterialMatrix2dIncomp_.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,45 @@ namespace gismo
2424

2525
// OG
2626
CLASS_TEMPLATE_INST gsMaterialMatrix<2,real_t,34,false>;
27+
28+
#ifdef GISMO_BUILD_PYBIND11
29+
30+
namespace py = pybind11;
31+
32+
void pybind11_init_gsMaterialMatrixNH2i(py::module &m)
33+
{
34+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
35+
using Class = gsMaterialMatrix<2,real_t,11,false>;
36+
py::class_<Class,Base>(m, "gsMaterialNH2i")
37+
38+
// Constructors
39+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
40+
;
41+
}
42+
43+
void pybind11_init_gsMaterialMatrixMR2i(py::module &m)
44+
{
45+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
46+
using Class = gsMaterialMatrix<2,real_t,13,false>;
47+
py::class_<Class,Base>(m, "gsMaterialMR2i")
48+
49+
// Constructors
50+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
51+
;
52+
}
53+
54+
void pybind11_init_gsMaterialMatrixOG2i(py::module &m)
55+
{
56+
using Base = gsMaterialMatrixBaseDim<2,real_t>;
57+
using Class = gsMaterialMatrix<2,real_t,34,false>;
58+
py::class_<Class,Base>(m, "gsMaterialOG2i")
59+
60+
// Constructors
61+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
62+
;
63+
}
64+
65+
#endif
66+
2767
}
2868

gsMaterialMatrix3dComp_.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,44 @@ namespace gismo
2525
// OG
2626
CLASS_TEMPLATE_INST gsMaterialMatrix<3,real_t,34,true>;
2727

28+
#ifdef GISMO_BUILD_PYBIND11
29+
30+
namespace py = pybind11;
31+
32+
void pybind11_init_gsMaterialMatrixNH3c(py::module &m)
33+
{
34+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
35+
using Class = gsMaterialMatrix<3,real_t,11,true>;
36+
py::class_<Class,Base>(m, "gsMaterialNH3c")
37+
38+
// Constructors
39+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
40+
;
41+
}
42+
43+
void pybind11_init_gsMaterialMatrixMR3c(py::module &m)
44+
{
45+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
46+
using Class = gsMaterialMatrix<3,real_t,13,true>;
47+
py::class_<Class,Base>(m, "gsMaterialMR3c")
48+
49+
// Constructors
50+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
51+
;
52+
}
53+
54+
void pybind11_init_gsMaterialMatrixOG3c(py::module &m)
55+
{
56+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
57+
using Class = gsMaterialMatrix<3,real_t,34,true>;
58+
py::class_<Class,Base>(m, "gsMaterialOG3c")
59+
60+
// Constructors
61+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
62+
;
63+
}
64+
65+
#endif
66+
2867
}
2968

gsMaterialMatrix3dIncomp_.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,44 @@ namespace gismo
2525
// OG
2626
CLASS_TEMPLATE_INST gsMaterialMatrix<3,real_t,34,false>;
2727

28+
#ifdef GISMO_BUILD_PYBIND11
29+
30+
namespace py = pybind11;
31+
32+
void pybind11_init_gsMaterialMatrixNH3i(py::module &m)
33+
{
34+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
35+
using Class = gsMaterialMatrix<3,real_t,11,false>;
36+
py::class_<Class,Base>(m, "gsMaterialNH3i")
37+
38+
// Constructors
39+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
40+
;
41+
}
42+
43+
void pybind11_init_gsMaterialMatrixMR3i(py::module &m)
44+
{
45+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
46+
using Class = gsMaterialMatrix<3,real_t,13,false>;
47+
py::class_<Class,Base>(m, "gsMaterialMR3i")
48+
49+
// Constructors
50+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
51+
;
52+
}
53+
54+
void pybind11_init_gsMaterialMatrixOG3i(py::module &m)
55+
{
56+
using Base = gsMaterialMatrixBaseDim<3,real_t>;
57+
using Class = gsMaterialMatrix<3,real_t,34,false>;
58+
py::class_<Class,Base>(m, "gsMaterialOG3i")
59+
60+
// Constructors
61+
.def(py::init<gsFunctionSet<real_t>&,gsFunction<real_t>&>())
62+
;
63+
}
64+
65+
#endif
66+
2867
}
2968

gsMaterialMatrixBase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,13 @@ class gsMaterialMatrixBase
198198
const gsFunctionSet<T> * m_defpatches;
199199
};
200200

201+
#ifdef GISMO_BUILD_PYBIND11
202+
203+
/**
204+
* @brief Initializes the Python wrapper for the class: gsMaterialMatrixBase
205+
*/
206+
void pybind11_init_gsMaterialMatrixBase(pybind11::module &m);
207+
208+
#endif // GISMO_BUILD_PYBIND11
209+
201210
} // namespace

gsMaterialMatrixBaseDim.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ class gsMaterialMatrixBaseDim : public gsMaterialMatrixBase<T>
165165

166166
};
167167

168+
#ifdef GISMO_BUILD_PYBIND11
169+
170+
/**
171+
* @brief Initializes the Python wrapper for the class: gsMaterialMatrixBaseDim
172+
*/
173+
void pybind11_init_gsMaterialMatrixBaseDim2(pybind11::module &m);
174+
void pybind11_init_gsMaterialMatrixBaseDim3(pybind11::module &m);
175+
176+
#endif // GISMO_BUILD_PYBIND11
177+
168178
} // namespace
169179

170180
#ifndef GISMO_BUILD_LIB

gsMaterialMatrixBase_.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,53 @@ namespace gismo
1010

1111
CLASS_TEMPLATE_INST gsMaterialMatrixBaseDim<2,real_t>;
1212
CLASS_TEMPLATE_INST gsMaterialMatrixBaseDim<3,real_t>;
13+
14+
#ifdef GISMO_BUILD_PYBIND11
15+
16+
namespace py = pybind11;
17+
18+
void pybind11_init_gsMaterialMatrixBase(py::module &m)
19+
{
20+
using Class = gsMaterialMatrixBase<real_t>;
21+
py::class_<Class>(m, "gsMaterialMatrixBase")
22+
23+
// Member functions
24+
.def("setOptions", &Class::setOptions, "Sets the options")
25+
.def("density_into", &Class::density_into, "Computes the density into a matrix")
26+
.def("stretch_into", &Class::stretch_into, "Computes the stretches into a matrix")
27+
.def("stretchDir_into", &Class::stretchDir_into, "Computes the stretch directions into a matrix")
28+
.def("thickness_into", &Class::thickness_into, "Computes the thickness into a matrix")
29+
.def("transform_into", &Class::transform_into, "Computes the stretch transformation into a matrix")
30+
.def("eval3D_matrix", &Class::eval3D_matrix, "Evaluates the material matrix")
31+
.def("eval3D_vector", &Class::eval3D_vector, "Evaluates the stress vector")
32+
.def("eval3D_pstress", &Class::eval3D_pstress, "Evaluates the principal stress vector")
33+
34+
.def("setYoungsModulus", &Class::setYoungsModulus, "Sets the Young's Modulus")
35+
.def("setPoissonsRatio", &Class::setPoissonsRatio, "Sets the Poisson's Ratio")
36+
.def("setRatio" , &Class::setRatio , "Sets the Ratio for MR model")
37+
.def("setMu" , &Class::setMu , "Sets the Mu_i for OG model")
38+
.def("setAlpha" , &Class::setAlpha , "Sets the Alpha_i for OG model")
39+
.def("setDensity" , &Class::setDensity , "Sets the Density")
40+
;
41+
}
42+
43+
void pybind11_init_gsMaterialMatrixBaseDim2(py::module &m)
44+
{
45+
using Base = gsMaterialMatrixBase<real_t>;
46+
using Class = gsMaterialMatrixBaseDim<2,real_t>;
47+
py::class_<Class,Base>(m, "gsMaterialMatrixBaseDim2")
48+
;
49+
}
50+
51+
void pybind11_init_gsMaterialMatrixBaseDim3(py::module &m)
52+
{
53+
using Base = gsMaterialMatrixBase<real_t>;
54+
using Class = gsMaterialMatrixBaseDim<3,real_t>;
55+
py::class_<Class,Base>(m, "gsMaterialMatrixBaseDim3")
56+
;
57+
}
58+
59+
#endif
60+
1361
}
1462

0 commit comments

Comments
 (0)