diff --git a/python/SConscript b/python/SConscript index d730297..4081cad 100644 --- a/python/SConscript +++ b/python/SConscript @@ -1,68 +1,69 @@ # -*- mode:python; coding: utf-8 -*- # vim: set ft=python: # @file # @section LICENSE # # Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from __future__ import print_function from os.path import abspath from SCons.Script import Import, Split, Copy Import('main_env') # Pybind11 wrapper env_pybind = main_env.Clone(SHLIBPREFIX='') env_pybind.Tool(pybind11) pybind_sources = Split(""" tamaas_module.cpp wrap/core.cpp wrap/percolation.cpp wrap/surface.cpp wrap/model.cpp wrap/solvers.cpp +wrap/compute.cpp wrap/test_features.cpp """) if main_env['CXX'] != 'icpc': pybind_sources += ["wrap/bem.cpp"] env_pybind.AppendUnique(CPPDEFINES="LEGACY_BEM") # Building the pybind library tamaas_wrap = env_pybind.SharedLibrary( target='tamaas/_tamaas', source=pybind_sources, LIBS=['Tamaas'], RPATH=[abspath('../src')] ) # For some reason link happens too early Import('libTamaas') env_pybind.Depends(tamaas_wrap, libTamaas) # Copying the __init__.py file with extra python classes copy_env = env_pybind.Clone( PRINT_CMD_LINE_FUNC=main_env['gen_print']("Copying", "red", main_env)) copy_env.Command(Dir('tamaas'), Dir('#python/tamaas'), Copy("$TARGET", "$SOURCE")) copy_env.Command('setup.py', '#python/setup.py', Copy("$TARGET", "$SOURCE")) # Cleaning the tamaas python package main_env.Execute(Delete('tamaas')) diff --git a/python/tamaas/compute.py b/python/tamaas/compute.py new file mode 100644 index 0000000..03b41ee --- /dev/null +++ b/python/tamaas/compute.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# @file +# @section LICENSE +# +# Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +from ._tamaas.compute import * # noqa diff --git a/python/tamaas_module.cpp b/python/tamaas_module.cpp index f5c4f4b..1638db8 100644 --- a/python/tamaas_module.cpp +++ b/python/tamaas_module.cpp @@ -1,82 +1,83 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "tamaas.hh" #include "tamaas_info.hh" #include "wrap.hh" /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ namespace tamaas { namespace py = pybind11; /// Creating the tamaas python module PYBIND11_MODULE(_tamaas, mod) { mod.doc() = "Tamaas module for python"; // Wrapping the base methods mod.def("initialize", &initialize, py::arg("num_threads") = 0, "Initialize tamaas with desired number of threads"); mod.def("finalize", &finalize, "Final cleanup"); // Wrapping release information auto info = py::class_(mod, "TamaasInfo"); #ifndef STRIP_INFO info.attr("build_type") = TamaasInfo::build_type; info.attr("branch") = TamaasInfo::branch; info.attr("commit") = TamaasInfo::commit; info.attr("diff") = TamaasInfo::diff; info.attr("remotes") = TamaasInfo::remotes; #else info.attr("build_type") = ""; info.attr("branch") = ""; info.attr("commit") = ""; info.attr("diff") = ""; info.attr("remotes") = ""; #endif // Wrapping tamaas components wrap::wrapCore(mod); wrap::wrapPercolation(mod); wrap::wrapSurface(mod); wrap::wrapModel(mod); wrap::wrapSolvers(mod); + wrap::wrapCompute(mod); /// Wrapping test features wrap::wrapTestFeatures(mod); // Legacy wrap py::class_>(mod, "smart_pointer_UInt") .def("assign", &wrap::smart_pointer::assign); py::class_>(mod, "smart_pointer_Real") .def("assign", &wrap::smart_pointer::assign); py::class_>(mod, "smart_pointer_long") .def("assign", &wrap::smart_pointer::assign); #if defined(LEGACY_BEM) wrap::wrapBEM(mod); #endif } } // namespace tamaas diff --git a/python/wrap.hh b/python/wrap.hh index 2ca2cbc..35f63a1 100644 --- a/python/wrap.hh +++ b/python/wrap.hh @@ -1,73 +1,74 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __WRAP_HH__ #define __WRAP_HH__ /* -------------------------------------------------------------------------- */ #include "tamaas.hh" #include "numpy.hh" #include "cast.hh" /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ namespace tamaas { namespace wrap { namespace py = pybind11; /// For naming classes templated with dimension inline std::string makeDimensionName(const std::string& name, UInt dim) { std::stringstream str; str << name << dim << "D"; return str.str(); } template class smart_pointer { public: smart_pointer(T* ptr) : ptr(ptr) {} void assign(T val) { *ptr = val; } private: T* ptr; }; /* -------------------------------------------------------------------------- */ /* Prototypes for wrapping of tamaas components */ /* -------------------------------------------------------------------------- */ void wrapCore(py::module& mod); void wrapPercolation(py::module& mod); void wrapSurface(py::module& mod); void wrapModel(py::module& mod); void wrapSolvers(py::module& mod); void wrapTestFeatures(py::module& mod); +void wrapCompute(py::module& mod); #if defined(LEGACY_BEM) void wrapBEM(py::module& mod); #endif } // namespace wrap } // namespace tamaas #endif // __WRAP_HH__ diff --git a/src/core/eigenvalues.hh b/python/wrap/compute.cpp similarity index 61% rename from src/core/eigenvalues.hh rename to python/wrap/compute.cpp index fd464fc..6ff493c 100644 --- a/src/core/eigenvalues.hh +++ b/python/wrap/compute.cpp @@ -1,49 +1,46 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ -#ifndef EIGENVALUES_HH -#define EIGENVALUES_HH +#include "computes.hh" +#include "wrap.hh" /* -------------------------------------------------------------------------- */ -#include "eigenvalues.hh" -#include "grid.hh" -#include "loop.hh" -#include "model_type.hh" -#include "ranges.hh" -#include "static_types.hh" -#include namespace tamaas { +namespace wrap { -/// Compute eigenvalues of a symmetric matrix field -template -void eigenvalues(Grid& eigs, const Grid& field) { - Loop::loop([](auto eig, auto f) { eig = eigenvalues(f); }, - range>(eigs), - range>(field)); -} - -void eigenvalues(model_type type, GridBase& eigs, - const GridBase& field); +using namespace py::literals; +void wrapCompute(py::module& mod) { + auto compute_mod = mod.def_submodule("compute"); + compute_mod.def( + "eigenvalues", + [](model_type type, Grid& eigs, const Grid& field) { + eigenvalues(type, eigs, field); + }, + "model_type"_a, "eigenvalues_out"_a, "field"_a); + compute_mod.def("von_mises", + [](model_type type, Grid& vm, + const Grid& field) { vonMises(type, vm, field); }, + "model_type"_a, "von_mises"_a, "field"_a); +} +} // namespace wrap } // namespace tamaas - -#endif /* EIGENVALUES_HH */ diff --git a/python/wrap/test_features.cpp b/python/wrap/test_features.cpp index 14510b8..c9cfdbe 100644 --- a/python/wrap/test_features.cpp +++ b/python/wrap/test_features.cpp @@ -1,120 +1,110 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "boussinesq.hh" -#include "eigenvalues.hh" #include "isotropic_hardening.hh" #include "kelvin.hh" #include "mindlin.hh" #include "model.hh" #include "model_type.hh" #include "volume_potential.hh" #include "wrap.hh" /* -------------------------------------------------------------------------- */ namespace tamaas { namespace wrap { using namespace py::literals; template