|
1 | 1 | Adding a problem |
2 | 2 | ================ |
3 | 3 |
|
4 | | -The easiest way to add a problem is to copy an existing problem setup |
5 | | -in the solver you wish to use (in its problems/ sub-directory). Three |
6 | | -different files will need to be copied (created): |
7 | | - |
8 | | -* ``problem.py``: this is the main initialization routine. The |
9 | | - function ``init_data()`` is called at runtime by the ``Simulation`` |
10 | | - object's ``initialize()`` method. Two arguments are passed in, the |
11 | | - simulation's ``CellCenterData2d`` object and the |
12 | | - ``RuntimeParameters`` object. The job of ``init_data()`` is to fill |
13 | | - all of the variables defined in the ``CellCenterData2d`` object. |
14 | | - |
15 | | -* ``_problem.defaults``: this contains the runtime parameters and |
16 | | - their defaults for your problem. They should be placed in a block |
17 | | - with the heading ``[problem]`` (where ``problem`` is your problem's |
18 | | - name). Anything listed here will be available through the |
19 | | - ``RuntimeParameters`` object at runtime. |
20 | | - |
21 | | -* ``inputs.problem``: this is the inputs file that is used at runtime |
22 | | - to set the parameters for your problem. Any of the general |
23 | | - parameters (like the grid size, boundary conditions, etc.) as well |
24 | | - as the problem-specific parameters can be set here. Once the |
25 | | - problem is defined, you need to add the problem name to the |
26 | | - ``__all__`` list in the ``__init__.py`` file in the ``problems/`` |
27 | | - sub-directory. This lets python know about the problem. |
| 4 | +Problem setups are defined in a ``problems/`` subdirectory under each |
| 5 | +solver. For example, the problem setups for ``compressible`` are here: |
| 6 | +https://github.com/python-hydro/pyro2/tree/main/pyro/compressible/problems |
| 7 | + |
| 8 | +When you install pyro via ``pip``, these problem setups become available. |
| 9 | +At the moment, the way to add a new problem is to directly put files |
| 10 | +into these directories. |
| 11 | + |
| 12 | +.. tip:: |
| 13 | + |
| 14 | + If you are working on adding problems, it is |
| 15 | + recommended that you install pyro from source and do it as an |
| 16 | + `editable install |
| 17 | + <https://setuptools.pypa.io/en/latest/userguide/development_mode.html>`_ |
| 18 | + as: |
| 19 | + |
| 20 | + .. prompt:: bash |
| 21 | + |
| 22 | + pip install -e . |
| 23 | + |
| 24 | +Every problem needs a python module of the form *problem_name.py*. |
| 25 | +This will define the runtime parameters that the problem expects |
| 26 | +and do the initialization of the state variables. |
| 27 | + |
| 28 | +Many problems will also provide an *inputs* file that overrides |
| 29 | +some of the runtime parameter defaults (like the domain size and BCs) |
| 30 | +to be appropriate for this problem. |
| 31 | + |
| 32 | +"`problem.py`" |
| 33 | +-------------- |
| 34 | + |
| 35 | +A python module named after the problem (we'll call it ``problem.py`` here) |
| 36 | +provides the following: |
| 37 | + |
| 38 | +* ``PROBLEM_PARAMS`` : this is a dictionary (it can be empty, ``{}``) |
| 39 | + that defines the runtime parameters that are needed to this problem |
| 40 | + setup. For instance, for the ``compressible`` ``sod`` problem: |
| 41 | + |
| 42 | + .. code:: python |
| 43 | +
|
| 44 | + PROBLEM_PARAMS = {"sod.direction": "x", |
| 45 | + "sod.dens_left": 1.0, |
| 46 | + "sod.dens_right": 0.125, |
| 47 | + "sod.u_left": 0.0, |
| 48 | + "sod.u_right": 0.0, |
| 49 | + "sod.p_left": 1.0, |
| 50 | + "sod.p_right": 0.1} |
| 51 | +
|
| 52 | + Each key in the dictionary should be of the form |
| 53 | + *problem-name.parameter*, and the values are the default value of |
| 54 | + the parameter. |
| 55 | + |
| 56 | + Any of these runtime parameters can be overridden in an inputs file |
| 57 | + or on the commandline (when running via ``pyro_sim.py``) or via the |
| 58 | + ``inputs_dict`` keyword argument (when running via the |
| 59 | + :func:`Pyro <pyro.pyro_sim.Pyro>` class). |
| 60 | + |
| 61 | +* ``DEFAULT_INPUTS`` : this is the name of an inputs file to be |
| 62 | + read in by default when using the ``Pyro`` class interface. It |
| 63 | + can be ``None``. |
| 64 | + |
| 65 | + This is not used when running via ``pyro_sim.py``. |
| 66 | + |
| 67 | +* ``init_data()`` : this is the main initialization routine. It has |
| 68 | + the signature: |
| 69 | + |
| 70 | + .. code:: python |
| 71 | +
|
| 72 | + def init_data(my_data, rp) |
| 73 | +
|
| 74 | + where |
| 75 | + |
| 76 | + * ``my_data`` is a :func:`CellCenterData2d <pyro.mesh.patch.CellCenterData2d>` or :func:`FV2d <pyro.mesh.fv.FV2d>` object. The ``Grid`` object can be obtained from this |
| 77 | + as needed. |
| 78 | + |
| 79 | + * ``rp`` is a :func:`RuntimeParameters <pyro.util.runparams.RuntimeParameters>` object. |
| 80 | + Any of the runtime parameters (including the problem-specific ones |
| 81 | + defined via ``PROBLEM_PARAMS``) can be accessed via this. |
| 82 | + |
| 83 | + .. note:: |
| 84 | + |
| 85 | + The interface for ``init_data`` is the same for all solvers. |
| 86 | + |
| 87 | + The job of ``init_data`` is to initialize the state data that is |
| 88 | + managed by the ``my_data`` object passed in. Exactly which variables |
| 89 | + are included there will depend on the solver. |
| 90 | + |
| 91 | +* ``finalize()`` : this is called at the very end of evolution. It |
| 92 | + is meant to output instructions to the user on how the can analyze the |
| 93 | + data. It takes no arguments. |
| 94 | + |
| 95 | +.. important:: |
| 96 | + |
| 97 | + Once the problem is defined, you need to add the problem name to |
| 98 | + the ``__all__`` list in the ``__init__.py`` file in the |
| 99 | + ``problems/`` sub-directory. This lets python know about the |
| 100 | + problem. |
0 commit comments