|
1 | 1 | Box model |
2 | 2 | ========= |
| 3 | +.. note:: |
| 4 | + |
| 5 | + MusicBox uses the Model-Independent Chemical Module (MICM) as its core chemistry solver. For more information about available reaction types, |
| 6 | + species configuration, and solver behavior, see the `MICM documentation <micm:index>`_. |
3 | 7 |
|
4 | | -This section details the components of the box model, including reactions, mechanisms, conditions, and solutions. |
| 8 | +This section details the components of the box model, a mechanism (the set of reactions and species), conditions, and solutions. To use the MusicBox model, |
| 9 | +import the :class:`acom_music_box.music_box.MusicBox` class:: |
| 10 | + |
| 11 | + from acom_music_box import MusicBox, Conditions |
5 | 12 |
|
6 | | -.. toctree:: |
7 | | - :maxdepth: 1 |
| 13 | +Using the previously defined in-code mechanism (see :ref:`Defining chemical systems <species>`), a box model can now be created and initialized with it:: |
| 14 | + |
| 15 | + box_model = MusicBox() |
| 16 | + box_model.load_mechanism(mechanism) |
8 | 17 |
|
9 | | - reactions |
10 | | - Chemical mechanisms <mechanisms> |
11 | | - Initial and evolving conditions <conditions> |
12 | | - Configuration options <configurations> |
| 18 | +Initial and evolving conditions |
| 19 | +-------------------------------- |
| 20 | +Use :class:`acom_music_box.conditions.Conditions` to set environmental parameters and species concentrations (:math:`\textsf{mol m}^{-3}`). Initial conditions define the environment that |
| 21 | +the mechanism takes place in at the start of the simulation through the parameters temperature (K), pressure (Pa), and optionally |
| 22 | +air density. Without an air density provided, the Ideal Gas Law is used to calculate this parameter. The initial concentrations of each |
| 23 | +Species is also included:: |
| 24 | + |
| 25 | + box_model.initial_conditions = Conditions( temperature=298.15, pressure=101325.0, species_concentrations={"X": 3.75, "Y": 5.0, "Z": 2.5,}) |
13 | 26 |
|
| 27 | +Evolving conditions (see :class:`acom_music_box.evolving_conditions.EvolvingConditions`) change the environment of the mechanism at a defined time value (Seconds), its first argument. Like importnitial conditions, |
| 28 | +these changes can also include temperature, pressure, air density, and Species concentrations:: |
| 29 | + |
| 30 | + box_model.add_evolving_condition(100.0, Conditions(temperature=310.0, pressure=100100.0)) |
| 31 | + |
| 32 | +Additional model options |
| 33 | +------------------------- |
| 34 | +Each box model also contains three time parameters that must be defined: |
| 35 | + |
| 36 | +* simulation_length: the number of seconds that the simulation lasts for |
| 37 | +* chem_step_time: the number of time steps between each simulation calculation |
| 38 | +* output_step_time: the number of seconds between each output of the model |
| 39 | + |
| 40 | +See :mod:`acom_music_box.model_options` for further details. The time parameters can be used as follows:: |
| 41 | + |
| 42 | + box_model.box_model_options.simulation_length = 200 # Units: Seconds (s) |
| 43 | + box_model.box_model_options.chem_step_time = 1 # Units: Seconds (s) |
| 44 | + box_model.box_model_options.output_step_time = 20 # Units: Seconds (s) |
| 45 | + |
| 46 | +For further descriptions of these MusicBox attributes, please see the `API Reference <https://ncar.github.io/music-box/branch/main/api/index.html>`_. |
| 47 | + |
| 48 | +Solving |
| 49 | +-------- |
| 50 | +Once all components of the box model have been defined, it can be solved by calling:: |
| 51 | + |
| 52 | + df = box_model.solve() |
| 53 | + |
| 54 | +This returns the following dataframe of the conditions and Species concentrations as they've varied across time steps. |
| 55 | + |
| 56 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 57 | +| | time.s | ENV.temperature.K | ENV.pressure.Pa | ENV.air number density.mol m-3 | CONC.X.mol m-3 | CONC.Y.mol m-3 | CONC.Z.mol m-3 | |
| 58 | ++====+==========+=====================+===================+==================================+==================+==================+==================+ |
| 59 | +| 0 | 0 | 298.15 | 101325 | 40.874 | 3.75 | 5 | 2.5 | |
| 60 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 61 | +| 1 | 20 | 298.15 | 101325 | 40.874 | 3.41149 | 4.8714 | 2.96711 | |
| 62 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 63 | +| 2 | 40 | 298.15 | 101325 | 40.874 | 3.10354 | 4.72528 | 3.42118 | |
| 64 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 65 | +| 3 | 60 | 298.15 | 101325 | 40.874 | 2.82338 | 4.56584 | 3.86077 | |
| 66 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 67 | +| 4 | 80 | 298.15 | 101325 | 40.874 | 2.56852 | 4.39669 | 4.28479 | |
| 68 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 69 | +| 5 | 100 | 298.15 | 101325 | 40.874 | 2.33666 | 4.22086 | 4.69247 | |
| 70 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 71 | +| 6 | 120 | 310 | 100100 | 38.8363 | 2.12702 | 4.04212 | 5.08087 | |
| 72 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 73 | +| 7 | 140 | 310 | 100100 | 38.8363 | 1.93618 | 3.86147 | 5.45235 | |
| 74 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 75 | +| 8 | 160 | 310 | 100100 | 38.8363 | 1.76247 | 3.6807 | 5.80683 | |
| 76 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 77 | +| 9 | 180 | 310 | 100100 | 38.8363 | 1.60434 | 3.50128 | 6.14438 | |
| 78 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 79 | +| 10 | 200 | 310 | 100100 | 38.8363 | 1.4604 | 3.32443 | 6.46517 | |
| 80 | ++----+----------+---------------------+-------------------+----------------------------------+------------------+------------------+------------------+ |
| 81 | + |
| 82 | + |
| 83 | +Loading premade configurations (optional) |
| 84 | +------------------------------------------ |
| 85 | +As an alternative to using the steps thus far to define a chemical configuration in code, MusicBox |
| 86 | +also supports definitions via a configuration file in JSON format. This example assumes you are using a file called |
| 87 | +"custom_box_model.json" in a "config" subfolder:: |
| 88 | + |
| 89 | + import sys |
| 90 | + |
| 91 | + box_model = MusicBox() |
| 92 | + conditions_path = "config/custom_box_model.json" |
| 93 | + box_model.loadJson(conditions_path) |
| 94 | + df = box_model.solve() |
0 commit comments