diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f5b134..8289470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,159 +1,168 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date Mon Jul 28 12:20:03 2014 # # @brief This is the main CMake configuration file for LM # # @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/>. # #=============================================================================== #=============================================================================== # Project definition #=============================================================================== cmake_minimum_required(VERSION 2.8) project(LibMultiScale) enable_language(CXX) #=============================================================================== # Misc. config for cmake #=============================================================================== set(LIBMULTISCALE_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries.") #### temporary ################################################# INCLUDE_DIRECTORIES ("/usr/include/eigen3") ################################################################ include(LibMultiScaleMacros) include(CMakeFlagsHandling) include(CMakeVersionGenerator) include(CMakeDebugMessages) include(CMakePackagesSystem) #=============================================================================== # Version Number #=============================================================================== # LIBMULTISCALE version number. An even minor number corresponds to releases. set(LIBMULTISCALE_MAJOR_VERSION 2) set(LIBMULTISCALE_MINOR_VERSION 1) set(LIBMULTISCALE_BUILD_VERSION 0) define_project_version() #=============================================================================== # Options #=============================================================================== option(LIBMULTISCALE_OPTIMIZE "Set this if you want libmultiscale to be fully optimized" OFF) if(LIBMULTISCALE_OPTIMIZE) add_definitions(-DLM_OPTIMIZED) endif(LIBMULTISCALE_OPTIMIZE) add_flags(cxx -Wall -Wextra) add_flags(cxx -fPIC) add_flags(cxx -Wno-overloaded-virtual) # add_flags(cxx -Wno-literal-suffix) add_flags(cxx -std=c++14) add_flags(SHARED_LINKER -fPIC) if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") add_flags(cxx -vec-report=0) endif() #=============================================================================== # Release file target #=============================================================================== set(GET_RELEASE_INFO ${PROJECT_SOURCE_DIR}/get_release_info.sh) set(RELEASE_FILE ${PROJECT_BINARY_DIR}/release.cc) find_program(uuencode_exec "uuencode") mark_as_advanced(uuencode_exec) if(uuencode_exec) add_custom_command( OUTPUT ${RELEASE_FILE} COMMAND bash ${GET_RELEASE_INFO} ${uuencode_exec} ${PROJECT_BINARY_DIR} > ${RELEASE_FILE} DEPENDS ${LIBMULTISCALE_DEPEND_FILES} ${GET_RELEASE_INFO} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) else() message("install uuencode on the building machine to have access to release information.") file(WRITE "${RELEASE_FILE}" " #include <string> std::string lm_release_info = \" install uuencode on the building machine to have access to release information.\"; ") endif() add_custom_target(RELEASE_INFO DEPENDS ${RELEASE_FILE}) #=============================================================================== # LibMultiScale library #=============================================================================== #cmake_activate_debug_message(TestSystem) cmake_deactivate_debug_message() package_list_packages(${PROJECT_SOURCE_DIR}/packages EXTRA_PACKAGES_FOLDER ${PROJECT_SOURCE_DIR}/extra_packages) add_subdirectory(src) set(LIBMULTISCALE_DEPEND_FILES "") +#=============================================================================== +# LibMultiScale AMEL + LMPOST +#=============================================================================== + +package_is_activated(pybind11 PYBIND_ACTIVATED) +if(PYBIND_ACTIVATED) + add_subdirectory(python) +endif() + #=============================================================================== # LibMultiScale AMEL + LMPOST #=============================================================================== add_subdirectory(clients) #=============================================================================== # Documentation #=============================================================================== option(LIBMULTISCALE_DOCUMENTATION "Build documentation." OFF) if(LIBMULTISCALE_DOCUMENTATION) add_subdirectory(doc) endif(LIBMULTISCALE_DOCUMENTATION) #=============================================================================== # Tests #=============================================================================== package_declare(TESTS DESCRIPTION "Activate the tests" DEFAULT OFF ) package_get_option_name(TESTS _option_name) if(${_option_name}) enable_testing() include(CTest) add_subdirectory(test) mark_as_advanced(BUILD_TESTING) endif() #=============================================================================== # CPack #=============================================================================== include(LibMultiScaleCPack) diff --git a/clients/AMEL.py b/clients/AMEL.py index 91be1dc..2237bb1 100644 --- a/clients/AMEL.py +++ b/clients/AMEL.py @@ -1,3 +1,191 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +################################################################ +# ./python/AMEL.py +################################################################ +# author : Guillaume ANCIAUX (guillaume.anciaux@epfl.ch, g.anciaux@laposte.net) +# @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> +# +# @date Mon Sep 08 23:40:22 2014 +# +# @brief This describe the root objects to be combined +# into valid LM components +# +# @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/>. +################################################################ +import time +import datetime +import os +import argparse +import pylibmultiscale as lm +from mpi4py import MPI +################################################################ +lastdump = -1e30 +lastStep = 0 +nb_step = 0 +################################################################ + + +def printState(): + if lm.cvar.lm_my_proc_id != 0: + return + + global lastdump, lastStep, nb_step + gtime = time.time() + if (gtime - lastdump) < 2: + return + + nstep_done = - lastStep + lm.cvar.current_step + + info_steps = "{0:>2d} % - passing step {1:>5d}/{2:<5d}".format( + 100*lm.cvar.current_step/nb_step, + lm.cvar.current_step, nb_step) + + if lm.cvar.current_step > 0: + step_per_seconds = nstep_done/(gtime - lastdump) + time_per_step = datetime.timedelta( + seconds=(gtime - lastdump)/nstep_done) + remaining_time = time_per_step * (nb_step-lm.cvar.current_step) + step_per_seconds = "{0:.2f}".format(step_per_seconds) + info_steps += " {0: >5s} steps/seconds".format(step_per_seconds) + info_steps += " remaining {0}".format(remaining_time) + + print(info_steps) + + lastStep = lm.cvar.current_step + lastdump = gtime + +################################################################ + + +def Usage(): + + parser = argparse.ArgumentParser( + description='AMEL: LibMultiScale basic client, Python version') + parser.add_argument('input_file', + help='global config file of the simulation') + parser.add_argument('nsteps', type=int, + help='Number of step wanted to be run (>=0)') + + try: + args = parser.parse_args() + except SystemExit as e: + print("\nGenerated release file: release.info") + open('release.info', 'w').write(lm.release_info) + raise e + + return args.input_file, args.nsteps + +################################################################ + + +def main(): + + lm.loadModules() + + global nb_step + conf, nb_step = Usage() + + try: + os.mkdir('paraview') + except: + pass + + print(nb_step) + nb_step_next_event = nb_step + + comm = MPI.COMM_WORLD + comm.Barrier() + + dom = lm.DomainMultiScale.getManager() + dom.build(conf) + + print(type(dom)) + md = dom.getObject('md') + print(md.getEcin()) + print(type(md)) + cont = md.getContainer() + print(cont.size()) + for i in range(0, cont.size()/100): + at = cont.get(i) + print( + at.position(0).value(), + at.position(1).value(), + at.position(2).value()) + + actions = dom.getActionManager() + nb_step += lm.cvar.current_step + + comm.Barrier() + + shouldPrintState = True + min_dt = dom.getTimeStep() + + current_time = lm.cvar.current_step*min_dt + + for current_step in range(lm.cvar.current_step, nb_step): + lm.cvar.current_step = current_step + current_time += min_dt + + if shouldPrintState: + printState() + lm.cvar.current_stage = lm.PRE_DUMP + actions.action() + lm.cvar.current_stage = lm.PRE_STEP1 + actions.action() + + dom.performStep1() + dom.coupling(lm.COUPLING_STEP1) + + lm.cvar.current_stage = lm.PRE_STEP2 + actions.action() + + dom.performStep2() + dom.coupling(lm.COUPLING_STEP2) + + lm.cvar.current_stage = lm.PRE_STEP3 + actions.action() + + dom.performStep3() + + dom.coupling(lm.COUPLING_STEP3) + + lm.cvar.current_stage = lm.PRE_STEP4 + actions.action() + + dom.coupling(lm.COUPLING_STEP4) + + comm.Barrier() + + lm.cvar.current_stage = lm.PRE_DUMP + actions.action() + current_stage = lm.PRE_STEP1 + actions.action() + + dom.destroy() + + lm.closeModules() + print("Done") + +################################################################ + + +if __name__ == "__main__": + main() -import libmultiscale diff --git a/packages/pybind11.cmake b/packages/pybind11.cmake index 9572465..3d439a7 100644 --- a/packages/pybind11.cmake +++ b/packages/pybind11.cmake @@ -1,15 +1,15 @@ set(PYBIND11_PYTHON_VERSION ${LIBMULTISCALE_PREFERRED_PYTHON_VERSION} CACHE INTERNAL "") package_declare(pybind11 EXTERNAL - EXTRA_PACKAGE_OPTIONS ARGS "2.2;CONFIG" LINK_LIBRARIES pybind11::embed pybind11::module PREFIX pybind11 + EXTRA_PACKAGE_OPTIONS ARGS "2.2;CONFIG" LINK_LIBRARIES pybind11::embed PREFIX pybind11 DESCRIPTION "LibMultiScale's pybind11 interface" SYSTEM AUTO third-party/cmake/pybind11.cmake EXCLUDE_FROM_ALL ) package_add_third_party_script_variable(pybind11 PYBIND11_VERSION "v2.2") package_add_third_party_script_variable(pybind11 PYBIND11_GIT "https://github.com/pybind/pybind11.git") -package_declare_sources(pybind11 common/python.cc) + diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 0000000..8306320 --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,28 @@ +package_get_all_include_directories( + LIBMULTISCALE_INCLUDE_DIRS + ) + +package_get_all_source_files( + LIBMULTISCALE_SRCS + LIBMULTISCALE_PUBLIC_HDRS + LIBMULTISCALE_PRIVATE_HDRS + ) + +package_get_all_external_informations( + LIBMULTISCALE_EXTERNAL_INCLUDE_DIR + LIBMULTISCALE_EXTERNAL_LIBRARIES +) + +include_directories(${LIBMULTISCALE_INCLUDE_DIRS} ${LIBMULTISCALE_EXTERNAL_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/src) + +package_get_all_definitions(LIBMULTISCALE_DEFINITIONS) +foreach(_dep ${LIBMULTISCALE_DEFINITIONS}) + add_definitions(-D${_dep}) +endforeach() + +add_library(pylibmultiscale MODULE python.cc) +target_link_libraries(pylibmultiscale PRIVATE pybind11::module multiscale) +set_target_properties(pylibmultiscale PROPERTIES + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" + ) diff --git a/python/python.cc b/python/python.cc new file mode 100644 index 0000000..aee7f2b --- /dev/null +++ b/python/python.cc @@ -0,0 +1,31 @@ +#include "lm_common.hh" +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include "domain_multiscale.hh" + +namespace py = pybind11; +namespace lm = libmultiscale; + +void loadModules(){ + auto sys = py::module::import("sys"); + auto argv = sys.attr("argv"); + auto cpp_argv = py::cast<std::vector<std::string>>(argv); + std::vector<const char*> c_argv; + for (auto && v: cpp_argv){ + c_argv.push_back(v.c_str()); + } + lm::loadModules(cpp_argv.size(), const_cast<char**>(c_argv.data())); +} + +extern std::string lm_release_info; + +PYBIND11_MODULE(pylibmultiscale, m) { + m.doc() = "LibMultiScale python module"; + + m.def("loadModules", &loadModules, + "Load all the module dependencies of libmultiscale"); + + m.attr("release_info") = py::cast(lm_release_info); + + py::class_<lm::DomainMultiScale>(m, "DomainMultiScale"); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 297b0d1..d227c48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,141 +1,142 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date Wed Apr 03 23:50:25 2013 # # @brief This is the main CMake configuration file for LM library # # @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. # #=============================================================================== package_get_all_source_files( LIBMULTISCALE_SRCS LIBMULTISCALE_PUBLIC_HDRS LIBMULTISCALE_PRIVATE_HDRS ) package_get_all_include_directories( LIBMULTISCALE_INCLUDE_DIRS ) package_get_all_external_informations( LIBMULTISCALE_EXTERNAL_INCLUDE_DIR LIBMULTISCALE_EXTERNAL_LIBRARIES ) list(APPEND LIBMULTISCALE_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/src) set(_lists_list atom_model compute continuum_model coupler dd_model dumper filter stimulation geometry ) foreach(__list ${_lists_list}) generate_list(${__list} ${CMAKE_CURRENT_BINARY_DIR}/${__list}_list.hh) list(APPEND LIBMULTISCALE_LIST_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${__list}_list.hh) endforeach() set(_hdrs_lists_list continuum dd dumper filter md stimulation geometry coupler ) foreach(_hdrs_list ${_hdrs_lists_list}) generate_module_header_file(${_hdrs_list} ${CMAKE_CURRENT_BINARY_DIR}/lib_${_hdrs_list}.hh) list(APPEND LIBMULTISCALE_LIST_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/lib_${_hdrs_list}.hh) endforeach() #set(LIBMULTISCALE_INCLUDE_DIRS ${LIBMULTISCALE_INCLUDE_DIRS} PARENT_SCOPE) #set(LIBMULTISCALE_SRCS ${LIBMULTISCALE_SRCS} PARENT_SCOPE) #set(LIBMULTISCALE_HDRS ${LIBMULTISCALE_HDRS} PARENT_SCOPE) #set(LIBMULTISCALE_INLINE_SRCS ${LIBMULTISCALE_INLINE_SRCS} PARENT_SCOPE) # include_directories(${LIBMULTISCALE_INCLUDE_DIRS} ${LIBMULTISCALE_EXTERNAL_INCLUDE_DIR}) package_get_all_definitions(LIBMULTISCALE_DEFINITIONS) foreach(_dep ${LIBMULTISCALE_DEFINITIONS}) add_definitions(-D${_dep}) endforeach() set_source_files_properties(${RELEASE_FILE} PROPERTIES GENERATED 1) add_library(multiscale ${LIBMULTISCALE_SRCS} ${LIBMULTISCALE_INLINE_SRCS} ${RELEASE_FILE}) add_dependencies(multiscale RELEASE_INFO) target_link_libraries(multiscale ${LIBMULTISCALE_EXTERNAL_LIBRARIES} rt) if(LIBMULTISCALE_LIBRARY_PROPERTIE) set_target_properties(multiscale PROPERTIES ${LIBMULTISCALE_LIBRARY_PROPERTIES}) endif() set(LIBMULTISCALE_PUBLIC_HEADERS ${LIBMULTISCALE_HDRS} ${LIBMULTISCALE_LIST_HEADERS}) set_target_properties(multiscale PROPERTIES PUBLIC_HEADER "${LIBMULTISCALE_PUBLIC_HEADERS}") + install(TARGETS multiscale EXPORT LibMultiScaleLibraryDepends LIBRARY DESTINATION lib COMPONENT lib ARCHIVE DESTINATION lib COMPONENT lib PUBLIC_HEADER DESTINATION include/libmultiscale/ COMPONENT dev ) install(EXPORT LibMultiScaleLibraryDepends DESTINATION lib/libmultiscale COMPONENT dev) #Export for build tree package_get_all_export_list(export_list) export(TARGETS multiscale ${export_list} FILE "${CMAKE_BINARY_DIR}/LibMultiScaleLibraryDepends.cmake") export(PACKAGE LibMultiScale) diff --git a/src/common/lm_functions.cc b/src/common/lm_functions.cc index f3fcfae..6c0343c 100644 --- a/src/common/lm_functions.cc +++ b/src/common/lm_functions.cc @@ -1,212 +1,217 @@ /** * @file lm_functions.cc * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @date Mon Sep 08 23:40:22 2014 * * @brief This file contains the global scope functions * * @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 "geometry.hh" #include "geometry_manager.hh" #include "lm_common.hh" #include "lm_parser.hh" #include <mpi.h> #include <memory> #include <cxxabi.h> #include <regex> #include <pybind11/pybind11.h> #include <pybind11/embed.h> __BEGIN_LIBMULTISCALE__ namespace py = pybind11; /* -------------------------------------------------------------------------- */ // c++ typeinfo /* -------------------------------------------------------------------------- */ std::string demangle(const char* name) { int status = -4; // some arbitrary value to eliminate the compiler warning std::unique_ptr<char, void(*)(void*)> res { abi::__cxa_demangle(name, NULL, NULL, &status), std::free }; std::regex r("libmultiscale::"); auto demangled_name = res.get(); return (status==0) ? std::regex_replace(demangled_name,r,"") : name ; } /* -------------------------------------------------------------------------- */ // MPI macros /* -------------------------------------------------------------------------- */ void loadMPI(int argc, char **argv) { int myrank, world, is_initialized; MPI_Initialized(&is_initialized); if (!is_initialized) { MPI_Init(&argc, &argv); } MPI_Comm_rank(MPI_COMM_WORLD, &myrank); lm_my_proc_id = (UInt)myrank; MPI_Comm_size(MPI_COMM_WORLD, &world); lm_world_size = (UInt)world; } void closeMPI() { MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); } /* -------------------------------------------------------------------------- */ // environment macro /* -------------------------------------------------------------------------- */ void loadENV() { char *varenv = lm_getenv("DEBUG_LEVEL"); if (varenv) global_level = lm_atoi(varenv); else global_level = DBG_WARNING; varenv = lm_getenv("DEBUG_PROC"); if (varenv) global_proc = lm_atoi(varenv); else global_proc = UINT_MAX; varenv = lm_getenv("DEBUG_PROC1"); if (varenv) global_proc1 = lm_atoi(varenv); else global_proc1 = UINT_MAX; varenv = lm_getenv("DEBUG_PROC2"); if (varenv) global_proc2 = lm_atoi(varenv); else global_proc2 = UINT_MAX; varenv = lm_getenv("DEBUG_START"); if (varenv) start_dump = lm_atoi(varenv); else start_dump = 0; varenv = lm_getenv("DEBUG_END"); if (varenv) end_dump = lm_atoi(varenv); else end_dump = UINT_MAX; varenv = lm_getenv("HOSTNAME"); if (varenv) my_hostname = varenv; else my_hostname = ""; varenv = lm_getenv("JOB_ID"); if (varenv) lm_job_id = lm_atoi(varenv); else lm_job_id = lm_world_size; varenv = lm_getenv("PRINT_CRAP_TO_FILE"); if (varenv) print_crap_to_file = true; else print_crap_to_file = false; varenv = lm_getenv("CREATE_SEG_FAULT"); if (varenv) create_seg_fault = true; else create_seg_fault = false; varenv = lm_getenv("WAIT_ON_FATAL"); if (varenv) wait_on_fatal = true; else wait_on_fatal = false; varenv = lm_getenv("WAIT_AT_STARTUP"); if (varenv) wait_at_startup = lm_atoi(varenv); else wait_at_startup = UINT_MAX; openGlobal(); } /* -------------------------------------------------------------------------- */ /// EPSN init macro /* -------------------------------------------------------------------------- */ #ifdef LIBMULTISCALE_USE_EPSN #include "Epsn..hh" #include "RedSYM..hh" EXTERN char xmlepsnfile[255]; EXTERN EPSN::Simulation::Interface *epsn_itfc; inline void loadEPSN() { epsn_itfc = NULL; epsn_itfc = new EPSN::Simulation::Interface; epsn_itfc->initORB(argc, argv); } inline closeEPSN() { epsn_itfc->finalize(); epsn_itfc->killORB(); delete epsn_itfc; } #else void loadEPSN() {} void closeEPSN() {} #endif /* -------------------------------------------------------------------------- */ /// Python init macro /* -------------------------------------------------------------------------- */ +bool embedded_interpreter = false; void loadPython(){ - py::initialize_interpreter(); + if (not Py_IsInitialized()){ + py::initialize_interpreter(); + embedded_interpreter = true; + } } void closePython(){ - py::finalize_interpreter(); + if (embedded_interpreter) + py::finalize_interpreter(); } /* -------------------------------------------------------------------------- */ // init functions /* -------------------------------------------------------------------------- */ void loadModules(int argc, char **argv) { loadMPI(argc, argv); loadEPSN(); loadENV(); loadPython(); } void closeModules() { GeometryManager::destroy(); Parser::freeMemory(); closeEPSN(); #ifdef LIBMULTISCALE_TIMER dumpTimes(lm_my_proc_id); #endif closeMPI(); closePython(); (*global_out).flush(); } __END_LIBMULTISCALE__ diff --git a/src/common/python.cc b/src/common/python.cc deleted file mode 100644 index 362d8e5..0000000 --- a/src/common/python.cc +++ /dev/null @@ -1,6 +0,0 @@ -#include <pybind11/pybind11.h> - -namespace py = pybind11; - -PYBIND11_MODULE(libmultiscale, m) { -} diff --git a/src/factory/domain_multiscale.hh b/src/factory/domain_multiscale.hh index e1f482d..26ac3e7 100644 --- a/src/factory/domain_multiscale.hh +++ b/src/factory/domain_multiscale.hh @@ -1,206 +1,208 @@ /** * @file domain_multiscale.hh * * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * * @date Wed Jan 15 17:00:43 2014 * * @brief This is a meta domain whose purpose is to handle other domains * * @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 __LIBMULTISCALE_DOMAIN_MULTISCALE_HH__ #define __LIBMULTISCALE_DOMAIN_MULTISCALE_HH__ /* -------------------------------------------------------------------------- */ #include "domain_interface.hh" //#include "communicator.hh" #include "id_manager.hh" /* -------------------------------------------------------------------------- */ __BEGIN_LIBMULTISCALE__ // backward declaration // class FilterManager; class CouplerManager; // class ActionManager; class GeometryManager; /* -------------------------------------------------------------------------- */ // helpful Macros /* -------------------------------------------------------------------------- */ #define DECLARE_RETURN_REAL_FUNCTION_BYSUM(name) Real name(); #define DECLARE_CALL_TO_SUBFUNCTION(name) void name(); #define DECLARE_CALL_TO_SUBFUNCTION_INTARG(name) void name(UInt arg1); #define DECLARE_CALL_TO_SUBFUNCTION_REALARG(name) void name(Real arg1); /* -------------------------------------------------------------------------- */ /** * Class DomainMultiScale * domaine generique multiechelle */ class DomainMultiScale : public DomainInterface, public IDManager<DomainInterface> { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ protected: friend class IDManager<DomainInterface>; DomainMultiScale(); + +public: virtual ~DomainMultiScale(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: static DomainMultiScale &getManager() { return IDManager<DomainInterface>::getManager<DomainMultiScale>(); } void compute_make_call() { LM_TOIMPLEMENT; } //! initialization method void init(){}; //! parse line for creation of a model UInt parseLineModel(std::stringstream &line); //! access to potential energy DECLARE_RETURN_REAL_FUNCTION_BYSUM(getEpot); //! access to kinetic energy // DECLARE_RETURN_REAL_FUNCTION_BYSUM(getEcin); // performw step1 DECLARE_CALL_TO_SUBFUNCTION(performStep1); // perform step2 DECLARE_CALL_TO_SUBFUNCTION(performStep2); // perform step3 DECLARE_CALL_TO_SUBFUNCTION(performStep3); //! function that calls all the stored coupling objects void coupling(CouplingStage stage); //! restart from xml file function void readXMLFile(const std::string &filename){}; //! This method build a full multiscale domain from a config file UInt build(const std::string &config); private: //! generic parser method that is called by the parser object on each red line ParseResult setParam(const std::string &key, std::stringstream &line); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: // set current step DECLARE_CALL_TO_SUBFUNCTION_INTARG(setCurrentStep); // set timestep DECLARE_CALL_TO_SUBFUNCTION_REALARG(setTimeStep); //! get current timestep to a given value UInt getCurrentStep(); //! get internal timestep to a given value Real getTimeStep(); //! return a model from its registering order index std::shared_ptr<DomainInterface> getModelByNumber(UInt i); //! return the number of registered models UInt getNbModels(); //! return the domain dimensions for this processor Cube getSubDomainBoundingBox() { LM_TOIMPLEMENT; }; //! return the entire domain dimensions Cube getDomainBoundingBox() { LM_TOIMPLEMENT; }; //! return the entire domain dimensions void setSubDomainBoundingBox(const Cube & cube) { LM_TOIMPLEMENT; }; //! return the entire domain dimensions void setDomainBoundingBox(const Cube & cube) { LM_TOIMPLEMENT; }; //! return the dimension of the domains UInt getDim() { return Dim; }; //! return product of force by descent direction (for AMELCG) DECLARE_RETURN_REAL_FUNCTION_BYSUM(getFdotDir); //! return max of forces (for AMELCG) Real getFMax(); //! return max of direction (for AMELCG) Real getDirMax(); //! return norm 2 of forces (for AMELCG) DECLARE_RETURN_REAL_FUNCTION_BYSUM(getFNorm2); //! return stuff for AMELCG DECLARE_RETURN_REAL_FUNCTION_BYSUM(getFdotOldF); //! update direction AMELCG DECLARE_CALL_TO_SUBFUNCTION_REALARG(updateDirection); //! return stuff for AMELCG DECLARE_CALL_TO_SUBFUNCTION(saveForceVector); //! displace in descent direction with given magnitude DECLARE_CALL_TO_SUBFUNCTION_REALARG(displaceTowardsDirection); /* ------------------------------------------------------------------------ */ /* friends */ /* ------------------------------------------------------------------------ */ friend class Parser; private: /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ //! mapping between IDs and communication group IDs //std::map<std::string, CommGroup> dom_group; //! notificator of the multitimestep (not used at present time) UInt multi_step; //! dimension of the multiscale material (should be unified) UInt Dim; //! couplers handler CouplerManager *coupler_manager; }; __END_LIBMULTISCALE__ #endif /* __LIBMULTISCALE_DOMAIN_MULTISCALE_HH__ */