-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MUSICA Tutorial Chapter 2 #141
Merged
+154
−0
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e9b7bc6
Start on test_micm_box_model.F90.
dwfncar 4a3c9bd
Start on test_micm_box_model.F90.
dwfncar 66d5091
In test_micm_box_model, create micm_t solver.
dwfncar 73f997d
Initialize some variables.
dwfncar de422c2
Use configs/analytical.
dwfncar 5e097cc
Use configs/analytical.
dwfncar 1ecd9ba
Added micm solve.
dwfncar 10ac01b
Start on Chapter 2.
dwfncar b30c177
Literal include for test_micm_box_model.
dwfncar fba18d3
Literal include json configs.
dwfncar 76d90f2
Updated CMakeLists.txt.
dwfncar a127623
Add config file description.
dwfncar c9bb25b
Tutorial Chapter 2.
dwfncar c482ec9
Tutorial Chapter 2.
dwfncar 4d2a500
Minor formatting.
dwfncar 0041617
Minor formatting.
dwfncar f49fa56
Merge branch 'main' into 70-tutorial-ch2
dwfncar 6e38172
Added link to MICM docs, test program output.
dwfncar 460bac7
Merging main.
dwfncar d63422f
Added test_micm_box_model executable.
dwfncar e96c6cb
Merge branch 'main' into 70-tutorial-ch2
dwfncar 498d34c
Updated test_micm_box_model with new micm solve.
dwfncar 156e2cc
Added deallocate( micm ) in test_micm_box_model.
dwfncar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Chapter 2 | ||
========= | ||
|
||
An MICM Box Model Fortran Example | ||
--------------------------------- | ||
|
||
In this next MUSICA Fortran example, | ||
we will setup a MICM solver, starting with a set of MICM configuration files, | ||
and run the solver for a single integration time step. | ||
|
||
The MICM configuration is specified in a top-level ``config.json`` file, | ||
which simply lists the chemical species configuration file followed by | ||
the reactions configuration file. | ||
|
||
.. literalinclude:: ../../../configs/analytical/config.json | ||
:language: json | ||
|
||
For this example, we will have a system of three chemical species | ||
`A`, `B`, and `C`, defined in the JSON file ``species.json`` as follows: | ||
|
||
.. literalinclude:: ../../../configs/analytical/species.json | ||
:language: json | ||
|
||
The ``reactions.json`` specifies a mechanism, or a set of reactions for the system. | ||
Here, we will introduce two Arrhenius type reactions, the first | ||
with `B` evolving to `C`, and specifying all five reaction parameters, | ||
and the second reaction with `A` evolving to `B` and using only two reaction parameters. | ||
The mechanism configuration might then be set up as: | ||
|
||
.. literalinclude:: ../../../configs/analytical/reactions.json | ||
:language: json | ||
|
||
More information on MICM configurations and reactions can be found in the MICM documentation | ||
at `https://ncar.github.io/micm/user_guide/`_ | ||
|
||
The Fortran example code is shown below in full: | ||
|
||
.. literalinclude:: ../../../fortran/test/fetch_content_integration/test_micm_box_model.F90 | ||
:language: f90 | ||
|
||
From the ``musica_util`` module we need the Fortran types | ||
``error_t``, ``string_t``, and ``mapping_t``. | ||
A pointer to a ``musica_micm::micm_t`` will serve as the interface to the MICM solver | ||
(in the example the pointer name is ``micm``). | ||
Note that the ``config_path`` in the code sample has been set to ``configs/analytical``, | ||
so that subdir should be created relative to the main program and contain | ||
the MICM JSON configuration files, | ||
or otherwise the ``config_path`` should be modified appropriately. | ||
The initial species concentrations are initialized in the ``concentrations`` array, | ||
which is an argument to the MICM solver. | ||
|
||
Finally, a single time step solution is obtained through a call to ``micm%solve``, | ||
after which the updated concentrations may be displayed. | ||
|
||
.. code-block:: bash | ||
|
||
$ ./test_micm_box_model | ||
Creating MICM solver... | ||
Species Name:A, Index: 1 | ||
Species Name:B, Index: 2 | ||
Species Name:C, Index: 3 | ||
Solving starts... | ||
After solving, concentrations 0.38 1.61E-009 2.62 | ||
$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ Tutorial | |
:caption: Contents: | ||
|
||
chapter1.rst | ||
chapter2.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
fortran/test/fetch_content_integration/test_micm_box_model.F90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
program test_micm_box_model | ||
|
||
use, intrinsic :: iso_c_binding | ||
use, intrinsic :: ieee_arithmetic | ||
|
||
use musica_util, only: error_t, string_t, mapping_t | ||
use musica_micm, only: micm_t | ||
|
||
implicit none | ||
|
||
call box_model() | ||
|
||
contains | ||
|
||
subroutine box_model() | ||
|
||
character(len=256) :: config_path | ||
|
||
real(c_double) :: time_step | ||
real(c_double) :: temperature | ||
real(c_double) :: pressure | ||
|
||
integer(c_int) :: num_concentrations = 3 | ||
real(c_double), dimension(3) :: concentrations | ||
|
||
integer(c_int) :: num_user_defined_reaction_rates = 0 | ||
real(c_double), dimension(:), allocatable :: user_defined_reaction_rates | ||
|
||
type(error_t) :: error | ||
type(micm_t), pointer :: micm | ||
|
||
integer :: i | ||
|
||
config_path = "configs/analytical" | ||
|
||
time_step = 200 | ||
temperature = 273.0 | ||
pressure = 1.0e5 | ||
|
||
concentrations = (/ 1.0, 1.0, 1.0 /) | ||
|
||
write(*,*) "Creating MICM solver..." | ||
micm => micm_t(config_path, error) | ||
|
||
do i = 1, size( micm%species_ordering ) | ||
associate(the_mapping => micm%species_ordering(i)) | ||
print *, "Species Name:", the_mapping%name(), ", Index:", the_mapping%index() | ||
end associate | ||
end do | ||
|
||
write(*,*) "Solving starts..." | ||
call micm%solve(time_step, temperature, pressure, num_concentrations, concentrations, & | ||
num_user_defined_reaction_rates, user_defined_reaction_rates, error) | ||
write(*,*) "After solving, concentrations", concentrations | ||
|
||
end subroutine box_model | ||
|
||
end program test_micm_box_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might need to add this line:
unless I'm just missing where this is