Skip to content

Commit

Permalink
Python API: unifying Element*
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Feb 18, 2021
1 parent 78598a8 commit 6fa8ceb
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 165 deletions.
6 changes: 2 additions & 4 deletions python/Element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ namespace py = pybind11;
void init_Element(py::module& m)
{

m.def(
"asElementVector",
m.def("asElementVector",
&GooseFEM::Element::asElementVector,
"Convert nodal vector [nnode, ndim] to nodal vector stored per element [nelem, nne, ndim]",
py::arg("conn"),
py::arg("nodevec"));

m.def(
"assembleElementVector",
m.def("assembleElementVector",
&GooseFEM::Element::assembleNodeVector,
"Assemble nodal vector stored per element [nelem, nne, ndim] to nodal vector [nnode, ndim]",
py::arg("conn"),
Expand Down
63 changes: 25 additions & 38 deletions python/ElementHex8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ void init_ElementHex8(py::module& m)

.def(py::init<const xt::xtensor<double, 3>&>(), "Quadrature", py::arg("x"))

.def(
py::init<
.def(py::init<
const xt::xtensor<double, 3>&,
const xt::xtensor<double, 2>&,
const xt::xtensor<double, 1>&>(),
Expand All @@ -27,96 +26,84 @@ void init_ElementHex8(py::module& m)
py::arg("xi"),
py::arg("w"))

.def(
"update_x",
.def("update_x",
&GooseFEM::Element::Hex8::Quadrature::update_x,
"Update the nodal positions")

.def("nelem", &GooseFEM::Element::Hex8::Quadrature::nelem, "Number of elements")

.def("nne", &GooseFEM::Element::Hex8::Quadrature::nne, "Number of nodes per element")

.def("ndim", &GooseFEM::Element::Hex8::Quadrature::ndim, "Number of dimensions")

.def("nip", &GooseFEM::Element::Hex8::Quadrature::nip, "Number of integration points")

.def("dV", &GooseFEM::Element::Hex8::Quadrature::dV, "Integration point volume (qscalar)")

.def(
"GradN_vector",
.def("GradN_vector",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Hex8::Quadrature::GradN_vector, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"GradN_vector_T",
.def("GradN_vector_T",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Hex8::Quadrature::GradN_vector_T, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"SymGradN_vector",
.def("SymGradN_vector",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Hex8::Quadrature::SymGradN_vector, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"Int_N_scalar_NT_dV",
.def("Int_N_scalar_NT_dV",
py::overload_cast<const xt::xtensor<double, 2>&>(
&GooseFEM::Element::Hex8::Quadrature::Int_N_scalar_NT_dV, py::const_),
"Integration, returns 'elemmat'",
py::arg("qscalar"))

.def(
"Int_gradN_dot_tensor2_dV",
.def("Int_gradN_dot_tensor2_dV",
py::overload_cast<const xt::xtensor<double, 4>&>(
&GooseFEM::Element::Hex8::Quadrature::Int_gradN_dot_tensor2_dV, py::const_),
"Integration, returns 'elemvec'",
py::arg("qtensor"))

.def(
"Int_gradN_dot_tensor4_dot_gradNT_dV",
.def("Int_gradN_dot_tensor4_dot_gradNT_dV",
py::overload_cast<const xt::xtensor<double, 6>&>(
&GooseFEM::Element::Hex8::Quadrature::Int_gradN_dot_tensor4_dot_gradNT_dV,
py::const_),
"Integration, returns 'elemvec'",
py::arg("qtensor"))

.def(
"AsTensor",
// Derived from QuadratureBase

.def("nelem", &GooseFEM::Element::Hex8::Quadrature::nelem, "Number of elements")

.def("nne", &GooseFEM::Element::Hex8::Quadrature::nne, "Number of nodes per element")

.def("ndim", &GooseFEM::Element::Hex8::Quadrature::ndim, "Number of dimensions")

.def("nip", &GooseFEM::Element::Hex8::Quadrature::nip, "Number of integration points")

.def("AsTensor",
(xt::xarray<double>(GooseFEM::Element::Hex8::Quadrature::*)(
size_t, const xt::xtensor<double, 2>&) const)
&GooseFEM::Element::Hex8::Quadrature::AsTensor<double>,
"Convert 'qscalar' to 'qtensor' of certain rank")

.def(
"AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Hex8::Quadrature::*)(
size_t) const)
.def("AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Hex8::Quadrature::*)(size_t) const)
&GooseFEM::Element::Hex8::Quadrature::AllocateQtensor<double>,
"Allocate 'qtensor'",
py::arg("rank"))

.def(
"AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Hex8::Quadrature::*)(
size_t, double) const)
.def("AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Hex8::Quadrature::*)(size_t, double) const)
&GooseFEM::Element::Hex8::Quadrature::AllocateQtensor<double>,
"Allocate 'qtensor'",
py::arg("rank"),
py::arg("val"))

.def(
"AllocateQscalar",
.def("AllocateQscalar",
py::overload_cast<>(
&GooseFEM::Element::Hex8::Quadrature::AllocateQscalar<double>, py::const_),
"Allocate 'qscalar'")

.def(
"AllocateQscalar",
.def("AllocateQscalar",
py::overload_cast<double>(
&GooseFEM::Element::Hex8::Quadrature::AllocateQscalar<double>, py::const_),
"Allocate 'qscalar'",
Expand Down
48 changes: 16 additions & 32 deletions python/ElementQuad4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ void init_ElementQuad4(py::module& m)

.def(py::init<const xt::xtensor<double, 3>&>(), "Quadrature", py::arg("x"))

.def(
py::init<
.def(py::init<
const xt::xtensor<double, 3>&,
const xt::xtensor<double, 2>&,
const xt::xtensor<double, 1>&>(),
Expand All @@ -27,56 +26,48 @@ void init_ElementQuad4(py::module& m)
py::arg("xi"),
py::arg("w"))

.def(
"update_x",
.def("update_x",
&GooseFEM::Element::Quad4::Quadrature::update_x,
"Update the nodal positions")

.def("dV", &GooseFEM::Element::Quad4::Quadrature::dV, "Integration point volume (qscalar)")

.def(
"Interp_N_vector",
.def("Interp_N_vector",
&GooseFEM::Element::Quad4::Quadrature::Interp_N_vector<double>,
"See :cpp:class:`GooseFEM::Quad4::Quadrature::Interp_N_vector`.",
py::arg("elemvec"))

.def(
"GradN_vector",
.def("GradN_vector",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Quad4::Quadrature::GradN_vector, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"GradN_vector_T",
.def("GradN_vector_T",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Quad4::Quadrature::GradN_vector_T, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"SymGradN_vector",
.def("SymGradN_vector",
py::overload_cast<const xt::xtensor<double, 3>&>(
&GooseFEM::Element::Quad4::Quadrature::SymGradN_vector, py::const_),
"Dyadic product, returns 'qtensor'",
py::arg("elemvec"))

.def(
"Int_N_scalar_NT_dV",
.def("Int_N_scalar_NT_dV",
py::overload_cast<const xt::xtensor<double, 2>&>(
&GooseFEM::Element::Quad4::Quadrature::Int_N_scalar_NT_dV, py::const_),
"Integration, returns 'elemmat'",
py::arg("qscalar"))

.def(
"Int_gradN_dot_tensor2_dV",
.def("Int_gradN_dot_tensor2_dV",
py::overload_cast<const xt::xtensor<double, 4>&>(
&GooseFEM::Element::Quad4::Quadrature::Int_gradN_dot_tensor2_dV, py::const_),
"Integration, returns 'elemvec'",
py::arg("qtensor"))

.def(
"Int_gradN_dot_tensor4_dot_gradNT_dV",
.def("Int_gradN_dot_tensor4_dot_gradNT_dV",
py::overload_cast<const xt::xtensor<double, 6>&>(
&GooseFEM::Element::Quad4::Quadrature::Int_gradN_dot_tensor4_dot_gradNT_dV,
py::const_),
Expand All @@ -93,48 +84,41 @@ void init_ElementQuad4(py::module& m)

.def("nip", &GooseFEM::Element::Quad4::Quadrature::nip, "Number of integration points")

.def(
"AsTensor",
.def("AsTensor",
(xt::xarray<double>(GooseFEM::Element::Quad4::Quadrature::*)(
size_t, const xt::xtensor<double, 2>&) const)
&GooseFEM::Element::Quad4::Quadrature::AsTensor<double>,
"Convert 'qscalar' to 'qtensor' of certain rank")

.def(
"ShapeQtensor",
.def("ShapeQtensor",
(std::vector<size_t>(GooseFEM::Element::Quad4::Quadrature::*)(size_t) const)
&GooseFEM::Element::Quad4::Quadrature::ShapeQtensor,
"Shape of 'qtensor'",
py::arg("rank"))

.def(
"ShapeQscalar",
.def("ShapeQscalar",
&GooseFEM::Element::Quad4::Quadrature::ShapeQscalar,
"Shape of 'qscalar'")

.def(
"AllocateQtensor",
.def("AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Quad4::Quadrature::*)(size_t) const)
&GooseFEM::Element::Quad4::Quadrature::AllocateQtensor<double>,
"Allocate 'qtensor'",
py::arg("rank"))

.def(
"AllocateQtensor",
.def("AllocateQtensor",
(xt::xarray<double>(GooseFEM::Element::Quad4::Quadrature::*)(size_t, double) const)
&GooseFEM::Element::Quad4::Quadrature::AllocateQtensor<double>,
"Allocate 'qtensor'",
py::arg("rank"),
py::arg("val"))

.def(
"AllocateQscalar",
.def("AllocateQscalar",
py::overload_cast<>(
&GooseFEM::Element::Quad4::Quadrature::AllocateQscalar<double>, py::const_),
"Allocate 'qscalar'")

.def(
"AllocateQscalar",
.def("AllocateQscalar",
py::overload_cast<double>(
&GooseFEM::Element::Quad4::Quadrature::AllocateQscalar<double>, py::const_),
"Allocate 'qscalar'",
Expand Down
Loading

0 comments on commit 6fa8ceb

Please sign in to comment.