Skip to content
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

clean-up and document jac_cell #1738

Merged
merged 6 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jac_cell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Run jac_cell
run: |
cd unit_test/jac_cell
./main3d.gnu.ex inputs_aprox13 > test.out
./main3d.gnu.ex inputs > test.out
- name: Compare to stored output
run: |
Expand Down
2 changes: 2 additions & 0 deletions Docs/source/eos_cell.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _sec:eos_cell:

************
``eos_cell``
************
Expand Down
98 changes: 98 additions & 0 deletions Docs/source/jac_cell.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. _sec:jac_cell:

************
``jac_cell``
************

.. index:: jac_cell, numerical_jacobian.H

``jac_cell`` is used to test the accuracy of an analytic Jacobian
provided by a network, but comparing to a finite-difference
approximation. Given a thermodynamic state, ``jac_cell`` evaluates
the analytic Jacobian as well as a numerical approximation to it, and
then outputs (to ``stdout``) the Jacobian elements side-by-side for
each method of computing the Jacobian.

.. note::

Some integrators, like VODE, have their own numerical Jacobian
routines. This test uses the implementation in
``integration/util/numerical_jacobian.H``, which closely follows the ideas
of the VODE numerical approximation, as described in :cite:`lsode`.


Getting Started
===============

The ``jac_cell`` code is located in
``Microphysics/unit_test/jac_cell``. An inputs file which sets the
default parameters for your thermodynamic state is needed to run the
test.

Setting the thermodynamics
--------------------------

The parameters that affect the thermodynamics are:

* ``unit_test.density`` : the initial density

* ``unit_test.temperature`` : the initial temperature

* ``unit_test.small_temp`` : the low temperature cutoff used in the equation of state

* ``unit_test.small_dens`` : the low density cutoff used in the equation of state

While the mass fractions can be set individually (using
``unit_test.X1``, ``unit_test.X2``, ...), it is recommended to use
``unit_test.uniform_xn=1`` to initialize all the mass fractions to be
equal.


Building and Running the Code
=============================

The code can be built simply as:

.. prompt:: bash

make

.. note::

By default, this will build with the ``aprox13`` network, which
uses the C++ templating method (:ref:`sec:templated_rhs`) of
building the analytic Jacobian at compile-time. The network can be
changed via the build parameter ``NETWORK_DIR``.

.. important::

The screening routines provided by Microphysics do not return the
derivative of the screening factor with respect to composition. This
means that the analytic Jacobian provided by the network will ignore
this contribution, but the numerical Jacobian will implicitly include
it.

To compare just the network Jacobian elements, it is suggested that
you build with ``SCREEN_METHOD=null``.


The build process will automatically create links in the build
directory to any required EOS table.

To run the code, in the ``jac_cell`` directory run::

./main3d.gnu.ex inputs

where ``inputs`` is the provided inputs file. You may edit the
thermodynamic state in that file prior to running.


Output
======

All output is directed to ``stdout``. Example output is shown below
(this output includes screening, highlighting the difference that the
screening composition derivatives make):


.. literalinclude:: ../../unit_test/jac_cell/ci-benchmarks/jac_cell_aprox13.out
1 change: 1 addition & 0 deletions Docs/source/one_zone_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ have analysis scripts, which we describe in the next sections.

burn_cell.rst
eos_cell.rst
jac_cell.rst
9 changes: 9 additions & 0 deletions Docs/source/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -774,3 +774,12 @@ @ARTICLE{tillotson:1962
journal = {Internal Report, General Atomics},
url = {https://apps.dtic.mil/sti/citations/AD0486711}
}

@article{lsode,
title = {Description and {Use} of {LSODE}, the {Livermore} {Solver} for {Ordinary} {Differential} {Equations}},
language = {en},
year = {1993},
author = {{Radhakrishnan}, Krishnan and {Hindmarsh}, Alan C.},
journal = {Lawrence Livermore National Laboratory Report UCRL-ID-113855},
pages = {124}
}
2 changes: 2 additions & 0 deletions Docs/source/templated_networks.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _sec:templated_rhs:

*********************************
Templated Network Righthand Sides
*********************************
Expand Down
6 changes: 3 additions & 3 deletions Docs/source/unit_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ One-zone tests
* ``burn_cell`` :

given a $\rho$, $T$, and $X_k$, integrate a reaction network through a specified time
and output the new state.
and output the new state. See :ref:`sec:burn_cell` for more information.

* ``burn_cell_primordial_chem`` :

Expand All @@ -133,14 +133,14 @@ One-zone tests
* ``eos_cell`` :

given a $\rho$, $T$, and $X_k$, call the equation of state and print out
the thermodynamic information.
the thermodynamic information. See :ref:`sec:eos_cell` for more information.

* ``jac_cell`` :

for a single thermodynamic state, compute the analytic Jacobian
(using the functions provided by the network) and a numerical
finite-difference approximation to the Jacobian and output them,
element-by-element, to the display.
element-by-element, to the display. See :ref:`sec:jac_cell` for more information.

* ``nse_table_cell`` :

Expand Down
6 changes: 6 additions & 0 deletions unit_test/jac_cell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
For a single thermodynamic condition, evaluate the Jacobian using both
the analytic version from the network and the finite-difference
numerical approximation.

Note: most analytic Jacobians do not consider the derivative of the
screening factor with respect to composition. To get a more accurate
comparison of how the analytic and numerical terms compare, considering
just the reactive part, build with `SCREEN_METHOD=null`.

11 changes: 0 additions & 11 deletions unit_test/jac_cell/_parameters
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
@namespace: unit_test

run_prefix string ""

small_temp real 1.e5
small_dens real 1.e5

# the final time to integrate to
tmax real 1.e-2

# first output time -- we will output in nsteps logarithmically spaced steps between [tfirst, tmax]
tfirst real 0.0

# number of steps (logarithmically spaced)
nsteps int 100

density real 1.e7

temperature real 3.e9
Expand Down
Loading
Loading