From dcb5e4919122189d74c5ac33119a14eca2badc5e Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 25 Sep 2023 11:08:50 -0600 Subject: [PATCH 01/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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 0519ef86331b3a37fb760de892470c27e1556f69 Mon Sep 17 00:00:00 2001 From: Matt Dawson Date: Thu, 28 Sep 2023 10:51:41 -0700 Subject: [PATCH 14/37] add no-micm test and fix --- .github/workflows/test.yml | 11 ++++++++++ CMakeLists.txt | 8 ++++++++ Dockerfile.no_micm | 41 ++++++++++++++++++++++++++++++++++++++ musica/src/CMakeLists.txt | 4 +++- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.no_micm diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c70d6ee4..f80a606b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,17 @@ jobs: run: docker build -t musica . - name: run tests in container run: docker run --name test-container -t musica bash -c 'make test' + build_test_connections_without_micm: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: build Docker image + run: docker build -t musica -f Dockerfile.no_micm . + - name: run tests in container + run: docker run --name test-container -t musica bash -c 'make test' build_test_connections_with_openmp: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name diff --git a/CMakeLists.txt b/CMakeLists.txt index b4184e79..02442d2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,14 @@ include(GNUInstallDirs) set(INSTALL_PREFIX "musica-${PROJECT_VERSION}") set(INSTALL_MOD_DIR "${INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") +# MUSICA library components +if(ENABLE_TUVX) + add_definitions(-DMUSICA_USE_TUVX) +endif() +if(ENABLE_MICM) + add_definitions(-DMUSICA_USE_MICM) +endif() + # MPI if(ENABLE_MPI) add_definitions(-DMUSICA_USE_MPI) diff --git a/Dockerfile.no_micm b/Dockerfile.no_micm new file mode 100644 index 00000000..e8a98cc9 --- /dev/null +++ b/Dockerfile.no_micm @@ -0,0 +1,41 @@ +FROM fedora:35 + +RUN dnf -y update \ + && dnf -y install \ + cmake \ + gcc-c++ \ + gcc-gfortran \ + git \ + lcov \ + make \ + netcdf-fortran-devel \ + valgrind \ + && dnf clean all + +# Install json-fortran +RUN curl -LO https://github.com/jacobwilliams/json-fortran/archive/8.2.0.tar.gz \ + && tar -zxvf 8.2.0.tar.gz \ + && cd json-fortran-8.2.0 \ + && mkdir build \ + && cd build \ + && cmake -D SKIP_DOC_GEN:BOOL=TRUE .. \ + && make install + +# Set environment variables +ENV FC=gfortran +ENV JSON_FORTRAN_HOME="/usr/local/jsonfortran-gnu-8.2.0" + +# Copy the musica code +COPY . musica + +# Build +RUN cd musica \ + && cmake -S . \ + -B build \ + -D ENABLE_TESTS=ON \ + -D ENABLE_TUVX=ON \ + -D ENABLE_MICM=OFF \ + && cd build \ + && make install -j 8 + +WORKDIR musica/build diff --git a/musica/src/CMakeLists.txt b/musica/src/CMakeLists.txt index 752e230b..585b6731 100644 --- a/musica/src/CMakeLists.txt +++ b/musica/src/CMakeLists.txt @@ -7,4 +7,6 @@ target_sources(musica ${CMAKE_BINARY_DIR}/version.c ) -add_subdirectory(micm) \ No newline at end of file +if(ENABLE_MICM) + add_subdirectory(micm) +endif() \ No newline at end of file From 122369275c8c995668d5641b528e7ecfc9ce608d Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 29 Sep 2023 03:22:06 +0900 Subject: [PATCH 15/37] 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 16/37] 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 17/37] 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 18/37] 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 19/37] 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 20/37] 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 dad130805ae5aa4c4c791f40c33ef754317a3ab2 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Wed, 11 Oct 2023 11:40:26 -0500 Subject: [PATCH 21/37] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 378815e6..4fcc82f2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # MUSICA +[![GitHub Releases](https://img.shields.io/github/release/NCAR/musica.svg)](https://github.com/NCAR/musica/releases) [![License](https://img.shields.io/github/license/NCAR/musica.svg)](https://github.com/NCAR/musica/blob/main/LICENSE) [![CI Status](https://github.com/NCAR/musica/actions/workflows/test.yml/badge.svg)](https://github.com/NCAR/musica/actions/workflows/test.yml) @@ -60,4 +61,4 @@ MUSICAv0 description and evaluation: eprint = {https://agupubs.onlinelibrary.wiley.com/doi/pdf/10.1029/2021MS002889}, year = {2022} } -``` \ No newline at end of file +``` From b886b0c45116f94cc9666d3e445840b3ce6b9590 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 16 Oct 2023 11:38:13 -0600 Subject: [PATCH 22/37] 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 23/37] 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 24/37] 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 25/37] 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 26/37] 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) From 5c592870b16985167f7a32319055e5156c90bdab Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 26 Oct 2023 15:06:42 -0600 Subject: [PATCH 27/37] change micm mod name to avoid duplicates from atmospheric micm mod --- musica-fortran/src/micm/micm_mod.F90 | 2 +- musica-fortran/test/test_musica_api.F90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index fbed7551..811f1972 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -1,4 +1,4 @@ -module micm +module musica_micm use iso_c_binding implicit none diff --git a/musica-fortran/test/test_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index 8ee59b26..a084df37 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -1,6 +1,6 @@ program test use iso_c_binding - use micm + use musica_micm implicit none type(micm_t) :: m From 759bfc6ca89dff931fc86cbbcbb3aacb4051a28e Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 5 Jan 2024 13:21:45 -0700 Subject: [PATCH 28/37] update the submodule --- 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 48d3ed14..f4c20088 160000 --- a/lib/micm +++ b/lib/micm @@ -1 +1 @@ -Subproject commit 48d3ed14927e65314e5028590a049d6bb4074591 +Subproject commit f4c20088c403f90dc65746d744e471232b985ead diff --git a/lib/musica-core b/lib/musica-core index a0b2da06..d5bdc303 160000 --- a/lib/musica-core +++ b/lib/musica-core @@ -1 +1 @@ -Subproject commit a0b2da0681a5f7f24721bf7b9997e297cd88f5be +Subproject commit d5bdc303fe9afbae8f7585a11bcb660534b97f23 diff --git a/lib/tuv-x b/lib/tuv-x index 16e7e8a4..daba6579 160000 --- a/lib/tuv-x +++ b/lib/tuv-x @@ -1 +1 @@ -Subproject commit 16e7e8a4b10dc387311530c7591cebb5b609a60c +Subproject commit daba657958baa3a499ae7fa470f3df0073655c67 From b1d78074de4a4e2421efe8fc3a2238fc48317bfa Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 5 Jan 2024 13:24:03 -0700 Subject: [PATCH 29/37] update the version --- CMakeLists.txt | 2 +- musica-fortran/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02442d2d..def7209a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21) project( musica - VERSION 0.4.0 + VERSION 0.5.0 LANGUAGES Fortran CXX C ) diff --git a/musica-fortran/CMakeLists.txt b/musica-fortran/CMakeLists.txt index 3d71e3b7..a6f94c6e 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.4.0 REQUIRED) +find_package(musica 0.5.0 REQUIRED) target_link_libraries(musica-fortran PUBLIC From 1562bb26cd76d3c080183317849fc62cb67217d4 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 5 Jan 2024 14:53:58 -0700 Subject: [PATCH 30/37] fix the type for state --- musica/src/micm/micm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica/src/micm/micm.cpp b/musica/src/micm/micm.cpp index 4f391d68..2015efb9 100644 --- a/musica/src/micm/micm.cpp +++ b/musica/src/micm/micm.cpp @@ -44,7 +44,7 @@ void MICM::solve(double temperature, double pressure, double time_step, double*& { v_concentrations_.assign(concentrations, concentrations + num_concentrations); - micm::State state = solver_->GetState(); + auto state = solver_->GetState(); for(size_t i{}; i < NUM_GRID_CELLS; ++i) { state.conditions_[i].temperature_ = temperature; From 95d4c132d3734a6a5089862625ad75de3382c7f9 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 5 Jan 2024 16:38:46 -0700 Subject: [PATCH 31/37] change the mod name --- musica-fortran/src/micm/micm_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musica-fortran/src/micm/micm_mod.F90 b/musica-fortran/src/micm/micm_mod.F90 index 811f1972..6484b22d 100644 --- a/musica-fortran/src/micm/micm_mod.F90 +++ b/musica-fortran/src/micm/micm_mod.F90 @@ -1,4 +1,4 @@ -module musica_micm +module micm_mod use iso_c_binding implicit none From cfb1a859d97bf5441a161efc4e00341621fd24e4 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 8 Jan 2024 14:16:23 -0700 Subject: [PATCH 32/37] submodule micm update --- lib/micm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micm b/lib/micm index f4c20088..b36c5f8c 160000 --- a/lib/micm +++ b/lib/micm @@ -1 +1 @@ -Subproject commit f4c20088c403f90dc65746d744e471232b985ead +Subproject commit b36c5f8c94d8e3db7fa93f8690935fffb1466f6e From da283090c3016d71e89a0ef0743e3789089e6f18 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 8 Jan 2024 14:37:21 -0700 Subject: [PATCH 33/37] update the git tag --- musica-fortran/test/CMakeLists.txt | 2 +- musica-fortran/test/test_musica_api.F90 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/musica-fortran/test/CMakeLists.txt b/musica-fortran/test/CMakeLists.txt index eb67929e..62692725 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 bad9756 # TODO(jiwon) - update the tag + GIT_TAG cfb1a85 # TODO(jiwon) - update the tag ) FetchContent_MakeAvailable(musica) diff --git a/musica-fortran/test/test_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index a084df37..12c59cad 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -1,6 +1,6 @@ program test use iso_c_binding - use musica_micm + use micm_mod implicit none type(micm_t) :: m @@ -33,6 +33,6 @@ program test write(*,*) " * [Fortran] After solving, concentrations", concentrations write(*,*) " * [Fortran] Calling destructor for MICM" - call m%delete + call m%delete_micm() end program \ No newline at end of file From d8bc42933702fdc35543f52fda66e48aff37f6d7 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 8 Jan 2024 14:42:42 -0700 Subject: [PATCH 34/37] remove delete call --- musica-fortran/test/test_musica_api.F90 | 3 --- 1 file changed, 3 deletions(-) diff --git a/musica-fortran/test/test_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index 12c59cad..7bc34abd 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -32,7 +32,4 @@ program test 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_micm() - end program \ No newline at end of file From 264396b0688d419f9a19cc255cef6e9a333c29ac Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 9 Jan 2024 13:45:20 -0700 Subject: [PATCH 35/37] Replaced the old configuration with the standard one for musica fortran test --- Dockerfile.fortran | 2 +- .../test/configs/chapman/config.json | 6 ++ .../test/configs/chapman/reactions.json | 97 +++++++++++++++++++ .../test/configs/chapman/species.json | 29 ++++++ .../test/micm_config/mechanism.json | 1 - musica-fortran/test/micm_config/species.json | 1 - musica-fortran/test/test_musica_api.F90 | 8 +- musica/src/micm/micm.cpp | 9 +- 8 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 musica-fortran/test/configs/chapman/config.json create mode 100644 musica-fortran/test/configs/chapman/reactions.json create mode 100644 musica-fortran/test/configs/chapman/species.json delete mode 100644 musica-fortran/test/micm_config/mechanism.json delete mode 100644 musica-fortran/test/micm_config/species.json diff --git a/Dockerfile.fortran b/Dockerfile.fortran index 4bdc13ed..fd4f23b0 100644 --- a/Dockerfile.fortran +++ b/Dockerfile.fortran @@ -70,6 +70,6 @@ RUN cd musica/musica-fortran/test \ && make RUN cd musica/musica-fortran/test \ - && cp -r micm_config ./build/micm_config + && cp -r configs/chapman ./build/chapman WORKDIR musica/musica-fortran/test/build \ No newline at end of file diff --git a/musica-fortran/test/configs/chapman/config.json b/musica-fortran/test/configs/chapman/config.json new file mode 100644 index 00000000..04d0ef28 --- /dev/null +++ b/musica-fortran/test/configs/chapman/config.json @@ -0,0 +1,6 @@ +{ + "camp-files": [ + "species.json", + "reactions.json" + ] +} diff --git a/musica-fortran/test/configs/chapman/reactions.json b/musica-fortran/test/configs/chapman/reactions.json new file mode 100644 index 00000000..679593f9 --- /dev/null +++ b/musica-fortran/test/configs/chapman/reactions.json @@ -0,0 +1,97 @@ +{ + "camp-data": [ + { + "name": "Chapman", + "type": "MECHANISM", + "reactions": [ + { + "type": "PHOTOLYSIS", + "reactants": { + "O2": {} + }, + "products": { + "O": { + "yield": 2.0 + } + }, + "MUSICA name": "R1" + }, + { + "type": "ARRHENIUS", + "A": 8.018e-17, + "reactants": { + "O": {}, + "O2": {} + }, + "products": { + "O3": {} + }, + "MUSICA name": "R2" + }, + { + "type": "PHOTOLYSIS", + "reactants": { + "O3": {} + }, + "products": { + "O": {}, + "O2": {} + }, + "MUSICA name": "R3" + }, + { + "type": "ARRHENIUS", + "A": 1.576e-15, + "reactants": { + "O": {}, + "O3": {} + }, + "products": { + "O2": { + "yield": 2.0 + } + }, + "MUSICA name": "R4" + }, + { + "type": "PHOTOLYSIS", + "reactants": { + "O3": {} + }, + "products": { + "O1D": {}, + "O2": {} + }, + "MUSICA name": "R5" + }, + { + "type": "ARRHENIUS", + "A": 7.11e-11, + "reactants": { + "O1D": {}, + "M": {} + }, + "products": { + "O": {}, + "M": {} + }, + "MUSICA name": "R6" + }, + { + "type": "ARRHENIUS", + "A": 1.2e-10, + "reactants": { + "O1D": {}, + "O3": {} + }, + "products": { + "O2": { + "yield": 2.0 + } + }, + "MUSICA name": "R7" + } + ] + } + ] +} \ No newline at end of file diff --git a/musica-fortran/test/configs/chapman/species.json b/musica-fortran/test/configs/chapman/species.json new file mode 100644 index 00000000..c962907f --- /dev/null +++ b/musica-fortran/test/configs/chapman/species.json @@ -0,0 +1,29 @@ +{ + "camp-data": [ + { + "name": "M", + "type": "CHEM_SPEC", + "tracer type": "CONSTANT" + }, + { + "name": "O2", + "type": "CHEM_SPEC", + "tracer type": "CONSTANT" + }, + { + "name": "O", + "type": "CHEM_SPEC", + "absolute tolerance": 1e-12 + }, + { + "name": "O1D", + "type": "CHEM_SPEC", + "absolute tolerance": 1e-12 + }, + { + "name": "O3", + "type": "CHEM_SPEC", + "absolute tolerance": 1e-12 + } + ] +} \ No newline at end of file diff --git a/musica-fortran/test/micm_config/mechanism.json b/musica-fortran/test/micm_config/mechanism.json deleted file mode 100644 index acf1a257..00000000 --- a/musica-fortran/test/micm_config/mechanism.json +++ /dev/null @@ -1 +0,0 @@ -{"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 deleted file mode 100644 index 298de527..00000000 --- a/musica-fortran/test/micm_config/species.json +++ /dev/null @@ -1 +0,0 @@ -{"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_musica_api.F90 b/musica-fortran/test/test_musica_api.F90 index 7bc34abd..0ac2b88d 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -7,17 +7,17 @@ program test real(c_double) :: temperature real(c_double) :: pressure real(c_double) :: time_step - real(c_double), dimension(10) :: concentrations + real(c_double), dimension(5) :: concentrations integer(c_size_t) :: num_concentrations temperature = 10d0 pressure = 20d0 time_step = 1d0 - concentrations = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0 /) - num_concentrations = 10 + concentrations = (/ 0.75, 0.4, 0.8, 0.01, 0.02 /) + num_concentrations = 5 write(*,*) " * [Fortran] Creating MICM" - m = micm_t("micm_config") + m = micm_t("chapman") write(*,*) " * [Fortran] Creating solver" write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " diff --git a/musica/src/micm/micm.cpp b/musica/src/micm/micm.cpp index 2015efb9..79e2c49d 100644 --- a/musica/src/micm/micm.cpp +++ b/musica/src/micm/micm.cpp @@ -29,7 +29,7 @@ int MICM::create_solver() params.reorder_state_ = false; solver_ = new VectorRosenbrockSolver{solver_params.system_, solver_params.processes_, - params}; + params}; } else { @@ -42,15 +42,14 @@ int MICM::create_solver() void MICM::solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations) { - v_concentrations_.assign(concentrations, concentrations + num_concentrations); - - auto state = solver_->GetState(); + micm::State state = solver_->GetState(); for(size_t i{}; i < NUM_GRID_CELLS; ++i) { state.conditions_[i].temperature_ = temperature; state.conditions_[i].pressure_ = pressure; } + v_concentrations_.assign(concentrations, concentrations + num_concentrations); state.variables_[0] = v_concentrations_; auto result = solver_->Solve(time_step, state); @@ -60,4 +59,4 @@ void MICM::solve(double temperature, double pressure, double time_step, double*& { concentrations[i] = v_concentrations_[i]; } -} +} \ No newline at end of file From efdb8c16bc772b01b0666f625a1e2b22dca21122 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 9 Jan 2024 13:50:52 -0700 Subject: [PATCH 36/37] 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 62692725..d62e1234 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 cfb1a85 # TODO(jiwon) - update the tag + GIT_TAG 264396b # TODO(jiwon) - update the tag ) FetchContent_MakeAvailable(musica) From f6cfc960ff155610000d2e27930b041470c5c6b0 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 9 Jan 2024 16:16:29 -0700 Subject: [PATCH 37/37] replace intel image to ubuntu image for the muscia fortran test --- .github/workflows/test.yml | 20 +++++++-- Dockerfile.fortran-ubuntu | 60 +++++++++++++++++++++++++ musica-fortran/test/test_musica_api.F90 | 25 +++++++---- musica/src/micm/micm.cpp | 8 ++-- 4 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 Dockerfile.fortran-ubuntu diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f80a606b..2de74426 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,7 +58,21 @@ jobs: run: docker build -t musica-mpi-openmp -f Dockerfile.mpi_openmp . - name: run tests in container run: docker run --name test-container -t musica-mpi-openmp bash -c 'make test' - build_test_connections_musica-fortran: + # build_test_connections_musica-fortran: + # runs-on: ubuntu-latest + # if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + # steps: + # - name: delete unnessary tools to free up space + # run: rm -rf /opt/hostedtoolcache + + # - uses: actions/checkout@v2 + # with: + # submodules: recursive + # - name: build Docker image + # run: docker build -t musica-fortran -f Dockerfile.fortran . + # - name: run tests in container + # run: docker run --name test-container -t musica-fortran bash -c 'make test' + build_test_connections_musica-fortran-same-compiler: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name steps: @@ -69,6 +83,6 @@ jobs: with: submodules: recursive - name: build Docker image - run: docker build -t musica-fortran -f Dockerfile.fortran . + run: docker build -t musica-fortran-ubuntu -f Dockerfile.fortran-ubuntu . - name: run tests in container - run: docker run --name test-container -t musica-fortran bash -c 'make test' + run: docker run --name test-container -t musica-fortran-ubuntu bash -c 'make test' diff --git a/Dockerfile.fortran-ubuntu b/Dockerfile.fortran-ubuntu new file mode 100644 index 00000000..3c4f6b00 --- /dev/null +++ b/Dockerfile.fortran-ubuntu @@ -0,0 +1,60 @@ +FROM ubuntu:22.04 + +RUN apt update \ + && apt -y install \ + cmake \ + cmake-curses-gui \ + curl \ + libcurl4-openssl-dev \ + libhdf5-dev \ + m4 \ + nlohmann-json3-dev \ + vim \ + zlib1g-dev \ + git \ + lcov \ + make \ + libnetcdff-dev \ + valgrind \ + gcc \ + gfortran \ + g++ \ + && apt clean + +# Set environment variables to install MUSICA using gcc +ENV FC=gfortran +ENV FFLAGS="-I/usr/include/" + +# Install json-fortran for gnu version +RUN curl -LO https://github.com/jacobwilliams/json-fortran/archive/8.2.0.tar.gz \ + && tar -zxvf 8.2.0.tar.gz \ + && cd json-fortran-8.2.0 \ + && mkdir build \ + && cd build \ + && cmake -D SKIP_DOC_GEN:BOOL=TRUE .. \ + && make install + +# Copy the musica code +COPY . musica + +# Set json-fortran variable to install MUSICA using gcc +ENV JSON_FORTRAN_HOME="/usr/local/jsonfortran-gnu-8.2.0" + +# Build and install MUSICA +RUN cd musica \ + && cmake -S . \ + -B build \ + -D ENABLE_TESTS=ON \ + -D ENABLE_TUVX=OFF \ + && cd build \ + && make install -j 8 + +RUN cd musica/musica-fortran/test \ + && mkdir build && cd build \ + && cmake .. \ + && make + +RUN cd musica/musica-fortran/test \ + && cp -r configs/chapman ./build/chapman + +WORKDIR musica/musica-fortran/test/build \ 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 0ac2b88d..5cbc562a 100644 --- a/musica-fortran/test/test_musica_api.F90 +++ b/musica-fortran/test/test_musica_api.F90 @@ -9,6 +9,7 @@ program test real(c_double) :: time_step real(c_double), dimension(5) :: concentrations integer(c_size_t) :: num_concentrations + integer :: errcode temperature = 10d0 pressure = 20d0 @@ -20,16 +21,22 @@ program test m = micm_t("chapman") write(*,*) " * [Fortran] Creating solver" - write(*,*) " * [Fortran] Solver creating status indicates ", m%create_solver(), " (1 is success, else failure) " + errcode = m%create_solver() - 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 + if (errcode == 1) then + write(*,*) " * [Fortran] Failed in creating solver" + stop 3 + else + write(*,*) " * [Fortran] Initial temp", temperature + write(*,*) " * [Fortran] Initial pressure", pressure + write(*,*) " * [Fortran] Initial time_step", time_step + write(*,*) " * [Fortran] Initial number of concentrations", num_concentrations + write(*,*) " * [Fortran] Initial concentrations", concentrations - write(*,*) " * [Fortran] Starting to solve" - call m%solve(temperature, pressure, time_step, concentrations, num_concentrations) - write(*,*) " * [Fortran] After solving, concentrations", concentrations + write(*,*) " * [Fortran] Solving starts..." + call m%solve(temperature, pressure, time_step, concentrations, num_concentrations) + + write(*,*) " * [Fortran] After solving, concentrations", concentrations + endif end program \ No newline at end of file diff --git a/musica/src/micm/micm.cpp b/musica/src/micm/micm.cpp index 79e2c49d..838948d8 100644 --- a/musica/src/micm/micm.cpp +++ b/musica/src/micm/micm.cpp @@ -16,7 +16,7 @@ MICM::~MICM() int MICM::create_solver() { - bool success = 1; // TODO(jiwon): can we specifiy error type with int? + int faliure = 0; // TODO(jiwon): can we specifiy error type with int? // read and parse the config micm::SolverConfig solver_config; @@ -34,10 +34,10 @@ int MICM::create_solver() else { std::cout << " * [C++] Failed creating solver" << std::endl; - success = 0; + faliure = 1; } - return success; + return faliure; } void MICM::solve(double temperature, double pressure, double time_step, double*& concentrations, size_t num_concentrations) @@ -53,7 +53,7 @@ void MICM::solve(double temperature, double pressure, double time_step, double*& state.variables_[0] = v_concentrations_; auto result = solver_->Solve(time_step, state); - + v_concentrations_ = result.result_.AsVector(); for (int i=0; i