Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/mpm2' into magnetoelasticity
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Faltus committed Sep 11, 2024
2 parents d445628 + c9ef232 commit 30b664d
Show file tree
Hide file tree
Showing 252 changed files with 7,350 additions and 727 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ if (USE_PYBIND_BINDINGS)
endif ()
include_directories (${pybind11_INCLUDE_DIR} ${Python_INCLUDE_DIRS})
list (APPEND EXT_LIBS ${Python_LIBRARIES})
pybind11_add_module(oofempy THIN_LTO ${oofem_SOURCE_DIR}/bindings/python/oofem.cpp ${oofem_SOURCE_DIR}/src/oofemcfg.C ${PYBIND11_HEADERS})
pybind11_add_module(oofempy THIN_LTO ${oofem_SOURCE_DIR}/bindings/python/oofem.cpp ${PYBIND11_HEADERS})
target_link_libraries(oofempy PRIVATE liboofem)
set_target_properties (oofempy PROPERTIES SUFFIX "${PYTHON_MODULE_EXTENSION}")

Expand Down Expand Up @@ -773,12 +773,12 @@ endif ()

# OOFEM target
if (USE_SHARED_LIB) # Prefer dynamic lib if available.
add_executable (oofem ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/src/main/main.C)
add_executable (oofem ${oofem_SOURCE_DIR}/src/main/main.C)
add_dependencies(oofem version)

target_link_libraries (oofem liboofem)
else ()
add_executable (oofem ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/src/main/main.C ${LIBS})
add_executable (oofem ${oofem_SOURCE_DIR}/src/main/main.C ${LIBS})
add_dependencies(oofem version)

target_link_libraries (oofem ${EXT_LIBS})
Expand All @@ -794,33 +794,33 @@ endif ()
if (USE_OOFEG)
# OOFEG target:
if (USE_SHARED_LIB)
add_executable (oofeg ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/src/main/oofeg.C)
add_executable (oofeg ${oofem_SOURCE_DIR}/src/main/oofeg.C)
target_link_libraries (oofeg liboofem)
else ()
add_executable (oofeg ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/src/main/oofeg.C ${LIBS})
add_executable (oofeg ${oofem_SOURCE_DIR}/src/main/oofeg.C ${LIBS})
target_link_libraries (oofeg ${EXT_LIBS})
endif ()
install(TARGETS oofeg DESTINATION bin)
add_dependencies(oofeg version)
endif ()


