├── .github └── workflows │ └── pylint.backup ├── .gitignore ├── CMakeLists.txt ├── LICENSE-Apache-v2 ├── LICENSE-GPL-v3 ├── README.md ├── changelog ├── cmake └── MUIConfig.cmake.in ├── doc ├── .gitignore ├── Doxyfile └── resources │ ├── MUI_FSI.jpg │ ├── MUI_logo_small.png │ ├── fem-dpd.jpg │ ├── graft.jpg │ └── logo_files │ ├── MUI_logo.svg │ ├── MUI_logo_circle.svg │ └── MUI_logo_transparent.png ├── src ├── communication │ ├── comm.h │ ├── comm_factory.h │ ├── comm_mpi.h │ ├── comm_mpi_smart.h │ ├── comm_tcp.h │ ├── lib_dispatcher.h │ ├── lib_mpi_helper.h │ ├── lib_mpi_multidomain.h │ ├── lib_mpi_split.h │ ├── lib_singleton.h │ ├── lib_uri.h │ └── message │ │ ├── message.h │ │ └── reader_variable.h ├── config.h ├── general │ ├── dim.h │ ├── endian_traits.h │ ├── exception.h │ └── util.h ├── geometry │ ├── geometry.h │ ├── point.h │ └── span.h ├── linear_algebra │ ├── README.md │ ├── linalg_util.h │ ├── matrix.h │ ├── matrix_arithmetic.h │ ├── matrix_asserts.h │ ├── matrix_ctor_dtor.h │ ├── matrix_io_info.h │ ├── matrix_manipulation.h │ ├── preconditioner.h │ ├── preconditioner_diagonal.h │ ├── preconditioner_ic.h │ ├── preconditioner_ilu.h │ ├── preconditioner_ssor.h │ ├── solver.h │ ├── solver_bicgstab.h │ ├── solver_cg.h │ ├── solver_ge.h │ └── test │ │ ├── Makefile │ │ ├── Resource │ │ ├── Aas.csv │ │ ├── Css.csv │ │ ├── Hi.csv │ │ ├── Makefile │ │ └── solver_compare_with_Eigen.cpp │ │ ├── matrix_arithmetics.cpp │ │ ├── matrix_manipulations.cpp │ │ └── solver.cpp ├── mui.h ├── samplers │ ├── algorithm │ │ ├── algo_aitken.h │ │ ├── algo_fixed_relaxation.h │ │ └── algo_null.h │ ├── sampler.h │ ├── spatial │ │ ├── sampler_exact.h │ │ ├── sampler_gauss.h │ │ ├── sampler_mov_avg.h │ │ ├── sampler_nn.h │ │ ├── sampler_null.h │ │ ├── sampler_pseudo_n2_linear.h │ │ ├── sampler_pseudo_nn.h │ │ ├── sampler_rbf.h │ │ ├── sampler_shepard_quintic.h │ │ ├── sampler_sph_quintic.h │ │ └── sampler_sum_quintic.h │ └── temporal │ │ ├── temporal_sampler_exact.h │ │ ├── temporal_sampler_gauss.h │ │ ├── temporal_sampler_mean.h │ │ ├── temporal_sampler_null.h │ │ └── temporal_sampler_sum.h ├── storage │ ├── bin.h │ ├── dynstorage.h │ ├── spatial_storage.h │ ├── stream.h │ ├── stream_ordered.h │ ├── stream_string.h │ ├── stream_tuple.h │ ├── stream_unordered.h │ ├── stream_vector.h │ └── virtual_container.h └── uniface.h └── wrappers ├── C ├── .gitignore ├── Makefile ├── README.md ├── config_c_wrapper.h ├── mui_c_wrapper_1d.cpp ├── mui_c_wrapper_1d.h ├── mui_c_wrapper_2d.cpp ├── mui_c_wrapper_2d.h ├── mui_c_wrapper_3d.cpp ├── mui_c_wrapper_3d.h ├── mui_c_wrapper_general.cpp ├── mui_c_wrapper_general.h ├── unit_test_multi.c └── unit_test_single.c ├── Fortran ├── .gitignore ├── Makefile ├── README.md ├── config_f_wrapper.h ├── mui_f_wrapper_1d.cpp ├── mui_f_wrapper_1d.f90 ├── mui_f_wrapper_2d.cpp ├── mui_f_wrapper_2d.f90 ├── mui_f_wrapper_3d.cpp ├── mui_f_wrapper_3d.f90 ├── mui_f_wrapper_general.cpp ├── mui_f_wrapper_general.f90 ├── unit_test.f90 └── unit_test_multi.f90 └── Python ├── .gitignore ├── CMakeLists.txt ├── README.md ├── mui4py ├── __init__.py ├── algorithms.py ├── common.py ├── config.py ├── cpp │ ├── algorithm.cpp │ ├── algorithm_name.h │ ├── compiler_info.h │ ├── config_name.h │ ├── geometry.cpp │ ├── mui4py.cpp │ ├── sampler.cpp │ ├── sampler_name.h │ ├── temporal_name.h │ ├── temporal_sampler.cpp │ ├── uniface1d.cpp │ ├── uniface1f.cpp │ ├── uniface2d.cpp │ ├── uniface2f.cpp │ ├── uniface3d.cpp │ ├── uniface3f.cpp │ └── uniface_base.h ├── geometry.py ├── mui4py.py ├── samplers.py ├── temporal_samplers.py └── types.py ├── setup.cfg └── setup.py /.github/workflows/pylint.backup: -------------------------------------------------------------------------------- 1 | #name: flake8 2 | # 3 | #on: [push] 4 | # 5 | #jobs: 6 | # build: 7 | # runs-on: ubuntu-latest 8 | # strategy: 9 | # matrix: 10 | # python-version: ["3.8", "3.9", "3.10"] 11 | # steps: 12 | # - uses: actions/checkout@v3 13 | # - name: Set up Python ${{ matrix.python-version }} 14 | # uses: actions/setup-python@v3 15 | # with: 16 | # python-version: ${{ matrix.python-version }} 17 | # - name: Install dependencies 18 | # run: | 19 | # python -m pip install --upgrade pip 20 | # pip install flake8 21 | # - name: Analysing the code with flake8 22 | # run: | 23 | # cd wrappers/Python 24 | # flake8 . 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cproject 2 | .project 3 | .settings 4 | .pydevproject 5 | Debug 6 | Release 7 | build 8 | src/linear_algebra/test/matrix_arithmetics 9 | src/linear_algebra/test/matrix_manipulations 10 | src/linear_algebra/test/matrix.csv 11 | src/linear_algebra/test/matrix_vector_* 12 | src/linear_algebra/test/solver 13 | src/linear_algebra/test/Resource/solver_compare_with_Eigen 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MUI - Multiscale Universal Interface 2 | Concurrently coupled numerical simulations using heterogeneous solvers are powerful tools for modeling both multiscale and multiphysics phenomena. However, major modifications to existing codes are often required to enable such simulations, posing significant difficulties in practice. Here we present the Multiscale Universal Interface (MUI), which is capable of facilitating the coupling effort for a wide range of simulation types. 3 | 4 | The library adopts a header-only form with minimal external dependency and hence can be easily dropped into existing codes. A data sampler concept is introduced, combined with a hybrid dynamic/static typing mechanism, to create an easily customizable framework for solver-independent data interpretation. 5 | 6 | The library integrates MPI MPMD support and an asynchronous communication protocol to handle inter-solver information exchange irrespective of the solvers’ own MPI awareness. Template metaprogramming is heavily employed to simultaneously improve runtime performance and code flexibility. 7 | 8 | In the publication referenced below, the library is validated by solving three different multiscale type problems, which also serve to demonstrate the flexibility of the framework in handling heterogeneous models and solvers associated with multiphysics problems. In the first example, a Couette flow was simulated using two concurrently coupled Smoothed Particle Hydrodynamics (SPH) simulations of different spatial resolutions. In the second example, we coupled the deterministic SPH method with the stochastic Dissipative Particle Dynamics (DPD) method to study the effect of surface grafting on the hydrodynamics properties on the surface. In the third example, we consider conjugate heat transfer between a solid domain and a fluid domain by coupling the particle-based energy-conserving DPD (eDPD) method with the Finite Element Method (FEM). 9 | 10 | ## Licensing 11 | 12 | The source code is dual-licensed under either the GNU General Purpose License v3 or Apache License v2.0, copies of both licenses should have been provided along with this source code. 13 | 14 | ## Installation 15 | 16 | MUI is a C++ header-only library with one dependency - an MPI implementation that supports the MPMD paradigm. 17 | 18 | Wrappers are provided for C, Fortran and Python, these require compilation and therefore when using MUI with any of thee languages the library can no longer be considered header-only. 19 | 20 | As a header-only library using MUI in your own source code is straight forward, there are two ways to utilise the library in this scenario: 21 | 22 | 1. Include "mui.h" in your code and add appropriate paths to your compiler, if you wish to utilise a wrapper then go to the /wrappers folder and utilise the Makefile build system in each to generate compiled libraries to link against, any associated header files are also located here. 23 | 1. (preferred) Utilise the provided CMake build files to create a local or system-wide installation of the library. In this case there are a number of CMake parameters you should consider: 24 | 1. CMAKE_INSTALL_PREFIX=[path] - Set the path to install the library, otherwise the system default will be used 25 | 2. CMAKE_BUILD_TYPE=Release/Debug/.. - Set the compilation type (only changes options for compiled wrappers) 26 | 3. C_WRAPPER=ON/OFF - Specifies whether to compile the C wrapper during installation 27 | 4. FORTRAN_WRAPPER=ON/OFF - Specifies whether to compile the Fortran wrapper during installation 28 | 5. PYTHON_WRAPPER=ON/OFF - Specifies whether to compile and install the Python wrapper during installation, relies on a working Python3 toolchain and uses pip 29 | 30 | ## Publication 31 | 32 | **Tang** Y.-H., **Kudo**, S., **Bian**, X., **Li**, Z., & **Karniadakis**, G. E. Multiscale Universal Interface: A Concurrent Framework for Coupling Heterogeneous Solvers, *Journal of Computational Physics*, **2015**, 297.15, 13-31. 33 | 34 | ## Contact 35 | 36 | Should you have any question please do not hesitate to contact the developers, a list can be found within the MxUI about page. 37 | 38 | ## Examples 39 | 40 | | Computational Fluid Dynamics (CFD) - Finite Element (FEM) Fluid Structure Interaction | 41 | |:------------------------------------------------------------------------------------------------------------------:| 42 | | | 43 | 44 | | Finite Element (FEM) - Dissipative Particle Dynamics (DPD) Conjugate Heat Transfer | 45 | |:------------------------------------------------------------------------------------------------------------------:| 46 | | | 47 | 48 | | Dissipative Particle Dynamics (DPD) - Smoothed Particle Hydrodynamics (SPH) flow past a polymer-grafted surface | 49 | |:------------------------------------------------------------------------------------------------------------------:| 50 | | | 51 | -------------------------------------------------------------------------------- /changelog: -------------------------------------------------------------------------------- 1 | ############################################ 2 | # Multiscale Universal Interface Changelog # 3 | ############################################ 4 | 5 | [21 August 2023, 2.0+] 6 | - Fixed bugs related to memory leak of Aitken coupling algorithm 7 | - Add residual calculation and output function on Fixed Relaxation coupling algorithm 8 | - Updated wrappers on new Fixed Relaxation API and get L2 norm functions 9 | 10 | [01 August 2023, 2.0] 11 | - Refactor code base into new directory structure 12 | - Add new coupling algorithms 13 | - Rename "chrono" filters to "temporal" to avoid conflation with STL and other projects 14 | - Change API so functions that take two time_type values take a new iterator_type value instead 15 | - Update C and Fortran wrappers 16 | - Refactor Python wrapper for smaller footprint and CMake based build 17 | - Update top-level CMake for refactored Python wrapper and directory structure 18 | - Add standalone linear algebra capability mui::linalg 19 | - Update RBF filter to utilise new mui::linalg package 20 | - Add parallel capability to RBF filter 21 | - Remove Eigen dependency and USE_RBF compile time parameter 22 | 23 | [05 October 2022, 1.2.4] 24 | - Refactor RBF filter 25 | - Generalise capability of RBF filter so partitioned approach available for both conservative and consistent forms 26 | - Optimise RBF matrix generation 27 | - Fix CMake bug around use of languages other than C++ 28 | 29 | [13 September 2022, 1.2.3] 30 | - Add multiple uniface helper function (create_uniface) to Fortran wrapper 31 | - Add mod file generation to Fortran wrapper build systems (CMake and Makefile) 32 | - Add creation of static libraries for Fortran and C wrappers to CMake build system 33 | 34 | [20 April 2022, 1.2.2] 35 | - Improved endianness detection and implementation (in particular for Apple platforms) 36 | 37 | [25 February 2022, 1.2.1] 38 | - Performance improvements (in particular with large peer numbers). 39 | - Add new parameters to RBF filter API. 40 | - Update C/Fortran/Python wrapper to reflect new RBF API. 41 | - Update mui4py version system to reflect the main library. 42 | 43 | [16 December 2021, 1.2] 44 | - Complete C/Fortran/Python wrappers (minor ommisions listed as ToDo list in local README.md files for each). 45 | - Top-level CMake now complete for all components. 46 | - Directory restructure to make more logical. 47 | - A number of bug fixes. 48 | - Addition of global synchronisation mechanism to Smart Send. 49 | 50 | [07 October 2021, 1.1.3] 51 | - Top-level CMake build system redesign. 52 | - Bug fixes and compilation warnings removal for RBF filter. 53 | 54 | [27 August 2021, 1.1.2] 55 | - A complete C wrapper is included and new Fortran framework in place. 56 | - The create_uniface() function now outputs a std::vector of uniface objects in the same order they were input, rather than hash-value order. 57 | - A number of small bug fixes. 58 | 59 | [02 August 2021, 1.1.1] 60 | - Reverse MPI bugfix from 1.1 and implement new fix. 61 | 62 | [19 March 2021, 1.1] 63 | - RBF spatial filter: 64 | - New Wendland basis functions. 65 | - New Shepard smoothing function. 66 | - Bug fixes for problems involving small sample sizes. 67 | - Single and double time entries available for all functions that rely on a time stamp. 68 | - Ability to disable debug output as part of config. 69 | - Fixes within Python wrapper. 70 | - Performance and bug fixes. 71 | - Important MPI bugfix. 72 | 73 | [31 January 2020, 1.0] 74 | - Initial release. 75 | -------------------------------------------------------------------------------- /cmake/MUIConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(MUI_VERSION 2.0) 2 | 3 | @PACKAGE_INIT@ 4 | 5 | set_and_check(MUI_INCLUDE_DIR "@PACKAGE_MUI_INCLUDE_INSTALL_DIR@") 6 | set_and_check(MUI_LIB_DIR "@PACKAGE_MUI_LIB_INSTALL_DIR@") 7 | set_and_check(MUI_BASE_DIR "@PACKAGE_MUI_INSTALL_DIR@") 8 | 9 | check_required_components(MUI) 10 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | documentation/ 2 | -------------------------------------------------------------------------------- /doc/resources/MUI_FSI.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MxUI/MUI/7b0e83b6172ec6e518f03c8198ab78b5631f4e01/doc/resources/MUI_FSI.jpg -------------------------------------------------------------------------------- /doc/resources/MUI_logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MxUI/MUI/7b0e83b6172ec6e518f03c8198ab78b5631f4e01/doc/resources/MUI_logo_small.png -------------------------------------------------------------------------------- /doc/resources/fem-dpd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MxUI/MUI/7b0e83b6172ec6e518f03c8198ab78b5631f4e01/doc/resources/fem-dpd.jpg -------------------------------------------------------------------------------- /doc/resources/graft.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MxUI/MUI/7b0e83b6172ec6e518f03c8198ab78b5631f4e01/doc/resources/graft.jpg -------------------------------------------------------------------------------- /doc/resources/logo_files/MUI_logo_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MxUI/MUI/7b0e83b6172ec6e518f03c8198ab78b5631f4e01/doc/resources/logo_files/MUI_logo_transparent.png -------------------------------------------------------------------------------- /src/communication/comm.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file comm.h 42 | * @author S. Kudo 43 | * @date 10 February 2014 44 | * @brief File containing class definition of communication interface. 45 | * This is the base class for all other communication related classes. 46 | */ 47 | 48 | #ifndef COMM_H_ 49 | #define COMM_H_ 50 | 51 | #include 52 | #include "message/message.h" 53 | 54 | namespace mui { 55 | class communicator { 56 | private: 57 | // Comm is not copyable. 58 | communicator( const communicator& ) = delete; 59 | communicator& operator=( const communicator& ) = delete; 60 | public: 61 | communicator() {} 62 | virtual ~communicator() {} 63 | 64 | virtual int local_rank() const { return 0; } 65 | virtual int local_size() const { return 1; } 66 | virtual int remote_size() const { return 1; } 67 | virtual std::string uri_host() const { return std::string(); } 68 | virtual std::string uri_path() const { return std::string(); } 69 | virtual std::string uri_protocol() const { return std::string(); } 70 | 71 | // send message 72 | void send( message msg, const std::vector &is_sending ) { 73 | if( is_sending.size() == static_cast(remote_size()) ) 74 | return send_impl_(std::move(msg), is_sending); 75 | else { 76 | std::vector dest = is_sending; 77 | dest.resize(remote_size(), true); 78 | return send_impl_(std::move(msg), dest); 79 | } 80 | } 81 | void send( message msg ) { 82 | std::vector is_sending(remote_size(),true); 83 | return send_impl_(std::move(msg),is_sending); 84 | } 85 | 86 | // recv messages 87 | message recv() { 88 | return recv_impl_(); 89 | } 90 | 91 | 92 | protected: 93 | virtual void send_impl_( message msg, const std::vector &is_sending ) = 0; 94 | virtual message recv_impl_() = 0; 95 | }; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/communication/comm_factory.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | ******************************************************************************/ 39 | 40 | /** 41 | * @file comm_factory.h 42 | * @author Y. H. Tang 43 | * @date 14 March 2014 44 | * @brief Structures and methods to create a new communicator based on chosen 45 | * protocols. 46 | */ 47 | 48 | #ifndef COMM_FACTORY_H_ 49 | #define COMM_FACTORY_H_ 50 | 51 | #include "../general/util.h" 52 | #include "../general/exception.h" 53 | #include "lib_uri.h" 54 | #include "lib_dispatcher.h" 55 | #include "lib_singleton.h" 56 | #include "comm.h" 57 | 58 | namespace mui { 59 | 60 | struct comm_factory: public singleton > > 61 | { 62 | static communicator *create_comm( const char URI[], const bool quiet ) { 63 | if ( !instance().exist(uri(URI).protocol()) ) { 64 | exception_segv( "MUI Error [comm_factory.h]: Unknown communicator type ", uri(URI).protocol() ); 65 | } 66 | return instance()[uri(URI).protocol()]( URI, quiet ); 67 | } 68 | }; 69 | 70 | } 71 | 72 | #endif /* COMM_FACTORY_H_ */ 73 | -------------------------------------------------------------------------------- /src/communication/lib_dispatcher.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file lib_dispatcher.h 42 | * @author Y. H. Tang 43 | * @date 10 March 2014 44 | * @brief Structure for communicator used in comm_factory.h 45 | */ 46 | 47 | #ifndef LIB_DISPATCHER_H_ 48 | #define LIB_DISPATCHER_H_ 49 | 50 | #include "../general/util.h" 51 | #include "../general/exception.h" 52 | #include 53 | 54 | namespace mui 55 | { 56 | 57 | template< 58 | typename UUID, 59 | class FPTR, 60 | class EXCEPTION=exception_segv> 61 | struct dispatcher 62 | { 63 | FPTR dispatch( const UUID &id ) { 64 | auto i = dtable_.find(id); 65 | if ( i == dtable_.end() ) EXCEPTION(); 66 | return i->second; 67 | } 68 | bool exist( const UUID &id ) { 69 | return dtable_.find(id) != dtable_.end(); 70 | } 71 | FPTR operator [] ( const UUID &id ) { 72 | return dispatch(id); 73 | } 74 | bool link( const UUID &id, FPTR parser ) { 75 | return dtable_.insert( std::make_pair(id,parser) ).second; 76 | } 77 | bool unlink( const UUID &id ) { 78 | return dtable_.erase(id) == 1; 79 | } 80 | protected: 81 | using assoc_table = std::unordered_map; 82 | assoc_table dtable_; 83 | }; 84 | 85 | } 86 | 87 | #endif /* LIB_DISPATCHER_H_ */ 88 | -------------------------------------------------------------------------------- /src/communication/lib_mpi_helper.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file lib_mpi_helper.h 42 | * @author Y. H. Tang 43 | * @date 1 June 2015 44 | * @brief MPI data types used internally by MUI. 45 | */ 46 | 47 | #ifndef LIB_MPI_HELPER_H_ 48 | #define LIB_MPI_HELPER_H_ 49 | 50 | #include 51 | 52 | namespace mui { 53 | 54 | namespace mpi { 55 | 56 | template 57 | inline MPI_Datatype mpi_type( T const& t ); 58 | inline MPI_Datatype mpi_type( int const &t ) { return MPI_INT; } 59 | inline MPI_Datatype mpi_type( long const &t ) { return MPI_LONG; } 60 | inline MPI_Datatype mpi_type( unsigned long const &t ) { return MPI_UNSIGNED_LONG; } 61 | inline MPI_Datatype mpi_type( long long const &t ) { return MPI_LONG_LONG; } 62 | inline MPI_Datatype mpi_type( float const &t ) { return MPI_FLOAT; } 63 | inline MPI_Datatype mpi_type( double const &t ) { return MPI_DOUBLE; } 64 | inline MPI_Datatype mpi_type( char const &t ) { return MPI_CHAR; } 65 | inline MPI_Datatype mpi_type( short const &t ) { return MPI_SHORT; } 66 | inline MPI_Datatype mpi_type( unsigned short const &t ) { return MPI_UNSIGNED_SHORT; } 67 | 68 | template inline std::vector gather( T t, MPI_Comm comm ) { 69 | int size, rank; 70 | MPI_Comm_size( comm, &size ); 71 | MPI_Comm_rank( comm, &rank ); 72 | std::vector v; 73 | if ( rank == 0 ) v.resize( size ); 74 | MPI_Gather( &t, 1, mpi_type(t), v.data(), 1, mpi_type(t), 0, comm ); 75 | return v; 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | #endif /* LIB_MPI_HELPER_H_ */ 83 | -------------------------------------------------------------------------------- /src/communication/lib_mpi_split.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file lib_mpi_split.h 42 | * @author Y. H. Tang 43 | * @date 14 March 2014 44 | * @brief Provides helper functions to generate (and finalize) a new MPI 45 | * comm world that can then be used by an already MPI enabled application 46 | * to ensure MPI_COMM_WORLD remains free for use by MUI. 47 | */ 48 | 49 | #ifndef LIB_MPI_SPLIT_H_ 50 | #define LIB_MPI_SPLIT_H_ 51 | 52 | #include 53 | namespace mui { 54 | 55 | inline void mpi_finalize_after_split() { 56 | int flag; 57 | MPI_Finalized(&flag); 58 | if (!flag) MPI_Finalize(); 59 | } 60 | 61 | inline MPI_Comm mpi_split_by_app( int argc=0, char **argv=NULL, int threadType=-1, int *thread_support=NULL ) 62 | { 63 | { 64 | int flag; 65 | MPI_Initialized(&flag); 66 | if( !flag ) { 67 | if(threadType != -1) { 68 | MPI_Init_thread( &argc, &argv, threadType, thread_support ); 69 | } 70 | else { 71 | MPI_Init( &argc, &argv ); 72 | } 73 | atexit( mpi_finalize_after_split ); 74 | } 75 | } 76 | void* v; 77 | int flag; 78 | MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_APPNUM,&v,&flag); 79 | if (!flag) { 80 | std::cout << "MUI Info [lib_mpi_split.h]: Calling mpi_split_by_app() when run as a single application" << std::endl; 81 | } 82 | int appnum = *static_cast(v); 83 | int rank; 84 | MPI_Comm_rank(MPI_COMM_WORLD,&rank); 85 | MPI_Comm domain; 86 | MPI_Comm_split(MPI_COMM_WORLD,appnum,rank,&domain); 87 | return domain; 88 | } 89 | } 90 | 91 | #endif /* LIB_MPI_SPLIT_H_ */ 92 | -------------------------------------------------------------------------------- /src/communication/lib_singleton.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file lib_singleton.h 42 | * @author Y. H. Tang 43 | * @date 14 March 2014 44 | * @brief Base class to contain communicator in comm_factory.h 45 | */ 46 | 47 | #ifndef LIB_SINGLETON_H_ 48 | #define LIB_SINGLETON_H_ 49 | 50 | #include "../general/util.h" 51 | 52 | namespace mui { 53 | 54 | template 55 | class singleton 56 | { 57 | public: 58 | static T& instance() { 59 | static T instance_; 60 | return instance_; 61 | } 62 | private: 63 | // make all constructors etc. private to guarantee uniqueness 64 | singleton(); 65 | singleton(const singleton&); 66 | singleton& operator=(const singleton&); 67 | ~singleton(); 68 | }; 69 | 70 | } 71 | 72 | #endif /* LIB_SINGLETON_H_ */ 73 | -------------------------------------------------------------------------------- /src/communication/lib_uri.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file lib_uri.h 42 | * @author Y. H. Tang 43 | * @date 14 March 2014 44 | * @brief Base class to contain and manipulate a unique URI (Uniform Resource 45 | * Identifier). 46 | */ 47 | 48 | #ifndef LIB_URI_H_ 49 | #define LIB_URI_H_ 50 | 51 | #include "../general/util.h" 52 | 53 | namespace mui { 54 | 55 | class uri { 56 | public: 57 | uri(const std::string& url_s) { 58 | parse(url_s); 59 | } 60 | uri(const char url_c[]) { 61 | parse(url_c); 62 | } 63 | const std::string& protocol() const { return protocol_; } 64 | const std::string& host() const { return host_; } 65 | const std::string& path() const { return path_; } 66 | 67 | uri( const uri &another ) = delete; 68 | uri& operator = ( const uri &another ) = delete; 69 | private: 70 | void parse(const std::string& url_s) { 71 | // "__protocol__://__host__/__path__" 72 | std::size_t prot_end = url_s.find("://"); 73 | protocol_ = url_s.substr(0,prot_end); 74 | std::size_t host_end = url_s.find("/",prot_end+3); 75 | host_ = url_s.substr(prot_end+3,host_end-prot_end-3); 76 | path_ = url_s.substr(host_end+1); 77 | 78 | std::transform(protocol_.begin(), protocol_.end(), protocol_.begin(), ::tolower); 79 | std::transform(host_.begin(), host_.end(), host_.begin(), ::tolower); 80 | } 81 | 82 | std::string protocol_, host_, path_; 83 | }; 84 | 85 | } 86 | 87 | #endif /* LIB_URI_H_ */ 88 | -------------------------------------------------------------------------------- /src/communication/message/reader_variable.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file reader_variable.h 42 | * @author Y. H. Tang 43 | * @date 11 March 2014 44 | * @brief Creates a structure to parse a message as variables and pass them 45 | * to a function as arguments. 46 | */ 47 | 48 | #ifndef READER_VARIABLE_H_ 49 | #define READER_VARIABLE_H_ 50 | 51 | #include 52 | #include 53 | #include 54 | #include "message.h" 55 | #include "../../storage/stream.h" 56 | #include "../../storage/stream_tuple.h" 57 | #include "../../storage/stream_string.h" 58 | 59 | namespace mui 60 | { 61 | 62 | // parse message as variables and pass them to f as arguments of it 63 | template 64 | struct reader_variables { 65 | typedef std::function function_type; 66 | typedef std::tuple::type...> tuple_type; 67 | 68 | reader_variables() = default; 69 | reader_variables( function_type f ) : f_(std::move(f)) {} 70 | void operator()( const message& msg ){ 71 | // parse msg as tuple of variables 72 | auto stream = make_istream(msg.data()); 73 | tuple_type t; 74 | stream >> t; 75 | // split tuple before applying 76 | apply(t, typename make_index_sequence::type()); 77 | } 78 | private: 79 | template 80 | void apply( tuple_type& t, index_sequence ){ 81 | f_(std::get(std::move(t))...); 82 | } 83 | function_type f_; 84 | }; 85 | 86 | } 87 | 88 | 89 | #endif /* READER_VARIABLE_H_ */ 90 | -------------------------------------------------------------------------------- /src/general/exception.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file exception.h 42 | * @author Y. H. Tang 43 | * @date 10 March 2014 44 | * @brief Base class for exception handling. 45 | */ 46 | 47 | #ifndef EXCEPTION_H_ 48 | #define EXCEPTION_H_ 49 | 50 | #include "util.h" 51 | 52 | namespace mui { 53 | 54 | inline std::ostream& operator << ( std::ostream &out, std::exception const& err ) { 55 | return ( out << err.what() ); 56 | } 57 | 58 | struct exception_segv { 59 | explicit inline exception_segv() { 60 | handle(); 61 | } 62 | template 63 | inline exception_segv( HEAD const &head, TAIL const &... tail ) { 64 | handle( head, tail... ); 65 | } 66 | template 67 | inline void handle( HEAD const &head, TAIL const &... tail ) { 68 | std::cerr << head; 69 | handle( tail... ); 70 | } 71 | inline void handle( void ) { 72 | raise( SIGSEGV ); 73 | } 74 | }; 75 | 76 | struct exception_abort { 77 | inline exception_abort( const std::exception& except ) { 78 | std::cerr << except.what() << std::endl; 79 | raise( SIGABRT ); 80 | } 81 | }; 82 | 83 | struct exception_throw { 84 | inline exception_throw( const std::exception& ) { 85 | throw; 86 | } 87 | }; 88 | 89 | } 90 | #endif /* EXCEPTION_H_ */ 91 | -------------------------------------------------------------------------------- /src/linear_algebra/README.md: -------------------------------------------------------------------------------- 1 | # Information about the MUI Linear Algebra 2 | This is MUI linear algebra system with namespace of mui::linalg. 3 | The MUI linear algebra system support COO, CSR and CSC matrix formats. 4 | Linear solvers and preconditioners have been implemented. 5 | 6 | # Compilation notes 7 | It relies on C++11 standard. 8 | 9 | # Folder and file structure 10 | The MUI linear algebra system with namespace of mui::linalg is self-contained. Three top level files are in the folder on different aspects: 11 | * matris.h 12 | -- It is the base file for the MUI sparse matrix system. 13 | * solver.h 14 | -- It is the base file of the linear system solver. 15 | * preconditioner.h 16 | -- It is the based file of the preconditioners for the linear system solver. 17 | * linalg_util.h 18 | -- It is the file of the utility functions for the MUI linear algebra system. 19 | 20 | Implementations are in seperate files with the name of the basic file name plus underscore and the name of the specific implementation content. 21 | 22 | # Potential performance improvement 23 | - Current MUI linear system solver implemented Gaussian Elimination (direct) solver, Conjugate Gradient (iteritive) solver and BiCGStab solver. Generalized minimal residual method (GRMRES) with restart function should be implemented for large matrix. 24 | 25 | - Current MUI linear algebra system are mainly serial codes, which makes the assumption that MUI has already finished the particion of the matrix (points) into a number of processors. The MUI linear algebra system, then, be applied into every processor to mainipulate/solver the linear formulations locally. If there are scenarios that needed other processors to help the linear formulations mainipulation/solving of the local processor, the serial MUI linear algebra code should be extended to parallel. 26 | 27 | # Unit tests 28 | Unit test code are provided in the "test" folder: 29 | 1. matrix_arithmetics.cpp and matrix_manipulations.cpp 30 | They are test codes for the MUI sparse matrix system, covers the test of basic matrix setting, I/O, mainipulation, arithmetic operations (addition, subtraction, multiplication, scalar multiplication, hadamard product, transpose and inverse), LU decomposition and QR decomposition. 31 | 2. solver.cpp 32 | It is a test code for the MUI linear system solvers, covers the MUI Gaussian Elimination solver and MUI Conjugate Gradient solver with different preconditioners (Incomplete LU, Incomplete Cholesky and Symmetric Successive Over Relaxation) and with/without initial guess. -------------------------------------------------------------------------------- /src/linear_algebra/linalg_util.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file linalg_util.h 42 | * @author W. Liu 43 | * @date 17 mAY 2023 44 | * @brief Utility functions for mui::linalg. 45 | */ 46 | 47 | #ifndef MUI_LINALG_UTIL_H_ 48 | #define MUI_LINALG_UTIL_H_ 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | namespace mui { 56 | namespace linalg { 57 | 58 | // Function to left trim a string - helper function on matrix file I/O 59 | inline std::string ltrim(const std::string &s) { 60 | const std::string WHITESPACE = " \n\r\t\f\v"; 61 | std::string::size_type start = s.find_first_not_of(WHITESPACE); 62 | return (start == std::string::npos) ? "" : s.substr(start); 63 | } 64 | 65 | // Function to right trim a string - helper function on matrix file I/O 66 | inline std::string rtrim(const std::string &s) { 67 | const std::string WHITESPACE = " \n\r\t\f\v"; 68 | std::string::size_type end = s.find_last_not_of(WHITESPACE); 69 | return (end == std::string::npos) ? "" : s.substr(0, end + 1); 70 | } 71 | 72 | // Function to trim a string on both sides - helper function on matrix file I/O 73 | inline std::string trim(const std::string &s) { 74 | return rtrim(ltrim(s)); 75 | } 76 | 77 | // Function to convert the input string to all lowercase characters - helper function on matrix file I/O 78 | inline std::string string_to_lower(const std::string &s) { 79 | std::string lower; 80 | std::transform(s.begin(), s.end(), std::back_inserter(lower), [](unsigned char c){ return std::tolower(c); }); 81 | return lower; 82 | } 83 | 84 | // Function to convert the input string to all uppercase characters - helper function on matrix file I/O 85 | inline std::string string_to_upper(const std::string &s) { 86 | std::string upper; 87 | std::transform(s.begin(), s.end(), std::back_inserter(upper), [](unsigned char c){ return std::toupper(c); }); 88 | return upper; 89 | } 90 | 91 | } // linalg 92 | } // mui 93 | 94 | #endif /* MUI_LINALG_UTIL_H_ */ 95 | -------------------------------------------------------------------------------- /src/linear_algebra/preconditioner_diagonal.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file preconditioner_diagonal.h 42 | * @author W. Liu 43 | * @date 28 March 2023 44 | * @brief Diagonal (Jacobi) preconditioner. 45 | */ 46 | 47 | #ifndef MUI_PRECONDITIONER_DIAGONAL_H_ 48 | #define MUI_PRECONDITIONER_DIAGONAL_H_ 49 | 50 | #include 51 | #include 52 | 53 | namespace mui { 54 | namespace linalg { 55 | 56 | // Constructor 57 | template 58 | diagonal_preconditioner::diagonal_preconditioner(const sparse_matrix& A) { 59 | // Initialise the lower triangular matrix 60 | inv_diag_.resize(A.get_rows(), A.get_cols()); 61 | // Construct the inverse diagonal matrix 62 | for (int i = 0; i < A.get_rows(); i++) { 63 | if (std::abs(A.get_value(i,i)) >= std::numeric_limits::min()) { 64 | inv_diag_.set_value(i, i, 1.0 / A.get_value(i,i)); 65 | } else { 66 | inv_diag_.set_value(i, i, 1.0); 67 | } 68 | } 69 | } 70 | 71 | // Destructor 72 | template 73 | diagonal_preconditioner::~diagonal_preconditioner() { 74 | // Deallocate the memory for the inverse diagonal matrix 75 | inv_diag_.set_zero(); 76 | } 77 | 78 | // Member function on preconditioner apply 79 | template 80 | sparse_matrix diagonal_preconditioner::apply(const sparse_matrix& x) { 81 | assert((x.get_cols()==1) && 82 | "MUI Error [preconditioner_diagonal.h]: apply only works for column vectors"); 83 | sparse_matrix z(x.get_rows(), x.get_cols()); 84 | 85 | for (int i = 0; i < x.get_rows(); i++) { 86 | if (std::abs(inv_diag_.get_value(i,i)) >= std::numeric_limits::min()) { 87 | z.set_value(i, 0, inv_diag_.get_value(i,i)*x.get_value(i,0)); 88 | } else { 89 | z.set_value(i, 0, 0.0); 90 | } 91 | } 92 | 93 | return z; 94 | } 95 | 96 | } // linalg 97 | } // mui 98 | 99 | #endif /* MUI_PRECONDITIONER_DIAGONAL_H_ */ 100 | -------------------------------------------------------------------------------- /src/linear_algebra/test/Makefile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC = mpic++ 4 | CFLAGS = -std=c++11 -O3 5 | 6 | SCR = $(wildcard *.cpp) 7 | EXE = $(SCR:.cpp=) 8 | 9 | default: $(EXE) 10 | 11 | % : %.cpp 12 | $(CC) $(CFLAGS) $< -o $@ 13 | 14 | clean: 15 | rm -f $(EXE) *.csv 16 | -------------------------------------------------------------------------------- /src/linear_algebra/test/Resource/Makefile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC = mpic++ 4 | CFLAGS = -std=c++11 -O3 5 | EIGEN_PATH ?= ./ 6 | 7 | SCR = $(wildcard *.cpp) 8 | EXE = $(SCR:.cpp=) 9 | 10 | default: $(EXE) 11 | 12 | % : %.cpp 13 | $(CC) $(CFLAGS) -I$(EIGEN_PATH) $< -o $@ 14 | 15 | clean: 16 | rm -f $(EXE) 17 | -------------------------------------------------------------------------------- /src/samplers/algorithm/algo_null.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * W. Liu * 6 | * * 7 | * This software is jointly licensed under the Apache License, Version 2.0 * 8 | * and the GNU General Public License version 3, you may use it according * 9 | * to either. * 10 | * * 11 | * ** Apache License, version 2.0 ** * 12 | * * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * 14 | * you may not use this file except in compliance with the License. * 15 | * You may obtain a copy of the License at * 16 | * * 17 | * http://www.apache.org/licenses/LICENSE-2.0 * 18 | * * 19 | * Unless required by applicable law or agreed to in writing, software * 20 | * distributed under the License is distributed on an "AS IS" BASIS, * 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | * See the License for the specific language governing permissions and * 23 | * limitations under the License. * 24 | * * 25 | * ** GNU General Public License, version 3 ** * 26 | * * 27 | * This program is free software: you can redistribute it and/or modify * 28 | * it under the terms of the GNU General Public License as published by * 29 | * the Free Software Foundation, either version 3 of the License, or * 30 | * (at your option) any later version. * 31 | * * 32 | * This program is distributed in the hope that it will be useful, * 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 35 | * GNU General Public License for more details. * 36 | * * 37 | * You should have received a copy of the GNU General Public License * 38 | * along with this program. If not, see . * 39 | *****************************************************************************/ 40 | 41 | /** 42 | * @file algor_null.h 43 | * @author W. Liu 44 | * @date 06 October 2022 45 | * @brief Dummy coupling algorithm intended as a file template for creating 46 | * new coupling algorithms. 47 | */ 48 | 49 | #ifndef MUI_COUPLING_ALGORITHM_NULL_H_ 50 | #define MUI_COUPLING_ALGORITHM_NULL_H_ 51 | 52 | #include "../../general/util.h" 53 | #include "../../config.h" 54 | 55 | namespace mui { 56 | 57 | template class algo_null { 58 | public: 59 | using REAL = typename CONFIG::REAL; 60 | using INT = typename CONFIG::INT; 61 | using time_type = typename CONFIG::time_type; 62 | using point_type = typename CONFIG::point_type; 63 | 64 | algo_null( ) { 65 | 66 | } 67 | 68 | //- relaxation based on single time value 69 | template 70 | OTYPE relaxation(time_type t, point_type focus, OTYPE filteredValue) const { 71 | 72 | } 73 | 74 | }; 75 | 76 | } 77 | 78 | #endif /* MUI_COUPLING_ALGORITHM_NULL_H_ */ 79 | -------------------------------------------------------------------------------- /src/samplers/sampler.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler.h 42 | * @author Y. H. Tang 43 | * @date 10 February 2014 44 | * @brief A reference file for making custom samplers. The new sampler does 45 | * not have to derive from this class, it just needs to implement all the 46 | * interfaces with the signatures specified. 47 | */ 48 | 49 | #ifndef MUI_SAMPLER_H_ 50 | #define MUI_SAMPLER_H_ 51 | 52 | #include "../config.h" 53 | #include "../geometry/geometry.h" 54 | #include "../storage/virtual_container.h" 55 | 56 | namespace mui { 57 | /* 58 | class sampler { 59 | public: 60 | sampler() { 61 | r = 1.0; 62 | } 63 | 64 | double filter( point focus, const virtual_container &data_points ) const { 65 | double sum = 0.; 66 | int n = 0; 67 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 68 | if ( ( focus - data_points[i].first ).norm() < r ) { 69 | sum += data_points[i].second; 70 | n++; 71 | } 72 | } 73 | if (n) return sum / n; 74 | else return 0; 75 | } 76 | inline span<> support() const { 77 | return span<>() || geometry::sphere<>( point(0), r ); 78 | } 79 | 80 | protected: 81 | double r; 82 | }; 83 | */ 84 | } 85 | 86 | #endif /* MUI_SAMPLER_H_ */ 87 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_exact.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_exact.h 42 | * @author Y. H. Tang 43 | * @date 10 February 2014 44 | * @brief Spatial sampler that provides a value at an exact point with 45 | * no interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_EXACT_H_ 49 | #define MUI_SAMPLER_EXACT_H_ 50 | 51 | #include 52 | #include "../../config.h" 53 | #include "../sampler.h" 54 | 55 | namespace mui { 56 | 57 | template 58 | class sampler_exact { 59 | public: 60 | using OTYPE = O_TP; 61 | using ITYPE = I_TP; 62 | using REAL = typename CONFIG::REAL; 63 | using INT = typename CONFIG::INT; 64 | using point_type = typename CONFIG::point_type; 65 | 66 | static const bool QUIET = CONFIG::QUIET; 67 | 68 | sampler_exact( REAL tol = std::numeric_limits::epsilon() ) { 69 | int exponent; 70 | frexp10( std::numeric_limits::max(), exponent ); 71 | real_precision = static_cast( exponent ); 72 | tolerance = tol; 73 | point_tolerance = tolerance*real_precision; 74 | } 75 | 76 | template class CONTAINER> 77 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 78 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 79 | if ( norm( focus - data_points[i].first ) < point_tolerance ) { 80 | return data_points[i].second; 81 | } 82 | } 83 | 84 | if( !QUIET ) 85 | std::cout << "MUI Warning [sampler_exact.h]: Hit nothing, check sampling location..." << std::endl; 86 | 87 | return OTYPE(); 88 | } 89 | 90 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 91 | return geometry::sphere( focus, tolerance*domain_mag*real_precision ); 92 | } 93 | 94 | protected: 95 | REAL tolerance; 96 | REAL point_tolerance; 97 | REAL real_precision; 98 | }; 99 | 100 | } 101 | 102 | #endif /* MUI_SAMPLER_EXACT_H_ */ 103 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_gauss.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_gauss.h 42 | * @author Y. H. Tang 43 | * @date 10 February 2014 44 | * @brief Spatial sampler that provides a value at a point using Gaussian 45 | * interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_GAUSS_H_ 49 | #define MUI_SAMPLER_GAUSS_H_ 50 | 51 | #include "../../general/util.h" 52 | #include "../../config.h" 53 | #include "../sampler.h" 54 | 55 | namespace mui { 56 | 57 | template 58 | class sampler_gauss { 59 | public: 60 | using OTYPE = O_TP; 61 | using ITYPE = I_TP; 62 | using REAL = typename CONFIG::REAL; 63 | using INT = typename CONFIG::INT; 64 | using point_type = typename CONFIG::point_type; 65 | 66 | sampler_gauss( REAL r_, REAL h_ ) : r(r_), h(h_), nh(std::pow(2*PI*h,-0.5*CONFIG::D)) {} 67 | 68 | template class CONTAINER> 69 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 70 | REAL exp_val = -0.5/h; 71 | REAL r2 = r*r; 72 | REAL wsum = 0; 73 | OTYPE vsum = 0; 74 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 75 | REAL d = normsq( focus - data_points[i].first ); 76 | if ( d < r2 ) { 77 | REAL w = nh * std::exp( exp_val * d ); 78 | vsum += data_points[i].second * w; 79 | wsum += w; 80 | } 81 | } 82 | if ( wsum ) return vsum / wsum; 83 | else return REAL(0.); 84 | } 85 | 86 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 87 | return geometry::sphere( focus, r ); 88 | } 89 | 90 | protected: 91 | REAL r; 92 | REAL h; 93 | REAL nh; 94 | }; 95 | 96 | } 97 | 98 | #endif /* MUI_SAMPLER_GAUSS_H_ */ 99 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_mov_avg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_mov_avg.h 42 | * @author Y. H. Tang 43 | * @date 10 February 2014 44 | * @brief Spatial sampler that provides a value at a point using a moving 45 | * average interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_MOVING_AVG_H_ 49 | #define MUI_SAMPLER_MOVING_AVG_H_ 50 | 51 | #include "../../config.h" 52 | #include "../sampler.h" 53 | #include 54 | 55 | namespace mui { 56 | 57 | template 58 | class sampler_moving_average { 59 | public: 60 | using OTYPE = O_TP; 61 | using ITYPE = I_TP; 62 | using REAL = typename CONFIG::REAL; 63 | using INT = typename CONFIG::INT; 64 | using point_type = typename CONFIG::point_type; 65 | 66 | sampler_moving_average( point_type bbox_ ) { 67 | bbox = bbox_; 68 | } 69 | 70 | template class CONTAINER> 71 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 72 | size_t n(0); 73 | OTYPE vsum(0); 74 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 75 | point_type dx(REAL(0.0)); 76 | for (INT j = 0 ; j < CONFIG::D ; j++) { 77 | dx[j] = std::fabs(data_points[i].first[j] - focus[j]); 78 | } 79 | bool within = true; 80 | for( INT i = 0 ; within && i < CONFIG::D ; i++ ) within = within && ( dx[i] < bbox[i] ); 81 | if ( within ) { 82 | vsum += data_points[i].second; 83 | n++; 84 | } 85 | } 86 | if (CONFIG::DEBUG) assert( n!=0 ); 87 | return n ? ( vsum / OTYPE(n) ): OTYPE(0.); 88 | } 89 | 90 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 91 | return geometry::box( focus - REAL(0.5) * bbox, focus + REAL(0.5) * bbox ); 92 | } 93 | 94 | protected: 95 | point_type bbox; 96 | }; 97 | 98 | } 99 | 100 | #endif /* MUI_SAMPLER_MOVING_AVG_H_ */ 101 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_nn.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_nn.h 42 | * @author Y. H. Tang 43 | * @date 10 February 2014 44 | * @brief Spatial sampler that provides a value at a point using a nearest 45 | * neighbour interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_NN_H_ 49 | #define MUI_SAMPLER_NN_H_ 50 | 51 | #include "../../config.h" 52 | #include "../sampler.h" 53 | 54 | namespace mui { 55 | 56 | template 57 | class sampler_nearest_neighbor { 58 | public: 59 | using OTYPE = O_TP; 60 | using ITYPE = I_TP; 61 | using REAL = typename CONFIG::REAL; 62 | using INT = typename CONFIG::INT; 63 | using point_type = typename CONFIG::point_type; 64 | 65 | sampler_nearest_neighbor() {} 66 | 67 | template class CONTAINER> 68 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 69 | REAL r2min = std::numeric_limits::max(); 70 | OTYPE value = 0; 71 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 72 | REAL dr2 = normsq( focus - data_points[i].first ); 73 | if ( dr2 < r2min ) { 74 | r2min = dr2; 75 | value = data_points[i].second ; 76 | } 77 | } 78 | return value; 79 | } 80 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 81 | return geometry::point( focus ); 82 | } 83 | }; 84 | 85 | } 86 | 87 | #endif /* MUI_SAMPLER_NN_H_ */ 88 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_null.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_null.h 42 | * @author Y. H. Tang 43 | * @date 11 November 2014 44 | * @brief Dummy spatial sampler that provides a template for creating 45 | * new samplers. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_NULL_H_ 49 | #define MUI_SAMPLER_NULL_H_ 50 | 51 | #include "../../general/util.h" 52 | #include "../../config.h" 53 | #include "../sampler.h" 54 | 55 | namespace mui { 56 | 57 | template 58 | class sampler_null { 59 | public: 60 | using OTYPE = O_TP; 61 | using ITYPE = I_TP; 62 | using REAL = typename CONFIG::REAL; 63 | using INT = typename CONFIG::INT; 64 | using point_type = typename CONFIG::point_type; 65 | 66 | sampler_null() { 67 | // to do: initialization 68 | } 69 | 70 | template class CONTAINER> 71 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 72 | // to do: interpolation algorithm 73 | } 74 | 75 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 76 | // to do: scope of points needed expressed in terms of mui::geometry::... 77 | } 78 | }; 79 | 80 | } 81 | 82 | #endif /* MUI_SAMPLER_NULL_H_ */ 83 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_pseudo_n2_linear.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_pseudo_n2_linear.h 42 | * @author Y. H. Tang 43 | * @date 10 October 2014 44 | * @brief Spatial sampler that provides a value at a point using a 45 | * pseudo-linear n^2 interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_PSEUDO_N2_LINEAR_H_ 49 | #define MUI_SAMPLER_PSEUDO_N2_LINEAR_H_ 50 | 51 | #include "../../config.h" 52 | #include "../sampler.h" 53 | 54 | namespace mui { 55 | 56 | template 57 | class sampler_pseudo_n2_linear { 58 | public: 59 | using OTYPE = O_TP; 60 | using ITYPE = I_TP; 61 | using REAL = typename CONFIG::REAL; 62 | using INT = typename CONFIG::INT; 63 | using point_type = typename CONFIG::point_type; 64 | 65 | sampler_pseudo_n2_linear( REAL h_ ) : h(h_) {} 66 | 67 | template class CONTAINER> 68 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 69 | REAL r2min_1st = std::numeric_limits::max(); 70 | REAL r2min_2nd = std::numeric_limits::max(); 71 | OTYPE value_1st = 0, value_2nd = 0; 72 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 73 | REAL dr2 = normsq( focus - data_points[i].first ); 74 | if ( dr2 < r2min_1st ) { 75 | r2min_2nd = r2min_1st; 76 | value_2nd = value_1st; 77 | r2min_1st = dr2; 78 | value_1st = data_points[i].second ; 79 | } else if ( dr2 < r2min_2nd ) { 80 | r2min_2nd = dr2; 81 | value_2nd = data_points[i].second ; 82 | } 83 | } 84 | REAL r1 = std::sqrt( r2min_1st ); 85 | REAL r2 = std::sqrt( r2min_2nd ); 86 | return ( value_1st * r2 + value_2nd * r1 ) / ( r1 + r2 ); 87 | } 88 | 89 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 90 | return geometry::sphere( focus, h ); 91 | } 92 | protected: 93 | REAL h; 94 | }; 95 | 96 | } 97 | 98 | #endif /* MUI_SAMPLER_NN_H_ */ 99 | -------------------------------------------------------------------------------- /src/samplers/spatial/sampler_pseudo_nn.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_pseudo_nn.h 42 | * @author Y. H. Tang 43 | * @date 10 October 2014 44 | * @brief Spatial sampler that provides a value at a point using a 45 | * pseudo nearest neighbour interpolation. 46 | */ 47 | 48 | #ifndef MUI_SAMPLER_PSEUDO_NN_H_ 49 | #define MUI_SAMPLER_PSEUDO_NN_H_ 50 | 51 | #include "../../config.h" 52 | #include "../sampler.h" 53 | 54 | namespace mui { 55 | 56 | template 57 | class sampler_pseudo_nearest_neighbor { 58 | public: 59 | using OTYPE = O_TP; 60 | using ITYPE = I_TP; 61 | using REAL = typename CONFIG::REAL; 62 | using INT = typename CONFIG::INT; 63 | using point_type = typename CONFIG::point_type; 64 | 65 | sampler_pseudo_nearest_neighbor( REAL h_ ) : h(h_) {} 66 | 67 | template class CONTAINER> 68 | inline OTYPE filter( point_type focus, const CONTAINER &data_points ) const { 69 | REAL r2min = std::numeric_limits::max(); 70 | OTYPE value = 0; 71 | for( size_t i = 0 ; i < data_points.size() ; i++ ) { 72 | REAL dr2 = normsq( focus - data_points[i].first ); 73 | if ( dr2 < r2min ) { 74 | r2min = dr2; 75 | value = data_points[i].second ; 76 | } 77 | } 78 | return value; 79 | } 80 | 81 | inline geometry::any_shape support( point_type focus, REAL domain_mag ) const { 82 | return geometry::sphere( focus, h ); 83 | } 84 | protected: 85 | REAL h; 86 | }; 87 | 88 | } 89 | 90 | #endif /* MUI_SAMPLER_NN_H_ */ 91 | -------------------------------------------------------------------------------- /src/samplers/temporal/temporal_sampler_null.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file temporal_sampler_null.h 42 | * @author Y. H. Tang 43 | * @date 5 November 2014 44 | * @brief Dummy temporal sampler intended as a file template for creating 45 | * new samplers. 46 | */ 47 | 48 | #ifndef MUI_TEMPORAL_SAMPLER_NULL_H_ 49 | #define MUI_TEMPORAL_SAMPLER_NULL_H_ 50 | 51 | #include "../../general/util.h" 52 | #include "../../config.h" 53 | 54 | namespace mui { 55 | 56 | template class temporal_sampler_null { 57 | public: 58 | using REAL = typename CONFIG::REAL; 59 | using INT = typename CONFIG::INT; 60 | using time_type = typename CONFIG::time_type; 61 | using iterator_type = typename CONFIG::iterator_type; 62 | 63 | temporal_sampler_null() { 64 | // to do: initialization 65 | } 66 | 67 | //- Filter based on time input 68 | template 69 | TYPE filter( time_type focus, const std::vector, TYPE> > &points ) const { 70 | // to do: interpolation algorithm 71 | } 72 | 73 | //- Filter based on time and iterator input 74 | template 75 | TYPE filter( std::pair focus, const std::vector, TYPE> > &points ) const { 76 | // to do: interpolation algorithm 77 | } 78 | 79 | time_type get_upper_bound( time_type focus ) const { 80 | // to do: return newest time needed with regard to focus 81 | } 82 | 83 | time_type get_lower_bound( time_type focus ) const { 84 | // to do: return oldest time needed with regard to focus 85 | } 86 | 87 | time_type tolerance() const { 88 | return time_type(0); 89 | } 90 | }; 91 | 92 | } 93 | 94 | #endif /* MUI_TEMPORAL_SAMPLER_NULL_H_ */ 95 | -------------------------------------------------------------------------------- /src/samplers/temporal/temporal_sampler_sum.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file temporal_sampler_sum.h 42 | * @author Y. H. Tang 43 | * @date 15 April 2014 44 | * @brief Temporal sampler that sums in time ranging from 45 | * [ now - left, now + right ]. 46 | */ 47 | 48 | #ifndef MUI_TEMPORAL_SAMPLER_SUM_H_ 49 | #define MUI_TEMPORAL_SAMPLER_SUM_H_ 50 | 51 | #include "../../general/util.h" 52 | #include "../../config.h" 53 | 54 | namespace mui { 55 | 56 | template class temporal_sampler_sum { 57 | public: 58 | using REAL = typename CONFIG::REAL; 59 | using INT = typename CONFIG::INT; 60 | using time_type = typename CONFIG::time_type; 61 | using iterator_type = typename CONFIG::iterator_type; 62 | 63 | temporal_sampler_sum( time_type left = time_type(0), time_type right = time_type(0) ) { 64 | left_ = left; 65 | right_ = right; 66 | } 67 | 68 | //- Filter based on time input 69 | template 70 | TYPE filter( time_type focus, const std::vector, TYPE> > &points ) const { 71 | TYPE sum = TYPE(0); 72 | 73 | for( auto i: points ) { 74 | if ( i.first.first <= focus + right_ && i.first.first >= focus - left_ ) { 75 | sum += i.second; 76 | } 77 | } 78 | 79 | return sum; 80 | } 81 | 82 | //- Filter based on time and iterator input - only time used 83 | template 84 | TYPE filter( std::pair focus, const std::vector, TYPE> > &points ) const { 85 | TYPE sum = TYPE(0); 86 | 87 | for( auto i: points ) { 88 | if ( i.first.first <= focus.first + right_ && i.first.first >= focus.first - left_ ) { 89 | sum += i.second; 90 | } 91 | } 92 | 93 | return sum; 94 | } 95 | 96 | time_type get_upper_bound( time_type focus ) const { 97 | return focus + right_; 98 | } 99 | 100 | time_type get_lower_bound( time_type focus ) const { 101 | return focus - left_; 102 | } 103 | 104 | time_type tolerance() const { 105 | return time_type(0); 106 | } 107 | 108 | protected: 109 | time_type left_; 110 | time_type right_; 111 | }; 112 | 113 | } 114 | 115 | #endif /* MUI_TEMPORAL_SAMPLER_SUM_H_ */ 116 | -------------------------------------------------------------------------------- /src/storage/stream_string.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file stream_string.h 42 | * @author S. Kudo 43 | * @date 18 March 2014 44 | * @brief Defines the stream in/out for std::string data type. 45 | * 46 | */ 47 | 48 | #ifndef MUI_STREAM_STRING_H 49 | #define MUI_STREAM_STRING_H 50 | 51 | #include 52 | 53 | #include "stream.h" 54 | 55 | namespace mui { 56 | inline istream& operator>>(istream& stream, std::string& ret) 57 | { 58 | std::size_t size; 59 | stream >> size; 60 | std::string str(size, '*'); 61 | for( char& a: str ) stream >> a; 62 | ret.swap(str); 63 | return stream; 64 | } 65 | inline ostream& operator<< ( ostream& stream, const std::string& str ) 66 | { 67 | std::size_t size = {str.size()}; 68 | stream << size; 69 | stream.write(str.c_str(), str.size()); 70 | return stream; 71 | } 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/storage/stream_tuple.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file stream_tuple.h 42 | * @author S. Kudo 43 | * @date 26 March 2014 44 | * @brief Defines the stream in/out for std::tuple data type. 45 | * 46 | * The order of elements in stream-in/out is first-argument to last-argument. 47 | */ 48 | 49 | #ifndef MUI_STREAM_TUPLE_H 50 | #define MUI_STREAM_TUPLE_H 51 | 52 | #include 53 | 54 | #include "stream.h" 55 | 56 | namespace mui { 57 | 58 | // build integer sequence 0, 1, ... in compile time 59 | template 60 | struct index_sequence { 61 | typedef index_sequence next; 62 | }; 63 | template 64 | struct make_index_sequence { 65 | typedef typename make_index_sequence::type::next type; 66 | }; 67 | template<> 68 | struct make_index_sequence<0>{ 69 | typedef index_sequence<> type; 70 | }; 71 | 72 | 73 | namespace { 74 | template 75 | struct input_tuple_impl_ { 76 | static void apply( istream& stream, std::tuple& t){ 77 | stream >> std::get(t); 78 | input_tuple_impl_::apply(stream,t); 79 | } 80 | }; 81 | template 82 | struct input_tuple_impl_ { 83 | static void apply( istream& , std::tuple& ){} 84 | }; 85 | } 86 | 87 | template 88 | inline istream& operator>> ( istream& stream, std::tuple& ret ) 89 | { 90 | std::tuple t; 91 | input_tuple_impl_<0,sizeof...(Args),Args...>::apply(stream,t); 92 | ret.swap(t); 93 | return stream; 94 | } 95 | 96 | 97 | namespace{ 98 | template 99 | struct output_tuple_impl_ { 100 | static void apply( ostream& stream, const std::tuple& t){ 101 | stream << std::get(t); 102 | output_tuple_impl_::apply(stream,t); 103 | } 104 | }; 105 | template 106 | struct output_tuple_impl_ { 107 | static void apply( ostream& , const std::tuple& ){} 108 | }; 109 | } 110 | 111 | template 112 | inline ostream& operator<< ( ostream& stream, const std::tuple& t ) 113 | { 114 | output_tuple_impl_<0,sizeof...(Args),Args...>::apply(stream,t); 115 | return stream; 116 | } 117 | 118 | } 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /src/storage/stream_vector.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file stream_vector.h 42 | * @author S. Kudo 43 | * @date 18 March 2014 44 | * @brief Defines the stream in/out for std::vector data type. 45 | * 46 | */ 47 | 48 | #ifndef MUI_STREAM_VECTOR_H 49 | #define MUI_STREAM_VECTOR_H 50 | 51 | #include 52 | 53 | #include "stream.h" 54 | 55 | namespace mui { 56 | template 57 | inline istream& operator>>(istream& stream, std::vector& ret) 58 | { 59 | std::size_t size; 60 | stream >> size; 61 | std::vector vec(size); 62 | for( auto& a: vec ) stream >> a; 63 | ret.swap(vec); 64 | return stream; 65 | } 66 | // specialization is only for char because of endian problem 67 | inline istream& operator>>(istream& stream, std::vector& ret) 68 | { 69 | std::size_t size; 70 | stream >> size; 71 | std::vector vec(size); 72 | stream.read(vec.data(), size); 73 | ret.swap(vec); 74 | return stream; 75 | } 76 | 77 | template 78 | inline ostream& operator<<(ostream& stream, const std::vector& vec) 79 | { 80 | stream << vec.size(); 81 | for( const auto& a: vec ) stream << a; 82 | return stream; 83 | } 84 | inline ostream& operator<<(ostream& stream, const std::vector& vec) 85 | { 86 | stream << vec.size(); 87 | stream.write(vec.data(), vec.size()); 88 | return stream; 89 | } 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /wrappers/C/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.so 4 | unit_test_c_wrapper_single 5 | unit_test_c_wrapper_multi 6 | -------------------------------------------------------------------------------- /wrappers/C/Makefile: -------------------------------------------------------------------------------- 1 | # Define compilers and MPI run option 2 | CC=mpicc 3 | CCX=mpic++ 4 | MPI=mpirun 5 | AR=ar 6 | 7 | # C compilation flags 8 | CFLAGS = -O3 -std=c11 9 | # C++ compilation flags 10 | CXXFLAGS = -O3 -std=c++11 -fpic 11 | 12 | default: mui_c_wrapper_general.o mui_c_wrapper_1d.o mui_c_wrapper_2d.o mui_c_wrapper_3d.o 13 | @echo "Compiling and linking MUI C wrapper..." 14 | ${CCX} ${CFLAGS} -shared -o libMUI_C_wrapper.so mui_c_wrapper_general.o mui_c_wrapper_1d.o mui_c_wrapper_2d.o mui_c_wrapper_3d.o 15 | ${AR} rcs libMUI_C_wrapper.a mui_c_wrapper_general.o mui_c_wrapper_1d.o mui_c_wrapper_2d.o mui_c_wrapper_3d.o 16 | 17 | mui_c_wrapper_general.o: mui_c_wrapper_general.cpp 18 | @echo "Generating C-wrapper general functions object file..." 19 | ${CCX} ${CXXFLAGS} -c mui_c_wrapper_general.cpp -o mui_c_wrapper_general.o 20 | 21 | mui_c_wrapper_1d.o: mui_c_wrapper_1d.cpp 22 | @echo "Generating C-wrapper 1D object file..." 23 | ${CCX} ${CXXFLAGS} -c mui_c_wrapper_1d.cpp -o mui_c_wrapper_1d.o 24 | 25 | mui_c_wrapper_2d.o: mui_c_wrapper_2d.cpp 26 | @echo "Generating C-wrapper 2D object file..." 27 | ${CCX} ${CXXFLAGS} -c mui_c_wrapper_2d.cpp -o mui_c_wrapper_2d.o 28 | 29 | mui_c_wrapper_3d.o: mui_c_wrapper_3d.cpp 30 | @echo "Generating C-wrapper 3D object file..." 31 | ${CCX} ${CXXFLAGS} -c mui_c_wrapper_3d.cpp -o mui_c_wrapper_3d.o 32 | 33 | test: 34 | @echo "Compiling and linking MUI C wrapper unit test code..." 35 | ${CC} ${CFLAGS} unit_test_single.c -o unit_test_c_wrapper_single -L${PWD} libMUI_C_wrapper.a -lstdc++ -lmpi_cxx -lm 36 | ${CC} ${CFLAGS} unit_test_multi.c -o unit_test_c_wrapper_multi -L${PWD} libMUI_C_wrapper.a -lstdc++ -lmpi_cxx -lm 37 | @echo "Launching C wrapper unit test code for single interface creation..." 38 | ${MPI} -np 1 ./unit_test_c_wrapper_single domain1 interface : -np 1 ./unit_test_c_wrapper_single domain2 interface 39 | @echo "Launching C wrapper unit test code for multi interface creation..." 40 | ${MPI} -np 1 ./unit_test_c_wrapper_multi domain1 interface 2 : -np 1 ./unit_test_c_wrapper_multi domain2 interface 2 41 | 42 | clean: 43 | rm -rf *.o *.a *.so unit_test_c_wrapper_single unit_test_c_wrapper_multi 44 | -------------------------------------------------------------------------------- /wrappers/C/README.md: -------------------------------------------------------------------------------- 1 | # Information about the MUI C wrapper 2 | This creates a C wrapper for the majority of the functionality provided by the C++ MUI library. 3 | 4 | # Compilation notes 5 | It relies on the C++11 standard and so a compliant compiler will be required. 6 | 7 | # Wrapper usage 8 | C wrapper usage: 9 | 1. include mui_c_wapper_[1d/2d/3d].h in C source 10 | 2. Compile with a C compiler & link against library 11 | 12 | # Unit tests 13 | Two unit tests are provided with the wrapper: 14 | 1. unit_test_single.c - Demonstrates creating and using a single instance of a 1D/2D/3D uniface 15 | 2. unit_test_multi.c - Demonstrates creating and using multiple 1D/2D/3D uniface instances using the mui::create_uniface() helper function 16 | -------------------------------------------------------------------------------- /wrappers/C/mui_c_wrapper_general.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2021 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis, * 5 | * S. M. Longshaw * 6 | * * 7 | * This software is jointly licensed under the Apache License, Version 2.0 * 8 | * and the GNU General Public License version 3, you may use it according * 9 | * to either. * 10 | * * 11 | * ** Apache License, version 2.0 ** * 12 | * * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * 14 | * you may not use this file except in compliance with the License. * 15 | * You may obtain a copy of the License at * 16 | * * 17 | * http://www.apache.org/licenses/LICENSE-2.0 * 18 | * * 19 | * Unless required by applicable law or agreed to in writing, software * 20 | * distributed under the License is distributed on an "AS IS" BASIS, * 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | * See the License for the specific language governing permissions and * 23 | * limitations under the License. * 24 | * * 25 | * ** GNU General Public License, version 3 ** * 26 | * * 27 | * This program is free software: you can redistribute it and/or modify * 28 | * it under the terms of the GNU General Public License as published by * 29 | * the Free Software Foundation, either version 3 of the License, or * 30 | * (at your option) any later version. * 31 | * * 32 | * This program is distributed in the hope that it will be useful, * 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 35 | * GNU General Public License for more details. * 36 | * * 37 | * You should have received a copy of the GNU General Public License * 38 | * along with this program. If not, see . * 39 | *****************************************************************************/ 40 | 41 | /** 42 | * @file mui_c_wrapper_general.cpp 43 | * @author S. M. Longshaw (derived from original 3D wrapper by Y. H. Tang) 44 | * @date Aug 4, 2021 45 | * @brief C wrapper for general MUI functions with no associated dimensionality 46 | */ 47 | 48 | // Main MUI header include (contains any other needed includes) 49 | #include "../../src/mui.h" 50 | 51 | extern "C" { 52 | 53 | // Function to split MPI communicator and return new, local communicator 54 | MPI_Comm mui_mpi_split_by_app() { 55 | return mui::mpi_split_by_app(); 56 | } 57 | 58 | // Function to split MPI communicator and return new, local communicator using threaded MPI init 59 | MPI_Comm mui_mpi_split_by_app_threaded(int argc, char **argv, int threadType, int *thread_support) { 60 | return mui::mpi_split_by_app(argc, argv, threadType, thread_support); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /wrappers/C/mui_c_wrapper_general.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2021 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis, * 5 | * S. M. Longshaw * 6 | * * 7 | * This software is jointly licensed under the Apache License, Version 2.0 * 8 | * and the GNU General Public License version 3, you may use it according * 9 | * to either. * 10 | * * 11 | * ** Apache License, version 2.0 ** * 12 | * * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * 14 | * you may not use this file except in compliance with the License. * 15 | * You may obtain a copy of the License at * 16 | * * 17 | * http://www.apache.org/licenses/LICENSE-2.0 * 18 | * * 19 | * Unless required by applicable law or agreed to in writing, software * 20 | * distributed under the License is distributed on an "AS IS" BASIS, * 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | * See the License for the specific language governing permissions and * 23 | * limitations under the License. * 24 | * * 25 | * ** GNU General Public License, version 3 ** * 26 | * * 27 | * This program is free software: you can redistribute it and/or modify * 28 | * it under the terms of the GNU General Public License as published by * 29 | * the Free Software Foundation, either version 3 of the License, or * 30 | * (at your option) any later version. * 31 | * * 32 | * This program is distributed in the hope that it will be useful, * 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 35 | * GNU General Public License for more details. * 36 | * * 37 | * You should have received a copy of the GNU General Public License * 38 | * along with this program. If not, see . * 39 | *****************************************************************************/ 40 | 41 | /** 42 | * @file mui_c_wrapper_general.h 43 | * @author S. M. Longshaw (derived from original 3D wrapper by Y. H. Tang) 44 | * @date Aug 4, 2021 45 | * @brief Header file for C wrapper for general MUI functions with no 46 | * associated dimensionality 47 | */ 48 | 49 | #ifndef MUI_C_WRAPPER_GENERAL_H_ 50 | #define MUI_C_WRAPPER_GENERAL_H_ 51 | 52 | #include "mpi.h" 53 | 54 | MPI_Comm mui_mpi_split_by_app(); 55 | MPI_Comm mui_mpi_split_by_app_threaded(int argc, char **argv, int threadType, int *thread_support); 56 | 57 | #endif /* MUI_C_WRAPPER_GENERAL_H_ */ 58 | -------------------------------------------------------------------------------- /wrappers/Fortran/.gitignore: -------------------------------------------------------------------------------- 1 | unit_test_fortran_wrapper 2 | unit_test_multi_fortran_wrapper 3 | *.o 4 | *.a 5 | *.so 6 | *.mod 7 | -------------------------------------------------------------------------------- /wrappers/Fortran/Makefile: -------------------------------------------------------------------------------- 1 | # Define compilers and MPI run option 2 | FC=mpifort 3 | CCX=mpic++ 4 | MPI=mpirun 5 | AR=ar 6 | 7 | # C compilation flags 8 | FFLAGS = -O3 -cpp -std=f2003 -fcheck=all -Wall 9 | # C++ compilation flags 10 | CXXFLAGS = -O3 -std=c++11 -fpic -shared 11 | 12 | default: mui_f_wrapper_general.o mui_f_wrapper_1d.o mui_f_wrapper_2d.o mui_f_wrapper_3d.o mui_f_wrapper_general.mod mui_f_wrapper_1d.mod mui_f_wrapper_2d.mod mui_f_wrapper_3d.mod 13 | @echo "Compiling and linking MUI Fortran wrapper..." 14 | ${CCX} ${CXXFLAGS} -o libMUI_Fortran_wrapper.so mui_f_wrapper_general.o mui_f_wrapper_1d.o mui_f_wrapper_2d.o mui_f_wrapper_3d.o 15 | ${AR} rcs libMUI_Fortran_wrapper.a mui_f_wrapper_general.o mui_f_wrapper_1d.o mui_f_wrapper_2d.o mui_f_wrapper_3d.o 16 | 17 | mui_f_wrapper_general.o: mui_f_wrapper_general.cpp 18 | @echo "Generating MUI Fortran wrapper general object file..." 19 | ${CCX} ${CXXFLAGS} -c mui_f_wrapper_general.cpp -o mui_f_wrapper_general.o 20 | 21 | mui_f_wrapper_1d.o: mui_f_wrapper_1d.cpp 22 | @echo "Generating MUI Fortran wrapper 1D object file..." 23 | ${CCX} ${CXXFLAGS} -c mui_f_wrapper_1d.cpp -o mui_f_wrapper_1d.o 24 | 25 | mui_f_wrapper_2d.o: mui_f_wrapper_2d.cpp 26 | @echo "Generating MUI Fortran wrapper 2D object file..." 27 | ${CCX} ${CXXFLAGS} -c mui_f_wrapper_2d.cpp -o mui_f_wrapper_2d.o 28 | 29 | mui_f_wrapper_3d.o: mui_f_wrapper_3d.cpp 30 | @echo "Generating MUI Fortran wrapper 3D object file..." 31 | ${CCX} ${CXXFLAGS} -c mui_f_wrapper_3d.cpp -o mui_f_wrapper_3d.o 32 | 33 | mui_f_wrapper_general.mod: mui_f_wrapper_general.f90 34 | @echo "Generating MUI Fortran wrapper general mod file..." 35 | ${FC} ${FFLAGS} -c mui_f_wrapper_general.f90 -o mui_f_wrapper_general.mod 36 | 37 | mui_f_wrapper_1d.mod: mui_f_wrapper_1d.f90 38 | @echo "Generating MUI Fortran wrapper 1D mod file..." 39 | ${FC} ${FFLAGS} -c mui_f_wrapper_1d.f90 -o mui_f_wrapper_1d.mod 40 | 41 | mui_f_wrapper_2d.mod: mui_f_wrapper_2d.f90 42 | @echo "Generating MUI Fortran wrapper 2D mod file..." 43 | ${FC} ${FFLAGS} -c mui_f_wrapper_2d.f90 -o mui_f_wrapper_2d.mod 44 | 45 | mui_f_wrapper_3d.mod: mui_f_wrapper_3d.f90 46 | @echo "Generating MUI Fortran wrapper 3D mod file..." 47 | ${FC} ${FFLAGS} -c mui_f_wrapper_3d.f90 -o mui_f_wrapper_3d.mod 48 | 49 | test: 50 | @echo "Compiling and linking MUI Fortran wrapper unit test code..." 51 | ${FC} ${FFLAGS} unit_test.f90 -o unit_test_fortran_wrapper -L. libMUI_Fortran_wrapper.a -lstdc++ -lmpi_cxx 52 | ${FC} ${FFLAGS} mui_f_wrapper_1d.f90 mui_f_wrapper_2d.f90 mui_f_wrapper_3d.f90 unit_test_multi.f90 -o unit_test_multi_fortran_wrapper -L. libMUI_Fortran_wrapper.a -lstdc++ -lmpi_cxx 53 | @echo "Launching unit test code for direct interface creation..." 54 | ${MPI} -np 1 ./unit_test_fortran_wrapper domain1 interface : -np 1 ./unit_test_fortran_wrapper domain2 interface 55 | @echo "Launching unit test code for interface creation using helper fucntion..." 56 | ${MPI} -np 1 ./unit_test_multi_fortran_wrapper domain1 interface 2 : -np 1 ./unit_test_multi_fortran_wrapper domain2 interface 2 57 | 58 | clean: 59 | rm -rf *.o *.mod *.so *.a unit_test_fortran_wrapper unit_test_multi_fortran_wrapper 60 | -------------------------------------------------------------------------------- /wrappers/Fortran/README.md: -------------------------------------------------------------------------------- 1 | # Information about the MUI Fortran wrapper 2 | This creates a Fortran wrapper for the majority of the functionality provided by the C++ MUI library. 3 | 4 | # Compilation notes 5 | It relies on C++11 and the f2003 ISO_C_BIND standard and so compliant compilers will be required. 6 | 7 | # Wrapper usage 8 | Fortran wrapper usage: 9 | 1. Compile application along with 1D/2D/3D module source 10 | 2. Link compiled mui_f_wrapper library 11 | 3. Enable f2003 standard during compilation 12 | 13 | Note: functions that return *arrays* of values perform memory allocation within the C function, therefore it is necessery to 14 | treat the returned memory locations accordingly within the calling Fortran application. 15 | 16 | # Unit tests 17 | A unit test is provided with the wrapper: 18 | 1. unit_test.f90 - Demonstrates creating and using a single instance of a 1D/2D/3D uniface 19 | 2. unit_test_multi.f90 - Demonstrates creating and using multiple 1D/2D/3D uniface instances using the create_and_get_uniface_multi_xx_f() helper function -------------------------------------------------------------------------------- /wrappers/Fortran/mui_f_wrapper_general.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2021 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis, * 5 | * S. M. Longshaw, W. Liu * 6 | * * 7 | * This software is jointly licensed under the Apache License, Version 2.0 * 8 | * and the GNU General Public License version 3, you may use it according * 9 | * to either. * 10 | * * 11 | * ** Apache License, version 2.0 ** * 12 | * * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * 14 | * you may not use this file except in compliance with the License. * 15 | * You may obtain a copy of the License at * 16 | * * 17 | * http://www.apache.org/licenses/LICENSE-2.0 * 18 | * * 19 | * Unless required by applicable law or agreed to in writing, software * 20 | * distributed under the License is distributed on an "AS IS" BASIS, * 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | * See the License for the specific language governing permissions and * 23 | * limitations under the License. * 24 | * * 25 | * ** GNU General Public License, version 3 ** * 26 | * * 27 | * This program is free software: you can redistribute it and/or modify * 28 | * it under the terms of the GNU General Public License as published by * 29 | * the Free Software Foundation, either version 3 of the License, or * 30 | * (at your option) any later version. * 31 | * * 32 | * This program is distributed in the hope that it will be useful, * 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 35 | * GNU General Public License for more details. * 36 | * * 37 | * You should have received a copy of the GNU General Public License * 38 | * along with this program. If not, see . * 39 | *****************************************************************************/ 40 | 41 | /** 42 | * @file mui_f_wrapper_general.cpp 43 | * @author S. M. Longshaw (derived from original 3D wrapper by S. Kudo) 44 | * @date 25 November 2021 45 | * @brief C interface for Fortran wrapper for general MUI functions with 46 | * no associated dimensionality 47 | */ 48 | 49 | // Main MUI header include (contains any other needed includes) 50 | #include "../../src/mui.h" 51 | #include "mpi.h" 52 | 53 | extern "C" { 54 | 55 | // Subroutine to split MPI communicator and return new, local communicator 56 | void mui_mpi_split_by_app_f(MPI_Fint *communicator) { 57 | *communicator = MPI_Comm_c2f(mui::mpi_split_by_app()); 58 | } 59 | 60 | // Function to split MPI communicator and return new, local communicator using threaded MPI init 61 | void mui_mpi_split_by_app_threaded_f(MPI_Fint *communicator, int *argc, char ***argv, int *threadType, int **thread_support) { 62 | *communicator = MPI_Comm_c2f(mui::mpi_split_by_app(*argc, *argv, *threadType, *thread_support)); 63 | } 64 | 65 | void mui_mpi_get_size_f(MPI_Fint *communicator, int *size) { 66 | MPI_Comm_size(MPI_Comm_f2c(*communicator), size); 67 | } 68 | 69 | void mui_mpi_get_rank_f(MPI_Fint *communicator, int *rank) { 70 | MPI_Comm_rank(MPI_Comm_f2c(*communicator), rank); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /wrappers/Fortran/mui_f_wrapper_general.f90: -------------------------------------------------------------------------------- 1 | !****************************************************************************** 2 | !* Multiscale Universal Interface Code Coupling Library * 3 | !* * 4 | !* Copyright (C) 2021 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis, * 5 | !* S. M. Longshaw, W. Liu * 6 | !* * 7 | !* This software is jointly licensed under the Apache License, Version 2.0 * 8 | !* and the GNU General Public License version 3, you may use it according * 9 | !* to either. * 10 | !* * 11 | !* ** Apache License, version 2.0 ** * 12 | !* * 13 | !* Licensed under the Apache License, Version 2.0 (the "License"); * 14 | !* you may not use this file except in compliance with the License. * 15 | !* You may obtain a copy of the License at * 16 | !* * 17 | !* http://www.apache.org/licenses/LICENSE-2.0 * 18 | !* * 19 | !* Unless required by applicable law or agreed to in writing, software * 20 | !* distributed under the License is distributed on an "AS IS" BASIS, * 21 | !* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 | !* See the License for the specific language governing permissions and * 23 | !* limitations under the License. * 24 | !* * 25 | !* ** GNU General Public License, version 3 ** * 26 | !* * 27 | !* This program is free software: you can redistribute it and/or modify * 28 | !* it under the terms of the GNU General Public License as published by * 29 | !* the Free Software Foundation, either version 3 of the License, or * 30 | !* (at your option) any later version. * 31 | !* * 32 | !* This program is distributed in the hope that it will be useful, * 33 | !* but WITHOUT ANY WARRANTY; without even the implied warranty of * 34 | !* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 35 | !* GNU General Public License for more details. * 36 | !* * 37 | !* You should have received a copy of the GNU General Public License * 38 | !* along with this program. If not, see . * 39 | !****************************************************************************** 40 | ! 41 | !** File Details ** 42 | ! 43 | !Filename: mui_f_wrapper_general.f90 44 | !Created: 15 September 2021 45 | !Author: S. M. Longshaw (derived from original 3D wrapper by S. Kudo) 46 | !Description: Fortran wrapper to create and manage MUI functions without 47 | ! dimensionality 48 | ! 49 | 50 | module mui_general_f 51 | use iso_c_binding 52 | implicit none 53 | public 54 | 55 | interface 56 | !Subroutine to split MPI communicator and return new, local communicator 57 | subroutine mui_mpi_split_by_app_f(communicator) bind(C) 58 | import :: c_int 59 | integer(kind=c_int), intent(in), target :: communicator 60 | end subroutine mui_mpi_split_by_app_f 61 | 62 | !Function to split MPI communicator and return new, local communicator 63 | subroutine mui_mpi_split_by_app_threaded_f(communicator,argc,argv,threadType,thread_support) bind(C) 64 | import :: c_ptr,c_char,c_int 65 | type(c_ptr), intent(out), target :: thread_support 66 | integer(kind=c_int), intent(in), target :: communicator 67 | integer(kind=c_int), intent(in) :: argc, threadType 68 | character(kind=c_char), intent(in), dimension(argc) :: argv(*) 69 | end subroutine mui_mpi_split_by_app_threaded_f 70 | 71 | !Function to get MPI size 72 | subroutine mui_mpi_get_size_f(communicator,local_size) bind(C) 73 | import :: c_int 74 | integer(kind=c_int), intent(in), target :: communicator 75 | integer(kind=c_int), intent(in) :: local_size 76 | end subroutine mui_mpi_get_size_f 77 | 78 | !Function to get MPI rank 79 | subroutine mui_mpi_get_rank_f(communicator,local_rank) bind(C) 80 | import :: c_int 81 | integer(kind=c_int), intent(in), target :: communicator 82 | integer(kind=c_int), intent(in) :: local_rank 83 | end subroutine mui_mpi_get_rank_f 84 | 85 | end interface 86 | 87 | end module mui_general_f 88 | -------------------------------------------------------------------------------- /wrappers/Python/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | __pycache__ 3 | *.so 4 | *.o 5 | -------------------------------------------------------------------------------- /wrappers/Python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | 3 | project(mui4py) 4 | 5 | # Set C++ standard before finding pybind11 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | set(CMAKE_CXX_EXTENSIONS OFF) 9 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_INCLUDE_DIRECTORIES}) 10 | include_directories(${PROJECT_SOURCE_DIR}/../../src) 11 | 12 | # Development component which includes both Development.Module and 13 | # Development.Embed is not required for building a Python module. Correct 14 | # COMPONENT specification Development.Module added only in CMake 3.18 and above. 15 | find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) 16 | 17 | find_package(MPI REQUIRED) 18 | 19 | # Check for numpy int size 20 | execute_process( 21 | COMMAND "${Python3_EXECUTABLE}" "-c" 22 | "import numpy; print(str(numpy.iinfo(int).dtype)[-2:])" 23 | OUTPUT_VARIABLE NUMPY_INT_SIZE 24 | RESULT_VARIABLE NUMPY_COMMAND_RESULT 25 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE 26 | ) 27 | 28 | message(STATUS "numpy int size = ${NUMPY_INT_SIZE}") 29 | 30 | find_package( 31 | pybind11 32 | 2.7.0 33 | REQUIRED 34 | CONFIG 35 | HINTS 36 | ${PYBIND11_DIR} 37 | ${PYBIND11_ROOT} 38 | $ENV{PYBIND11_DIR} 39 | $ENV{PYBIND11_ROOT} 40 | ) 41 | 42 | # Create the binding library pybind11 handles its own calls to 43 | # target_link_libraries 44 | pybind11_add_module(mui4py_mod MODULE 45 | mui4py/cpp/mui4py.cpp 46 | mui4py/cpp/geometry.cpp 47 | mui4py/cpp/sampler.cpp 48 | mui4py/cpp/temporal_sampler.cpp 49 | mui4py/cpp/algorithm.cpp 50 | mui4py/cpp/uniface1d.cpp 51 | mui4py/cpp/uniface2d.cpp 52 | mui4py/cpp/uniface3d.cpp 53 | mui4py/cpp/uniface1f.cpp 54 | mui4py/cpp/uniface2f.cpp 55 | mui4py/cpp/uniface3f.cpp) 56 | 57 | target_include_directories(mui4py_mod PRIVATE ${MPI_INCLUDE_PATH} ../..) 58 | target_compile_definitions(mui4py_mod PRIVATE PYTHON_BINDINGS PYTHON_INT_${NUMPY_INT_SIZE}) 59 | target_compile_options(mui4py_mod PRIVATE -Wall) 60 | 61 | # In Debug mode override pybind11 symbols visibility Symbols must be visible to 62 | # backtrace_symbols() to produce nice logs 63 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 64 | target_compile_options(mui4py_mod PRIVATE "-fvisibility=default") 65 | endif() 66 | 67 | target_link_libraries(mui4py_mod PUBLIC ${MPI_C_LIBRARIES}) 68 | 69 | # Check for mpi4py 70 | execute_process( 71 | COMMAND "${Python3_EXECUTABLE}" "-c" 72 | "import mpi4py; print(mpi4py.get_include())" 73 | OUTPUT_VARIABLE MPI4PY_INCLUDE_DIR 74 | RESULT_VARIABLE MPI4PY_COMMAND_RESULT 75 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE 76 | ) 77 | 78 | if(NOT MPI4PY_COMMAND_RESULT) 79 | message(STATUS "Found mpi4py include directory at ${MPI4PY_INCLUDE_DIR}") 80 | target_include_directories(mui4py_mod PRIVATE ${MPI4PY_INCLUDE_DIR}) 81 | else() 82 | message(FATAL_ERROR "mpi4py could not be found.") 83 | endif() 84 | -------------------------------------------------------------------------------- /wrappers/Python/README.md: -------------------------------------------------------------------------------- 1 | # Information about the MUI Python wrapper mui4py 2 | ### Notes 3 | - Support for `int32`, `int64`, `float`, `double` and `std::string` is included for `push()` and `fetch()` *-like* functions. `push_many()` and `fetch_many()` do not work with `std::string` as they use `numpy` arrays, which do not play well with strings at the `pybind11` level. 4 | 5 | - Only `sampler_exact` and `temporal_sampler_exact` classes work with `std::string` type. 6 | - Interfaces can be configured to be `1d`, `2d` or `3d` and to use `float` or `double` for point arithmetics and time stamps. 7 | - A `mui4py-demos` folder has been included in the `mui-demos` repository. 8 | 9 | ### Extra functionality 10 | - `push_many()` and `fetch_many()` functions. They can push/fetch a list of values at different locations using C looping. They can provide great speedups with respect to python loops. They make use of `numpy.ndarray` . 11 | - `get_mpi_version()`, `get_compiler_version()`and `get_compiler_info()` provide compile-time information about `mui4py`. 12 | 13 | # Building 14 | 15 | ## Installation 16 | - The easiest way to install the Python package is to use: 17 | 18 | ``` 19 | pip3 install . 20 | ``` 21 |        In the event that CMake encounter an error related to `mui.h` not being found during compilation, you can resolve this by adding the following flag to the CMAKE_ARGS: 22 | 23 | ``` 24 | -DCMAKE_INCLUDE_DIRECTORIES=/path/to/MUI/src 25 | ``` 26 |        In the event that CMake is unable to locate Python3 or is unable to find the correct version of Python3, you can use the following flag to the CMAKE_ARGS to specify the path to the correct Python3 executable: 27 | 28 | ``` 29 | -DPython3_EXECUTABLE=/path/to/python3 30 | ``` 31 |        If CMake is unable to locate pybind11 during the compilation process, you can use the following flag to the CMAKE_ARGS to specify the path to the pybind11 directory: 32 | 33 | ``` 34 | -DCMAKE_PREFIX_PATH=/path/to/pybind11 35 | ``` 36 | 37 | - Alternatively `python3 setup.py install` may work. 38 | 39 | 40 | - The C++ Python bindings can also be built directly with cmake and make, which is useful for testing. An example of built with cmake and make: 41 | 42 | ``` 43 | mkdir build && cd build 44 | cmake .. 45 | make 46 | cd .. && cp build/*.so mui4py/ 47 | ``` 48 |        Note that if built with cmake and make, the path to the MUI Python wrapper should be added to the PYTHONPATH before use: 49 | 50 | ``` 51 | export PYTHONPATH=$PYTHONPATH:/path/to/MUI/wrappers/Python 52 | ``` 53 | 54 | ### General 55 | 56 | - Bindings tested with: 57 | - `gcc 7.2.0` and `clang LLVM version 9.1.0`, but it should work with any version of them supporting `c++11`. 58 | - `Mpich 3.2.1`, `OpenMPI 3.1.0` and `Spectrum MPI 10.02`. 59 | 60 | - It is advised to use **conda** or **virtualenv** environments. This will provide isolation and control over the dependencies. 61 | 62 | ### Dependencies 63 | - mpi4py (3.0.0) 64 | - numpy (>1.13) 65 | - pybind11 (only at compile time) 66 | > `mpi4py` package should be compiled with the same compiler and MPI version as `mui4py`. Use `mpi4py.get_config()` and `mui4py.get_compiler_config()`, `mui4py.get_compiler_version()`, `mui4py.get_mpi_version()` to gather compile-time information. 67 | 68 | # Contact 69 | 70 | Please contact *Eduardo Ramos Fernandez* at eduardo.rf159@gmail.com and *Wendi Liu* at wendi.liu@stfc.ac.uk for issues about overall design or *Chris Richardson (Cambridge University)* for issues relating to packaging. 71 | 72 | # ToDo List 73 | 74 | - Include boolean OR operation of shapes in the bindings. 75 | - Write exception hierarchy to replace generic exceptions. 76 | - Add 'collide' function to library. 77 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | ############################################################################## 3 | # Multiscale Universal Interface Code Coupling Library # 4 | # # 5 | # Copyright (C) 2023 E. R. Fernandez, W. Liu # 6 | # # 7 | # This software is jointly licensed under the Apache License, Version 2.0 # 8 | # and the GNU General Public License version 3, you may use it according # 9 | # to either. # 10 | # # 11 | # ** Apache License, version 2.0 ** # 12 | # # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); # 14 | # you may not use this file except in compliance with the License. # 15 | # You may obtain a copy of the License at # 16 | # # 17 | # http://www.apache.org/licenses/LICENSE-2.0 # 18 | # # 19 | # Unless required by applicable law or agreed to in writing, software # 20 | # distributed under the License is distributed on an "AS IS" BASIS, # 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 22 | # See the License for the specific language governing permissions and # 23 | # limitations under the License. # 24 | # # 25 | # ** GNU General Public License, version 3 ** # 26 | # # 27 | # This program is free software: you can redistribute it and/or modify # 28 | # it under the terms of the GNU General Public License as published by # 29 | # the Free Software Foundation, either version 3 of the License, or # 30 | # (at your option) any later version. # 31 | # # 32 | # This program is distributed in the hope that it will be useful, # 33 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 34 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 35 | # GNU General Public License for more details. # 36 | # # 37 | # You should have received a copy of the GNU General Public License # 38 | # along with this program. If not, see . # 39 | ############################################################################## 40 | # 41 | # @file __init__.py 42 | # @author E. R. Fernandez, W. Liu 43 | # @date 25 January 2019 44 | # @brief Marker file denotes the directory containing the file as the MUI Python wrapper package. 45 | # 46 | """ 47 | 48 | # flake8: noqa 49 | from mui4py.mui4py import Uniface, mpi_split_by_app, set_quiet,\ 50 | set_data_types_unifaces, create_unifaces,\ 51 | get_mpi_version, get_compiler_version, get_compiler_config 52 | from mui4py.samplers import SamplerExact, SamplerGauss, SamplerMovingAverage,\ 53 | SamplerNearestNeighbor, SamplerPseudoNearest2Linear,\ 54 | SamplerPseudoNearestNeighbor, SamplerSherpardQuintic,\ 55 | SamplerSphQuintic, SamplerSumQuintic, SamplerRbf 56 | from mui4py.temporal_samplers import TemporalSamplerExact, TemporalSamplerGauss,\ 57 | TemporalSamplerMean, TemporalSamplerSum 58 | from mui4py.algorithms import AlgorithmFixedRelaxation, AlgorithmAitken 59 | from mui4py.types import STRING, INT32, INT64, INT, UINT32, UINT64, UINT, FLOAT32, FLOAT64, FLOAT, BOOL 60 | from mui4py.config import Config, set_default_config, get_default_config 61 | import mui4py.geometry 62 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/config.py: -------------------------------------------------------------------------------- 1 | """ 2 | ############################################################################## 3 | # Multiscale Universal Interface Code Coupling Library # 4 | # # 5 | # Copyright (C) 2023 E. R. Fernandez # 6 | # # 7 | # This software is jointly licensed under the Apache License, Version 2.0 # 8 | # and the GNU General Public License version 3, you may use it according # 9 | # to either. # 10 | # # 11 | # ** Apache License, version 2.0 ** # 12 | # # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); # 14 | # you may not use this file except in compliance with the License. # 15 | # You may obtain a copy of the License at # 16 | # # 17 | # http://www.apache.org/licenses/LICENSE-2.0 # 18 | # # 19 | # Unless required by applicable law or agreed to in writing, software # 20 | # distributed under the License is distributed on an "AS IS" BASIS, # 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 22 | # See the License for the specific language governing permissions and # 23 | # limitations under the License. # 24 | # # 25 | # ** GNU General Public License, version 3 ** # 26 | # # 27 | # This program is free software: you can redistribute it and/or modify # 28 | # it under the terms of the GNU General Public License as published by # 29 | # the Free Software Foundation, either version 3 of the License, or # 30 | # (at your option) any later version. # 31 | # # 32 | # This program is distributed in the hope that it will be useful, # 33 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 34 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 35 | # GNU General Public License for more details. # 36 | # # 37 | # You should have received a copy of the GNU General Public License # 38 | # along with this program. If not, see . # 39 | ############################################################################## 40 | # 41 | # @file config.py 42 | # @author E. R. Fernandez 43 | # @date 25 January 2019 44 | # @brief Configure functions for MUI Python wrapper. 45 | # 46 | """ 47 | 48 | from mui4py.types import map_type, UINT 49 | __default_config = None 50 | 51 | 52 | def set_default_config(config): 53 | global __default_config 54 | __default_config = config 55 | 56 | 57 | def get_default_config(): 58 | if __default_config is None: 59 | raise Exception("Default configuration not defined.") 60 | return __default_config 61 | 62 | 63 | class Config: 64 | def __init__(self, dim=None, float_type=float, force_casting=True): 65 | # NOTE: int_type is fixed to Python int size at compile time 66 | self.int_type = map_type[int] 67 | self.uint_type = map_type[UINT] 68 | self.float_type = map_type[float_type] 69 | self.dim = dim 70 | self._check_types() 71 | self.force_casting = force_casting 72 | 73 | def _check_types(self): 74 | pass 75 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/algorithm_name.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file algorithm_name.h 42 | * @author W. Liu 43 | * @date 18 March 2023 44 | * @brief Algorithm names for MUI Python wrapper. 45 | */ 46 | 47 | template class Talgorithm> 48 | std::string algorithm_name() 49 | { 50 | if (std::is_same, mui::algo_fixed_relaxation>::value) 51 | return "algorithm_fixed_relaxation"; 52 | if (std::is_same, mui::algo_aitken>::value) 53 | return "algorithm_aitken"; 54 | throw std::runtime_error("Invalid temporal sampler type"); 55 | } 56 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/compiler_info.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, E. R. Fernandez, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file compiler_info.h 42 | * @author C. Richardson, E. R. Fernandez, W. Liu 43 | * @date 11 March 2023 44 | * @brief Compiler info and MUI version for MUI Python wrapper. 45 | */ 46 | 47 | std::string get_mpi_version() 48 | { 49 | #ifdef MPI_VERSION_STR 50 | return MPI_VERSION_STR; 51 | #else 52 | return ""; 53 | #endif 54 | } 55 | 56 | std::string get_compiler_version() 57 | { 58 | #ifdef COMPILER_VERSION_STR 59 | return COMPILER_VERSION_STR; 60 | #else 61 | return ""; 62 | #endif 63 | } 64 | 65 | std::string get_compiler_config() 66 | { 67 | #ifdef COMPILER_CONFIG_STR 68 | return COMPILER_CONFIG_STR; 69 | #else 70 | return ""; 71 | #endif 72 | } 73 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/config_name.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file config_name.h 42 | * @author C. Richardson 43 | * @date 20 January 2023 44 | * @brief Config names for MUI Python wrapper. 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | template 51 | std::string config_name() 52 | { 53 | if (std::is_same()) 54 | return "1d_f64_i32"; 55 | if (std::is_same()) 56 | return "2d_f64_i32"; 57 | if (std::is_same()) 58 | return "3d_f64_i32"; 59 | if (std::is_same()) 60 | return "1d_f64_i64"; 61 | if (std::is_same()) 62 | return "2d_f64_i64"; 63 | if (std::is_same()) 64 | return "3d_f64_i64"; 65 | if (std::is_same()) 66 | return "1d_f32_i32"; 67 | if (std::is_same()) 68 | return "2d_f32_i32"; 69 | if (std::is_same()) 70 | return "3d_f32_i32"; 71 | if (std::is_same()) 72 | return "1d_f32_i64"; 73 | if (std::is_same()) 74 | return "2d_f32_i64"; 75 | if (std::is_same()) 76 | return "3d_f32_i64"; 77 | throw std::runtime_error("Invalid config type"); 78 | } 79 | 80 | template 81 | std::string type_name() 82 | { 83 | if (std::is_same::value) 84 | return "double"; 85 | if (std::is_same::value) 86 | return "float"; 87 | if (std::is_same::value) 88 | return "int32_t"; 89 | if (std::is_same::value) 90 | return "int64_t"; 91 | if (std::is_same::value) 92 | return "string"; 93 | throw std::runtime_error("Invalid type"); 94 | } 95 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/mui4py.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, E. R. Fernandez, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file mui4py.cpp 42 | * @author C. Richardson, E. R. Fernandez, W. Liu 43 | * @date 20 January 2023 44 | * @brief Main c++ file for MUI Python wrapper. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #include "compiler_info.h" 57 | 58 | // Declaration of other files 59 | void geometry(py::module &m); 60 | void sampler(py::module &m); 61 | void temporal_sampler(py::module &m); 62 | void algorithm(py::module &m); 63 | void uniface1d(py::module &m); 64 | void uniface2d(py::module &m); 65 | void uniface3d(py::module &m); 66 | void uniface1f(py::module &m); 67 | void uniface2f(py::module &m); 68 | void uniface3f(py::module &m); 69 | 70 | PYBIND11_MODULE(mui4py_mod, m) 71 | { 72 | m.doc() = "MUI bindings for Python."; 73 | 74 | // Expose numerical limits from C++ 75 | m.attr("numeric_limits_real") = std::numeric_limits::min(); 76 | m.attr("numeric_limits_int") = std::numeric_limits::min(); 77 | m.attr("numeric_limits_uint") = std::numeric_limits::lowest(); 78 | 79 | geometry(m); 80 | sampler(m); 81 | temporal_sampler(m); 82 | algorithm(m); 83 | uniface1d(m); 84 | uniface2d(m); 85 | uniface3d(m); 86 | uniface1f(m); 87 | uniface2f(m); 88 | uniface3f(m); 89 | 90 | m.def("set_quiet", &mui::set_quiet, ""); 91 | m.def( 92 | "mpi_split_by_app", []() -> py::handle 93 | { 94 | if (import_mpi4py() < 0) 95 | Py_RETURN_NONE; 96 | return PyMPIComm_New(mui::mpi_split_by_app()); }, 97 | ""); 98 | m.def("get_mpi_version", &get_mpi_version, ""); 99 | m.def("get_compiler_config", &get_compiler_config, ""); 100 | m.def("get_compiler_version", &get_compiler_version, ""); 101 | } 102 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/sampler_name.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file sampler_name.h 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Spacial sampler names for MUI Python wrapper. 45 | */ 46 | 47 | template class Tsampler> 48 | std::string sampler_name() 49 | { 50 | if (std::is_same, mui::sampler_exact>::value) 51 | return "exact"; 52 | if (std::is_same, mui::sampler_gauss>::value) 53 | return "gauss"; 54 | if (std::is_same, mui::sampler_moving_average>::value) 55 | return "moving_average"; 56 | if (std::is_same, mui::sampler_nearest_neighbor>::value) 57 | return "nearest_neighbor"; 58 | if (std::is_same, mui::sampler_pseudo_n2_linear>::value) 59 | return "pseudo_n2_linear"; 60 | if (std::is_same, mui::sampler_pseudo_nearest_neighbor>::value) 61 | return "pseudo_nearest_neighbor"; 62 | if (std::is_same, mui::sampler_shepard_quintic>::value) 63 | return "shepard_quintic"; 64 | if (std::is_same, mui::sampler_sph_quintic>::value) 65 | return "sph_quintic"; 66 | if (std::is_same, mui::sampler_sum_quintic>::value) 67 | return "sum_quintic"; 68 | if (std::is_same, mui::sampler_rbf>::value) 69 | return "rbf"; 70 | throw std::runtime_error("Invalid sampler type"); 71 | } 72 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/temporal_name.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file temporal_name.h 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Temporal sampler names for MUI Python wrapper. 45 | */ 46 | 47 | template class Ttemporal> 48 | std::string temporal_sampler_name() 49 | { 50 | if (std::is_same, mui::temporal_sampler_exact>::value) 51 | return "temporal_exact"; 52 | if (std::is_same, mui::temporal_sampler_gauss>::value) 53 | return "temporal_gauss"; 54 | if (std::is_same, mui::temporal_sampler_sum>::value) 55 | return "temporal_sum"; 56 | if (std::is_same, mui::temporal_sampler_mean>::value) 57 | return "temporal_mean"; 58 | throw std::runtime_error("Invalid temporal sampler type"); 59 | } 60 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface1d.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 1-D double for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface1d(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | declare_uniface_class(m); 53 | 54 | #elif defined PYTHON_INT_32 55 | declare_uniface_class(m); 56 | 57 | #else 58 | #error PYTHON_INT_[32|64] not defined. 59 | #endif 60 | } 61 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface1f.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 1-D float for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface1f(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | declare_uniface_class(m); 53 | 54 | #elif defined PYTHON_INT_32 55 | declare_uniface_class(m); 56 | 57 | 58 | #else 59 | #error PYTHON_INT_[32|64] not defined. 60 | #endif 61 | } 62 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface2d.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 2-D double for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface2d(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | 53 | declare_uniface_class(m); 54 | 55 | #elif defined PYTHON_INT_32 56 | 57 | declare_uniface_class(m); 58 | 59 | #else 60 | #error PYTHON_INT_[32|64] not defined. 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface2f.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 2-D float for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface2f(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | 53 | declare_uniface_class(m); 54 | 55 | #elif defined PYTHON_INT_32 56 | 57 | declare_uniface_class(m); 58 | 59 | #else 60 | #error PYTHON_INT_[32|64] not defined. 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface3d.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 3-D double for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface3d(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | declare_uniface_class(m); 53 | 54 | #elif defined PYTHON_INT_32 55 | 56 | declare_uniface_class(m); 57 | 58 | #else 59 | #error PYTHON_INT_[32|64] not defined. 60 | #endif 61 | } 62 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/cpp/uniface3f.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Multiscale Universal Interface Code Coupling Library * 3 | * * 4 | * Copyright (C) 2023 C. Richardson, W. Liu * 5 | * * 6 | * This software is jointly licensed under the Apache License, Version 2.0 * 7 | * and the GNU General Public License version 3, you may use it according * 8 | * to either. * 9 | * * 10 | * ** Apache License, version 2.0 ** * 11 | * * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); * 13 | * you may not use this file except in compliance with the License. * 14 | * You may obtain a copy of the License at * 15 | * * 16 | * http://www.apache.org/licenses/LICENSE-2.0 * 17 | * * 18 | * Unless required by applicable law or agreed to in writing, software * 19 | * distributed under the License is distributed on an "AS IS" BASIS, * 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 21 | * See the License for the specific language governing permissions and * 22 | * limitations under the License. * 23 | * * 24 | * ** GNU General Public License, version 3 ** * 25 | * * 26 | * This program is free software: you can redistribute it and/or modify * 27 | * it under the terms of the GNU General Public License as published by * 28 | * the Free Software Foundation, either version 3 of the License, or * 29 | * (at your option) any later version. * 30 | * * 31 | * This program is distributed in the hope that it will be useful, * 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 34 | * GNU General Public License for more details. * 35 | * * 36 | * You should have received a copy of the GNU General Public License * 37 | * along with this program. If not, see . * 38 | *****************************************************************************/ 39 | 40 | /** 41 | * @file uniface1d.cpp 42 | * @author C. Richardson, W. Liu 43 | * @date 11 March 2023 44 | * @brief Uniface 3-D float for MUI Python wrapper. 45 | */ 46 | 47 | #include "uniface_base.h" 48 | 49 | void uniface3f(py::module &m) 50 | { 51 | #ifdef PYTHON_INT_64 52 | 53 | declare_uniface_class(m); 54 | 55 | #elif defined PYTHON_INT_32 56 | 57 | declare_uniface_class(m); 58 | 59 | #else 60 | #error PYTHON_INT_[32|64] not defined. 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/geometry.py: -------------------------------------------------------------------------------- 1 | """ 2 | ############################################################################## 3 | # Multiscale Universal Interface Code Coupling Library # 4 | # # 5 | # Copyright (C) 2023 E. R. Fernandez # 6 | # # 7 | # This software is jointly licensed under the Apache License, Version 2.0 # 8 | # and the GNU General Public License version 3, you may use it according # 9 | # to either. # 10 | # # 11 | # ** Apache License, version 2.0 ** # 12 | # # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); # 14 | # you may not use this file except in compliance with the License. # 15 | # You may obtain a copy of the License at # 16 | # # 17 | # http://www.apache.org/licenses/LICENSE-2.0 # 18 | # # 19 | # Unless required by applicable law or agreed to in writing, software # 20 | # distributed under the License is distributed on an "AS IS" BASIS, # 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 22 | # See the License for the specific language governing permissions and # 23 | # limitations under the License. # 24 | # # 25 | # ** GNU General Public License, version 3 ** # 26 | # # 27 | # This program is free software: you can redistribute it and/or modify # 28 | # it under the terms of the GNU General Public License as published by # 29 | # the Free Software Foundation, either version 3 of the License, or # 30 | # (at your option) any later version. # 31 | # # 32 | # This program is distributed in the hope that it will be useful, # 33 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 34 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 35 | # GNU General Public License for more details. # 36 | # # 37 | # You should have received a copy of the GNU General Public License # 38 | # along with this program. If not, see . # 39 | ############################################################################## 40 | # 41 | # @file geometry.py 42 | # @author E. R. Fernandez 43 | # @date 25 January 2019 44 | # @brief Geometry functions for MUI Python wrapper. 45 | # 46 | """ 47 | 48 | from mui4py.common import CppClass, _Point 49 | from mui4py.config import Config 50 | 51 | 52 | class Geometry(CppClass): 53 | def __init__(self, args=(), kwargs={}): 54 | super(Geometry, self).__init__(Config(), args, kwargs) 55 | self.namespace = "geometry" 56 | 57 | def bbox(self): 58 | return self.raw.bbox() 59 | 60 | 61 | def collide(shape1, shape2): 62 | pass 63 | 64 | 65 | class Box(Geometry): 66 | def __init__(self, x1, x2): 67 | super(Box, self).__init__(args=(_Point(x1), _Point(x2))) 68 | 69 | 70 | class Sphere(Geometry): 71 | def __init__(self, x0, r): 72 | super(Sphere, self).__init__(args=(_Point(x0), r)) 73 | 74 | 75 | class Point(Geometry): 76 | def __init__(self, x0): 77 | super(Point, self).__init__(args=(_Point(x0), )) 78 | -------------------------------------------------------------------------------- /wrappers/Python/mui4py/temporal_samplers.py: -------------------------------------------------------------------------------- 1 | """ 2 | ############################################################################## 3 | # Multiscale Universal Interface Code Coupling Library # 4 | # # 5 | # Copyright (C) 2023 E. R. Fernandez, W. Liu # 6 | # # 7 | # This software is jointly licensed under the Apache License, Version 2.0 # 8 | # and the GNU General Public License version 3, you may use it according # 9 | # to either. # 10 | # # 11 | # ** Apache License, version 2.0 ** # 12 | # # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); # 14 | # you may not use this file except in compliance with the License. # 15 | # You may obtain a copy of the License at # 16 | # # 17 | # http://www.apache.org/licenses/LICENSE-2.0 # 18 | # # 19 | # Unless required by applicable law or agreed to in writing, software # 20 | # distributed under the License is distributed on an "AS IS" BASIS, # 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 22 | # See the License for the specific language governing permissions and # 23 | # limitations under the License. # 24 | # # 25 | # ** GNU General Public License, version 3 ** # 26 | # # 27 | # This program is free software: you can redistribute it and/or modify # 28 | # it under the terms of the GNU General Public License as published by # 29 | # the Free Software Foundation, either version 3 of the License, or # 30 | # (at your option) any later version. # 31 | # # 32 | # This program is distributed in the hope that it will be useful, # 33 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 34 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 35 | # GNU General Public License for more details. # 36 | # # 37 | # You should have received a copy of the GNU General Public License # 38 | # along with this program. If not, see . # 39 | ############################################################################## 40 | # 41 | # @file temporal_sampler.py 42 | # @author E. R. Fernandez, W. Liu 43 | # @date 18 March 2019 44 | # @brief Temporal sampler functions for the MUI Python wrapper. 45 | # 46 | """ 47 | 48 | from mui4py.common import CppClass 49 | from mui4py.config import Config 50 | from mui4py.types import UINT, UINT32, UINT64, FLOAT, FLOAT32, FLOAT64, INT, INT32, INT64, STRING, BOOL 51 | 52 | # Interface for TemporalSampler 53 | def sampler_fetch_signature(self): 54 | sig = self._split_class_name(title=False) 55 | sig = sig.replace("_sampler", "") 56 | return sig.replace("sampler_", "") 57 | 58 | # Temporal samplers 59 | class TemporalSampler(CppClass): 60 | def __init__(self, args=(), kwargs={}): 61 | # Empty config to not trigger error in default config. 62 | super(TemporalSampler, self).__init__(Config(), args, kwargs) 63 | 64 | 65 | TemporalSampler.fetch_signature = sampler_fetch_signature 66 | 67 | 68 | class TemporalSamplerExact(TemporalSampler): 69 | def __init__(self, tol=None): 70 | super(TemporalSamplerExact, self).__init__(kwargs={"tol": tol}) 71 | self._ALLOWED_IO_TYPES = [INT, INT32, INT64, UINT, UINT32, UINT64, FLOAT, FLOAT32, FLOAT64, STRING, BOOL] 72 | 73 | 74 | class TemporalSamplerGauss(TemporalSampler): 75 | def __init__(self, cutoff, sigma): 76 | super(TemporalSamplerGauss, self).__init__(args=(cutoff, sigma)) 77 | self._ALLOWED_IO_TYPES = [UINT, UINT32, UINT64, INT, INT32, INT64, FLOAT, FLOAT32, FLOAT64] 78 | 79 | 80 | class TemporalSamplerMean(TemporalSampler): 81 | def __init__(self, newleft=None, newright=None): 82 | super(TemporalSamplerMean, self).__init__(kwargs={"newleft": newleft, "newright": newright}) 83 | self._ALLOWED_IO_TYPES = [UINT, UINT32, UINT64, INT, INT32, INT64, FLOAT, FLOAT32, FLOAT64] 84 | 85 | 86 | class TemporalSamplerSum(TemporalSampler): 87 | def __init__(self, newleft=None, newright=None): 88 | super(TemporalSamplerSum, self).__init__(kwargs={"newleft": newleft, "newright": newright}) 89 | self._ALLOWED_IO_TYPES = [UINT, UINT32, UINT64, INT, INT32, INT64, FLOAT, FLOAT32, FLOAT64] 90 | -------------------------------------------------------------------------------- /wrappers/Python/setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | --------------------------------------------------------------------------------