-
Notifications
You must be signed in to change notification settings - Fork 140
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
Feature: CVODE Resize History #678
base: develop
Are you sure you want to change the base?
Changes from all commits
cb85340
766b6ac
de8b52d
b6e6794
3a176ba
4f0446d
1cbd2b0
83d0741
9ac34b6
5ae3176
45ba303
23c2288
c9eb07a
5e3b162
16aef3b
5b6ce07
d4b54eb
12fe3dc
16673e4
ecda452
967f4d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3274,6 +3274,83 @@ vector. | |||||
If an error occurred, ``CVodeReInit`` also sends an error message to the | ||||||
error handler function. | ||||||
|
||||||
CVODE resize function | ||||||
~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
For simulations involving changes to the number of equations and unknowns in the | ||||||
ODE system, CVODE maybe "resized" between steps by calling | ||||||
:c:func:`CVodeResizeHistory`. As the methods implemented in CVODE utilize | ||||||
solution or right-hand side history information, resizing the integrator | ||||||
requires providing the necessary history data (detailed below) at the new | ||||||
problem size. | ||||||
|
||||||
.. c:function:: int CVodeResizeHistory(void* cvode_mem, sunrealtype* t_hist, N_Vector* y_hist, N_Vector* f_hist, int num_y_hist, int num_f_hist) | ||||||
|
||||||
The function :c:func:`CVodeResizeHistory` resizes CVODE using the provided | ||||||
history data at the new problem size. | ||||||
|
||||||
For Adams methods the required history data is | ||||||
|
||||||
* Solution vectors: :math:`y(t_n)` and :math:`y(t_{n-1})` | ||||||
* Right-hand side vectors: :math:`f(t_n,y(t_n)), f(t_{n-1},y(t_{n-1})), \ldots, f(t_{n-k}, y(t_{n-k}))` | ||||||
|
||||||
For BDF methods the required history data is: | ||||||
|
||||||
* Solution vectors: :math:`y(t_n), y(t_{n-1}), \ldots, y(t_{n-k})` | ||||||
* Right-hand side vectors: :math:`f(t_n, y(t_n))` and :math:`f(t_{n-1}, y(t_{n-1}))`, | ||||||
Comment on lines
+3292
to
+3300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary to resolve for this PR, but this restriction is rather arbitrary. In principle, we can construct the Nordsieck vector for Adams and BDF just from y's. This is a reasonable scenario when using a one-step method as a starting procedure. I propose generalizing this to allow any number of |
||||||
|
||||||
In both cases, :math:`k=\min\{q+1,q_{\textrm{max}}\}` where :math:`q` is the | ||||||
order of the last step (see :c:func:`CVodeGetLastOrder`) and | ||||||
:math:`q_{\textrm{max}}` is maximum allowed order (see | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
:c:func:`CVodeSetMaxOrd`). The additional solution/right-hand side values | ||||||
beyond what is strictly needed for the method are used to determine if an | ||||||
order increase should occur after the next step. | ||||||
|
||||||
:param cvode_mem: pointer to the CVODE memory block. | ||||||
:param t_hist: an array of time values for the solution and right-hand side | ||||||
history. These must be ordered starting from the most recent | ||||||
value i.e., :math:`t_n > t_{n-1} > \ldots > t_{n-k}` for | ||||||
forward integration or :math:`t_n < t_{n-1} < \ldots < | ||||||
t_{n-k}` for backward integration. | ||||||
:param y_hist: an array of solution vectors ordered to align with the | ||||||
corresponding times given in ``t_hist``. | ||||||
:param f_hist: an array of right-hand side vectors ordered to align with the | ||||||
corresponding times and solutions given in ``t_hist`` and | ||||||
``y_hist``, respectively. | ||||||
:param n_y_hist: number of solution vectors vectors provided in | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``y_hist``. For Adams methods this should be 2 and for BDF | ||||||
methods this should be :math:`\min\{q+1,q_{\textrm{max}}\}`. | ||||||
:param n_f_hist: number of right-hand side vectors provided in | ||||||
``f_hist``. For Adams methods this should be | ||||||
:math:`\min\{q+1,q_{\textrm{max}}\}` and for BDF methods it | ||||||
should be 2. | ||||||
|
||||||
:retval CV_SUCCESS: The call was successful. | ||||||
:retval CV_MEM_NULL: The CVODE memory block was ``NULL``. | ||||||
:retval CV_ILL_INPUT: An input argument was an illegal value, see the output | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
error message for additional details. | ||||||
|
||||||
.. versionadded:: x.y.z | ||||||
|
||||||
.. note:: | ||||||
|
||||||
Any nonlinear or linear solvers attached to CVODE will also need to be | ||||||
resized. At present, for SUNDIALS-provided algebraic solvers, this | ||||||
requires be destroying, re-creating, and re-attaching the solvers | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
following each call to :c:func:`CVodeResizeHistory`. Similarly, any matrix | ||||||
objects provided when attaching the linear solver will also need to be | ||||||
resized. | ||||||
|
||||||
If using a vector of absolute tolerances, the absolute tolerance vector | ||||||
will be invalid after the call to :c:func:`CVodeResizeHistory`, so a new | ||||||
absolute tolerance vector should be create and set following each call to | ||||||
:c:func:`CVodeResizeHistory` through a new call to | ||||||
:c:func:`CVodeSVtolerances`. | ||||||
|
||||||
If inequality constraint checking is enabled, a call to | ||||||
:c:func:`CVodeResizeHistory` will disable constraint checking. A call to | ||||||
:c:func:`CVodeSetConstraints` is required to re-enable constraint | ||||||
checking. | ||||||
|
||||||
.. _CVODE.Usage.CC.user_fct_sim: | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3266,6 +3266,91 @@ vector. | |||||
If an error occurred, ``CVodeReInit`` also sends an error message to the error handler function. | ||||||
|
||||||
|
||||||
CVODES resize function | ||||||
~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
For simulations involving changes to the number of equations and unknowns in the | ||||||
ODE system, CVODES maybe "resized" between steps by calling | ||||||
:c:func:`CVodeResizeHistory`. As the methods implemented in CVODES utilize | ||||||
solution or right-hand side history information, resizing the integrator | ||||||
requires providing the necessary history data (detailed below) at the new | ||||||
problem size. | ||||||
|
||||||
.. c:function:: int CVodeResizeHistory(void* cvode_mem, sunrealtype* t_hist, N_Vector* y_hist, N_Vector* f_hist, int num_y_hist, int num_f_hist) | ||||||
|
||||||
The function :c:func:`CVodeResizeHistory` resizes CVODES using the provided | ||||||
history data at the new problem size. | ||||||
|
||||||
For Adams methods the required history data is | ||||||
|
||||||
* Solution vectors: :math:`y(t_n)` and :math:`y(t_{n-1})` | ||||||
* Right-hand side vectors: :math:`f(t_n,y(t_n)), f(t_{n-1},y(t_{n-1})), \ldots, f(t_{n-k}, y(t_{n-k}))` | ||||||
|
||||||
For BDF methods the required history data is: | ||||||
|
||||||
* Solution vectors: :math:`y(t_n), y(t_{n-1}), \ldots, y(t_{n-k})` | ||||||
* Right-hand side vectors: :math:`f(t_n, y(t_n))` and :math:`f(t_{n-1}, y(t_{n-1}))`, | ||||||
|
||||||
In both cases, :math:`k=\min\{q+1,q_{\textrm{max}}\}` where :math:`q` is the | ||||||
order of the last step (see :c:func:`CVodeGetLastOrder`) and | ||||||
:math:`q_{\textrm{max}}` is maximum allowed order (see | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
:c:func:`CVodeSetMaxOrd`). The additional solution/right-hand side values | ||||||
beyond what is strictly needed for the method are used to determine if an | ||||||
order increase should occur after the next step. | ||||||
|
||||||
:param cvode_mem: pointer to the CVODES memory block. | ||||||
:param t_hist: an array of time values for the solution and right-hand side | ||||||
history. These must be ordered starting from the most recent | ||||||
value i.e., :math:`t_n > t_{n-1} > \ldots > t_{n-k}` for | ||||||
forward integration or :math:`t_n < t_{n-1} < \ldots < | ||||||
t_{n-k}` for backward integration. | ||||||
:param y_hist: an array of solution vectors ordered to align with the | ||||||
corresponding times given in ``t_hist``. | ||||||
:param f_hist: an array of right-hand side vectors ordered to align with the | ||||||
corresponding times and solutions given in ``t_hist`` and | ||||||
``y_hist``, respectively. | ||||||
:param n_y_hist: number of solution vectors vectors provided in | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``y_hist``. For Adams methods this should be 2 and for BDF | ||||||
methods this should be :math:`\min\{q+1,q_{\textrm{max}}\}`. | ||||||
:param n_f_hist: number of right-hand side vectors provided in | ||||||
``f_hist``. For Adams methods this should be | ||||||
:math:`\min\{q+1,q_{\textrm{max}}\}` and for BDF methods it | ||||||
should be 2. | ||||||
|
||||||
:retval CV_SUCCESS: The call was successful. | ||||||
:retval CV_MEM_NULL: The CVODES memory block was ``NULL``. | ||||||
:retval CV_ILL_INPUT: An input argument was an illegal value, see the output | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
error message for additional details. | ||||||
|
||||||
.. versionadded:: x.y.z | ||||||
|
||||||
.. note:: | ||||||
|
||||||
At this time resizing is supported when using CVODES for the solution of | ||||||
initial value problems (IVPs) and is not currently compatible with forward | ||||||
or adjoint sensitivity analysis. | ||||||
|
||||||
.. note:: | ||||||
|
||||||
Any nonlinear or linear solvers attached to CVODE will also need to be | ||||||
resized. At present, for SUNDIALS-provided algebraic solvers, this | ||||||
requires be destroying, re-creating, and re-attaching the solvers | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
following each call to :c:func:`CVodeResizeHistory`. Similarly, any matrix | ||||||
objects provided when attaching the linear solver will also need to be | ||||||
resized. | ||||||
|
||||||
If using a vector of absolute tolerances, the absolute tolerance vector | ||||||
will be invalid after the call to :c:func:`CVodeResizeHistory`, so a new | ||||||
absolute tolerance vector should be create and set following each call to | ||||||
:c:func:`CVodeResizeHistory` through a new call to | ||||||
:c:func:`CVodeSVtolerances`. | ||||||
|
||||||
If inequality constraint checking is enabled, a call to | ||||||
:c:func:`CVodeResizeHistory` will disable constraint checking. A call to | ||||||
:c:func:`CVodeSetConstraints` is required to re-enable constraint | ||||||
checking. | ||||||
|
||||||
|
||||||
.. _CVODES.Usage.SIM.user_supplied: | ||||||
|
||||||
User-supplied functions | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. | ||
Author(s): David J. Gardner @ LLNL | ||
----------------------------------------------------------------------------- | ||
SUNDIALS Copyright Start | ||
Copyright (c) 2002-2025, Lawrence Livermore National Security | ||
and Southern Methodist University. | ||
All rights reserved. | ||
|
||
See the top-level LICENSE and NOTICE files for details. | ||
|
||
SPDX-License-Identifier: BSD-3-Clause | ||
SUNDIALS Copyright End | ||
----------------------------------------------------------------------------- | ||
|
||
.. _ARKODE.Alg: | ||
|
||
ARKODE | ||
====== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
FullRhs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any documentation regarding how to obtain the current "history" vectors from CVODE, so that they could subsequently be resized. I'd think that this kind of thing would be critical to allow CVODE to continue along a the current order of accuracy (assuming that the resized history data is sufficiently accurate). Is that an option at all, or is it just assumed that a user resizes the data and then CVODE restarts the calculation from first order?