Overview of the Code
The page is designed to give a brief overview of the code's structure. It's less about the scientific justification for the various treatments in the code and more about how the code is segmented and where to look for things.
Basic Algorithm​
Centering the code on the python wrap has made the underlying algorithm more difficult to follow than in older versions of the code. However, you can more or less see the whole procedure of solving the chemical model in solveAbundances
in src/fortran_src/wrap.f90
. The steps are:
-
Set all parameters to defaultparameters.f90 values
-
Read parameters from the dictionary input
-
Initialize physics variables such as column density and model specific values
-
Initialize chemical variables like initial abundances
-
While
time < finalTime
ordensity
<finalDens
- get a new target time
- update abundances from current time to target time
- update physics variables to new time
- Allow physics modules to affect abundances directly (eg to sputter ices)
- output parameters
-
output final abundances if
abundSaveFile
set.
Exactly what happens in the initialize physics and update physics sections depends on the physical model in question.
Physics​
There are a number of physics modules which all implement the same subroutines in different ways. They also all pull from core-physics.f90, a module that contains all the non-optional physics variables. When we initialize or update physics, we first call the initialize/update subroutine from core-physics.f90 and then call it from the physics module. This is achieved by passing the relevant physics module's subroutines to solveAbundances
from each of the various subroutines in wrap.f90.
If you'd like to implement your own physics model, you should try as closely as possible to follow this structure. Since core-physics is always updated first, you can override it with your module. For example, core-physics will calculate the Av and column density in the standard way but you could recalculate your column density in your updatePhysics subroutine to get new behaviour.
Chemistry​
A large number of the fortran files make up the chemistry module. There's:
chemistry.f90
which contains the core chemistry routines and variables.rates.f90
which is actually directly included inchemistry.f90
and just contains most of the reaction rate calculationssurfacereactions.f90
andphotoreactions.f90
which each contain a lot of the surface or photon chemistry related variables and subroutines. These are often so involved that we just separated them out to avoid overfillingrates.f90
.odes.f90
which is generated by MakeRates and is a huge file of ordinary differential equations.network.f90
is also generated by MakeRates and contains lists of things like species names, reaction types, the index of the species that is the nth reactant of each reaction, etc. If you want to store something like the index of a species or reaction, consider having MakeRates add to this file.
Constants​
All constants are defined in constants.f90
and are accessed by the constants
module. If you need a physical constant, it's best check if it's here before defining it. There should be no harm at all in importing this module into any other code as it compiles first and nothing is modifiable (eg you can't overwrite the value of PI
defined in constants.f90).
It's also where we declare dp
, which allows us to declare real64 variables in the iso standard way. All the real(dp)
variables you see declared in the code come from this.