add_executable(liboofem_benchmark ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/src/main/benchmark.C)
add_executable(liboofem_benchmark ${oofem_SOURCE_DIR}/src/main/benchmark.C)
add_dependencies(liboofem_benchmark version)
set_target_properties(liboofem_benchmark PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries (liboofem_benchmark liboofem benchmark)

# Example of using liboofem with dynamic input record:
add_executable(beam2d_1 ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/bindings/oofemlib/beam2d_1.C)
add_executable(beam2d_1 ${oofem_SOURCE_DIR}/bindings/oofemlib/beam2d_1.C)
add_dependencies(beam2d_1 version)
set_target_properties(beam2d_1 PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries (beam2d_1 liboofem)

add_executable(hexgrid ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/bindings/oofemlib/hexgrid.C)
add_executable(hexgrid ${oofem_SOURCE_DIR}/bindings/oofemlib/hexgrid.C)
set_target_properties(hexgrid PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries (hexgrid liboofem)

add_executable(dream3d_analysis ${oofem_SOURCE_DIR}/src/oofemcfg.C ${oofem_SOURCE_DIR}/bindings/oofemlib/dream3d_analysis.C)
add_executable(dream3d_analysis ${oofem_SOURCE_DIR}/bindings/oofemlib/dream3d_analysis.C)
set_target_properties(dream3d_analysis PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries(dream3d_analysis liboofem)

Expand Down
6 changes: 3 additions & 3 deletions bindings/python/examples/vtkdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
print ("Piece:", p)
print(p.getVertices())
print(p.getCellConnectivity())
print(p.getCellTypes(vtkxmlPy))
print(p.getCellTypes())
disp = p.getPrimaryVertexValues(oofempy.UnknownType.DisplacementVector)
sig = p.getInternalVertexValues(oofempy.InternalStateType.IST_StressTensor)
sigx = sig[:, 0]

grid = pv.UnstructuredGrid(p.getCellConnectivity(), p.getCellTypes(vtkxmlPy), p.getVertices())
grid.point_arrays['Sigma_xx'] = sigx
grid = pv.UnstructuredGrid(p.getCellConnectivity(), p.getCellTypes(), p.getVertices())
grid.point_data['Sigma_xx'] = sigx
grid['Disp'] = disp
print(grid.active_vectors)
warped = grid.warp_by_vector('Disp', factor=1000.)
Expand Down
125 changes: 119 additions & 6 deletions bindings/python/oofem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ namespace py = pybind11;

#include "uniformgridfield.h"
#include "unstructuredgridfield.h"
#include "vtkhdf5reader.h"
#include "dofmanvalfield.h"
#include "pythonfield.h"
#include <iostream>
#include "oofemutil.h"

#ifdef __MPM_MODULE
// mpm experimental
#include "integral.h"
#include "mpm.h"
#endif

#ifdef _OPENMP
#include <omp.h>
#endif
Expand Down Expand Up @@ -181,6 +189,9 @@ template <class ElementBase = oofem::Element> class PyElement : public PyFemComp
oofem::MaterialMode giveMaterialMode() override {
PYBIND11_OVERLOAD (oofem::MaterialMode, ElementBase, giveMaterialMode,);
}
oofem::Element_Geometry_Type giveGeometryType() const override {
PYBIND11_OVERLOAD_PURE (oofem::Element_Geometry_Type, ElementBase, giveGeometryType,);
}
const char *giveClassName() const override {
PYBIND11_OVERLOAD_PURE (const char*, ElementBase, giveClassName,);
}
Expand Down Expand Up @@ -970,6 +981,9 @@ PYBIND11_MODULE(oofempy, m) {
.def("giveNumberOfDomainEquations", &oofem::EngngModel::giveNumberOfDomainEquations)
.def("Instanciate_init", &oofem::EngngModel::Instanciate_init)
.def_property("ndomains", &oofem::EngngModel::getNumberOfDomains, &oofem::EngngModel::setNumberOfDomains)
#ifdef __MPM_MODULE
.def("addIntegral", &oofem::EngngModel::py_addIntegral, py::keep_alive<0, 1>())
#endif
;

py::class_<oofem::StaggeredProblem, oofem::EngngModel>(m, "StaggeredProblem")
Expand Down Expand Up @@ -1301,7 +1315,45 @@ PYBIND11_MODULE(oofempy, m) {
.def("printYourself", &oofem::SparseMtrx::printYourself)
;

py::class_<oofem::SparseLinearSystemNM>(m, "SparseLinearSystemNM")
.def("solve", (oofem::ConvergedReason (oofem::SparseLinearSystemNM::*) (SparseMtrx &A, FloatArray &b, FloatArray &x)) &oofem::SparseLinearSystemNM::solve)
;

#ifdef __MPM_MODULE
/* MPM stuff (experimental)*/

py::enum_<oofem::Variable::VariableType>(m, "VariableType")
.value("scalar", oofem::Variable::VariableType::scalar)
.value("vector", oofem::Variable::VariableType::vector)
;
py::enum_<oofem::Variable::VariableQuantity>(m, "VariableQuantity")
.value("Displacement", oofem::Variable::VariableQuantity::Displacement)
.value("Temperature", oofem::Variable::VariableQuantity::Temperature)
.value("Pressure", oofem::Variable::VariableQuantity::Pressure)
.value("VolumeFraction", oofem::Variable::VariableQuantity::VolumeFraction)
;

py::class_<oofem::FEInterpolation>(m,"FEInterpolation")
;

py::class_<oofem::Variable>(m, "Variable")
.def(py::init<const oofem::FEInterpolation&, oofem::Variable::VariableQuantity, oofem::Variable::VariableType, int, oofem::IntArray&, oofem::Variable*>()) // , py::arg("dual")=NULL
.def_readonly("dofIDs", &oofem::Variable::dofIDs)
.def_readonly("type", &oofem::Variable::type)
.def_readonly("q", &oofem::Variable::q)
;

py::class_<oofem::Term>(m, "Term")
;

py::class_<oofem::Integral>(m, "Integral")
.def(py::init<oofem::Domain*, oofem::Set&, oofem::Term&>())
.def("initialize", &oofem::Integral::initialize)
.def("assemble_lhs", &oofem::Integral::assemble_lhs)
.def("assemble_rhs", &oofem::Integral::assemble_rhs)
;
/* end mpm experimental */
#endif
py::class_<oofem::ClassFactory>(m, "ClassFactory")
.def("createElement", &oofem::ClassFactory::createElement)
.def("createEngngModel", &oofem::ClassFactory::createEngngModel)
Expand Down Expand Up @@ -1632,6 +1684,22 @@ PYBIND11_MODULE(oofempy, m) {
.value("IntSource_wh", oofem::MatResponseMode::IntSource_wh)
;

py::enum_<oofem::MaterialMode>(m, "MaterialMode")
.value("_Unknown", oofem::MaterialMode::_Unknown)
.value("_3dMat", oofem::MaterialMode::_3dMat)
.value("_PlaneStress", oofem::MaterialMode::_PlaneStress)
.value("_PlaneStrain", oofem::MaterialMode::_PlaneStrain)
.value("_1dMat", oofem::MaterialMode::_1dMat)
.value("_1dHeat", oofem::MaterialMode::_1dHeat)
.value("_2dHeat", oofem::MaterialMode::_2dHeat)
.value("_3dHeat", oofem::MaterialMode::_3dHeat)
.value("_2dUP", oofem::MaterialMode::_2dUP)
.value("_3dUP", oofem::MaterialMode::_3dUP)
.value("_2dUPV", oofem::MaterialMode::_2dUPV)
.value("_3dUPV", oofem::MaterialMode::_3dUPV)
;


py::enum_<oofem::TimeDiscretizationType>(m,"TimeDiscretizationType")
.value("TD_Unspecified", oofem::TimeDiscretizationType::TD_Unspecified)
.value("TD_ThreePointBackward", oofem::TimeDiscretizationType::TD_ThreePointBackward)
Expand All @@ -1641,8 +1709,17 @@ PYBIND11_MODULE(oofempy, m) {
.value("TD_Explicit", oofem::TimeDiscretizationType::TD_Explicit)
;

py::enum_<oofem::ConvergedReason>(m, "ConvergedReason")
.value("CR_UNKNOWN", oofem::ConvergedReason::CR_UNKNOWN)
.value("CR_CONVERGED", oofem::ConvergedReason::CR_CONVERGED)
.value("CR_DIVERGED_ITS", oofem::ConvergedReason::CR_DIVERGED_ITS)
.value("CR_DIVERGED_TOL", oofem::ConvergedReason::CR_DIVERGED_TOL)
.value("CR_FAILED", oofem::ConvergedReason::CR_FAILED)
;

m.def("linearStatic", &linearStatic, py::return_value_policy::move);
m.def("staticStructural", &staticStructural, py::return_value_policy::move);
m.def("dummyProblem", &dummyProblem, py::return_value_policy::move);
m.def("domain", &domain, py::return_value_policy::move);
m.def("truss1d", &truss1d, py::return_value_policy::move);
m.def("beam2d", &beam2d, py::return_value_policy::move);
Expand Down Expand Up @@ -1681,15 +1758,26 @@ PYBIND11_MODULE(oofempy, m) {
m.def("homExport", &homExport, py::return_value_policy::move);
m.def("createSet", &createSet, py::return_value_policy::move);

#ifdef __MPM_MODULE
// mpm experimental
m.def("skyline", &skyline, py::return_value_policy::move);
m.def("ldltfactorization", &ldltFactorization, py::return_value_policy::move);
m.def("q1", &q1, py::return_value_policy::move);
m.def("l1", &l1, py::return_value_policy::move);

m.def("fei2dquadlin", &fei2dquadlin, py::return_value_policy::move);
m.def("fei2dlinelin", &fei2dlinelin, py::return_value_policy::move);
m.def("linearinterpolation", &linearinterpolation, py::return_value_policy::move);
m.def("BTSigmaTerm", &BTSigma_Term, py::return_value_policy::move);
m.def("NTfTerm", &NTf_Term, py::return_value_policy::move);

m.def("upm", &upm, py::return_value_policy::move);
#endif

//std::shared_ptr<oofem::Field>
py::class_<oofem::Field, PyField, std::shared_ptr<oofem::Field>>(m, "Field")
.def(py::init<oofem::FieldType>())
// .def("evaluateAt", (int (oofem::Field::*)(oofem::FloatArray &answer, const oofem::FloatArray &coords, oofem::ValueModeType mode, oofem::TimeStep *tStep)) &oofem::Field::evaluateAt)

.def("evaluateAt", [](oofem::FloatArray &answer, const oofem::FloatArray &coords, oofem::ValueModeType mode, oofem::TimeStep *tStep){
return std::make_tuple(answer,coords);//TODO-how to invoke the function if it does not exist yet?
})
.def("evaluateAt", (int (oofem::Field::*)(oofem::FloatArray &answer, const oofem::FloatArray &coords, oofem::ValueModeType mode, oofem::TimeStep *tStep)) &oofem::Field::evaluateAt)
.def("giveType", &oofem::Field::giveType)
.def("setType", &oofem::Field::setType)
;
Expand All @@ -1715,6 +1803,13 @@ PYBIND11_MODULE(oofempy, m) {
.def("getNodeCoordinates", &oofem::DofManValueField::getNodeCoordinates )
;

py::class_<oofem::VTKHDF5Reader>(m, "VTKHDF5Reader")
.def(py::init<>())
.def("initialize", &oofem::VTKHDF5Reader::initialize)
.def("finalize", &oofem::VTKHDF5Reader::finalize)
.def("readMesh", &oofem::VTKHDF5Reader::readMesh)
.def("readField", &oofem::VTKHDF5Reader::readField)
;

//depends on Python.h
#ifdef _PYBIND_BINDINGS
Expand All @@ -1725,6 +1820,24 @@ PYBIND11_MODULE(oofempy, m) {
;
#endif


// Utility function to test presence of compiled oofem modules
m.def("hasModule", [](const std::string &name) {
#ifdef __SM_MODULE
if (name == "sm") return true;
#endif
#ifdef __TM_MODULE
if (name == "tm") return true;
#endif
#ifdef __FM_MODULE
if (name == "fm") return true;
#endif
#ifdef __AM_MODULE
if (name == "am") return true;
#endif
#ifdef __MPM_MODULE
if (name == "mpm") return true;
#endif
return false;
});
m.def("test", &test);
}
Loading

0 comments on commit 30b664d

Please sign in to comment.