From 0b5f817b673da1ad69ab3fd39c5fdd22c73ca603 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Thu, 2 May 2024 13:39:15 -0600 Subject: [PATCH 01/39] Save. --- docs/source/getting_started.rst | 2 -- docs/source/user_guide/index.rst | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 239263ba..d112c91f 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -2,5 +2,3 @@ Getting Started ############### -Build and Test -============== diff --git a/docs/source/user_guide/index.rst b/docs/source/user_guide/index.rst index 3ac2a7e9..a0adf91d 100644 --- a/docs/source/user_guide/index.rst +++ b/docs/source/user_guide/index.rst @@ -1,3 +1,12 @@ ########## User Guide ########## + +.. code-block:: console + + $ git clone https://github.com/NCAR/musica.git + $ cd musica + $ mkdir build + $ cd build + $ cmake .. + $ make From f775a511c14859cfd2ecc66314837b04a0d2fd0b Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Thu, 2 May 2024 13:51:01 -0600 Subject: [PATCH 02/39] Added installation subsection to getting started section. --- docs/source/getting_started.rst | 5 +++++ docs/source/installation.rst | 11 +++++++++++ docs/source/user_guide/index.rst | 9 --------- 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 docs/source/installation.rst diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index d112c91f..159b2212 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -2,3 +2,8 @@ Getting Started ############### +.. toctree:: + :maxdepth: 1 + :caption: Contents: + + installation diff --git a/docs/source/installation.rst b/docs/source/installation.rst new file mode 100644 index 00000000..f44d7b42 --- /dev/null +++ b/docs/source/installation.rst @@ -0,0 +1,11 @@ +Installation +============ + +.. code-block:: console + + $ git clone https://github.com/NCAR/musica.git + $ cd musica + $ mkdir build + $ cd build + $ cmake .. + $ make diff --git a/docs/source/user_guide/index.rst b/docs/source/user_guide/index.rst index a0adf91d..3ac2a7e9 100644 --- a/docs/source/user_guide/index.rst +++ b/docs/source/user_guide/index.rst @@ -1,12 +1,3 @@ ########## User Guide ########## - -.. code-block:: console - - $ git clone https://github.com/NCAR/musica.git - $ cd musica - $ mkdir build - $ cd build - $ cmake .. - $ make From 56e609a936666c65bb1df6774cd3bb266c3a5283 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 3 May 2024 09:57:45 -0600 Subject: [PATCH 03/39] Created getting_started subdir. --- docs/source/{ => getting_started}/getting_started.rst | 0 docs/source/{ => getting_started}/installation.rst | 0 docs/source/index.rst | 6 +++--- 3 files changed, 3 insertions(+), 3 deletions(-) rename docs/source/{ => getting_started}/getting_started.rst (100%) rename docs/source/{ => getting_started}/installation.rst (100%) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started/getting_started.rst similarity index 100% rename from docs/source/getting_started.rst rename to docs/source/getting_started/getting_started.rst diff --git a/docs/source/installation.rst b/docs/source/getting_started/installation.rst similarity index 100% rename from docs/source/installation.rst rename to docs/source/getting_started/installation.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 7bebc5de..62a1d2b5 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -16,7 +16,7 @@ Welcome to MUSICA's documentation! .. grid-item-card:: Getting started :img-top: _static/index_getting_started.svg - :link: getting_started + :link: getting_started/getting_started :link-type: doc Check out the getting started guide to build and install musica. @@ -41,12 +41,12 @@ Welcome to MUSICA's documentation! :maxdepth: 2 :caption: Contents: - getting_started + getting_started/getting_started user_guide/index api/index contributing/index -.. getting_started +.. getting_started/getting_started .. user_guide/index .. api/index .. contributing/index From 14925daa476ec23a6ac1a2bbe812a93343c0bd57 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Fri, 3 May 2024 11:08:26 -0600 Subject: [PATCH 04/39] Save. --- docs/source/getting_started/installation.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index f44d7b42..966eff63 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -1,6 +1,10 @@ Installation ============ +MUSICA source code may be cloned from its public GitHub repository +and configured and built with the cmake utility. +In brief: + .. code-block:: console $ git clone https://github.com/NCAR/musica.git From 35e423586ce2bee56224e068c79c265fd1ea3e4a Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 7 May 2024 09:41:46 -0600 Subject: [PATCH 05/39] Added config options list. --- docs/source/getting_started/installation.rst | 88 ++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 966eff63..2dfc6e5c 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -13,3 +13,91 @@ In brief: $ cd build $ cmake .. $ make + + +.. code-block:: console + + BUILD_DOCS OFF + BUILD_GMOCK OFF + BUILD_TESTING ON + CMAKE_BUILD_TYPE Release + CMAKE_INSTALL_PREFIX /usr/local + CREATE_ENVIRONMENT_MODULE OFF + ENABLE_COVERAGE OFF + ENABLE_MEMCHECK OFF + ENABLE_MICM ON + ENABLE_MPI OFF + ENABLE_NC_CONFIG OFF + ENABLE_TESTS ON + ENABLE_TUVX ON + FETCHCONTENT_BASE_DIR /MUSICA/build/_deps + FETCHCONTENT_FULLY_DISCONNECTE OFF + FETCHCONTENT_QUIET OFF + FETCHCONTENT_SOURCE_DIR_GOOGLE + FETCHCONTENT_SOURCE_DIR_JSON + FETCHCONTENT_SOURCE_DIR_MICM + FETCHCONTENT_SOURCE_DIR_PYBIND + FETCHCONTENT_SOURCE_DIR_TUVX + FETCHCONTENT_SOURCE_DIR_YAML-C + FETCHCONTENT_UPDATES_DISCONNEC OFF + GIT_SUBMODULE ON + GTEST_HAS_ABSL OFF + INSTALL_GTEST OFF + JSON_BuildTests OFF + JSON_CI OFF + JSON_Diagnostics OFF + JSON_DisableEnumSerialization OFF + JSON_GlobalUDLs ON + JSON_INCLUDE_DIR JSON_INCLUDE_DIR-NOTFOUND + JSON_ImplicitConversions ON + JSON_Install OFF + JSON_LIB JSON_LIB-NOTFOUND + JSON_LegacyDiscardedValueCompa OFF + JSON_MultipleHeaders ON + JSON_SystemInclude OFF + MAKE_MUSICA_FORTRAN_INSTALLABL ON + MICM_BUILD_DOCS OFF + MICM_DEFAULT_VECTOR_MATRIX_SIZ 4 + MICM_ENABLE_CLANG_TIDY OFF + MICM_ENABLE_COVERAGE OFF + MICM_ENABLE_CUDA OFF + MICM_ENABLE_EXAMPLES ON + MICM_ENABLE_JSON ON + MICM_ENABLE_LLVM OFF + MICM_ENABLE_MEMCHECK OFF + MICM_ENABLE_MPI OFF + MICM_ENABLE_OPENACC OFF + MICM_ENABLE_OPENMP OFF + MICM_ENABLE_TESTS ON + MICM_GPU_TYPE + MUSICA_BUILD_C_CXX_INTERFACE ON + MUSICA_BUILD_DOCS OFF + MUSICA_BUILD_FORTRAN_INTERFACE ON + MUSICA_CREATE_ENVIRONMENT_MODU OFF + MUSICA_ENABLE_INSTALL ON + MUSICA_ENABLE_MEMCHECK OFF + MUSICA_ENABLE_MICM ON + MUSICA_ENABLE_MPI OFF + MUSICA_ENABLE_OPENMP OFF + MUSICA_ENABLE_PYTHON_LIBRARY ON + MUSICA_ENABLE_TESTS ON + MUSICA_ENABLE_TUVX ON + PYBIND11_DISABLE_HANDLE_TYPE_N OFF + PYBIND11_FINDPYTHON OFF + PYBIND11_INSTALL OFF + PYBIND11_INTERNALS_VERSION + PYBIND11_NOPYTHON OFF + PYBIND11_NUMPY_1_ONLY OFF + PYBIND11_PYTHONLIBS_OVERWRITE ON + PYBIND11_PYTHON_VERSION + PYBIND11_SIMPLE_GIL_MANAGEMENT OFF + PYBIND11_TEST OFF + USE_MUSICA ON + USE_MUSICA_FORTRAN ON + YAML_BUILD_SHARED_LIBS ON + YAML_CPP_BUILD_CONTRIB ON + YAML_CPP_BUILD_TOOLS ON + YAML_CPP_CLANG_FORMAT_EXE YAML_CPP_CLANG_FORMAT_EXE-NOTFOUND + YAML_CPP_FORMAT_SOURCE ON + YAML_CPP_INSTALL OFF + From 57ce38e944f54596b7f30f1412f90ec8f5dd056a Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Wed, 8 May 2024 12:06:23 -0600 Subject: [PATCH 06/39] Added MUSICA overview subsection. --- .../getting_started/getting_started.rst | 1 + docs/source/getting_started/overview.rst | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 docs/source/getting_started/overview.rst diff --git a/docs/source/getting_started/getting_started.rst b/docs/source/getting_started/getting_started.rst index 159b2212..070ded6b 100644 --- a/docs/source/getting_started/getting_started.rst +++ b/docs/source/getting_started/getting_started.rst @@ -6,4 +6,5 @@ Getting Started :maxdepth: 1 :caption: Contents: + overview installation diff --git a/docs/source/getting_started/overview.rst b/docs/source/getting_started/overview.rst new file mode 100644 index 00000000..9f9d90b5 --- /dev/null +++ b/docs/source/getting_started/overview.rst @@ -0,0 +1,20 @@ +Overview +======== + +The specific goal of MUSICA is to produce a new model independent infrastructure, +which will enable chemistry and aerosols to be simulated +at a large number of different resolutions in a single, coherent fashion. +At first, MUSICA will be configured within the NCAR Community Earth system Model (CESM) +and through this enable full feedbacks between the atmosphere, ocean and land. +The infrastructure will unify the different chemical transport models +including CAM-Chem, WACCM and WRF-Chem, and NCAR LES with chemistry +and a box model in a single modular framework. +The model infrastructure will be open source, +flexible and computationally efficient in order +to facilitate community co-development and use for scientific and operational purposes. + +At the heart of MUSICA is the standalone Model Independent Chemistry Model (MICM) +that satisfies the requirements of the Common Community Physics Package (CCPP) +and that can be connected to any CCPP compliant atmosphere model. +MUSICA and MICM will have a flexible design to handle a variety of gas phase and aerosol schemes +and associated chemical modules such as deposition or photolysis. From f96236ba0bb34a0c5a0b5f525aa86046a63d3436 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Wed, 8 May 2024 13:09:28 -0600 Subject: [PATCH 07/39] Added empty user_guide/introduction. --- docs/source/index.rst | 6 +++--- docs/source/user_guide/model_linking.rst | 3 +++ docs/source/user_guide/{index.rst => user_guide.rst} | 0 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 docs/source/user_guide/model_linking.rst rename docs/source/user_guide/{index.rst => user_guide.rst} (100%) diff --git a/docs/source/index.rst b/docs/source/index.rst index 62a1d2b5..71560dbd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -23,7 +23,7 @@ Welcome to MUSICA's documentation! .. grid-item-card:: User guide :img-top: _static/index_user_guide.svg - :link: user_guide/index + :link: user_guide/user_guide :link-type: doc .. grid-item-card:: API reference @@ -42,12 +42,12 @@ Welcome to MUSICA's documentation! :caption: Contents: getting_started/getting_started - user_guide/index + user_guide/user_guide api/index contributing/index .. getting_started/getting_started -.. user_guide/index +.. user_guide/user_guid .. api/index .. contributing/index .. citing_and_bibliography/index diff --git a/docs/source/user_guide/model_linking.rst b/docs/source/user_guide/model_linking.rst new file mode 100644 index 00000000..df8d2797 --- /dev/null +++ b/docs/source/user_guide/model_linking.rst @@ -0,0 +1,3 @@ +############ +Introduction +############ diff --git a/docs/source/user_guide/index.rst b/docs/source/user_guide/user_guide.rst similarity index 100% rename from docs/source/user_guide/index.rst rename to docs/source/user_guide/user_guide.rst From 4a3dcdcf1dc3b62a8ac391468bbca9f214e687e0 Mon Sep 17 00:00:00 2001 From: dwfncar Date: Wed, 8 May 2024 14:25:16 -0600 Subject: [PATCH 08/39] Renamed section to model_interface. --- docs/source/user_guide/model_interface.rst | 3 +++ docs/source/user_guide/model_linking.rst | 3 --- docs/source/user_guide/user_guide.rst | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 docs/source/user_guide/model_interface.rst delete mode 100644 docs/source/user_guide/model_linking.rst diff --git a/docs/source/user_guide/model_interface.rst b/docs/source/user_guide/model_interface.rst new file mode 100644 index 00000000..ea1d64c1 --- /dev/null +++ b/docs/source/user_guide/model_interface.rst @@ -0,0 +1,3 @@ +############## +Model Inteface +############## diff --git a/docs/source/user_guide/model_linking.rst b/docs/source/user_guide/model_linking.rst deleted file mode 100644 index df8d2797..00000000 --- a/docs/source/user_guide/model_linking.rst +++ /dev/null @@ -1,3 +0,0 @@ -############ -Introduction -############ diff --git a/docs/source/user_guide/user_guide.rst b/docs/source/user_guide/user_guide.rst index 3ac2a7e9..38c0011a 100644 --- a/docs/source/user_guide/user_guide.rst +++ b/docs/source/user_guide/user_guide.rst @@ -1,3 +1,9 @@ ########## User Guide ########## + +.. toctree:: + :maxdepth: 1 + :caption: Contents: + + model_interface From c55cb0248cccad010e192b48c5c9c725f6590620 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 08:12:54 -0600 Subject: [PATCH 09/39] Updated MICM dependency github tag. --- cmake/dependencies.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 574f9cb8..f2c21556 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -50,7 +50,7 @@ endif() if (MUSICA_ENABLE_MICM AND MUSICA_BUILD_C_CXX_INTERFACE) set_git_default(MICM_GIT_REPOSITORY https://github.com/NCAR/micm.git) - set_git_default(MICM_GIT_TAG 2a5cd4e11a6973974f3c584dfa9841d70e0a42d5) + set_git_default(MICM_GIT_TAG 5afd404cde063276f4e8e1fe3d1bf2aa3e6d869a) FetchContent_Declare(micm GIT_REPOSITORY ${MICM_GIT_REPOSITORY} @@ -110,4 +110,4 @@ endif() if(MUSICA_BUILD_DOCS) find_package(Sphinx REQUIRED) -endif() \ No newline at end of file +endif() From 186f97d76cbd540ccc8285fbfac331a97d4b5227 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 08:23:52 -0600 Subject: [PATCH 10/39] Removed config options for installation.rst. --- docs/source/getting_started/installation.rst | 87 -------------------- 1 file changed, 87 deletions(-) diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 2dfc6e5c..250940e1 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -14,90 +14,3 @@ In brief: $ cmake .. $ make - -.. code-block:: console - - BUILD_DOCS OFF - BUILD_GMOCK OFF - BUILD_TESTING ON - CMAKE_BUILD_TYPE Release - CMAKE_INSTALL_PREFIX /usr/local - CREATE_ENVIRONMENT_MODULE OFF - ENABLE_COVERAGE OFF - ENABLE_MEMCHECK OFF - ENABLE_MICM ON - ENABLE_MPI OFF - ENABLE_NC_CONFIG OFF - ENABLE_TESTS ON - ENABLE_TUVX ON - FETCHCONTENT_BASE_DIR /MUSICA/build/_deps - FETCHCONTENT_FULLY_DISCONNECTE OFF - FETCHCONTENT_QUIET OFF - FETCHCONTENT_SOURCE_DIR_GOOGLE - FETCHCONTENT_SOURCE_DIR_JSON - FETCHCONTENT_SOURCE_DIR_MICM - FETCHCONTENT_SOURCE_DIR_PYBIND - FETCHCONTENT_SOURCE_DIR_TUVX - FETCHCONTENT_SOURCE_DIR_YAML-C - FETCHCONTENT_UPDATES_DISCONNEC OFF - GIT_SUBMODULE ON - GTEST_HAS_ABSL OFF - INSTALL_GTEST OFF - JSON_BuildTests OFF - JSON_CI OFF - JSON_Diagnostics OFF - JSON_DisableEnumSerialization OFF - JSON_GlobalUDLs ON - JSON_INCLUDE_DIR JSON_INCLUDE_DIR-NOTFOUND - JSON_ImplicitConversions ON - JSON_Install OFF - JSON_LIB JSON_LIB-NOTFOUND - JSON_LegacyDiscardedValueCompa OFF - JSON_MultipleHeaders ON - JSON_SystemInclude OFF - MAKE_MUSICA_FORTRAN_INSTALLABL ON - MICM_BUILD_DOCS OFF - MICM_DEFAULT_VECTOR_MATRIX_SIZ 4 - MICM_ENABLE_CLANG_TIDY OFF - MICM_ENABLE_COVERAGE OFF - MICM_ENABLE_CUDA OFF - MICM_ENABLE_EXAMPLES ON - MICM_ENABLE_JSON ON - MICM_ENABLE_LLVM OFF - MICM_ENABLE_MEMCHECK OFF - MICM_ENABLE_MPI OFF - MICM_ENABLE_OPENACC OFF - MICM_ENABLE_OPENMP OFF - MICM_ENABLE_TESTS ON - MICM_GPU_TYPE - MUSICA_BUILD_C_CXX_INTERFACE ON - MUSICA_BUILD_DOCS OFF - MUSICA_BUILD_FORTRAN_INTERFACE ON - MUSICA_CREATE_ENVIRONMENT_MODU OFF - MUSICA_ENABLE_INSTALL ON - MUSICA_ENABLE_MEMCHECK OFF - MUSICA_ENABLE_MICM ON - MUSICA_ENABLE_MPI OFF - MUSICA_ENABLE_OPENMP OFF - MUSICA_ENABLE_PYTHON_LIBRARY ON - MUSICA_ENABLE_TESTS ON - MUSICA_ENABLE_TUVX ON - PYBIND11_DISABLE_HANDLE_TYPE_N OFF - PYBIND11_FINDPYTHON OFF - PYBIND11_INSTALL OFF - PYBIND11_INTERNALS_VERSION - PYBIND11_NOPYTHON OFF - PYBIND11_NUMPY_1_ONLY OFF - PYBIND11_PYTHONLIBS_OVERWRITE ON - PYBIND11_PYTHON_VERSION - PYBIND11_SIMPLE_GIL_MANAGEMENT OFF - PYBIND11_TEST OFF - USE_MUSICA ON - USE_MUSICA_FORTRAN ON - YAML_BUILD_SHARED_LIBS ON - YAML_CPP_BUILD_CONTRIB ON - YAML_CPP_BUILD_TOOLS ON - YAML_CPP_CLANG_FORMAT_EXE YAML_CPP_CLANG_FORMAT_EXE-NOTFOUND - YAML_CPP_FORMAT_SOURCE ON - YAML_CPP_INSTALL OFF - From fa08421b320652c62a662f8494e0bfae06dee12d Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 12:51:10 -0600 Subject: [PATCH 11/39] Start on C Fortran interface example. --- docs/source/user_guide/model_interface.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/source/user_guide/model_interface.rst b/docs/source/user_guide/model_interface.rst index ea1d64c1..790f4f31 100644 --- a/docs/source/user_guide/model_interface.rst +++ b/docs/source/user_guide/model_interface.rst @@ -1,3 +1,25 @@ ############## Model Inteface ############## + +Fortran Interface Example +------------------------- + +.. code-block:: cpp + + #include + + void test_proc_c(int n, double A[3][2]) { + + printf("test_proc_c\n"); + printf("n = %d\n", n); + + printf("matrix A\n"); + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 3; j++) { + printf("%6.2f ", A[j][i]); + } + printf("\n"); + } + } From 8e852ba1fbd0b24a55f416946dbd8889b971b17e Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 12:55:48 -0600 Subject: [PATCH 12/39] Added example fortran subroutine with C binding. --- docs/source/user_guide/model_interface.rst | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/source/user_guide/model_interface.rst b/docs/source/user_guide/model_interface.rst index 790f4f31..c0bd40a6 100644 --- a/docs/source/user_guide/model_interface.rst +++ b/docs/source/user_guide/model_interface.rst @@ -23,3 +23,31 @@ Fortran Interface Example printf("\n"); } } + + +.. code-block:: f90 + + program demo_fort + use iso_c_binding, only: c_int, c_double + implicit none + integer :: i, j + integer(c_int) :: n_fort = 7 + real(c_double), dimension(2, 3) :: A_fort + + interface + subroutine test_proc_c(n_c, A_c) bind(C, name='test_proc_c') + use iso_c_binding, only: c_int, c_double + integer(c_int), intent(in), value :: n_c + real(c_double), dimension(2, 3), intent(in) :: A_c + end subroutine test_proc_c + end interface + + do j = 1, 3 + do i = 1, 2 + A_fort(i, j) = real(i + j, c_double) + end do + end do + + call test_proc_c(n_fort, A_fort) + end program demo_fort + From 3c6f2034c8975609f7103424fc630dc9a1e92427 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 13:03:07 -0600 Subject: [PATCH 13/39] Added example Makefile, output for demo Fortran C interface example. --- docs/source/user_guide/model_interface.rst | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/source/user_guide/model_interface.rst b/docs/source/user_guide/model_interface.rst index c0bd40a6..fa1ef2d1 100644 --- a/docs/source/user_guide/model_interface.rst +++ b/docs/source/user_guide/model_interface.rst @@ -2,8 +2,8 @@ Model Inteface ############## -Fortran Interface Example -------------------------- +Fortran C Interface Example +--------------------------- .. code-block:: cpp @@ -51,3 +51,28 @@ Fortran Interface Example call test_proc_c(n_fort, A_fort) end program demo_fort +.. code-block:: bash + + all: test_proc_c.o demo_fort.o demo_fort + + test_proc_c.o : test_proc_c.c + gcc -c test_proc_c.c + + demo_fort.o : demo_fort.f90 + gfortran -c demo_fort.f90 + + demo_fort : test_proc_c.o demo_fort.o + gfortran -o demo_fort demo_fort.o test_proc_c.o -lc + + clean: + rm -f test_proc_c.o demo_fort.o demo_fort + +.. code-block:: console + + $ ./demo_fort + test_proc_c + n = 7 + matrix A + 2.00 3.00 4.00 + 3.00 4.00 5.00 + From d9561edd598dffa6b5bdaafefa59887b49b9d4f5 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 23:04:10 -0600 Subject: [PATCH 14/39] Added get_micm_version. --- src/micm/micm.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/micm/micm.cpp b/src/micm/micm.cpp index 7c25ac50..d1079141 100644 --- a/src/micm/micm.cpp +++ b/src/micm/micm.cpp @@ -8,12 +8,17 @@ #include #include +#include #include #include #include namespace musica { +const char* get_micm_version() { + return micm::getMicmVersion(); +} + MICM *create_micm(const char *config_path, Error *error) { DeleteError(error); MICM *micm = new MICM(); @@ -212,4 +217,4 @@ std::map MICM::get_user_defined_reaction_rates_ordering(Err } } -} // namespace musica \ No newline at end of file +} // namespace musica From be494ade3027d62c94bf36ca161854a789729df3 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Mon, 27 May 2024 23:20:47 -0600 Subject: [PATCH 15/39] Added git_micm_version_c. --- fortran/micm.F90 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index 5c0dbdbe..c7761868 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -10,6 +10,11 @@ module musica_micm interface + function get_micm_version_c() bind(C, name="get_micm_version") + use musica_util, only: string_t_c + type(string_t_c) :: get_micm_version_c + end function get_micm_version_c + function create_micm_c(config_path, error) bind(C, name="create_micm") use musica_util, only: error_t_c import c_ptr, c_int, c_char From 05685272afa3e28e286f67de56c4e70b2cff1394 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 08:50:38 -0600 Subject: [PATCH 16/39] Added get_micm_version_c. --- fortran/micm.F90 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index c7761868..4b946854 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -10,11 +10,6 @@ module musica_micm interface - function get_micm_version_c() bind(C, name="get_micm_version") - use musica_util, only: string_t_c - type(string_t_c) :: get_micm_version_c - end function get_micm_version_c - function create_micm_c(config_path, error) bind(C, name="create_micm") use musica_util, only: error_t_c import c_ptr, c_int, c_char @@ -45,6 +40,13 @@ subroutine micm_solve_c(micm, time_step, temperature, pressure, num_concentratio type(error_t_c), intent(inout) :: error end subroutine micm_solve_c + function get_micm_version_c(micm) bind(C, name="get_micm_version") + use musica_util, only: string_t_c + import :: c_ptr + type(c_ptr), value, intent(in) :: micm + type(string_t_c) :: get_micm_version_c + end function get_micm_version_c + function get_species_property_string_c(micm, species_name, property_name, error) bind(c, name="get_species_property_string") use musica_util, only: error_t_c, string_t_c import :: c_ptr, c_char From bd02b47f8e91f5dd15d4c43236b6a7f4a69f04be Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 19:02:40 +0000 Subject: [PATCH 17/39] Added set(MAKE_Fortran_FLAGS -fPIE) to CMakeLists.txt. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08a2d584..5ed8aea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU") elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI") list(APPEND musica_compile_definitions MUSICA_USING_PGI) endif() +set(CMAKE_Fortran_FLAGS "-fPIE") if(MUSICA_BUILD_C_CXX_INTERFACE) # must be global so that it also applies to dependencies like google test, unless we want @@ -124,4 +125,4 @@ endif() # Musica python if(MUSICA_ENABLE_PYTHON_LIBRARY) add_subdirectory(python) -endif() \ No newline at end of file +endif() From 607d9444745d14b270efc6f7686a48293e4ddd0e Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 19:36:03 +0000 Subject: [PATCH 18/39] Don't need _c for get_micm_version in micm.F90. --- fortran/micm.F90 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index 4b946854..e0361b11 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -10,6 +10,11 @@ module musica_micm interface + function get_micm_version() bind(C, name="get_micm_version") + use musica_util, only: string_t_c + type(string_t_c) :: get_micm_version + end function get_micm_version + function create_micm_c(config_path, error) bind(C, name="create_micm") use musica_util, only: error_t_c import c_ptr, c_int, c_char @@ -40,13 +45,6 @@ subroutine micm_solve_c(micm, time_step, temperature, pressure, num_concentratio type(error_t_c), intent(inout) :: error end subroutine micm_solve_c - function get_micm_version_c(micm) bind(C, name="get_micm_version") - use musica_util, only: string_t_c - import :: c_ptr - type(c_ptr), value, intent(in) :: micm - type(string_t_c) :: get_micm_version_c - end function get_micm_version_c - function get_species_property_string_c(micm, species_name, property_name, error) bind(c, name="get_species_property_string") use musica_util, only: error_t_c, string_t_c import :: c_ptr, c_char From a95ccf30ef1d267726de06d462d404b31f830ce9 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 19:40:34 +0000 Subject: [PATCH 19/39] Added public :: get_micm_version. --- fortran/micm.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index e0361b11..b56ba5f8 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -5,7 +5,7 @@ module musica_micm use musica_util, only: assert, mapping_t implicit none - public :: micm_t + public :: micm_t, get_micm_version private From 868ebc80778d6ad420c1710b904ab295921f6f7a Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 19:51:24 +0000 Subject: [PATCH 20/39] In micm.cpp, have get_micm_version return String. --- fortran/test/fetch_content_integration/test_micm_api.F90 | 3 ++- src/micm/micm.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_micm_api.F90 b/fortran/test/fetch_content_integration/test_micm_api.F90 index 323bf451..f6734c0c 100644 --- a/fortran/test/fetch_content_integration/test_micm_api.F90 +++ b/fortran/test/fetch_content_integration/test_micm_api.F90 @@ -2,7 +2,7 @@ program test_micm_api use, intrinsic :: iso_c_binding use, intrinsic :: ieee_arithmetic - use musica_micm, only: micm_t + use musica_micm, only: micm_t, get_micm_version use musica_util, only: assert, error_t, mapping_t #include "micm/util/error.hpp" @@ -43,6 +43,7 @@ subroutine test_api() num_user_defined_reaction_rates = 3 user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /) + ! print *, "MICM version", get_micm_version() write(*,*) "[test micm fort api] Creating MICM solver..." micm => micm_t(config_path, error) diff --git a/src/micm/micm.cpp b/src/micm/micm.cpp index d1079141..615b479c 100644 --- a/src/micm/micm.cpp +++ b/src/micm/micm.cpp @@ -15,8 +15,8 @@ namespace musica { -const char* get_micm_version() { - return micm::getMicmVersion(); +String get_micm_version() { + return CreateString(micm::getMicmVersion()); } MICM *create_micm(const char *config_path, Error *error) { From 078edc47a7be952c7f8d1d290a309e175c922260 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 20:59:11 +0000 Subject: [PATCH 21/39] Comment get_micm_version for now. --- fortran/micm.F90 | 16 ++++++++++++---- .../fetch_content_integration/test_micm_api.F90 | 8 +++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index b56ba5f8..a5b17ba5 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -5,15 +5,15 @@ module musica_micm use musica_util, only: assert, mapping_t implicit none - public :: micm_t, get_micm_version + public :: get_micm_version, micm_t private interface - function get_micm_version() bind(C, name="get_micm_version") + function get_micm_version_c() bind(C, name="get_micm_version") use musica_util, only: string_t_c - type(string_t_c) :: get_micm_version - end function get_micm_version + type(string_t_c) :: get_micm_version_c + end function get_micm_version_c function create_micm_c(config_path, error) bind(C, name="create_micm") use musica_util, only: error_t_c @@ -127,6 +127,14 @@ end subroutine delete_mappings_c contains + function get_micm_version() result(value) + use musica_util, only: string_t, string_t_c, to_c_string + type(string_t) :: value + type(string_t_c) :: string_c + string_c = get_micm_version_c() + value = string_t(string_c) + end function get_micm_version + function constructor(config_path, error) result( this ) use musica_util, only: error_t_c, error_t, copy_mappings type(micm_t), pointer :: this diff --git a/fortran/test/fetch_content_integration/test_micm_api.F90 b/fortran/test/fetch_content_integration/test_micm_api.F90 index f6734c0c..80fc6e48 100644 --- a/fortran/test/fetch_content_integration/test_micm_api.F90 +++ b/fortran/test/fetch_content_integration/test_micm_api.F90 @@ -2,8 +2,9 @@ program test_micm_api use, intrinsic :: iso_c_binding use, intrinsic :: ieee_arithmetic - use musica_micm, only: micm_t, get_micm_version - use musica_util, only: assert, error_t, mapping_t + ! use musica_micm, only: micm_t, get_micm_version + use musica_micm, only: micm_t + use musica_util, only: assert, error_t, mapping_t, string_t_c #include "micm/util/error.hpp" @@ -43,7 +44,8 @@ subroutine test_api() num_user_defined_reaction_rates = 3 user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /) - ! print *, "MICM version", get_micm_version() + ! micm_version = get_micm_version() + ! print *, "MICM version", micm_version write(*,*) "[test micm fort api] Creating MICM solver..." micm => micm_t(config_path, error) From 61702cef38be06dbf2ed19cffbac008851189645 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 21:43:26 +0000 Subject: [PATCH 22/39] Save. --- fortran/micm.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index a5b17ba5..69731222 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -5,7 +5,8 @@ module musica_micm use musica_util, only: assert, mapping_t implicit none - public :: get_micm_version, micm_t + public :: micm_t + ! public :: get_micm_version, micm_t private @@ -128,7 +129,7 @@ end subroutine delete_mappings_c contains function get_micm_version() result(value) - use musica_util, only: string_t, string_t_c, to_c_string + use musica_util, only: string_t, string_t_c type(string_t) :: value type(string_t_c) :: string_c string_c = get_micm_version_c() From 200ce7cc2dac763c3202b419e52baee4e10bd035 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 17:49:19 -0600 Subject: [PATCH 23/39] Added get_micm_version to micm.hpp header. --- fortran/micm.F90 | 3 +-- include/musica/micm.hpp | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fortran/micm.F90 b/fortran/micm.F90 index 69731222..fb5fca93 100644 --- a/fortran/micm.F90 +++ b/fortran/micm.F90 @@ -5,8 +5,7 @@ module musica_micm use musica_util, only: assert, mapping_t implicit none - public :: micm_t - ! public :: get_micm_version, micm_t + public :: get_micm_version, micm_t private diff --git a/include/musica/micm.hpp b/include/musica/micm.hpp index 06477bbb..e6f079e9 100644 --- a/include/musica/micm.hpp +++ b/include/musica/micm.hpp @@ -23,6 +23,7 @@ extern "C" { #endif + String get_micm_version(void); MICM *create_micm(const char *config_path, Error *error); void delete_micm(const MICM *micm, Error *error); void micm_solve(MICM *micm, double time_step, double temperature, double pressure, int num_concentrations, double *concentrations, int num_custom_rate_parameters, double *custom_rate_parameters, Error *error); @@ -108,4 +109,4 @@ inline T MICM::get_species_property(const std::string &species_name, const std:: msg.c_str()); return T(); } -} // namespace musica \ No newline at end of file +} // namespace musica From 787e45b508265eb397dfa8804a46c26a140a8fd3 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 18:07:03 -0600 Subject: [PATCH 24/39] Call get_micm_version in test_micm_api.F90. --- fortran/test/fetch_content_integration/test_micm_api.F90 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_micm_api.F90 b/fortran/test/fetch_content_integration/test_micm_api.F90 index 80fc6e48..6932d186 100644 --- a/fortran/test/fetch_content_integration/test_micm_api.F90 +++ b/fortran/test/fetch_content_integration/test_micm_api.F90 @@ -2,9 +2,8 @@ program test_micm_api use, intrinsic :: iso_c_binding use, intrinsic :: ieee_arithmetic - ! use musica_micm, only: micm_t, get_micm_version - use musica_micm, only: micm_t - use musica_util, only: assert, error_t, mapping_t, string_t_c + use musica_micm, only: micm_t, get_micm_version + use musica_util, only: assert, error_t, mapping_t, string_t #include "micm/util/error.hpp" @@ -20,6 +19,7 @@ program test_micm_api subroutine test_api() + type(string_t) :: micm_version type(micm_t), pointer :: micm real(c_double) :: time_step real(c_double) :: temperature @@ -44,8 +44,7 @@ subroutine test_api() num_user_defined_reaction_rates = 3 user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /) - ! micm_version = get_micm_version() - ! print *, "MICM version", micm_version + micm_version = get_micm_version() write(*,*) "[test micm fort api] Creating MICM solver..." micm => micm_t(config_path, error) From 6d03be25aa87e02cd1ddb75d8dd274d8194f8836 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 18:49:46 -0600 Subject: [PATCH 25/39] Print MICM version in get_micm_version for testing. --- src/micm/micm.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/micm/micm.cpp b/src/micm/micm.cpp index 615b479c..e377257c 100644 --- a/src/micm/micm.cpp +++ b/src/micm/micm.cpp @@ -16,7 +16,9 @@ namespace musica { String get_micm_version() { - return CreateString(micm::getMicmVersion()); + String micm_version = CreateString(micm::getMicmVersion()); + std::cout << "MICM version " << micm_version.value_ << std::endl; + return micm_version; } MICM *create_micm(const char *config_path, Error *error) { From cac5253b2551affb1080c085a49937a922745f60 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 21:25:55 -0600 Subject: [PATCH 26/39] Added get_char_array in util.F90. --- fortran/test/fetch_content_integration/test_micm_api.F90 | 1 + fortran/util.F90 | 9 ++++++++- src/micm/micm.cpp | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_micm_api.F90 b/fortran/test/fetch_content_integration/test_micm_api.F90 index 6932d186..6cad2064 100644 --- a/fortran/test/fetch_content_integration/test_micm_api.F90 +++ b/fortran/test/fetch_content_integration/test_micm_api.F90 @@ -45,6 +45,7 @@ subroutine test_api() user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /) micm_version = get_micm_version() + print *, "[test micm fort api] MICM version ", micm_version%get_char_array() write(*,*) "[test micm fort api] Creating MICM solver..." micm => micm_t(config_path, error) diff --git a/fortran/util.F90 b/fortran/util.F90 index cc783f94..e2022f4b 100644 --- a/fortran/util.F90 +++ b/fortran/util.F90 @@ -22,6 +22,7 @@ module musica_util private character(len=:), allocatable :: value_ contains + procedure :: get_char_array => get_char_array_string_t procedure, private, pass(from) :: char_assign_string procedure, private, pass(to) :: string_assign_char procedure, private, pass(to) :: string_assign_string @@ -101,6 +102,12 @@ end subroutine delete_string_c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + function get_char_array_string_t( this ) result ( value ) + class(string_t), intent(in) :: this + character(len=:), allocatable :: value + allocate( value, source = this%value_ ) + end function get_char_array_string_t + function string_t_constructor_from_string_t_c( c_string ) result( new_string ) type(string_t_c), intent(inout) :: c_string @@ -385,4 +392,4 @@ end subroutine assert !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -end module musica_util \ No newline at end of file +end module musica_util diff --git a/src/micm/micm.cpp b/src/micm/micm.cpp index e377257c..480db1ae 100644 --- a/src/micm/micm.cpp +++ b/src/micm/micm.cpp @@ -17,7 +17,6 @@ namespace musica { String get_micm_version() { String micm_version = CreateString(micm::getMicmVersion()); - std::cout << "MICM version " << micm_version.value_ << std::endl; return micm_version; } From 395c54a5b6a2e0ab99b62d9b25ec1abec8ddb08f Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 21:31:37 -0600 Subject: [PATCH 27/39] Removed some example code blocks. --- docs/source/user_guide/model_interface.rst | 74 ---------------------- 1 file changed, 74 deletions(-) diff --git a/docs/source/user_guide/model_interface.rst b/docs/source/user_guide/model_interface.rst index fa1ef2d1..bc733bb0 100644 --- a/docs/source/user_guide/model_interface.rst +++ b/docs/source/user_guide/model_interface.rst @@ -2,77 +2,3 @@ Model Inteface ############## -Fortran C Interface Example ---------------------------- - -.. code-block:: cpp - - #include - - void test_proc_c(int n, double A[3][2]) { - - printf("test_proc_c\n"); - printf("n = %d\n", n); - - printf("matrix A\n"); - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 3; j++) { - printf("%6.2f ", A[j][i]); - } - printf("\n"); - } - } - - -.. code-block:: f90 - - program demo_fort - use iso_c_binding, only: c_int, c_double - implicit none - integer :: i, j - integer(c_int) :: n_fort = 7 - real(c_double), dimension(2, 3) :: A_fort - - interface - subroutine test_proc_c(n_c, A_c) bind(C, name='test_proc_c') - use iso_c_binding, only: c_int, c_double - integer(c_int), intent(in), value :: n_c - real(c_double), dimension(2, 3), intent(in) :: A_c - end subroutine test_proc_c - end interface - - do j = 1, 3 - do i = 1, 2 - A_fort(i, j) = real(i + j, c_double) - end do - end do - - call test_proc_c(n_fort, A_fort) - end program demo_fort - -.. code-block:: bash - - all: test_proc_c.o demo_fort.o demo_fort - - test_proc_c.o : test_proc_c.c - gcc -c test_proc_c.c - - demo_fort.o : demo_fort.f90 - gfortran -c demo_fort.f90 - - demo_fort : test_proc_c.o demo_fort.o - gfortran -o demo_fort demo_fort.o test_proc_c.o -lc - - clean: - rm -f test_proc_c.o demo_fort.o demo_fort - -.. code-block:: console - - $ ./demo_fort - test_proc_c - n = 7 - matrix A - 2.00 3.00 4.00 - 3.00 4.00 5.00 - From 00233f08c1ccb365d7456cc6632d3a334331e898 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 28 May 2024 22:58:10 -0600 Subject: [PATCH 28/39] Updated installation.rst. --- docs/source/getting_started/installation.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 250940e1..da375ba5 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -11,6 +11,24 @@ In brief: $ cd musica $ mkdir build $ cd build - $ cmake .. + $ ccmake .. $ make + $ make install +Linking +======= + +.. code-block:: f90 + + program demo + use musica_util, only: string_t + use musica_micm, only: get_micm_version + implicit none + type(string_t) :: micm_version + micm_version = get_micm_version() + print *, "MICM version ", micm_version%get_char_array() + end program demo + +.. code-block:: bash + + gfortran -o demo demo.f90 -I/include -L/lib -lmusica-fortran -lmusica -lstdc++ From 82d1fef82777a34477ddb6d26d34536b426775e3 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Wed, 29 May 2024 07:38:16 -0600 Subject: [PATCH 29/39] Added Tutorial section. --- docs/source/getting_started/installation.rst | 18 ----- docs/source/index.rst | 1 + docs/source/tutorial/chapter1.rst | 20 +++++ docs/source/tutorial/tutorial.rst | 9 +++ docs/source/user_guide/fortran_c.rst | 78 ++++++++++++++++++++ 5 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 docs/source/tutorial/chapter1.rst create mode 100644 docs/source/tutorial/tutorial.rst create mode 100644 docs/source/user_guide/fortran_c.rst diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index da375ba5..f8695695 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -14,21 +14,3 @@ In brief: $ ccmake .. $ make $ make install - -Linking -======= - -.. code-block:: f90 - - program demo - use musica_util, only: string_t - use musica_micm, only: get_micm_version - implicit none - type(string_t) :: micm_version - micm_version = get_micm_version() - print *, "MICM version ", micm_version%get_char_array() - end program demo - -.. code-block:: bash - - gfortran -o demo demo.f90 -I/include -L/lib -lmusica-fortran -lmusica -lstdc++ diff --git a/docs/source/index.rst b/docs/source/index.rst index 71560dbd..b597c9ae 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -43,6 +43,7 @@ Welcome to MUSICA's documentation! getting_started/getting_started user_guide/user_guide + tutorial/tutorial api/index contributing/index diff --git a/docs/source/tutorial/chapter1.rst b/docs/source/tutorial/chapter1.rst new file mode 100644 index 00000000..25107858 --- /dev/null +++ b/docs/source/tutorial/chapter1.rst @@ -0,0 +1,20 @@ +Chapter 1 +========= + +Linking a Fortran Model +----------------------- + +.. code-block:: f90 + + program demo + use musica_util, only: string_t + use musica_micm, only: get_micm_version + implicit none + type(string_t) :: micm_version + micm_version = get_micm_version() + print *, "MICM version ", micm_version%get_char_array() + end program demo + +.. code-block:: bash + + gfortran -o demo demo.f90 -I/include -L/lib -lmusica-fortran -lmusica -lstdc++ diff --git a/docs/source/tutorial/tutorial.rst b/docs/source/tutorial/tutorial.rst new file mode 100644 index 00000000..e4206e3d --- /dev/null +++ b/docs/source/tutorial/tutorial.rst @@ -0,0 +1,9 @@ +######## +Tutorial +######## + +.. toctree:: + :maxdepth: 1 + :caption: Contents: + + chapter1.rst diff --git a/docs/source/user_guide/fortran_c.rst b/docs/source/user_guide/fortran_c.rst new file mode 100644 index 00000000..fa1ef2d1 --- /dev/null +++ b/docs/source/user_guide/fortran_c.rst @@ -0,0 +1,78 @@ +############## +Model Inteface +############## + +Fortran C Interface Example +--------------------------- + +.. code-block:: cpp + + #include + + void test_proc_c(int n, double A[3][2]) { + + printf("test_proc_c\n"); + printf("n = %d\n", n); + + printf("matrix A\n"); + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 3; j++) { + printf("%6.2f ", A[j][i]); + } + printf("\n"); + } + } + + +.. code-block:: f90 + + program demo_fort + use iso_c_binding, only: c_int, c_double + implicit none + integer :: i, j + integer(c_int) :: n_fort = 7 + real(c_double), dimension(2, 3) :: A_fort + + interface + subroutine test_proc_c(n_c, A_c) bind(C, name='test_proc_c') + use iso_c_binding, only: c_int, c_double + integer(c_int), intent(in), value :: n_c + real(c_double), dimension(2, 3), intent(in) :: A_c + end subroutine test_proc_c + end interface + + do j = 1, 3 + do i = 1, 2 + A_fort(i, j) = real(i + j, c_double) + end do + end do + + call test_proc_c(n_fort, A_fort) + end program demo_fort + +.. code-block:: bash + + all: test_proc_c.o demo_fort.o demo_fort + + test_proc_c.o : test_proc_c.c + gcc -c test_proc_c.c + + demo_fort.o : demo_fort.f90 + gfortran -c demo_fort.f90 + + demo_fort : test_proc_c.o demo_fort.o + gfortran -o demo_fort demo_fort.o test_proc_c.o -lc + + clean: + rm -f test_proc_c.o demo_fort.o demo_fort + +.. code-block:: console + + $ ./demo_fort + test_proc_c + n = 7 + matrix A + 2.00 3.00 4.00 + 3.00 4.00 5.00 + From 9a4b68e828a7f5b8eab7027e86d186f00805c679 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Wed, 29 May 2024 08:30:44 -0600 Subject: [PATCH 30/39] Added Tutorial Chapter 1. --- docs/source/tutorial/chapter1.rst | 35 +++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorial/chapter1.rst b/docs/source/tutorial/chapter1.rst index 25107858..64491624 100644 --- a/docs/source/tutorial/chapter1.rst +++ b/docs/source/tutorial/chapter1.rst @@ -1,8 +1,13 @@ Chapter 1 ========= -Linking a Fortran Model ------------------------ +First Fortran MUSICA Program +---------------------------- +The MUSICA library can be used within a fortran program. +To get started, let us create a simple program that links +to MUSICA and prints the version of MICM. + +Here are the contents of the program `demo.f90`: .. code-block:: f90 @@ -15,6 +20,32 @@ Linking a Fortran Model print *, "MICM version ", micm_version%get_char_array() end program demo +From the ``musica_micm`` module, we only need the function ``get_micm_version``, +which returns a derived string type from the ``musica_util`` module, ``string_t``. +The ``string_t`` type will be discussed in more detail in later chapters. +To print the version string we just want the fortran character array, +accessed by ``get_char_array``. + +Now, to build this simple program, +invoke the `gfortran` compiler and link to ``libmusica-fortran``, ``libmusica``, +and the standard C++ library ``libstdc++``. +The full command is + .. code-block:: bash gfortran -o demo demo.f90 -I/include -L/lib -lmusica-fortran -lmusica -lstdc++ + +```` is the full path of the MUSICA installation directory, +specified by the option ``CMAKE_INSTALL_PREFIX`` +during the `cmake` configuration process. +Note the include path allows the linker to find the ``musica_micm.mod`` and ``musica_util.mod`` +module definition files. + +When the `demo` program is run it should display the MICM version: + +.. code-block:: bash + + $ ./demo + MICM version 3.5.0 + $ + From 0f7b871f74ebbb8ae940640046ac79cef14660a1 Mon Sep 17 00:00:00 2001 From: David Fillmore <1524012+dwfncar@users.noreply.github.com> Date: Wed, 29 May 2024 19:22:44 -0600 Subject: [PATCH 31/39] Update docs/source/getting_started/overview.rst Co-authored-by: Kyle Shores --- docs/source/getting_started/overview.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/getting_started/overview.rst b/docs/source/getting_started/overview.rst index 9f9d90b5..40613dbd 100644 --- a/docs/source/getting_started/overview.rst +++ b/docs/source/getting_started/overview.rst @@ -13,8 +13,7 @@ The model infrastructure will be open source, flexible and computationally efficient in order to facilitate community co-development and use for scientific and operational purposes. -At the heart of MUSICA is the standalone Model Independent Chemistry Model (MICM) -that satisfies the requirements of the Common Community Physics Package (CCPP) +At the heart of MUSICA is the standalone Model Independent Chemistry Model (MICM), which is a gas-phase kinetic solver. MICM is made available by the MUSICA wrapper which satisfies the requirements of the Common Community Physics Package (CCPP) and that can be connected to any CCPP compliant atmosphere model. MUSICA and MICM will have a flexible design to handle a variety of gas phase and aerosol schemes and associated chemical modules such as deposition or photolysis. From b7cfca67674334faa441a9771939a43c7e404deb Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Wed, 29 May 2024 19:36:29 -0600 Subject: [PATCH 32/39] Removed -fPIE gfortran option. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ed8aea0..3acdf42c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,6 @@ elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU") elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI") list(APPEND musica_compile_definitions MUSICA_USING_PGI) endif() -set(CMAKE_Fortran_FLAGS "-fPIE") if(MUSICA_BUILD_C_CXX_INTERFACE) # must be global so that it also applies to dependencies like google test, unless we want From 409ec7502f6fbd29f506d840aa99d9f42657034e Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 10:51:49 -0600 Subject: [PATCH 33/39] Created test/tutorial subdir, added test_get_micm_version.f90 tutorial example. --- test/tutorial/test_get_micm_version.f90 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/tutorial/test_get_micm_version.f90 diff --git a/test/tutorial/test_get_micm_version.f90 b/test/tutorial/test_get_micm_version.f90 new file mode 100644 index 00000000..3b9b90db --- /dev/null +++ b/test/tutorial/test_get_micm_version.f90 @@ -0,0 +1,8 @@ +program test_get_micm_version + use musica_util, only: string_t + use musica_micm, only: get_micm_version + implicit none + type(string_t) :: micm_version + micm_version = get_micm_version() + print *, "MICM version ", micm_version%get_char_array() +end program test_get_micm_version From 1bff1613e24f4de4f5c5f5e4b74b9a4aba8fc5eb Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 11:04:37 -0600 Subject: [PATCH 34/39] Added subdir test. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3acdf42c..06ad693c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ endif() # Tests if(MUSICA_ENABLE_TESTS) enable_testing() + add_subdirectory(test) endif() ################################################################################ From c4bc9a3655eb706ed37e0cd99726ac3348a9fd40 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 11:05:53 -0600 Subject: [PATCH 35/39] Added CMakeLists.txt at MUSICA/test level. --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/CMakeLists.txt diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..a29068b3 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(tutorial) From e6df2c26fc77874469e80bcf5329f9a075b49946 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 11:09:00 -0600 Subject: [PATCH 36/39] Added CMakeLists.txt. --- test/tutorial/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/tutorial/CMakeLists.txt diff --git a/test/tutorial/CMakeLists.txt b/test/tutorial/CMakeLists.txt new file mode 100644 index 00000000..c69e08e8 --- /dev/null +++ b/test/tutorial/CMakeLists.txt @@ -0,0 +1,8 @@ +################################################################################ +# Test utilities + +include(test_util) + +################################################################################ +# Tests +create_standard_test(NAME test_get_micm_version SOURCES test_get_micm_version.f90) From 4eee37c64135705ed9a4d49d6ec464753e54ebca Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 11:17:11 -0600 Subject: [PATCH 37/39] Moved test_get_micm_version.f90 to fortran/test_fetch_content_integration. --- CMakeLists.txt | 1 - .../fetch_content_integration}/test_get_micm_version.f90 | 0 test/CMakeLists.txt | 1 - test/tutorial/CMakeLists.txt | 8 -------- 4 files changed, 10 deletions(-) rename {test/tutorial => fortran/test/fetch_content_integration}/test_get_micm_version.f90 (100%) delete mode 100644 test/CMakeLists.txt delete mode 100644 test/tutorial/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 06ad693c..3acdf42c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,6 @@ endif() # Tests if(MUSICA_ENABLE_TESTS) enable_testing() - add_subdirectory(test) endif() ################################################################################ diff --git a/test/tutorial/test_get_micm_version.f90 b/fortran/test/fetch_content_integration/test_get_micm_version.f90 similarity index 100% rename from test/tutorial/test_get_micm_version.f90 rename to fortran/test/fetch_content_integration/test_get_micm_version.f90 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index a29068b3..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(tutorial) diff --git a/test/tutorial/CMakeLists.txt b/test/tutorial/CMakeLists.txt deleted file mode 100644 index c69e08e8..00000000 --- a/test/tutorial/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -################################################################################ -# Test utilities - -include(test_util) - -################################################################################ -# Tests -create_standard_test(NAME test_get_micm_version SOURCES test_get_micm_version.f90) From a07af2843dd995c3a65ceb450e04b376c69fcc14 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 4 Jun 2024 11:40:25 -0600 Subject: [PATCH 38/39] Added test_get_micm_version for tutorial. --- .../fetch_content_integration/CMakeLists.txt | 19 ++++++++++++++++++- ..._version.f90 => test_get_micm_version.F90} | 0 fortran/test/unit/CMakeLists.txt | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) rename fortran/test/fetch_content_integration/{test_get_micm_version.f90 => test_get_micm_version.F90} (100%) diff --git a/fortran/test/fetch_content_integration/CMakeLists.txt b/fortran/test/fetch_content_integration/CMakeLists.txt index 94a14fb6..f9a32dbc 100644 --- a/fortran/test/fetch_content_integration/CMakeLists.txt +++ b/fortran/test/fetch_content_integration/CMakeLists.txt @@ -32,6 +32,7 @@ enable_testing() # API Test if (MUSICA_ENABLE_MICM) add_executable(test_micm_fortran_api test_micm_api.F90) + add_executable(test_get_micm_version test_get_micm_version.F90) target_link_libraries(test_micm_fortran_api PRIVATE @@ -48,6 +49,22 @@ if (MUSICA_ENABLE_MICM) COMMAND $ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) + + target_link_libraries(test_get_micm_version + PRIVATE + musica::musica-fortran + ) + + set_target_properties(test_get_micm_version + PROPERTIES + LINKER_LANGUAGE Fortran + ) + + add_test( + NAME test_get_micm_version + COMMAND $ + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + ) endif() # API Test @@ -69,4 +86,4 @@ if (MUSICA_ENABLE_TUVX) COMMAND $ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) -endif() \ No newline at end of file +endif() diff --git a/fortran/test/fetch_content_integration/test_get_micm_version.f90 b/fortran/test/fetch_content_integration/test_get_micm_version.F90 similarity index 100% rename from fortran/test/fetch_content_integration/test_get_micm_version.f90 rename to fortran/test/fetch_content_integration/test_get_micm_version.F90 diff --git a/fortran/test/unit/CMakeLists.txt b/fortran/test/unit/CMakeLists.txt index 69e15730..2d5e274a 100644 --- a/fortran/test/unit/CMakeLists.txt +++ b/fortran/test/unit/CMakeLists.txt @@ -4,6 +4,7 @@ create_standard_test_fortran(NAME fortran_util SOURCES util.F90) if (MUSICA_ENABLE_MICM) create_standard_test_fortran(NAME micm_fortran_api SOURCES ../fetch_content_integration/test_micm_api.F90) + create_standard_test_fortran(NAME get_micm_version SOURCES ../fetch_content_integration/test_get_micm_version.F90) endif() if (MUSICA_ENABLE_TUVX) @@ -16,4 +17,4 @@ if (MUSICA_ENABLE_TUVX) if (MUSICA_ENABLE_MPI) create_standard_test_fortran(NAME connect_to_tuvx_mpi SOURCES tuvx_mpi.F90) endif() -endif() \ No newline at end of file +endif() From 823cc55f4b4fc94ef0f41f6f94e4188a37618b72 Mon Sep 17 00:00:00 2001 From: David Fillmore Date: Tue, 11 Jun 2024 09:39:37 -0600 Subject: [PATCH 39/39] Use literal include for chapter 1 tutorial with test_get_micm_version.F90. --- docs/source/tutorial/chapter1.rst | 12 ++---------- .../test_get_micm_version.F90 | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/docs/source/tutorial/chapter1.rst b/docs/source/tutorial/chapter1.rst index 64491624..a05c0529 100644 --- a/docs/source/tutorial/chapter1.rst +++ b/docs/source/tutorial/chapter1.rst @@ -9,16 +9,8 @@ to MUSICA and prints the version of MICM. Here are the contents of the program `demo.f90`: -.. code-block:: f90 - - program demo - use musica_util, only: string_t - use musica_micm, only: get_micm_version - implicit none - type(string_t) :: micm_version - micm_version = get_micm_version() - print *, "MICM version ", micm_version%get_char_array() - end program demo + .. literalinclude:: ../../../fortran/test/fetch_content_integration/test_get_micm_version.F90 + :language: f90 From the ``musica_micm`` module, we only need the function ``get_micm_version``, which returns a derived string type from the ``musica_util`` module, ``string_t``. diff --git a/fortran/test/fetch_content_integration/test_get_micm_version.F90 b/fortran/test/fetch_content_integration/test_get_micm_version.F90 index 3b9b90db..299411bc 100644 --- a/fortran/test/fetch_content_integration/test_get_micm_version.F90 +++ b/fortran/test/fetch_content_integration/test_get_micm_version.F90 @@ -1,8 +1,8 @@ -program test_get_micm_version +program demo use musica_util, only: string_t use musica_micm, only: get_micm_version implicit none type(string_t) :: micm_version micm_version = get_micm_version() print *, "MICM version ", micm_version%get_char_array() -end program test_get_micm_version +end program demo