Skip to content

Commit fb427a0

Browse files
committed
Fix Issue #184
1 parent bce2522 commit fb427a0

29 files changed

Lines changed: 522 additions & 50 deletions

bindings/julia/src/Integrate.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int integrateBehaviourData1(mgis::behaviour::BehaviourData& d,
2727
} // end of integrateBehaviourData1
2828

2929
static int integrateDebugBehaviourData1(mgis::behaviour::BehaviourData& d,
30-
const mgis::behaviour::Behaviour& b) {
30+
const mgis::behaviour::Behaviour& b) {
3131
auto v = mgis::behaviour::make_view(d);
3232
const auto s = mgis::behaviour::integrate_debug(v, b);
3333
return s;
@@ -73,7 +73,7 @@ void declareIntegrate(jlcxx::Module& m) {
7373
const mgis::behaviour::Behaviour&) =
7474
mgis::behaviour::integrate;
7575
int (*integrate_debug_ptr1)(mgis::behaviour::BehaviourDataView&,
76-
const mgis::behaviour::Behaviour&) =
76+
const mgis::behaviour::Behaviour&) =
7777
mgis::behaviour::integrate_debug;
7878
// int (*integrate_ptr2)(mgis::behaviour::MaterialDataManager&,
7979
// const IntegrationType, const mgis::real,
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
add_subdirectory(fenics)
22

3-
install(FILES __init__.py
4-
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
5-
COMPONENT python_bindings)
3+
if(MGIS_HAVE_TFEL AND TFEL_PYTHON_BINDINGS)
4+
install(FILES __init__-have-tfel.py
5+
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
6+
COMPONENT python_bindings
7+
RENAME __init__.py)
8+
else()
9+
install(FILES __init__.py
10+
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
11+
COMPONENT python_bindings)
12+
endif()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
try:
2+
import mfront.database
3+
except:
4+
print("loading mfront.database model failed")
5+
pass
6+
7+
from ._mgis import *

bindings/python/src/Behaviour.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,16 @@ Behaviour_getPostProcessingOutputs(const mgis::behaviour::Behaviour &b,
179179
return p->second.outputs;
180180
} // end of Behaviour_getPostProcessingOutputs
181181

