Skip to content

Commit

Permalink
Replaced the old configuration with the standard one for musica fortr…
Browse files Browse the repository at this point in the history
…an test
  • Loading branch information
boulderdaze committed Jan 9, 2024
1 parent d8bc429 commit 264396b
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.fortran
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions musica-fortran/test/configs/chapman/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"camp-files": [
"species.json",
"reactions.json"
]
}
97 changes: 97 additions & 0 deletions musica-fortran/test/configs/chapman/reactions.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
29 changes: 29 additions & 0 deletions musica-fortran/test/configs/chapman/species.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
1 change: 0 additions & 1 deletion musica-fortran/test/micm_config/mechanism.json

This file was deleted.

1 change: 0 additions & 1 deletion musica-fortran/test/micm_config/species.json

This file was deleted.

8 changes: 4 additions & 4 deletions musica-fortran/test/test_musica_api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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) "
Expand Down
9 changes: 4 additions & 5 deletions musica/src/micm/micm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int MICM::create_solver()
params.reorder_state_ = false;
solver_ = new VectorRosenbrockSolver{solver_params.system_,
solver_params.processes_,
params};
params};
}
else
{
Expand All @@ -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);
Expand All @@ -60,4 +59,4 @@ void MICM::solve(double temperature, double pressure, double time_step, double*&
{
concentrations[i] = v_concentrations_[i];
}
}
}

0 comments on commit 264396b

Please sign in to comment.