diff --git a/packages/core.cmake b/packages/core.cmake index f81e09c..9d38740 100644 --- a/packages/core.cmake +++ b/packages/core.cmake @@ -1,223 +1,224 @@ #=============================================================================== # @file core.cmake # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date Mon Oct 13 10:50:54 2014 # # @brief Core package # # @section LICENSE # # Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # LibMultiScale is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # LibMultiScale 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 Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>. # #=============================================================================== package_declare(core NOT_OPTIONAL DESCRIPTION "core package for LibMultiScale") set(LIBMULTISCALE_CONTINUUM_HDRS_LIST_CORE common/container_mesh.hh ) set(LIBMULTISCALE_GEOMETRY_HDRS_LIST_CORE geometry/geom_inter.hh geometry/cylinder.hh geometry/geometry.hh geometry/geom_sub.hh geometry/geom_composed.hh geometry/chaudron.hh geometry/ellipsoid.hh geometry/cube.hh geometry/geom_union.hh geometry/ball.hh geometry/cube_surface.hh ) set(LIBMULTISCALE_CORE_FILES common/lm_type_caster.hh common/lm_file.hh common/lm_file.cc common/lm_fwd.hh common/lm_libc.cc common/action_interface.cc common/action_interface.hh common/visitor_libmultiscale.hh common/model_list.hh common/id_manager.hh common/lm_log.hh common/lm_log.cc common/lm_ostream_types.hh common/lm_macros.hh common/lm_types.hh common/lm_globals.hh common/lm_globals.cc common/lm_common.hh common/domain_interface.hh common/domain_interface.cc common/ref_subset.cc common/ref_subset.hh common/ref_set.cc common/ref_set.hh common/reference_manager.cc common/reference_manager.hh common/reference_manager_interface.hh common/attached_object.hh common/ref_point.hh common/ref_point_data.hh common/ref_element.hh common/component_libmultiscale.hh common/lm_functions.cc common/lm_functions.hh common/lm_timer.cc common/lm_timer.hh common/lm_object.hh parser/lm_parser.cc parser/lm_parser_inline_impl.hh parser/parse_result.hh parser/xml_parser_restart.cc parser/algebraic_parser.cc parser/lm_parsable.cc parser/xml_parser_restart.hh parser/lm_parsable.hh parser/lm_parsable_inline_impl.hh parser/algebraic_parser.hh parser/xml_parser.hh parser/lm_parser.hh parser/lm_parameter.hh parser/lm_defaults.hh + parser/lm_defaults.cc # ${LIBMULTISCALE_MD_HDRS_LIST_CORE} md/domain_md_interface.hh md/spatial_filter_atomic.cc md/domain_md.cc md/trace_atom.cc md/domain_md_interface.cc md/container_neighbor_atoms.hh md/trace_atom.hh md/domain_md.hh md/spatial_filter_atomic.hh md/ref_atom.hh md/container_neighbor_atoms_interface.hh md/domain_md_interface.hh ${LIBMULTISCALE_GEOMETRY_HDRS_LIST_CORE} geometry/geometry_manager.cc geometry/spatial_grid_libmultiscale.hh geometry/geometry_manager.hh geometry/spatial_grid.hh geometry/spatial_grid.cc geometry/geometry.cc geometry/cube.cc geometry/ball.cc geometry/cylinder.cc geometry/geom_inter.cc geometry/geom_sub.cc geometry/geom_union.cc geometry/geom_composed.cc geometry/surface.hh geometry/surface.cc geometry/cube_surface.cc ${LIBMULTISCALE_CONTINUUM_HDRS_LIST_CORE} continuum/domain_continuum.cc continuum/domain_continuum_interface.cc continuum/ref_node_continuum.hh continuum/ref_elem_fe.hh continuum/domain_continuum.hh continuum/domain_continuum_interface.hh # ${LIBMULTISCALE_DD_HDRS_LIST_CORE} dd/domain_dd_interface.hh dd/domain_dd.hh dd/domain_dd.cc dd/domain_dd_interface.cc dd/ref_node_dd.hh dd/ref_elem_dd.hh factory/domain_multiscale.cc factory/factory_multiscale.cc factory/factory_multiscale.hh factory/domain_multiscale.hh units/units.hh units/units.cc units/units_converter.hh units/units_converter.cc units/quantity.hh communicator/comm_buffer.hh communicator/communicator.hh communicator/communicator.cc communicator/pack_buffer.hh communicator/comm_group.cc communicator/comm_group.hh container/container_array.hh container/iterator_array_base_type.hh container/container.hh container/iterator_array.hh container/field.hh fmm/fmm_multigrid.hh fmm/fmm_interface.hh fmm/moments.hh fmm/fmm.hh fmm/radial_function.hh math/low_pass_filter.hh math/cubic_spline.hh math/full_matrix.hh math/full_matrix_inline_impl.hh math/function_interface.hh math/band_matrix.hh math/hanning_window.hh math/constant_function.hh math/gaussian_function.hh math/array.hh math/array.cc math/product_function.hh math/dispersion_relation.hh math/spline_function.hh math/diag_matrix.hh math/tensor.hh math/hamming_window.hh math/math_tools.hh math/math_tools.cc math/matrix.c math/matrix.hh math/matrix_blaswrapper.h boost/for_each2.hpp ) set(LIBMULTISCALE_GEOMETRY_LIST_CORE "((Cylinder,CYLINDER))" "((Cube,CUBE))" "((Ball,BALL))" "((GeomSub,SUB))" "((GeomInter,INTER))" "((GeomUnion,UNION))" "((CubeSurface,CUBE_SURFACE))" ) package_declare_sources(core ${LIBMULTISCALE_CORE_FILES}) set_module_headers_from_package(geometry core ${LIBMULTISCALE_GEOMETRY_HDRS_LIST_CORE}) set_module_headers_from_package(continuum core ${LIBMULTISCALE_CONTINUUM_HDRS_LIST_CORE}) declare_boost_list_from_package(geometry core ${LIBMULTISCALE_GEOMETRY_LIST_CORE}) diff --git a/src/common/domain_interface.cc b/src/common/domain_interface.cc index 7dbc4f1..74b0ecd 100644 --- a/src/common/domain_interface.cc +++ b/src/common/domain_interface.cc @@ -1,98 +1,98 @@ /** * @file domain_interface.cc * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @date Mon Sep 08 23:45:56 2014 * * @brief This is the interface to all domain (model/plugins) * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * LibMultiScale is free software: you can redistribute it and/or modify it * under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * LibMultiScale 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>. * */ #include "domain_interface.hh" #include "cube.hh" #include "lm_common.hh" /* -------------------------------------------------------------------------- */ __BEGIN_LIBMULTISCALE__ /* -------------------------------------------------------------------------- */ DomainInterface::DomainInterface(CommGroup & group) : group_id(group) { restartfile = ""; } /* -------------------------------------------------------------------------- */ DomainInterface::~DomainInterface() {} /* -------------------------------------------------------------------------- */ Real DomainInterface::getEpot() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ void DomainInterface::performStep1() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ void DomainInterface::performStep2() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ void DomainInterface::performStep3() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ void DomainInterface::performStep4() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ void DomainInterface::performStep5() { LM_TOIMPLEMENT; } /* -------------------------------------------------------------------------- */ -UInt DomainInterface::getType() { return type; } +// UInt DomainInterface::getType() { return type; } /* -------------------------------------------------------------------------- */ CommGroup & DomainInterface::getCommGroup() { return group_id; } /* -------------------------------------------------------------------------- */ bool DomainInterface::shouldRestart() { return restartfile.size(); } /* -------------------------------------------------------------------------- */ const std::string &DomainInterface::getRestartFile() { return restartfile; } /* -------------------------------------------------------------------------- */ void DomainInterface::printself(std::ostream &stream, int indent) const {} /* -------------------------------------------------------------------------- */ /* LMDESC DomainInterface This section describe the section that is associated with every model. */ void DomainInterface::declareParams() { /* LMKEYWORD RESTART_FILE Specifies a filename to perform a restart just after initialization. */ this->parseKeyword("RESTART_FILE", restartfile, ""); /* LMKEYWORD RESTART_CONTINUE_IF_NOTFOUND Set a flag that allow RESTART routine to ignore the absence of a file while restarting. If the restart file is not existing no restart procedure is launched at and a warning message is outputed. */ this->parseTag("RESTART_CONTINUE_IF_NOTFOUND", restart_continue_if_notfound, false); } /* -------------------------------------------------------------------------- */ __END_LIBMULTISCALE__ diff --git a/src/common/domain_interface.hh b/src/common/domain_interface.hh index a1b7241..df43527 100644 --- a/src/common/domain_interface.hh +++ b/src/common/domain_interface.hh @@ -1,210 +1,210 @@ /** * @file domain_interface.hh * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @date Mon Sep 08 23:40:22 2014 * * @brief This is the interface to all domain (model/plugins) * * @section LICENSE * * Copyright INRIA and CEA * * The LibMultiScale is a C++ parallel framework for the multiscale * coupling methods dedicated to material simulations. This framework * provides an API which makes it possible to program coupled simulations * and integration of already existing codes. * * This Project was initiated in a collaboration between INRIA Futurs Bordeaux * within ScAlApplix team and CEA/DPTA Ile de France. * The project is now continued at the Ecole Polytechnique Fédérale de Lausanne * within the LSMS/ENAC laboratory. * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL-C * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, * that may mean that it is complicated to manipulate, and that also * therefore means that it is reserved for developers and experienced * professionals having in-depth computer knowledge. Users are therefore * encouraged to load and test the software's suitability as regards their * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. * */ /* -------------------------------------------------------------------------- */ #ifndef DOMAIN_INTERFACE_H #define DOMAIN_INTERFACE_H /* -------------------------------------------------------------------------- */ #include "comm_group.hh" #include "component_libmultiscale.hh" #include "lm_parsable.hh" /* -------------------------------------------------------------------------- */ __BEGIN_LIBMULTISCALE__ /* -------------------------------------------------------------------------- */ template <typename IT> class FactoryMultiScale; class FilterInterface; class ActionInterface; class Cube; /* -------------------------------------------------------------------------- */ /** * Class DomainInterface * is the most generic interface to domains */ class DomainInterface : public Parsable, public Component { public: /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ DomainInterface(CommGroup &group_id); virtual ~DomainInterface(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ //! initialization method virtual void init() = 0; //! generic access to potential energy virtual Real getEpot(); //! virtual first step of a domain virtual void performStep1(); //! virtual second step of a domain virtual void performStep2(); //! virtual third step of a domain virtual void performStep3(); //! virtual fourth step of a domain virtual void performStep4(); //! virtual fifth step of a domain virtual void performStep5(); //! set internal timestep to a given value virtual void setTimeStep(Real ts) = 0; //! set current timestep to a given value virtual void setCurrentStep(UInt ts) = 0; //! get internal timestep to a given value virtual Real getTimeStep() = 0; //! get current timestep to a given value virtual UInt getCurrentStep() = 0; //! restart from xml file function virtual void readXMLFile(const std::string &filename) = 0; /** the type of code used. Currently could be only of two kinds Atomic or Continu, for MD and continuum simulations */ //! type of simulation - UInt getType(); + //UInt getType(); /** return a group id referencing a subset of processor where a domain is ran on */ //! group of processor ID CommGroup &getCommGroup(); //! return the size of the domain ususefull to deal with pbc virtual Cube getDomainBoundingBox() = 0; //! return the size of the box associated to current processor virtual Cube getSubDomainBoundingBox() = 0; //! return the size of the box associated to current processor virtual void setDomainBoundingBox(const Cube &cube) = 0; //! return the size of the box associated to current processor virtual void setSubDomainBoundingBox(const Cube &cube) = 0; //! set the parameters common to all domains virtual void declareParams(); //! add points for vector of reals virtual void addPoints(const ContainerArray<Real> &allPositions) { LM_TOIMPLEMENT; }; /* -------------------------------------------------------------------------- */ // old material part /* ------------------------------------------------------------------------ */ bool shouldRestart(); //! function that return the restart file name const std::string &getRestartFile(); /* -------------------------------------------------------------------------- */ // functions for AMELCG /* ------------------------------------------------------------------------ */ //! return product of force by descent direction (for AMELCG) */ virtual Real getFdotDir() = 0; //! return max of forces (for AMELCG) virtual Real getFMax() = 0; //! return max of direction vector (for AMELCG) virtual Real getDirMax() = 0; //! return norm 2 of forces (for AMELCG) virtual Real getFNorm2() = 0; //! return stuff for AMELCG virtual Real getFdotOldF() = 0; //! update direction AMELCG virtual void updateDirection(Real beta) = 0; //! return stuff for AMELCG virtual void saveForceVector() = 0; //! displace in descent direction with given magnitude virtual void displaceTowardsDirection(Real alpha) = 0; //! get amount of work done by external forces /* virtual double getExternalWork()=0; */ /* //! set amount of work done by external forces */ /* virtual void setExternalWork(double work)=0; */ //! function to print the contain of the class virtual void printself(std::ostream &stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: //! type identifier UInt type; // type fe, md meshless, xfem /* -------------------------------------------------------------------------- */ // old material part /* ------------------------------------------------------------------------ */ //! restartfile name std::string restartfile; //! restart if exists flag bool restart_continue_if_notfound; private: //! number for private group of communication CommGroup &group_id; }; /* -------------------------------------------------------------------------- */ inline std::ostream &operator<<(std::ostream &os, DomainInterface &obj) { obj.printself(os); return os; } /* -------------------------------------------------------------------------- */ __END_LIBMULTISCALE__ #endif // DOMAIN_INTERFACE_H diff --git a/src/parser/lm_defaults.cc b/src/parser/lm_defaults.cc new file mode 100644 index 0000000..764be18 --- /dev/null +++ b/src/parser/lm_defaults.cc @@ -0,0 +1,113 @@ +#include "lm_defaults.hh" +#include "compute_impulse.hh" +#include "cube_surface.hh" +#include "lm_type_caster.hh" +__BEGIN_LIBMULTISCALE__ + +/* -------------------------------------------------------------------------- */ +#define ARG(...) __VA_ARGS__ + +#define DECLARE_ASSIGN(T) \ + template <> void assign_value<T>(T & to_set, pybind11::object val) { \ + Assign<T>::doit(to_set, pybind11::cast<T>(val)); \ + } + +DECLARE_ASSIGN(ARG(std::vector<FieldType>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Length, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Mass, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Energy, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Time, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<MassDensity, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Force, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Pressure, Real>)); +DECLARE_ASSIGN(ARG(PhysicalScalar<Temperature, Real>)); + +DECLARE_ASSIGN(ARG(Quantity<Length, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Mass, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Energy, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Time, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<MassDensity, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Force, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Pressure, 1u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Temperature, 1u, Real>)); + +DECLARE_ASSIGN(ARG(Quantity<Length, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Mass, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Energy, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Time, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<MassDensity, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Force, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Pressure, 2u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Temperature, 2u, Real>)); + +DECLARE_ASSIGN(ARG(Quantity<Length, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Mass, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Energy, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Time, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<MassDensity, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Force, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Pressure, 3u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Temperature, 3u, Real>)); + +DECLARE_ASSIGN(ARG(Quantity<Length, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Mass, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Energy, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Time, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<MassDensity, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Force, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Pressure, 6u, Real>)); +DECLARE_ASSIGN(ARG(Quantity<Temperature, 6u, Real>)); + +DECLARE_ASSIGN(ARG(Vector<1u, UInt>)); +DECLARE_ASSIGN(ARG(Vector<2u, UInt>)); +DECLARE_ASSIGN(ARG(Vector<3u, UInt>)); + +DECLARE_ASSIGN(ARG(Vector<1u>)); +DECLARE_ASSIGN(ARG(Vector<2u>)); +DECLARE_ASSIGN(ARG(Vector<3u>)); + +DECLARE_ASSIGN(CubeSurface::Face); +DECLARE_ASSIGN(Operator); +DECLARE_ASSIGN(DOFType); + +DECLARE_ASSIGN(int); +DECLARE_ASSIGN(char); +DECLARE_ASSIGN(long); +DECLARE_ASSIGN(bool); +DECLARE_ASSIGN(UInt); +DECLARE_ASSIGN(std::string); +DECLARE_ASSIGN(Real); +DECLARE_ASSIGN(std::vector<int>); +DECLARE_ASSIGN(std::vector<UInt>); +DECLARE_ASSIGN(std::vector<std::string>); +DECLARE_ASSIGN(Impulse::ImpulseType); +DECLARE_ASSIGN(IntegrationSchemeMask); +DECLARE_ASSIGN(UnitSystem); +DECLARE_ASSIGN(FieldType); + +DECLARE_ASSIGN(ARG(std::map<std::string, ArgumentContainer *>)) + +#undef DECLARE_ASSIGN + +#define DECLARE_ASSIGN(type, Dim) \ + template <> \ + void assign_value<type[Dim]>(type(&to_set)[Dim], pybind11::object val) { \ + type l[Dim]; \ + std::vector<type> vec = pybind11::cast<std::vector<type>>(val); \ + for (UInt i = 0; i < Dim; ++i) \ + l[i] = vec[i]; \ + assign_value(to_set, l); \ + } + +DECLARE_ASSIGN(bool, 3); +DECLARE_ASSIGN(Real, 3); +DECLARE_ASSIGN(Real, 2); +DECLARE_ASSIGN(int, 6); +DECLARE_ASSIGN(int, 3); +DECLARE_ASSIGN(std::string, 2); +DECLARE_ASSIGN(std::string, 3); + +#undef DECLARE_ASSIGN +#undef ARG + +__END_LIBMULTISCALE__ diff --git a/src/parser/lm_defaults.hh b/src/parser/lm_defaults.hh index 76f85b0..847b62e 100644 --- a/src/parser/lm_defaults.hh +++ b/src/parser/lm_defaults.hh @@ -1,253 +1,244 @@ /** * @file lm_defaults.hh * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @date Tue Oct 29 18:26:07 2013 * * @brief Handles the defaults for the parsing system * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * LibMultiScale is free software: you can redistribute it and/or modify it * under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * LibMultiScale 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>. * */ #ifndef __LIBMULTISCALE_LM_DEFAULTS_HH__ #define __LIBMULTISCALE_LM_DEFAULTS_HH__ /* -------------------------------------------------------------------------- */ #include "quantity.hh" #include <map> -#include <pybind11/pybind11.h> -#include <pybind11/stl.h> #include <vector> -#include "lm_type_caster.hh" /* -------------------------------------------------------------------------- */ +// backward declaration + +namespace pybind11 { +class object; +class dict; +} // namespace pybind11 + +namespace py = pybind11; __BEGIN_LIBMULTISCALE__ /* -------------------------------------------------------------------------- */ template <typename T> struct Assign { static void doit(T &to_set, const T &val) { to_set = val; } }; template <typename T, UInt nb> struct Assign<T[nb]> { static void doit(T to_set[nb], const T val[nb]) { for (UInt i = 0; i < nb; ++i) to_set[i] = val[i]; } }; template <typename T> void assign_value(T &to_set, const T &val) { Assign<T>::doit(to_set, val); } -/* -------------------------------------------------------------------------- */ -template <typename T> -std::enable_if_t<not std::is_array<T>::value> -assign_value(T &to_set, pybind11::object val) { - Assign<T>::doit(to_set, pybind11::cast<T>(val)); -} - /* -------------------------------------------------------------------------- */ template <typename T> -std::enable_if_t<std::is_array<T>::value> assign_value(T &to_set, - pybind11::object val) { - using _type = std::remove_extent_t<T>; - constexpr UInt _extent = std::extent<T>::value; - _type l[_extent]; - std::vector<_type> vec = pybind11::cast<std::vector<_type>>(val); - for (UInt i = 0; i < _extent; ++i) - l[i] = vec[i]; - assign_value(to_set, l); -} +void assign_value(T &to_set, pybind11::object val); /* -------------------------------------------------------------------------- */ template <typename T> class default_val { public: default_val() { is_set = false; }; default_val(const T &v) { is_set = true; assign_value(val, v); }; bool setDefault(T &to_set) const { if (!this->is_set) return false; assign_value(to_set, val); return true; }; const T &getVal() const { return val; }; private: bool is_set; T val; }; + + /* -------------------------------------------------------------------------- */ template <typename T, typename V> struct MakeDefault { static inline default_val<T> make_default(const V &def); }; template <typename T, typename V> std::enable_if_t<!std::is_same<T, V>::value, default_val<T>> make_default(const V &def) { return MakeDefault<T, V>::make_default(def); } template <typename T> default_val<T> make_default(const T &def) { return def; } /* -------------------------------------------------------------------------- */ template <typename T, UInt nb> struct MakeDefault<Vector<nb, T>, T> { using type = Vector<nb, T>; using default_type = default_val<type>; static default_type make_default(const T &def) { type tmp = def; return default_type(tmp); }; }; template <typename T, UInt nb> struct MakeDefault<Vector<nb, T>, std::vector<T>> { using type = Vector<nb, T>; using default_type = default_val<type>; static default_val<Vector<nb, T>> make_default(const std::vector<T> &def) { if (def.size() < nb) LM_FATAL("internal error: " << def.size() << " < " << nb); type tmp = type::Zero(); for (UInt i = 0; i < nb; ++i) tmp[i] = def[i]; return default_type(tmp); }; }; template <PhysicalQuantity q, typename T, UInt nb> struct MakeDefault<Quantity<q, nb, T>, T> { using type = Quantity<q, nb, T>; using default_type = default_val<type>; static default_type make_default(const T &def) { type tmp = def; return default_type(tmp); }; }; template <PhysicalQuantity q, typename T, UInt nb> struct MakeDefault<Quantity<q, nb, T>, std::vector<T>> { using type = Quantity<q, nb, T>; using default_type = default_val<type>; static default_type make_default(const std::vector<T> &def) { if (def.size() < nb) LM_FATAL("internal error: " << def.size() << " < " << nb); type tmp = type::Zero(); for (UInt i = 0; i < nb; ++i) tmp[i] = def[i]; return default_type(tmp); }; }; template <> struct MakeDefault<std::string, char const *> { using default_type = default_val<std::string>; static default_type make_default(const std::string &def) { return def; }; }; template <> struct MakeDefault<IntegrationSchemeMask, IntegrationSchemeStage> { using default_type = default_val<IntegrationSchemeMask>; static default_type make_default(const IntegrationSchemeStage &stage) { return default_type(stage); } }; /* -------------------------------------------------------------------------- */ template <typename T, UInt nb> struct MakeDefault<T[nb], std::vector<T>> { using type = T[nb]; using default_type = default_val<type>; static default_type make_default(const std::vector<T> &def) { if (def.size() < nb) LM_FATAL("internal error: " << def.size() << " < " << nb); type tmp; for (UInt i = 0; i < nb; ++i) tmp[i] = def[i]; return default_type(tmp); }; }; /* -------------------------------------------------------------------------- */ template <typename T> struct type_converter_helper { using type = T; }; template <> struct type_converter_helper<char *> { using type = std::string; }; template <> struct type_converter_helper<const char *> { using type = std::string; }; template <typename T> auto VEC_DEFAULTS(std::initializer_list<T> l) { return Vector<l.size(), T>(l); } template <typename T> auto VEC_DEFAULTS(T arg) { using type = typename type_converter_helper<T>::type; std::vector<type> res; res.push_back(arg); return res; } template <typename T, typename... Args> auto VEC_DEFAULTS(T arg1, Args... args) { using type = typename type_converter_helper<T>::type; std::vector<type> res; res.push_back(arg1); auto res2 = VEC_DEFAULTS(args...); res.insert(res.end(), res2.begin(), res2.end()); return res; } __END_LIBMULTISCALE__ #endif /* __LIBMULTISCALE_LM_DEFAULTS_HH__ */