182+
static mgis::behaviour::Behaviour Behaviour_loadFromDatabase(
183+
const std::string &n,
184+
const mgis::behaviour::Hypothesis h,
185+
const std::optional<std::string> &m) {
186+
return mgis::behaviour::loadFromDatabase(
187+
{.name = n, .hypothesis = h, .material = m});
188+
} // end of Behaviour_loadFromDatabase
189+
182190
void declareBehaviour(pybind11::module_ &m) {
191+
using namespace pybind11::literals;
183192
using mgis::behaviour::Behaviour;
184193
using mgis::behaviour::BehaviourDescription;
185194
using mgis::behaviour::FiniteStrainBehaviourOptions;
@@ -250,6 +259,9 @@ void declareBehaviour(pybind11::module_ &m) {
250259

251260
m.def("load", load_ptr);
252261
m.def("load", load_ptr2);
262+
m.def("loadFromDatabase", Behaviour_loadFromDatabase, "name"_a,
263+
"hypothesis"_a, "material"_a = std::optional<std::string>{});
264+
253265
m.def("setParameter", setParameter1);
254266
m.def("setIntegerParameter", setParameter2);
255267
m.def("setUnsignedShortParameter", setParameter3);

bindings/python/src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ function(mgis_python_module fullname name)
3030
COMPONENT python_bindings)
3131
endfunction(mgis_python_module)
3232

33-
mgis_python_module(mgis _mgis
33+
set(MGIS_MODULE_SOURCES)
34+
list(APPEND MGIS_MODULE_SOURCES
3435
mgis-module.cxx
3536
ThreadPool.cxx)
37+
if(MGIS_HAVE_TFEL)
38+
list(APPEND MGIS_MODULE_SOURCES
39+
Database.cxx)
40+
endif(MGIS_HAVE_TFEL)
41+
mgis_python_module(mgis _mgis ${MGIS_MODULE_SOURCES})
3642

3743
mgis_python_module(mgis_material_property material_property
3844
material_property-module.cxx

bindings/python/src/Database.cxx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*!
2+
* \file bindings/python/src/Database.cxx
3+
* \brief
4+
* \author Thomas Helfer
5+
* \date 31/10/2018
6+
* \copyright (C) Copyright Thomas Helfer 2018.
7+
* Use, modification and distribution are subject
8+
* to one of the following licences:
9+
* - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying
10+
* file LGPL-3.0.txt)
11+
* - CECILL-C, Version 1.0 (See accompanying files
12+
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
13+
*/
14+
15+
#include <pybind11/pybind11.h>
16+
#include "MGIS/Database.hxx"
17+
18+
void declareDatabase(pybind11::module_&);
19+
20+
void declareDatabase(pybind11::module_& m) {
21+
m.def("getDatabase", mgis::getDatabase,
22+
pybind11::return_value_policy::reference);
23+
} // end of declareDatabase

bindings/python/src/Integrate.cxx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int integrateBehaviourData1(mgis::behaviour::BehaviourData& d,
3030
} // end of integrateBehaviourData
3131

3232
static int integrateDebugBehaviourData1(mgis::behaviour::BehaviourData& d,
33-
const mgis::behaviour::Behaviour& b) {
33+
const mgis::behaviour::Behaviour& b) {
3434
auto v = mgis::behaviour::make_view(d);
3535
const auto s = mgis::behaviour::integrate_debug(v, b);
3636
return s;
@@ -246,12 +246,14 @@ void declareIntegrate(pybind11::module_& m) {
246246
MultiThreadedBehaviourIntegrationResult (*integrate_ptr5)(
247247
mgis::ThreadPool&, MaterialDataManager&,
248248
const BehaviourIntegrationOptions&, const mgis::real) = integrate;
249-
int (*integrate_debug_ptr1)(BehaviourDataView&, const Behaviour&) = integrate_debug;
249+
int (*integrate_debug_ptr1)(BehaviourDataView&, const Behaviour&) =
250+
integrate_debug;
250251
int (*integrate_debug_ptr2)(MaterialDataManager&, const IntegrationType,
251-
const mgis::real, const mgis::size_type,
252-
const mgis::size_type) = integrate_debug;
252+
const mgis::real, const mgis::size_type,
253+
const mgis::size_type) = integrate_debug;
253254
int (*integrate_debug_ptr3)(mgis::ThreadPool&, MaterialDataManager&,
254-
const IntegrationType, const mgis::real) = integrate_debug;
255+
const IntegrationType, const mgis::real) =
256+
integrate_debug;
255257
BehaviourIntegrationResult (*integrate_debug_ptr4)(
256258
MaterialDataManager&, const BehaviourIntegrationOptions&,
257259
const mgis::real, const mgis::size_type, const mgis::size_type) =

bindings/python/src/Model.cxx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,27 @@
1313
*/
1414

1515
#include <pybind11/pybind11.h>
16+
#include <pybind11/stl.h>
1617
#include "MGIS/Model/Model.hxx"
1718

1819
// forward declaration
1920
void declareModel(pybind11::module_& m);
2021

22+
static mgis::model::Model Model_loadFromDatabase(
23+
const std::string& n,
24+
const mgis::behaviour::Hypothesis h,
25+
const std::optional<std::string>& m) {
26+
return mgis::model::loadFromDatabase(
27+
{.name = n, .hypothesis = h, .material = m});
28+
} // end of Behaviour_loadFromDatabase
29+
2130
void declareModel(pybind11::module_& m) {
31+
using namespace pybind11::literals;
2232
// wrapping free functions
23-
m.def("load", mgis::model::load);
33+
m.def("load", pybind11::overload_cast<const std::string&, const std::string&,
34+
const mgis::behaviour::Hypothesis>(
35+
mgis::model::load));
36+
m.def("loadFromDatabase", Model_loadFromDatabase, "name"_a, "hypothesis"_a,
37+
"material"_a = std::optional<std::string>{});
38+
2439
} // end of declareModel

bindings/python/src/NumPySupport.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace mgis::python {
4141
return pybind11::array_t<double>(
4242
{v.size() / nc, nc}, /* Buffer dimensions */
4343
{nc * sizeof(double), sizeof(double)}, v.data(), pybind11::none());
44-
} // end of wrapInNumPyArray
44+
} // end of wrapInNumPyArray
4545

4646
pybind11::array_t<double> wrapInNumPyArray(std::vector<double>& v,
4747
const size_type nc) {

bindings/python/src/mgis-module.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@
1515
#include <pybind11/pybind11.h>
1616

1717
void declareThreadPool(pybind11::module_&);
18+
#ifdef MGIS_HAVE_TFEL
19+
void declareDatabase(pybind11::module_&);
20+
#endif /* MGIS_HAVE_TFEL */
1821

19-
PYBIND11_MODULE(_mgis, m) { declareThreadPool(m); } // end of module behaviour
22+
PYBIND11_MODULE(_mgis, m) {
23+
declareThreadPool(m);
24+
#ifdef MGIS_HAVE_TFEL
25+
declareDatabase(m);
26+
#endif /* MGIS_HAVE_TFEL */
27+
} // end of module behaviour

0 commit comments

Comments
 (0)