From dcb5e4919122189d74c5ac33119a14eca2badc5e Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 25 Sep 2023 11:08:50 -0600 Subject: [PATCH 01/24] added creating solver interface --- lib/micm | 2 +- musica-fortran/src/micm/CMakeLists.txt | 4 +- musica-fortran/src/micm/MICM_C_def.F90 | 33 ++++++++ musica-fortran/src/micm/MICM_mod.F90 | 69 ++++++++++++++++ musica-fortran/test/CMakeLists.txt | 3 +- .../test/micm_config/mechanism.json | 1 + musica-fortran/test/micm_config/species.json | 1 + musica-fortran/test/test.F90 | 38 +++++++++ musica/include/micm/MICM.hpp | 39 +++++++++ musica/include/micm/MICM_C.h | 18 +++++ musica/src/micm/CMakeLists.txt | 4 +- musica/src/micm/MICM.cpp | 80 +++++++++++++++++++ musica/src/micm/MICM_C_API.cpp | 33 ++++++++ 13 files changed, 321 insertions(+), 4 deletions(-) create mode 100644 musica-fortran/src/micm/MICM_C_def.F90 create mode 100644 musica-fortran/src/micm/MICM_mod.F90 create mode 100644 musica-fortran/test/micm_config/mechanism.json create mode 100644 musica-fortran/test/micm_config/species.json create mode 100644 musica-fortran/test/test.F90 create mode 100644 musica/include/micm/MICM.hpp create mode 100644 musica/include/micm/MICM_C.h create mode 100644 musica/src/micm/MICM.cpp create mode 100644 musica/src/micm/MICM_C_API.cpp diff --git a/lib/micm b/lib/micm index fb5efb82..fb8e3d31 160000 --- a/lib/micm +++ b/lib/micm @@ -1 +1 @@ -Subproject commit fb5efb82034def032dbc5d9643947e1641df39d1 +Subproject commit fb8e3d318f30884d4838afeafe7387d255ed4943 diff --git a/musica-fortran/src/micm/CMakeLists.txt b/musica-fortran/src/micm/CMakeLists.txt index 7e743d8f..6642d996 100644 --- a/musica-fortran/src/micm/CMakeLists.txt +++ b/musica-fortran/src/micm/CMakeLists.txt @@ -1,4 +1,6 @@ target_sources(musica-fortran PUBLIC - interface.F90 + # interface.F90 + MICM_C_def.F90 + MICM_mod.F90 ) \ No newline at end of file diff --git a/musica-fortran/src/micm/MICM_C_def.F90 b/musica-fortran/src/micm/MICM_C_def.F90 new file mode 100644 index 00000000..a6e7e562 --- /dev/null +++ b/musica-fortran/src/micm/MICM_C_def.F90 @@ -0,0 +1,33 @@ +! C functions declaration +interface + function create_micm_c(config_path) bind(C, name="create_micm") + use iso_c_binding + implicit none + type(c_ptr) :: create_micm_c + character(len=1, kind=C_CHAR), intent(in) :: config_path(*) + end function + + subroutine delete_micm_c(micm) bind(C, name="delete_micm") + use iso_c_binding + implicit none + type(c_ptr), value :: micm + end subroutine + + function micm_create_solver_c(micm) bind(C, name="micm_create_solver") + use iso_c_binding + implicit none + integer(c_int) :: micm_create_solver_c ! TODO(jiwon) return value? + type(c_ptr), intent(in), value :: micm + end function + + subroutine micm_solve_c(micm, temperature, pressure, time_step, concentrations, num_concentrations) bind(C, name="micm_solve") + use iso_c_binding + implicit none + type(c_ptr), intent(in), value :: micm + real(c_double), value :: temperature + real(c_double), value :: pressure + real(c_double), value :: time_step + real(c_double), dimension(*), intent(inout) :: concentrations + integer(c_size_t), value, intent(in) :: num_concentrations + end subroutine +end interface diff --git a/musica-fortran/src/micm/MICM_mod.F90 b/musica-fortran/src/micm/MICM_mod.F90 new file mode 100644 index 00000000..289efb0c --- /dev/null +++ b/musica-fortran/src/micm/MICM_mod.F90 @@ -0,0 +1,69 @@ +module libmicm + use iso_c_binding + + private + public :: micm + + include "MICM_C_def.F90" + + type micm + private + type(c_ptr) :: ptr + contains + procedure :: delete => delete_micm_polymorph + procedure :: create_solver => micm_create_solver + procedure :: solve => micm_solve + end type + + interface micm + procedure create_micm + end interface + +contains + function create_micm(config_path) + implicit none + type(micm) :: create_micm + character(len=*), intent(in) :: config_path + character(len=1, kind=C_CHAR) :: c_config_path(len_trim(config_path) + 1) + integer :: N, i + + ! Converting Fortran string to C string + N = len_trim(config_path) + do i = 1, N + c_config_path(i) = config_path(i:i) + end do + c_config_path(N + 1) = C_NULL_CHAR + + create_micm%ptr = create_micm_c(c_config_path) + end function + + subroutine delete_micm(this) + implicit none + type(micm) :: this + call delete_micm_c(this%ptr) + end subroutine + + subroutine delete_micm_polymorph(this) + implicit none + class(micm) :: this + call delete_micm_c(this%ptr) + end subroutine + + integer function micm_create_solver(this) + implicit none + class(micm), intent(in) :: this + micm_create_solver = micm_create_solver_c(this%ptr) + end function + + subroutine micm_solve(this, temperature, pressure, time_step, concentrations, num_concentrations) + implicit none + class(micm), intent(in) :: this + real(c_double), intent(in) :: temperature + real(c_double), intent(in) :: pressure + real(c_double), intent(in) :: time_step + real(c_double), dimension(*), intent(inout) :: concentrations + integer(c_size_t), intent(in) :: num_concentrations + call micm_solve_c(this%ptr, temperature, pressure, time_step, concentrations, num_concentrations) + end subroutine + +end module \ No newline at end of file diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 9f7eea38..242aca1f 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -22,7 +22,8 @@ FetchContent_MakeAvailable(musica) ################################################################################ # Tests -add_executable(test_musica_api test_musica_api.F90) +# add_executable(test_musica_api test_musica_api.F90) +add_executable(test_musica_api test.F90) target_link_libraries(test_musica_api PUBLIC diff --git a/musica-fortran/test/micm_config/mechanism.json b/musica-fortran/test/micm_config/mechanism.json new file mode 100644 index 00000000..acf1a257 --- /dev/null +++ b/musica-fortran/test/micm_config/mechanism.json @@ -0,0 +1 @@ +{"camp-data": [{"name": "Chapman", "type": "MECHANISM", "reactions": [{"type": "ARRHENIUS", "reactants": {"spec_0": {}, "spec_1": {}, "spec_2": {}}, "products": {"spec_3": {"yield": 0.7}, "spec_4": {"yield": 0.6}, "spec_5": {"yield": 0.4}, "spec_6": {"yield": 0.1}}, "MUSICA name": "reaction_0", "A": 0.06307742014373313, "C": -4.580502916806157}, {"type": "ARRHENIUS", "reactants": {"spec_7": {}, "spec_8": {}}, "products": {"spec_9": {"yield": 1.4}}, "MUSICA name": "reaction_1", "A": 0.04349975747486285, "C": 0.9227077653687363}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}, "spec_6": {}, "spec_8": {}}, "products": {"spec_5": {"yield": 1.2}, "spec_0": {"yield": 0.5}, "spec_7": {"yield": 0.6}, "spec_8": {"yield": 0.3}}, "MUSICA name": "reaction_2", "A": 0.06852791722073094, "C": 3.2487346324460002}, {"type": "ARRHENIUS", "reactants": {"spec_8": {}, "spec_4": {}}, "products": {"spec_9": {"yield": 0.5}, "spec_1": {"yield": 0.7}, "spec_6": {"yield": 1.1}, "spec_8": {"yield": 1.3}, "spec_4": {"yield": 1.2}, "spec_3": {"yield": 0.4}}, "MUSICA name": "reaction_3", "A": 0.25712668426775886, "C": -1.6984663902168808}, {"type": "ARRHENIUS", "reactants": {"spec_9": {}, "spec_1": {}}, "products": {"spec_5": {"yield": 0.6}}, "MUSICA name": "reaction_4", "A": 0.09981506051562195, "C": 4.434345327828195}, {"type": "ARRHENIUS", "reactants": {"spec_8": {}, "spec_1": {}, "spec_3": {}}, "products": {"spec_0": {"yield": 0.7}}, "MUSICA name": "reaction_5", "A": 0.04095822066544459, "C": -0.9768070373515956}, {"type": "ARRHENIUS", "reactants": {"spec_1": {}, "spec_7": {}}, "products": {"spec_8": {"yield": 1.1}, "spec_1": {"yield": 1.5}}, "MUSICA name": "reaction_6", "A": 0.05421274033990674, "C": -2.8281780970323145}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}}, "products": {"spec_5": {"yield": 0.8}, "spec_8": {"yield": 0.6}}, "MUSICA name": "reaction_7", "A": 0.48935553510912033, "C": -4.956655119700008}, {"type": "ARRHENIUS", "reactants": {"spec_3": {}}, "products": {"spec_7": {"yield": 0.9}, "spec_3": {"yield": 1.0}, "spec_2": {"yield": 1.3}}, "MUSICA name": "reaction_8", "A": 0.18950947076801095, "C": 0.04442551245927007}, {"type": "ARRHENIUS", "reactants": {"spec_6": {}}, "products": {"spec_4": {"yield": 0.7}, "spec_9": {"yield": 0.5}, "spec_3": {"yield": 0.8}, "spec_1": {"yield": 0.6}, "spec_5": {"yield": 0.2}}, "MUSICA name": "reaction_9", "A": 0.021971337763203702, "C": -2.81627531289537}]}]} \ No newline at end of file diff --git a/musica-fortran/test/micm_config/species.json b/musica-fortran/test/micm_config/species.json new file mode 100644 index 00000000..298de527 --- /dev/null +++ b/musica-fortran/test/micm_config/species.json @@ -0,0 +1 @@ +{"camp-data": [{"name": "spec_0", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_1", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_2", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_3", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_4", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_5", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_6", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_7", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_8", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}, {"name": "spec_9", "type": "CHEM_SPEC", "absolute tolerance": 1e-12}]} \ No newline at end of file diff --git a/musica-fortran/test/test.F90 b/musica-fortran/test/test.F90 new file mode 100644 index 00000000..c7aa3396 --- /dev/null +++ b/musica-fortran/test/test.F90 @@ -0,0 +1,38 @@ +program test + use iso_c_binding + use libmicm + implicit none + type(micm) :: m + + real(c_double) :: temp + real(c_double) :: pressure + real(c_double) :: time_step + real(c_double), dimension(10) :: concentrations + integer(c_size_t) :: num_concentrations + + temp = 10d0 + pressure = 20d0 + time_step = 1d0 + concentrations = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0 /) + num_concentrations = 10 + + write(*,*) " * [Fortran] Creating MICM" + m = micm("micm_config") + + write(*,*) " * [Fortran] Creating solver" + write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " + + write(*,*) " * [Fortran] Initial temp", temp + write(*,*) " * [Fortran] Initial pressure", pressure + write(*,*) " * [Fortran] Initial time_step", time_step + write(*,*) " * [Fortran] Initial concentrations", concentrations + write(*,*) " * [Fortran] Initial number of concentrations", num_concentrations + + write(*,*) " * [Fortran] Starting to solve" + call m%solve(temp, pressure, time_step, concentrations, num_concentrations) + write(*,*) " * [Fortran] After solving, concentrations", concentrations + + write(*,*) " * [Fortran] Calling destructor for MICM" + call m%delete + +end program \ No newline at end of file diff --git a/musica/include/micm/MICM.hpp b/musica/include/micm/MICM.hpp new file mode 100644 index 00000000..8235b8e1 --- /dev/null +++ b/musica/include/micm/MICM.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +class MICM +{ +public: + MICM(const std::string& config_path); + ~MICM(); + + // TODO(jiwon): can return type indicate error? + int create_solver(); + void delete_solver() const; + void solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations); + +private: + static constexpr size_t NUM_GRID_CELLS = 1; // TODO(jiwon) + + std::string config_path_; + + // TODO(jiwon) - currently hard coded + std::vector v_concentrations_; + + // TODO(jiwon) - currently hard coded + template + using Vector1MatrixParam = micm::VectorMatrix; + template + using Vector1SparseMatrixParam = micm::SparseMatrix>; + typedef micm::RosenbrockSolver VectorRosenbrockSolver; + VectorRosenbrockSolver* solver_; +}; + diff --git a/musica/include/micm/MICM_C.h b/musica/include/micm/MICM_C.h new file mode 100644 index 00000000..d0c7c213 --- /dev/null +++ b/musica/include/micm/MICM_C.h @@ -0,0 +1,18 @@ +#include + +#ifdef __cplusplus +extern "C" { + class MICM; + typedef MICM Micm; +#endif + +Micm* create_micm(const char* config_path); +void delete_micm(const Micm* micm); +int micm_create_solver(Micm* micm); +void micm_solve(Micm* micm, double temperature, double pressure, double time_step, + double* concentrations, size_t num_concentrations); + +#ifdef __cplusplus +} +#endif + diff --git a/musica/src/micm/CMakeLists.txt b/musica/src/micm/CMakeLists.txt index 964ff510..97d00d7d 100644 --- a/musica/src/micm/CMakeLists.txt +++ b/musica/src/micm/CMakeLists.txt @@ -1,4 +1,6 @@ target_sources(musica PRIVATE - interface.cpp + # interface.cpp + MICM_C_API.cpp + MICM.cpp ) \ No newline at end of file diff --git a/musica/src/micm/MICM.cpp b/musica/src/micm/MICM.cpp new file mode 100644 index 00000000..82b10d20 --- /dev/null +++ b/musica/src/micm/MICM.cpp @@ -0,0 +1,80 @@ +#include + +// #include "MICM.hpp" // TODO(jiwon) - do we want angle bracket, also how about relative path? +#include "../../include/micm/MICM.hpp" + +// #include // TODO - remove +#include + + +MICM::MICM(const std::string& config_path) + : config_path_(config_path), + solver_(nullptr) + { + std::cout << " * [C++] MICM constructor" << std::endl; + } + +MICM::~MICM() +{ + std::cout << " * [C++] MICM Destructor" << std::endl; +} + +int MICM::create_solver() +{ + std::cout << " * [C++] Creating solver" << std::endl; + bool success = 1; // TODO(jiwon): can we specifiy error type with int? + + // read and parse the config + micm::SolverConfig solver_config; + micm::ConfigParseStatus status = solver_config.ReadAndParse(config_path_); + micm::SolverParameters solver_params = solver_config.GetSolverParams(); + + if (status == micm::ConfigParseStatus::Success) + { + std::cout << " * [C++] Successfully read confiure file from the direcotry path: " << config_path_ << std::endl; + + auto params = micm::RosenbrockSolverParameters::three_stage_rosenbrock_parameters(NUM_GRID_CELLS); // TODO(jiwon) - three_stage + params.reorder_state_ = false; + solver_ = new VectorRosenbrockSolver{solver_params.system_, + solver_params.processes_, + params}; + } + else + { + std::cout << " * [C++] Failed creating solver" << std::endl; + success = 0; + } + + return success; +} + +void MICM::delete_solver() const +{ + std::cout << " * [C++] Deallocating solver" << std::endl; + delete solver_; +} + +void MICM::solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations) +{ + std::cout << " * [C++] Start solving " << std::endl; + + v_concentrations_.assign(concentrations, concentrations + num_concentrations); + + micm::State state = solver_->GetState(); + + for(size_t i{}; i < NUM_GRID_CELLS; ++i) { + state.conditions_[i].temperature_ = temperature; + state.conditions_[i].pressure_ = pressure; + } + + state.variables_[0] = v_concentrations_; // TODO: + + auto result = solver_->Solve(time_step, state); + // state.variables_[0] = result.result_.AsVector(); //TODO(jiwon): doesn't need because stae will get destroyed? + + v_concentrations_ = result.result_.AsVector(); + for (int i=0; idelete_solver(); + delete micm; +} + +int micm_create_solver(Micm* micm) +{ + std::cout << " * [C API] Creating solver" << std::endl; + return micm->create_solver(); +} + +void micm_solve(Micm* micm, double temperature, double pressure, double time_step, double* concentrations, size_t num_concentrations) +{ + std::cout << " * [C API] Starting solving" << std::endl; + + micm->solve(temperature, pressure, time_step, concentrations, num_concentrations); +} \ No newline at end of file From 978c04c58a9ed8d4cd175747db5ad18caa368b90 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Mon, 25 Sep 2023 16:43:40 -0500 Subject: [PATCH 02/24] updating stuff to try to make things build --- Dockerfile.fortran | 2 ++ musica-fortran/test/CMakeLists.txt | 1 + musica/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile.fortran b/Dockerfile.fortran index 73b196cd..f098755a 100644 --- a/Dockerfile.fortran +++ b/Dockerfile.fortran @@ -9,6 +9,7 @@ RUN apt update \ libcurl4-openssl-dev \ libhdf5-dev \ m4 \ + nlohmann-json3-dev \ vim \ zlib1g-dev \ git \ @@ -44,6 +45,7 @@ RUN cd musica \ && cmake -S . \ -B build \ -D ENABLE_TESTS=ON \ + -D ENABLE_TUVX=OFF \ && cd build \ && make install -j 8 diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 242aca1f..7922ae1d 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -12,6 +12,7 @@ include(FetchContent) set(USE_MUSICA OFF) set(USE_MUSICA_FORTRAN ON) +set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git diff --git a/musica/CMakeLists.txt b/musica/CMakeLists.txt index cb556df0..1a659588 100644 --- a/musica/CMakeLists.txt +++ b/musica/CMakeLists.txt @@ -136,7 +136,7 @@ if (ENABLE_MICM) install( DIRECTORY - ${PROJECT_SOURCE_DIR}/lib/micm/include/micm + ${PROJECT_SOURCE_DIR}/lib/micm/include DESTINATION ${INSTALL_MOD_DIR} ) From 1c2a7c8dbec7383979e172d9b39990349cbd3a14 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Mon, 25 Sep 2023 16:56:58 -0500 Subject: [PATCH 03/24] fixed the tag issue --- musica-fortran/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 7922ae1d..1cf822b2 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG 0cc0192 ## todo: jiwon update this + GIT_TAG v0.4.0 ) FetchContent_MakeAvailable(musica) From c6c7a72480354f41fea7c4c2bc92d5579e6465b4 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 25 Sep 2023 17:58:25 -0600 Subject: [PATCH 04/24] update musica core version --- lib/musica-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/musica-core b/lib/musica-core index f2133112..a0b2da06 160000 --- a/lib/musica-core +++ b/lib/musica-core @@ -1 +1 @@ -Subproject commit f2133112a25aa0dc8ae1a5109003bf72ac5680cf +Subproject commit a0b2da0681a5f7f24721bf7b9997e297cd88f5be From 24e0201f0181207eca4e42f9eea9bb22e8c3af9c Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 25 Sep 2023 18:08:33 -0600 Subject: [PATCH 05/24] change tag --- musica-fortran/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 1cf822b2..e83c709d 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG v0.4.0 + GIT_TAG 1c2a7c8 ) FetchContent_MakeAvailable(musica) From 38b7fc6c582a5064ec3a568cc0629e2f052f72d5 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 26 Sep 2023 11:45:19 -0600 Subject: [PATCH 06/24] update the musica version for fetching --- musica-fortran/CMakeLists.txt | 2 +- musica/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/musica-fortran/CMakeLists.txt b/musica-fortran/CMakeLists.txt index 1c7c7a92..3d71e3b7 100644 --- a/musica-fortran/CMakeLists.txt +++ b/musica-fortran/CMakeLists.txt @@ -28,7 +28,7 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(netcdff IMPORTED_TARGET REQUIRED netcdf-fortran) # Find MUSICA package -find_package(musica 0.3.0 REQUIRED) +find_package(musica 0.4.0 REQUIRED) target_link_libraries(musica-fortran PUBLIC diff --git a/musica/CMakeLists.txt b/musica/CMakeLists.txt index 1a659588..e0823902 100644 --- a/musica/CMakeLists.txt +++ b/musica/CMakeLists.txt @@ -89,7 +89,7 @@ target_sources(musica add_subdirectory(${PROJECT_SOURCE_DIR}/lib/musica-core/src ${MUSICA_LIB_DIR}/musica-core/src) -# #################### +#################### # TUV-x if (ENABLE_TUVX) add_definitions(-DMUSICA_USE_TUVX) @@ -122,7 +122,7 @@ if (ENABLE_TUVX) ) endif() -# #################### +#################### # MICM if (ENABLE_MICM) add_definitions(-DMUSICA_USE_MICM) From 32e213c23c7cff9fcbfbc19b7119955f965e1c47 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 26 Sep 2023 14:21:56 -0600 Subject: [PATCH 07/24] update tuvx --- lib/tuv-x | 2 +- musica-fortran/test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tuv-x b/lib/tuv-x index 35b19b37..16e7e8a4 160000 --- a/lib/tuv-x +++ b/lib/tuv-x @@ -1 +1 @@ -Subproject commit 35b19b3716bcce45b0ff93ef7e948a0225ebddd5 +Subproject commit 16e7e8a4b10dc387311530c7591cebb5b609a60c diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index e83c709d..96396faa 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG 1c2a7c8 + GIT_TAG 38b7fc6 ) FetchContent_MakeAvailable(musica) From b02bb56b2e60b992b3b7cb5fc3f8fb64933d88be Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 26 Sep 2023 14:42:46 -0600 Subject: [PATCH 08/24] update the tag --- musica-fortran/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 96396faa..38afd1f3 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG 38b7fc6 + GIT_TAG 32e213c ) FetchContent_MakeAvailable(musica) From 44ae12b437ecf334421ac0c0bc109a23d0e726f5 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 26 Sep 2023 14:58:58 -0600 Subject: [PATCH 09/24] update musica version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29958f6c..b4184e79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21) project( musica - VERSION 0.3.0 + VERSION 0.4.0 LANGUAGES Fortran CXX C ) From bfad77f1039573c9a7c284b02f371f314532d8aa Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 26 Sep 2023 16:02:22 -0600 Subject: [PATCH 10/24] exclude def file from src --- musica-fortran/src/micm/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/src/micm/CMakeLists.txt b/musica-fortran/src/micm/CMakeLists.txt index 6642d996..6370c94a 100644 --- a/musica-fortran/src/micm/CMakeLists.txt +++ b/musica-fortran/src/micm/CMakeLists.txt @@ -1,6 +1,6 @@ target_sources(musica-fortran PUBLIC # interface.F90 - MICM_C_def.F90 + # MICM_C_def.F90 MICM_mod.F90 ) \ No newline at end of file From 18530c23bd3f8f923bb15ba32a3b6fb4909a8176 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 27 Sep 2023 15:19:46 -0600 Subject: [PATCH 11/24] code clean up --- musica-fortran/src/micm/CMakeLists.txt | 4 +- musica-fortran/src/micm/interface.F90 | 22 ---------- .../micm/{MICM_C_def.F90 => micm_c_def.F90} | 3 +- .../src/micm/{MICM_mod.F90 => micm_mod.F90} | 2 +- musica-fortran/test/CMakeLists.txt | 5 +-- musica-fortran/test/test.F90 | 38 ---------------- musica-fortran/test/test_musica_api.F90 | 44 +++++++++++++++---- musica/include/micm/interface.hpp | 24 ---------- musica/include/micm/{MICM.hpp => micm.hpp} | 2 +- musica/include/micm/{MICM_C.h => micm_c.h} | 0 musica/src/micm/CMakeLists.txt | 5 +-- musica/src/micm/interface.cpp | 41 ----------------- musica/src/micm/{MICM.cpp => micm.cpp} | 12 ++--- .../micm/{MICM_C_API.cpp => micm_c_api.cpp} | 11 +++-- 14 files changed, 52 insertions(+), 161 deletions(-) delete mode 100644 musica-fortran/src/micm/interface.F90 rename musica-fortran/src/micm/{MICM_C_def.F90 => micm_c_def.F90} (97%) rename musica-fortran/src/micm/{MICM_mod.F90 => micm_mod.F90} (98%) delete mode 100644 musica-fortran/test/test.F90 delete mode 100644 musica/include/micm/interface.hpp rename musica/include/micm/{MICM.hpp => micm.hpp} (98%) rename musica/include/micm/{MICM_C.h => micm_c.h} (100%) delete mode 100644 musica/src/micm/interface.cpp rename musica/src/micm/{MICM.cpp => micm.cpp} (78%) rename musica/src/micm/{MICM_C_API.cpp => micm_c_api.cpp} (81%) diff --git a/musica-fortran/src/micm/CMakeLists.txt b/musica-fortran/src/micm/CMakeLists.txt index 6370c94a..a6fc43b4 100644 --- a/musica-fortran/src/micm/CMakeLists.txt +++ b/musica-fortran/src/micm/CMakeLists.txt @@ -1,6 +1,4 @@ target_sources(musica-fortran PUBLIC - # interface.F90 - # MICM_C_def.F90 - MICM_mod.F90 + micm_mod.F90 ) \ No newline at end of file diff --git a/musica-fortran/src/micm/interface.F90 b/musica-fortran/src/micm/interface.F90 deleted file mode 100644 index 355f69c9..00000000 --- a/musica-fortran/src/micm/interface.F90 +++ /dev/null @@ -1,22 +0,0 @@ -module micm - use iso_c_binding - - implicit none - - interface - - type(c_funptr) function get_solver(filepath) bind(c) - import :: c_char, c_funptr - character(len=*, kind=c_char), dimension(*), intent(in) :: filepath - end function get_solver - - subroutine solver(state, state_size, time_step) bind(c) - import :: c_ptr, c_double, c_int64_t - real(c_double), dimension(*) :: state - integer(c_int64_t), value :: state_size - integer(c_int64_t), value :: time_step - end subroutine - - end interface - -end module micm \ No newline at end of file diff --git a/musica-fortran/src/micm/MICM_C_def.F90 b/musica-fortran/src/micm/micm_c_def.F90 similarity index 97% rename from musica-fortran/src/micm/MICM_C_def.F90 rename to musica-fortran/src/micm/micm_c_def.F90 index a6e7e562..eabacdf2 100644 --- a/musica-fortran/src/micm/MICM_C_def.F90 +++ b/musica-fortran/src/micm/micm_c_def.F90 @@ -1,5 +1,4 @@ -! C functions declaration -interface +interface function create_micm_c(config_path) bind(C, name="create_micm") use iso_c_binding implicit none diff --git a/musica-fortran/src/micm/MICM_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 similarity index 98% rename from musica-fortran/src/micm/MICM_mod.F90 rename to musica-fortran/src/micm/micm_mod.F90 index 289efb0c..d13ac690 100644 --- a/musica-fortran/src/micm/MICM_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -4,7 +4,7 @@ module libmicm private public :: micm - include "MICM_C_def.F90" + include "micm_c_def.F90" type micm private diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 38afd1f3..b1572544 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,15 +16,14 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG 32e213c + GIT_TAG bfad77f # TODO(jiwon) - update the tag ) FetchContent_MakeAvailable(musica) ################################################################################ # Tests -# add_executable(test_musica_api test_musica_api.F90) -add_executable(test_musica_api test.F90) +add_executable(test_musica_api test_musica_api.F90) target_link_libraries(test_musica_api PUBLIC diff --git a/musica-fortran/test/test.F90 b/musica-fortran/test/test.F90 deleted file mode 100644 index c7aa3396..00000000 --- a/musica-fortran/test/test.F90 +++ /dev/null @@ -1,38 +0,0 @@ -program test - use iso_c_binding - use libmicm - implicit none - type(micm) :: m - - real(c_double) :: temp - real(c_double) :: pressure - real(c_double) :: time_step - real(c_double), dimension(10) :: concentrations - integer(c_size_t) :: num_concentrations - - temp = 10d0 - pressure = 20d0 - time_step = 1d0 - concentrations = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0 /) - num_concentrations = 10 - - write(*,*) " * [Fortran] Creating MICM" - m = micm("micm_config") - - write(*,*) " * [Fortran] Creating solver" - write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " - - write(*,*) " * [Fortran] Initial temp", temp - write(*,*) " * [Fortran] Initial pressure", pressure - write(*,*) " * [Fortran] Initial time_step", time_step - write(*,*) " * [Fortran] Initial concentrations", concentrations - write(*,*) " * [Fortran] Initial number of concentrations", num_concentrations - - write(*,*) " * [Fortran] Starting to solve" - call m%solve(temp, pressure, time_step, concentrations, num_concentrations) - write(*,*) " * [Fortran] After solving, concentrations", concentrations - - write(*,*) " * [Fortran] Calling destructor for MICM" - call m%delete - -end program \ No newline at end of file diff --git a/musica-fortran/test/test_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index 8ec61ac8..89e4805b 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -1,10 +1,38 @@ -program test_musica_api - use iso_c_binding - use micm +program test + use iso_c_binding + use libmicm + implicit none + type(micm) :: m - character(len=5, kind=c_char) :: c_filepath - type(c_funptr) :: csolver_func_pointer - c_filepath = 'asdf' - csolver_func_pointer = get_solver(c_filepath) + real(c_double) :: temperature + real(c_double) :: pressure + real(c_double) :: time_step + real(c_double), dimension(10) :: concentrations + integer(c_size_t) :: num_concentrations -end program test_musica_api + temperature = 10d0 + pressure = 20d0 + time_step = 1d0 + concentrations = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0 /) + num_concentrations = 10 + + write(*,*) " * [Fortran] Creating MICM" + m = micm("micm_config") + + write(*,*) " * [Fortran] Creating solver" + write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " + + write(*,*) " * [Fortran] Initial temp", temperature + write(*,*) " * [Fortran] Initial pressure", pressure + write(*,*) " * [Fortran] Initial time_step", time_step + write(*,*) " * [Fortran] Initial concentrations", concentrations + write(*,*) " * [Fortran] Initial number of concentrations", num_concentrations + + write(*,*) " * [Fortran] Starting to solve" + call m%solve(temperature, pressure, time_step, concentrations, num_concentrations) + write(*,*) " * [Fortran] After solving, concentrations", concentrations + + write(*,*) " * [Fortran] Calling destructor for MICM" + call m%delete + +end program \ No newline at end of file diff --git a/musica/include/micm/interface.hpp b/musica/include/micm/interface.hpp deleted file mode 100644 index 74c9bd40..00000000 --- a/musica/include/micm/interface.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -#include -#include -#include - -class MICM { - public: - micm::RosenbrockSolver* solver_; -}; - -#ifdef __cplusplus - extern "C" - { -#endif - - typedef void (*FuncPtr)(double[], int64_t, int64_t); - - FuncPtr get_solver(char filepath[]); - -#ifdef __cplusplus - } // extern "C" -#endif - diff --git a/musica/include/micm/MICM.hpp b/musica/include/micm/micm.hpp similarity index 98% rename from musica/include/micm/MICM.hpp rename to musica/include/micm/micm.hpp index 8235b8e1..e7807f32 100644 --- a/musica/include/micm/MICM.hpp +++ b/musica/include/micm/micm.hpp @@ -3,12 +3,12 @@ #include #include #include -#include #include #include #include + class MICM { public: diff --git a/musica/include/micm/MICM_C.h b/musica/include/micm/micm_c.h similarity index 100% rename from musica/include/micm/MICM_C.h rename to musica/include/micm/micm_c.h diff --git a/musica/src/micm/CMakeLists.txt b/musica/src/micm/CMakeLists.txt index 97d00d7d..bf1ab6d6 100644 --- a/musica/src/micm/CMakeLists.txt +++ b/musica/src/micm/CMakeLists.txt @@ -1,6 +1,5 @@ target_sources(musica PRIVATE - # interface.cpp - MICM_C_API.cpp - MICM.cpp + micm_c_api.cpp + micm.cpp ) \ No newline at end of file diff --git a/musica/src/micm/interface.cpp b/musica/src/micm/interface.cpp deleted file mode 100644 index 6fcb42ea..00000000 --- a/musica/src/micm/interface.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#include - -// assumes that photo_rates, matches order in c++ already -void fortran_solve(void *micm_address, double time_start, double time_end, double *concentrations, double temperature, double pressure, double *photo_rates) -{ - MICM *micm = static_cast(micm_address); - micm::State state = micm->solver_->GetState(); - - for (auto param : state.custom_rate_parameters_[0]) - { - param = *(photo_rates++); - } - state.conditions_[0].pressure_ = pressure; - state.conditions_[0].temperature_ = temperature; - - auto result = micm->solver_->Solve(time_start, time_end, state); -} - -void solver( - double state[], // NOLINT(misc-unused-parameters,cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - int64_t state_size, - int64_t - timestep) -{ - std::cout << "state size: " << state_size << std::endl; - std::cout << "timestep: " << timestep << std::endl; - - for (int64_t i{}; i < state_size; ++i) - { - std::cout << "state[" << i << "] = " << state[i] << std::endl; - } -} - -FuncPtr get_solver( - char filepath[]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) -{ - std::cout << "file path: " << filepath << "\n"; - return &solver; -} \ No newline at end of file diff --git a/musica/src/micm/MICM.cpp b/musica/src/micm/micm.cpp similarity index 78% rename from musica/src/micm/MICM.cpp rename to musica/src/micm/micm.cpp index 82b10d20..792a3645 100644 --- a/musica/src/micm/MICM.cpp +++ b/musica/src/micm/micm.cpp @@ -1,9 +1,6 @@ #include -// #include "MICM.hpp" // TODO(jiwon) - do we want angle bracket, also how about relative path? -#include "../../include/micm/MICM.hpp" - -// #include // TODO - remove +#include "../../include/micm/micm.hpp" // TODO(jiwon) relative include path? #include @@ -31,9 +28,7 @@ int MICM::create_solver() if (status == micm::ConfigParseStatus::Success) { - std::cout << " * [C++] Successfully read confiure file from the direcotry path: " << config_path_ << std::endl; - - auto params = micm::RosenbrockSolverParameters::three_stage_rosenbrock_parameters(NUM_GRID_CELLS); // TODO(jiwon) - three_stage + auto params = micm::RosenbrockSolverParameters::three_stage_rosenbrock_parameters(NUM_GRID_CELLS); params.reorder_state_ = false; solver_ = new VectorRosenbrockSolver{solver_params.system_, solver_params.processes_, @@ -67,10 +62,9 @@ void MICM::solve(double temperature, double pressure, double time_step, double*& state.conditions_[i].pressure_ = pressure; } - state.variables_[0] = v_concentrations_; // TODO: + state.variables_[0] = v_concentrations_; auto result = solver_->Solve(time_step, state); - // state.variables_[0] = result.result_.AsVector(); //TODO(jiwon): doesn't need because stae will get destroyed? v_concentrations_ = result.result_.AsVector(); for (int i=0; idelete_solver(); delete micm; } @@ -22,6 +20,7 @@ void delete_micm(const Micm* micm) int micm_create_solver(Micm* micm) { std::cout << " * [C API] Creating solver" << std::endl; + return micm->create_solver(); } From 3d6f0037e97c2675d17d8fa1214e890b8ac95fbb Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 02:06:46 +0900 Subject: [PATCH 12/24] copy config --- Dockerfile.fortran | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile.fortran b/Dockerfile.fortran index f098755a..4bdc13ed 100644 --- a/Dockerfile.fortran +++ b/Dockerfile.fortran @@ -69,4 +69,7 @@ RUN cd musica/musica-fortran/test \ && cmake .. \ && make +RUN cd musica/musica-fortran/test \ + && cp -r micm_config ./build/micm_config + WORKDIR musica/musica-fortran/test/build \ No newline at end of file From 20c5d38bb58835f4b05c61637241e922f4ae0ff7 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 02:26:20 +0900 Subject: [PATCH 13/24] include json package --- Dockerfile | 3 ++- Dockerfile.mpi | 1 + Dockerfile.mpi_openmp | 1 + Dockerfile.openmp | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7879439b..67bc8b20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN dnf -y update \ lcov \ make \ netcdf-fortran-devel \ + json-devel \ valgrind \ && dnf clean all @@ -35,5 +36,5 @@ RUN cd musica \ -D ENABLE_TESTS=ON \ && cd build \ && make install -j 8 - + WORKDIR musica/build diff --git a/Dockerfile.mpi b/Dockerfile.mpi index bccbf9ae..8590801a 100644 --- a/Dockerfile.mpi +++ b/Dockerfile.mpi @@ -18,6 +18,7 @@ RUN sudo dnf -y install \ make \ netcdf-fortran-devel \ openmpi-devel \ + json-devel \ valgrind-openmpi \ && dnf clean all diff --git a/Dockerfile.mpi_openmp b/Dockerfile.mpi_openmp index a751b1cd..875f0d4f 100644 --- a/Dockerfile.mpi_openmp +++ b/Dockerfile.mpi_openmp @@ -17,6 +17,7 @@ RUN sudo dnf -y install \ lcov \ make \ netcdf-fortran-devel \ + json-devel \ openmpi-devel \ valgrind-openmpi \ && dnf clean all diff --git a/Dockerfile.openmp b/Dockerfile.openmp index b73afd2e..cb21aca2 100644 --- a/Dockerfile.openmp +++ b/Dockerfile.openmp @@ -17,6 +17,7 @@ RUN sudo dnf -y install \ lcov \ make \ netcdf-fortran-devel \ + json-devel \ openmpi-devel \ valgrind-openmpi \ && dnf clean all From 122369275c8c995668d5641b528e7ecfc9ce608d Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 03:22:06 +0900 Subject: [PATCH 14/24] change the micm mod name --- musica-fortran/src/micm/micm_c_def.F90 | 12 ++++++------ musica-fortran/src/micm/micm_mod.F90 | 18 +++++++++--------- musica-fortran/test/test_musica_api.F90 | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/musica-fortran/src/micm/micm_c_def.F90 b/musica-fortran/src/micm/micm_c_def.F90 index eabacdf2..107ddfe4 100644 --- a/musica-fortran/src/micm/micm_c_def.F90 +++ b/musica-fortran/src/micm/micm_c_def.F90 @@ -6,23 +6,23 @@ function create_micm_c(config_path) bind(C, name="create_micm") character(len=1, kind=C_CHAR), intent(in) :: config_path(*) end function - subroutine delete_micm_c(micm) bind(C, name="delete_micm") + subroutine delete_micm_c(micm_t) bind(C, name="delete_micm") use iso_c_binding implicit none - type(c_ptr), value :: micm + type(c_ptr), value :: micm_t end subroutine - function micm_create_solver_c(micm) bind(C, name="micm_create_solver") + function micm_create_solver_c(micm_t) bind(C, name="micm_create_solver") use iso_c_binding implicit none integer(c_int) :: micm_create_solver_c ! TODO(jiwon) return value? - type(c_ptr), intent(in), value :: micm + type(c_ptr), intent(in), value :: micm_t end function - subroutine micm_solve_c(micm, temperature, pressure, time_step, concentrations, num_concentrations) bind(C, name="micm_solve") + subroutine micm_solve_c(micm_t, temperature, pressure, time_step, concentrations, num_concentrations) bind(C, name="micm_solve") use iso_c_binding implicit none - type(c_ptr), intent(in), value :: micm + type(c_ptr), intent(in), value :: micm_t real(c_double), value :: temperature real(c_double), value :: pressure real(c_double), value :: time_step diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index d13ac690..612ba49a 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -1,12 +1,12 @@ -module libmicm +module micm use iso_c_binding private - public :: micm + public :: micm_t include "micm_c_def.F90" - type micm + type micm_t private type(c_ptr) :: ptr contains @@ -15,14 +15,14 @@ module libmicm procedure :: solve => micm_solve end type - interface micm + interface micm_t procedure create_micm end interface contains function create_micm(config_path) implicit none - type(micm) :: create_micm + type(micm_t) :: create_micm character(len=*), intent(in) :: config_path character(len=1, kind=C_CHAR) :: c_config_path(len_trim(config_path) + 1) integer :: N, i @@ -39,25 +39,25 @@ function create_micm(config_path) subroutine delete_micm(this) implicit none - type(micm) :: this + type(micm_t) :: this call delete_micm_c(this%ptr) end subroutine subroutine delete_micm_polymorph(this) implicit none - class(micm) :: this + class(micm_t) :: this call delete_micm_c(this%ptr) end subroutine integer function micm_create_solver(this) implicit none - class(micm), intent(in) :: this + class(micm_t), intent(in) :: this micm_create_solver = micm_create_solver_c(this%ptr) end function subroutine micm_solve(this, temperature, pressure, time_step, concentrations, num_concentrations) implicit none - class(micm), intent(in) :: this + class(micm_t), intent(in) :: this real(c_double), intent(in) :: temperature real(c_double), intent(in) :: pressure real(c_double), intent(in) :: time_step diff --git a/musica-fortran/test/test_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index 89e4805b..8ee59b26 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -1,8 +1,8 @@ program test use iso_c_binding - use libmicm + use micm implicit none - type(micm) :: m + type(micm_t) :: m real(c_double) :: temperature real(c_double) :: pressure @@ -17,7 +17,7 @@ program test num_concentrations = 10 write(*,*) " * [Fortran] Creating MICM" - m = micm("micm_config") + m = micm_t("micm_config") write(*,*) " * [Fortran] Creating solver" write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " From 10f8126427e10d617ef48af170667ae4ebac4006 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 03:33:33 +0900 Subject: [PATCH 15/24] remove delete polymorph --- musica-fortran/src/micm/micm_mod.F90 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index 612ba49a..96b3caea 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -10,7 +10,7 @@ module micm private type(c_ptr) :: ptr contains - procedure :: delete => delete_micm_polymorph + procedure :: delete => delete_micm procedure :: create_solver => micm_create_solver procedure :: solve => micm_solve end type @@ -38,12 +38,6 @@ function create_micm(config_path) end function subroutine delete_micm(this) - implicit none - type(micm_t) :: this - call delete_micm_c(this%ptr) - end subroutine - - subroutine delete_micm_polymorph(this) implicit none class(micm_t) :: this call delete_micm_c(this%ptr) From 80f0858435a3a2f70220bf74e80497d87fbfae49 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 03:35:01 +0900 Subject: [PATCH 16/24] update the tag --- musica-fortran/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index b1572544..064d52f3 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG bfad77f # TODO(jiwon) - update the tag + GIT_TAG 10f8126 # TODO(jiwon) - update the tag ) FetchContent_MakeAvailable(musica) From f159a5ee767d31df6a4fc6ebc0809c8f5a08b4a1 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 04:27:24 +0900 Subject: [PATCH 17/24] submodule update --- lib/micm | 2 +- lib/musica-core | 2 +- lib/tuv-x | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/micm b/lib/micm index fb8e3d31..40dd6a92 160000 --- a/lib/micm +++ b/lib/micm @@ -1 +1 @@ -Subproject commit fb8e3d318f30884d4838afeafe7387d255ed4943 +Subproject commit 40dd6a92e869241059db39232aca2a2e942d48cd diff --git a/lib/musica-core b/lib/musica-core index a0b2da06..f2133112 160000 --- a/lib/musica-core +++ b/lib/musica-core @@ -1 +1 @@ -Subproject commit a0b2da0681a5f7f24721bf7b9997e297cd88f5be +Subproject commit f2133112a25aa0dc8ae1a5109003bf72ac5680cf diff --git a/lib/tuv-x b/lib/tuv-x index 16e7e8a4..35b19b37 160000 --- a/lib/tuv-x +++ b/lib/tuv-x @@ -1 +1 @@ -Subproject commit 16e7e8a4b10dc387311530c7591cebb5b609a60c +Subproject commit 35b19b3716bcce45b0ff93ef7e948a0225ebddd5 From a1ac6855d84c3d61fec175f234ead2ad8f67e149 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 05:06:22 +0900 Subject: [PATCH 18/24] update submodules --- lib/micm | 2 +- lib/musica-core | 2 +- lib/tuv-x | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/micm b/lib/micm index 40dd6a92..48d3ed14 160000 --- a/lib/micm +++ b/lib/micm @@ -1 +1 @@ -Subproject commit 40dd6a92e869241059db39232aca2a2e942d48cd +Subproject commit 48d3ed14927e65314e5028590a049d6bb4074591 diff --git a/lib/musica-core b/lib/musica-core index f2133112..a0b2da06 160000 --- a/lib/musica-core +++ b/lib/musica-core @@ -1 +1 @@ -Subproject commit f2133112a25aa0dc8ae1a5109003bf72ac5680cf +Subproject commit a0b2da0681a5f7f24721bf7b9997e297cd88f5be diff --git a/lib/tuv-x b/lib/tuv-x index 35b19b37..16e7e8a4 160000 --- a/lib/tuv-x +++ b/lib/tuv-x @@ -1 +1 @@ -Subproject commit 35b19b3716bcce45b0ff93ef7e948a0225ebddd5 +Subproject commit 16e7e8a4b10dc387311530c7591cebb5b609a60c From e2eab127acf16a4b1ebc80f927c2b6676cad9717 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 05:41:13 +0900 Subject: [PATCH 19/24] remove implicit none in functions --- musica-fortran/src/micm/micm_mod.F90 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index 96b3caea..9b6d57e3 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -1,5 +1,6 @@ module micm use iso_c_binding + implicit none private public :: micm_t @@ -21,7 +22,6 @@ module micm contains function create_micm(config_path) - implicit none type(micm_t) :: create_micm character(len=*), intent(in) :: config_path character(len=1, kind=C_CHAR) :: c_config_path(len_trim(config_path) + 1) @@ -38,19 +38,16 @@ function create_micm(config_path) end function subroutine delete_micm(this) - implicit none class(micm_t) :: this call delete_micm_c(this%ptr) end subroutine integer function micm_create_solver(this) - implicit none class(micm_t), intent(in) :: this micm_create_solver = micm_create_solver_c(this%ptr) end function subroutine micm_solve(this, temperature, pressure, time_step, concentrations, num_concentrations) - implicit none class(micm_t), intent(in) :: this real(c_double), intent(in) :: temperature real(c_double), intent(in) :: pressure From b886b0c45116f94cc9666d3e445840b3ce6b9590 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 16 Oct 2023 11:38:13 -0600 Subject: [PATCH 20/24] remove delete solver function --- musica/include/micm/micm.hpp | 1 - musica/src/micm/micm.cpp | 9 +++------ musica/src/micm/micm_c_api.cpp | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/musica/include/micm/micm.hpp b/musica/include/micm/micm.hpp index e7807f32..cf55cbde 100644 --- a/musica/include/micm/micm.hpp +++ b/musica/include/micm/micm.hpp @@ -17,7 +17,6 @@ class MICM // TODO(jiwon): can return type indicate error? int create_solver(); - void delete_solver() const; void solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations); private: diff --git a/musica/src/micm/micm.cpp b/musica/src/micm/micm.cpp index 792a3645..fbe11093 100644 --- a/musica/src/micm/micm.cpp +++ b/musica/src/micm/micm.cpp @@ -13,6 +13,9 @@ MICM::MICM(const std::string& config_path) MICM::~MICM() { + std::cout << " * [C++] Deallocating solver" << std::endl; + delete solver_; + std::cout << " * [C++] MICM Destructor" << std::endl; } @@ -43,12 +46,6 @@ int MICM::create_solver() return success; } -void MICM::delete_solver() const -{ - std::cout << " * [C++] Deallocating solver" << std::endl; - delete solver_; -} - void MICM::solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations) { std::cout << " * [C++] Start solving " << std::endl; diff --git a/musica/src/micm/micm_c_api.cpp b/musica/src/micm/micm_c_api.cpp index 6bdfd62e..0ec31e5a 100644 --- a/musica/src/micm/micm_c_api.cpp +++ b/musica/src/micm/micm_c_api.cpp @@ -13,7 +13,6 @@ void delete_micm(const Micm* micm) { std::cout << " * [C API] Deleting MICM" << std::endl; - micm->delete_solver(); delete micm; } From 6ac5bc586282eb051c02c02d37663759d4260191 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 16 Oct 2023 15:38:20 -0600 Subject: [PATCH 21/24] add final keyword --- musica-fortran/src/micm/micm_mod.F90 | 4 ++-- musica/src/micm/micm.cpp | 10 +--------- musica/src/micm/micm_c_api.cpp | 8 -------- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index 9b6d57e3..fbed7551 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -11,9 +11,9 @@ module micm private type(c_ptr) :: ptr contains - procedure :: delete => delete_micm procedure :: create_solver => micm_create_solver procedure :: solve => micm_solve + final :: delete_micm end type interface micm_t @@ -38,7 +38,7 @@ function create_micm(config_path) end function subroutine delete_micm(this) - class(micm_t) :: this + type(micm_t) :: this call delete_micm_c(this%ptr) end subroutine diff --git a/musica/src/micm/micm.cpp b/musica/src/micm/micm.cpp index fbe11093..4f391d68 100644 --- a/musica/src/micm/micm.cpp +++ b/musica/src/micm/micm.cpp @@ -7,21 +7,15 @@ MICM::MICM(const std::string& config_path) : config_path_(config_path), solver_(nullptr) - { - std::cout << " * [C++] MICM constructor" << std::endl; - } + {} MICM::~MICM() { - std::cout << " * [C++] Deallocating solver" << std::endl; delete solver_; - - std::cout << " * [C++] MICM Destructor" << std::endl; } int MICM::create_solver() { - std::cout << " * [C++] Creating solver" << std::endl; bool success = 1; // TODO(jiwon): can we specifiy error type with int? // read and parse the config @@ -48,8 +42,6 @@ int MICM::create_solver() void MICM::solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations) { - std::cout << " * [C++] Start solving " << std::endl; - v_concentrations_.assign(concentrations, concentrations + num_concentrations); micm::State state = solver_->GetState(); diff --git a/musica/src/micm/micm_c_api.cpp b/musica/src/micm/micm_c_api.cpp index 0ec31e5a..caf3f84e 100644 --- a/musica/src/micm/micm_c_api.cpp +++ b/musica/src/micm/micm_c_api.cpp @@ -4,28 +4,20 @@ Micm* create_micm(const char* config_path) { - std::cout << " * [C API] Creating MICM" << std::endl; - return new MICM(std::string(config_path)); } void delete_micm(const Micm* micm) { - std::cout << " * [C API] Deleting MICM" << std::endl; - delete micm; } int micm_create_solver(Micm* micm) { - std::cout << " * [C API] Creating solver" << std::endl; - return micm->create_solver(); } void micm_solve(Micm* micm, double temperature, double pressure, double time_step, double* concentrations, size_t num_concentrations) { - std::cout << " * [C API] Starting solving" << std::endl; - micm->solve(temperature, pressure, time_step, concentrations, num_concentrations); } \ No newline at end of file From 85104efdfef562c0e22f6cabd90ba7f04b7bc110 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 16 Oct 2023 17:10:46 -0600 Subject: [PATCH 22/24] test github action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f80a606b..c2a661eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,7 +65,7 @@ jobs: - name: delete unnessary tools to free up space run: rm -rf /opt/hostedtoolcache - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - name: build Docker image From bad9756810f755ecc67a2c2d59f61ae6e4f82761 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 17 Oct 2023 10:33:13 -0600 Subject: [PATCH 23/24] revert back checkout version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2a661eb..f80a606b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,7 +65,7 @@ jobs: - name: delete unnessary tools to free up space run: rm -rf /opt/hostedtoolcache - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 with: submodules: recursive - name: build Docker image From b81615d89fda2aab795a2785416277dd658a3845 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 17 Oct 2023 10:46:50 -0600 Subject: [PATCH 24/24] update the tag --- musica-fortran/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index 064d52f3..eb67929e 100644 --- a/musica-fortran/test/CMakeLists.txt +++ b/musica-fortran/test/CMakeLists.txt @@ -16,7 +16,7 @@ set(ENABLE_TUVX OFF) FetchContent_Declare(musica GIT_REPOSITORY https://github.com/NCAR/musica.git - GIT_TAG 10f8126 # TODO(jiwon) - update the tag + GIT_TAG bad9756 # TODO(jiwon) - update the tag ) FetchContent_MakeAvailable(musica)