Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77941786
bind_py_solvers.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 09:03
Size
3 KB
Mime Type
text/x-c++
Expires
Mon, Aug 19, 09:03 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
19928900
Attached To
rMUSPECTRE µSpectre
bind_py_solvers.cc
View Options
/**
* file bind_py_solver.cc
*
* @author Till Junge <till.junge@epfl.ch>
*
* @date 09 Jan 2018
*
* @brief python bindings for the muSpectre solvers
*
* @section LICENCE
*
* Copyright © 2018 Till Junge
*
* µSpectre is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3, or (at
* your option) any later version.
*
* µSpectre 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "common/common.hh"
#include "solver/solvers.hh"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/eigen.h>
#include <sstream>
using namespace muSpectre;
namespace py=pybind11;
using namespace pybind11::literals;
/**
* Solvers instanciated for systems with equal spatial and material dimension
*/
template <Dim_t sdim>
void add_newton_cg_helper(py::module & mod) {
std::stringstream name_stream {};
name_stream << "newton_cg" << sdim << "d";
constexpr Dim_t mdim{sdim};
using sys = SystemBase<sdim, mdim>;
using grad = Grad_t<sdim>;
using grad_vec = Grad_t<sdim>;
mod.def(name_stream.str().c_str(),
[](sys & s, const grad & g, Formulation f, Real ct, Real nt,
Uint max, Dim_t verb) -> typename sys::StrainField_t & {
return newton_cg(s, g, f, ct, nt, max, verb);
},
"system"_a,
"ΔF₀"_a,
"formulation"_a,
"cg_tol"_a,
"newton_tol"_a,
"maxiter"_a=0,
"verbose"_a=0);
mod.def(name_stream.str().c_str(),
[](sys & s, const grad_vec & g, Formulation f, Real ct, Real nt,
Uint max, Dim_t verb) -> typename sys::StrainField_t & {
return newton_cg(s, g, f, ct, nt, max, verb);
},
"system"_a,
"ΔF₀"_a,
"formulation"_a,
"cg_tol"_a,
"newton_tol"_a,
"maxiter"_a=0,
"verbose"_a=0);
}
template <Dim_t sdim>
void add_de_geus_helper(py::module & mod) {
std::stringstream name_stream {};
name_stream << "de_geus" << sdim << "d";
constexpr Dim_t mdim{sdim};
using sys = SystemBase<sdim, mdim>;
using grad = Grad_t<sdim>;
using grad_vec = Grad_t<sdim>;
mod.def(name_stream.str().c_str(),
[](sys & s, const grad & g, Formulation f, Real ct, Real nt,
Uint max, Dim_t verb) -> typename sys::StrainField_t & {
return de_geus(s, g, f, ct, nt, max, verb);
},
"system"_a,
"ΔF₀"_a,
"formulation"_a,
"cg_tol"_a,
"newton_tol"_a,
"maxiter"_a=0,
"verbose"_a=0);
mod.def(name_stream.str().c_str(),
[](sys & s, const grad_vec & g, Formulation f, Real ct, Real nt,
Uint max, Dim_t verb) -> typename sys::StrainField_t & {
return de_geus(s, g, f, ct, nt, max, verb);
},
"system"_a,
"ΔF₀"_a,
"formulation"_a,
"cg_tol"_a,
"newton_tol"_a,
"maxiter"_a=0,
"verbose"_a=0);
}
template <Dim_t dim>
void add_solver_helper(py::module & mod) {
add_newton_cg_helper<dim>(mod);
add_de_geus_helper <dim>(mod);
}
void add_solvers(py::module & mod) {
add_solver_helper<twoD >(mod);
add_solver_helper<threeD>(mod);
}
PYBIND11_PLUGIN(solvers) {
py::module::import("common");
py::module::import("system");
py::module mod("solvers", "bindings for solvers");
add_solvers(mod);
return mod.ptr();
}
Event Timeline
Log In to Comment