Skip to content

Commit 1a5339f

Browse files
authored
SUNDIALS interface updates (#4562)
## Summary * Check SUNDIALS return flags * Abort if a required callback function is called but not set * Fix selecting a specific IMEX method with SUNDIALS * Document time integrator runtime inputs * Read base class parameters at construction * Add options for selecting the algebraic solvers with implicit methods * Add option to set a stop time * Only output settings and final statistics with verbose output is enabled ## Additional background Various fixes and enhancements from testing methods in FerroX ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [x] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [x] include documentation in the code and/or rst files, if appropriate
1 parent af07c6f commit 1a5339f

File tree

5 files changed

+636
-77
lines changed

5 files changed

+636
-77
lines changed

Docs/sphinx_documentation/source/RuntimeParameters.rst

Lines changed: 348 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ to :cpp:`amrex::Initialize` and the function adds parameters to AMReX's
1717
.. important:: AMReX reserves the following prefixes in :cpp:`ParmParse`
1818
parameters: ``amr``, ``amrex``, ``blprofiler``, ``device``,
1919
``DistributionMapping``, ``eb2``, ``fab``, ``fabarray``,
20-
``geometry``, ``particles``, ``tiny_profiler``, and
21-
``vismf``.
20+
``geometry``, ``integration``, ``particles``, ``tiny_profiler``,
21+
and ``vismf``.
2222

2323
AMR
2424
---
@@ -268,7 +268,7 @@ Amr Class
268268
^^^^^^^^^
269269

270270
.. warning:: These parameters are specific to :cpp:`class Amr` based
271-
applications. If your application use :cpp:`class AmrCore`
271+
applications. If your application uses :cpp:`class AmrCore`
272272
directly, they do not apply unless you have provided
273273
implementations for them.
274274

@@ -937,7 +937,7 @@ Geometry
937937
--------
938938

939939
All these parameters are optional for constructing a :ref:`Geometry <sec:basics:geom>`
940-
object. There are only used if the information is not provided via function
940+
object. They are only used if the information is not provided via function
941941
arguments.
942942

943943
.. py:data:: geometry.coord_sys
@@ -1201,6 +1201,350 @@ Tiling
12011201
enabled for CPU runs with a tile size of 8 in the y and z-directions (if
12021202
they exist).
12031203

1204+
.. _sec:inputs:timeintegration:
1205+
1206+
Time Integration
1207+
----------------
1208+
1209+
All these parameters are optional for constructing or configuring a
1210+
:ref:`TimeIntegrator <sec:basics:timeintegration>` object.
1211+
1212+
.. py:data:: integration.type
1213+
:type: string
1214+
:value: [none]
1215+
1216+
This parameter sets the type of time integrator to use. The supported values
1217+
are:
1218+
1219+
* ForwardEuler
1220+
* RungeKutta
1221+
* SUNDIALS
1222+
1223+
.. py:data:: integration.time_step
1224+
:type: amrex::Real
1225+
:value: [none]
1226+
1227+
This parameter sets the fixed time step size to use.
1228+
1229+
For SUNDIALS methods, this parameter sets a fixed step size for single rate
1230+
methods (e.g., ERK) or a fixed slow time scale step size for multirate
1231+
methods (e.g., EX-MRI).
1232+
1233+
.. _sec:inputs:timeintegration:rungekutta:
1234+
1235+
Runge--Kutta Methods
1236+
^^^^^^^^^^^^^^^^^^^^
1237+
1238+
These parameters are relevant only when :py:data:`integration.type` is
1239+
"RungeKutta".
1240+
1241+
.. py:data:: integration.rk.type
1242+
:type: string
1243+
:value: [none]
1244+
1245+
This parameter sets the Runge--Kutta method to use. The supported values are:
1246+
1247+
* User
1248+
* ForwardEuler
1249+
* Trapezoid
1250+
* SSPRK3
1251+
* RK4
1252+
1253+
User-specificed Runge--Kutta Method
1254+
"""""""""""""""""""""""""""""""""""
1255+
1256+
When :py:data:`integration.rk.type` is "User", the following parameters can be
1257+
used to set a user-specificed explicit Butcher tableau,
1258+
1259+
.. math::
1260+
1261+
B \; \equiv \;
1262+
\begin{array}{r|c}
1263+
c & A \\
1264+
\hline
1265+
& b \\
1266+
& \tilde{b}
1267+
\end{array},
1268+
1269+
where, for a method with :math:`s` stages, :math:`c`, and :math:`b`,
1270+
:math:`\tilde{b}` are arrays of :math:`s` values and :math:`A` is a lower
1271+
triangular :math:`s \times s` matrix.
1272+
1273+
.. py:data:: integration.rk.nodes
1274+
:type: amrex::Real array
1275+
:value: [none]
1276+
1277+
The :math:`c` values of the Butcher tableau.
1278+
1279+
.. py:data:: integration.rk.tableau
1280+
:type: amrex::Real array
1281+
:value: [none]
1282+
1283+
The :math:`A` values of the Butcher tableau.
1284+
1285+
.. py:data:: integration.rk.weights
1286+
:type: amrex::Real array
1287+
:value: [none]
1288+
1289+
The :math:`b` values of the Butcher tableau.
1290+
1291+
.. py:data:: integration.rk.extended_weights
1292+
:type: amrex::Real array
1293+
:value: [none]
1294+
1295+
The :math:`\tilde{b}` values of the Butcher tableau. These values are only
1296+
required if the method has an embedding.
1297+
1298+
.. _sec:inputs:timeintegration:sundials:
1299+
1300+
SUNDIALS
1301+
^^^^^^^^
1302+
1303+
These parameters are relevant only when support for SUNDIALS time integrators is
1304+
enabled (see :ref:`sec:time_int:sundials`) and :py:data:`integration.type` is
1305+
"SUNDIALS".
1306+
1307+
.. _sec:inputs:timeintegration:sundials:methods:
1308+
1309+
Methods
1310+
"""""""
1311+
1312+
.. py:data:: integration.sundials.type
1313+
:type: string
1314+
:value: ERK
1315+
1316+
This parameter sets type of SUNDIALS time integrator to use. See the table
1317+
below for supported values.
1318+
1319+
+-----------------+---------------------------------------------------------+
1320+
| Parameter Value | SUNDIALS Method Type |
1321+
+=================+=========================================================+
1322+
| ERK | Explicit Runge-Kutta method |
1323+
+-----------------+---------------------------------------------------------+
1324+
| DIRK | Diagonally Implicit Runge-Kutta method |
1325+
+-----------------+---------------------------------------------------------+
1326+
| IMEX-RK | Implicit-Explicit Additive Runge-Kutta method |
1327+
+-----------------+---------------------------------------------------------+
1328+
| EX-MRI | Explicit Multirate Infinitesimal method |
1329+
+-----------------+---------------------------------------------------------+
1330+
| IM-MRI | Implicit Multirate Infinitesimal method |
1331+
+-----------------+---------------------------------------------------------+
1332+
| IMEX-MRI | Implicit-Explicit Multirate Infinitesimal method |
1333+
+-----------------+---------------------------------------------------------+
1334+
1335+
.. py:data:: integration.sundials.fast_type
1336+
:type: string
1337+
:value: ERK
1338+
1339+
When using a multirate method, this parameter sets the type of time
1340+
integrator to use at the fast time scale. Currently, ERK and DIRK methods are
1341+
supported.
1342+
1343+
.. py:data:: integration.sundials.method
1344+
:type: string
1345+
:value: [none]
1346+
1347+
This parameter sets the name of the specific time integration method to
1348+
use. See the sections listed below in the SUNDIALS documentation for valid
1349+
method names. Note, IMEX method must be specified using the
1350+
:py:data:`integration.sundials.method_i` and
1351+
:py:data:`integration.sundials.method_e` parameters. If a method name is not
1352+
provided, the SUNDIALS default method is used.
1353+
1354+
* `ERK methods <https://sundials.readthedocs.io/en/latest/arkode/Butcher_link.html#explicit-butcher-tables>`__
1355+
* `DIRK methods <https://sundials.readthedocs.io/en/latest/arkode/Butcher_link.html#implicit-butcher-tables>`__
1356+
* `MRI methods <https://sundials.readthedocs.io/en/latest/arkode/Usage/MRIStep/MRIStepCoupling.html#mri-coupling-tables>`__
1357+
1358+
.. py:data:: integration.sundials.method_i
1359+
:type: string
1360+
:value: [none]
1361+
1362+
When using an IMEX method, both the implicit and explicit methods must be
1363+
specified. This parameter can be used to select the *implicit* portion of the
1364+
IMEX method. See the `ImEx methods <https://sundials.readthedocs.io/en/latest/arkode/Butcher_link.html#additive-butcher-tables>`__
1365+
section in the SUNDIALS documentation for valid method names. If a method
1366+
name is not provided, the SUNDIALS default method is used.
1367+
1368+
.. py:data:: integration.sundials.method_e
1369+
:type: string
1370+
:value: [none]
1371+
1372+
When using an IMEX method, both the implicit and explicit methods must be
1373+
specified. This parameter can be used to select the *explicit* portion of the
1374+
IMEX method. See the `ImEx methods <https://sundials.readthedocs.io/en/latest/arkode/Butcher_link.html#additive-butcher-tables>`__
1375+
section in the SUNDIALS documentation for valid method names. If a method
1376+
name is not provided, the SUNDIALS default method is used.
1377+
1378+
.. py:data:: integration.sundials.fast_method
1379+
:type: string
1380+
:value: [none]
1381+
1382+
When using a multirate method, this parameter sets the method to use at the
1383+
fast time scale. If a method name is not provided, the SUNDIALS default
1384+
method is used.
1385+
1386+
.. _sec:inputs:timeintegration:sundials:stepsizes:
1387+
1388+
Step Sizes
1389+
""""""""""
1390+
1391+
.. note::
1392+
1393+
The parameter :py:data:`integration.time_step` is used to set a fixed step
1394+
size with single rate methods (e.g., ERK) or a fixed slow time scale step
1395+
size with multirate methods (e.g., EX-MRI).
1396+
1397+
.. py:data:: integration.fast_time_step
1398+
:type: amrex::Real
1399+
:value: [none]
1400+
1401+
When using a multirate method, this parameter sets the fixed step size to use
1402+
at the fast time scale.
1403+
1404+
.. py:data:: integration.use_adaptive_time_step
1405+
:type: bool
1406+
:value: false
1407+
1408+
This parameter enables adaptive time step sizes with single rate methods
1409+
(e.g., ERK) or adaptive time step sizes at the slow time scale with multirate
1410+
methods (e.g., EX-MRI).
1411+
1412+
.. py:data:: integration.use_adaptive_fast_time_step
1413+
:type: bool
1414+
:value: false
1415+
1416+
This parameter enables adaptive time step sizes at the fast time scale with
1417+
multirate methods (e.g., EX-MRI).
1418+
1419+
.. py:data:: integration.sundials.max_num_steps
1420+
:type: int
1421+
:value: 500
1422+
1423+
When using the ``evolve`` method, which allows the integrator to take
1424+
multiple time steps to reach the specified output time, this parameter sets
1425+
the maximum number of time steps allowed before reaching the output time. If
1426+
this limit is reached before the output time, SUNDIALS will return an error.
1427+
1428+
.. py:data:: integration.sundials.stop_time
1429+
:type: amrex::Real
1430+
:value: [none]
1431+
1432+
When using the ``evolve`` method (especially with adaptive time step sizes),
1433+
the SUNDIALS integrator may step past the requested output time and return an
1434+
interpolated solution at the requested time. This parameter will force the
1435+
integrator to stop and return the solution at the requested time.
1436+
1437+
.. _sec:inputs:timeintegration:sundials:tolerances:
1438+
1439+
Tolerances
1440+
""""""""""
1441+
1442+
When using adaptive time step sizes or an implicit method (e.g., DIRK),
1443+
selecting appropriate tolerances for the target application is a critical factor
1444+
in method performance. For advice on selecting tolerances see the `SUNDIALS
1445+
documentation
1446+
<https://sundials.readthedocs.io/en/latest/arkode/Usage/User_callable.html#general-advice-on-the-choice-of-tolerances>`__.
1447+
1448+
.. py:data:: integration.rel_tol
1449+
:type: amrex::Real
1450+
:value: 1.e-4
1451+
1452+
Relative tolerance for temporal error control.
1453+
1454+
.. py:data:: integration.abs_tol
1455+
:type: amrex::Real
1456+
:value: 1.e-9
1457+
1458+
Absolute tolerance for temporal error control.
1459+
1460+
.. py:data:: integration.fast_rel_tol
1461+
:type: amrex::Real
1462+
:value: 1.e-4
1463+
1464+
Relative tolerance for the temporal error at the fast time scale with
1465+
multrate methods.
1466+
1467+
.. py:data:: integration.fast_abs_tol
1468+
:type: amrex::Real
1469+
:value: 1.e-9
1470+
1471+
Absolute tolerance for the temporal error at the fast time scale with
1472+
multrate methods.
1473+
1474+
.. _sec:inputs:timeintegration:sundials:algebraicsolvers:
1475+
1476+
Algebraic Solvers
1477+
"""""""""""""""""
1478+
1479+
The parameters provide control over the nonlinear and linear solvers utilized
1480+
with implicit methods (e.g., DIRK).
1481+
1482+
.. py:data:: integration.sundials.nonlinear_solver
1483+
:type: string
1484+
:value: Newton
1485+
1486+
The nonlinear solver used with single rate methods (e.g., DIRK) or at the
1487+
slow time scale with multirate methods (e.g., IM-MRI). The supported values
1488+
are:
1489+
1490+
* Newton
1491+
* fixed-point
1492+
1493+
.. py:data:: integration.sundials.max_nonlinear_iters
1494+
:type: int
1495+
:value: 3
1496+
1497+
The maximum number of nonlinear iterations allowed per solve with single rate
1498+
methods (e.g., DIRK) or at the slow time scale with multirate methods (e.g.,
1499+
IM-MRI).
1500+
1501+
.. py:data:: integration.sundials.linear_solver
1502+
:type: string
1503+
:value: GMRES
1504+
1505+
The linear solver used with Newton's method for single rate methods (e.g.,
1506+
DIRK) or at the slow time scale with multirate methods (e.g., IM-MRI).
1507+
1508+
.. py:data:: integration.sundials.max_linear_iters
1509+
:type: int
1510+
:value: 5
1511+
1512+
The maximum number of linear iterations allowed per solve with single rate
1513+
methods (e.g., DIRK) or at the slow time scale with multirate methods (e.g.,
1514+
IM-MRI).
1515+
1516+
.. py:data:: integration.sundials.fast_nonlinear_solver
1517+
:type: string
1518+
:value: Newton
1519+
1520+
The nonlinear solver used at the fast time scale with multirate methods
1521+
(e.g., when the fast method is DIRK). The supported values are:
1522+
1523+
* Newton
1524+
* fixed-point
1525+
1526+
.. py:data:: integration.sundials.fast_max_nonlinear_iters
1527+
:type: int
1528+
:value: 3
1529+
1530+
The maximum number of nonlinear iterations allowed per solve at the fast time
1531+
scale (e.g., when the fast method is DIRK).
1532+
1533+
.. py:data:: integration.sundials.fast_linear_solver
1534+
:type: string
1535+
:value: GMRES
1536+
1537+
The linear solver used with Newton's method at the fast time scale with
1538+
multirate methods (e.g., when the fast method is DIRK).
1539+
1540+
.. py:data:: integration.sundials.fast_max_linear_iters
1541+
:type: int
1542+
:value: 5
1543+
1544+
The maximum number of linear iterations allowed at the fast time scale per
1545+
solve with multirate methods (e.g., when the fast method is DIRK).
1546+
1547+
12041548
Tiny Profiler
12051549
-------------
12061550

0 commit comments

Comments
 (0)