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

Example guide CVODE update (currently without Deep Dive) #309

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
06f845c
Added 2 examples for ARKODE.
danmm16 Jun 5, 2023
57a2ea0
Debugged ark_bruss_f2003 and created output file
drreynolds Jun 5, 2023
2557a09
Added templates for 2 more arkode Fortran examples and added them to …
danmm16 Jun 7, 2023
cc455c9
added a bit to the template for bruss1D
danmm16 Jun 8, 2023
42a474f
Polished off the template, need to copy functions to ode_mod for impl…
danmm16 Jun 8, 2023
43601c7
fixed minor variable business
danmm16 Jun 8, 2023
87e7ca6
Added comments about suggested changes
drreynolds Jun 8, 2023
0826ba4
Added comments about suggested changes
drreynolds Jun 8, 2023
b401af5
finished ark_roberts_dsnL in F2003_serial and made progress on ark_br…
danmm16 Jun 9, 2023
c6d02cb
Updated and mostly finished, without testing, ark_diurnal_kry_bp and …
danmm16 Jun 11, 2023
a8b44b2
Fixed the Fortran 2003 Serial sphinx documentation code.
danmm16 Jun 12, 2023
f353ce4
Fixes from meeting
drreynolds Jun 12, 2023
d9e7dc5
Debugged ark_roberts_dns_f2003.f90
drreynolds Jun 12, 2023
0a32403
Resolved build issues with ark_diurnal_kry_bp_f2003
drreynolds Jun 12, 2023
0dd6591
Added missing call to close the output file stream
drreynolds Jun 12, 2023
c50a015
Fixed some bugs with F2003 example ark_diurnal and started working on…
danmm16 Jun 13, 2023
4bbd90c
Added comments on some missing pieces
drreynolds Jun 13, 2023
675c4e6
add lapackdense f2003 interface
balos1 Jun 14, 2023
2aaedab
Finished three more CVODE example F2003 codes.
danmm16 Jun 14, 2023
8624568
Updated LAPACK for Fortran 2003. Merge branch 'LAPACK_update' into de…
danmm16 Jun 14, 2023
fadc77a
Started working on CVODE Sphinx documentation code using ARKODE templ…
danmm16 Jun 15, 2023
262d31a
Removed 'built' cvode Sphinx example guide
drreynolds Jun 15, 2023
2d9780b
Removed non-compiling example
drreynolds Jun 15, 2023
28bd101
Updates from meeting
drreynolds Jun 15, 2023
60455e6
Reorganized CVODE example guide files
drreynolds Jun 15, 2023
b5cfdca
Stashed changes and finished roberts_klu.
danmm16 Jun 19, 2023
44d3e27
Fixed duplicate 'ode_mod' name
drreynolds Jun 19, 2023
9617f18
Starting CVODE example docs and finishing KINSOL serial example.
danmm16 Jun 19, 2023
2e40790
Merge branch 'develop' of https://github.com/danmm16/sundials-f2003-e…
danmm16 Jun 19, 2023
55e191b
Fixed merge
drreynolds Jun 19, 2023
3ca49d3
Added commented-up version of ark_heat2D_f2003.f90 for Daniel to work…
drreynolds Jun 19, 2023
58efec8
Finished kinsol example (with bugs).
danmm16 Jun 19, 2023
b342410
Updated examples/arkode/F2003_parallel/CMakeLists to remove extraneou…
drreynolds Jun 20, 2023
19cf529
Finished ark_heat2D_f2003 MPI example. Still needs testing.
danmm16 Jun 20, 2023
57069ce
Possibly fixed merge conflicts.
danmm16 Jun 20, 2023
276f543
Reverted my last commit
drreynolds Jun 20, 2023
fdb5024
Merged with upstream changes
drreynolds Jun 20, 2023
a6b5ab5
Checking to resolve compatibility.
danmm16 Jun 20, 2023
39289c1
The MPI code ark_heat2D_f2003 compiles (finally), with a segmentation…
danmm16 Jun 20, 2023
2bea696
Added testing routine for new F2003 LAPACK-Dense SUNLinearSolver inte…
drreynolds Jun 21, 2023
6424459
Committed dnsL code and arkode MPI heat2D for meeting with Dr. Reynolds.
danmm16 Jun 22, 2023
bc37c8f
Merge ../lapack-sunlinsol-f2003 into develop
drreynolds Jun 22, 2023
7717dbf
Completed ark_roberts_dnsL_f2003.f90 example
drreynolds Jun 22, 2023
b536a99
Minor updates to cv_roberts_klu_f2003.f90
drreynolds Jun 22, 2023
a4f2870
Updates from meeting (still stuck)
drreynolds Jun 22, 2023
b84763e
Made some changes to ark_heat2D_f2003 in F2003_parallel (still doesn'…
danmm16 Jun 22, 2023
89fc730
Worked on two CVODE serial codes. One works. Also, copied the templat…
danmm16 Jun 26, 2023
b302a75
Added exemplar function with comments and new preconditioner solution…
drreynolds Jun 26, 2023
990ff31
Finished cv_diurnal_kry_f2003.f90 successfully.
danmm16 Jun 27, 2023
71c796e
Cleaned up the file a bit.
danmm16 Jun 27, 2023
065551b
Minor typo fix
drreynolds Jun 28, 2023
902f884
Created F2003 version of ark_heat2D example problem
drreynolds Jun 28, 2023
c7e70de
Merged with upstream changes
drreynolds Jun 28, 2023
592a8af
Unfinished advdiff code.
danmm16 Jun 28, 2023
d959873
Merge branch 'develop' of https://github.com/danmm16/sundials-f2003-e…
danmm16 Jun 28, 2023
15a7bb3
Updated cv_advdiff_f2003, but it still doesn't work.
danmm16 Jun 28, 2023
c3343fb
Finished ark_diag_non_f2003.f90 and started ark_diag_kry_bbd_f2003.f9…
danmm16 Jun 29, 2023
f1b7042
Fixed compilation issue
drreynolds Jun 29, 2023
e1e1454
Fixed cv_advdiff_bnd_f2003 example to handle differences in how bande…
drreynolds Jun 29, 2023
8449fd6
debugged ark_diag_non_f2003.f90
drreynolds Jun 29, 2023
37ad288
Finished two CVODE parallel F2003 examples and updated CMake files so…
danmm16 Jun 30, 2023
0b920c7
Tried to finish the OpenMP example unsuccessfully. All CVODE MPI exam…
danmm16 Jul 2, 2023
fe8b86f
Removed irrelevant OpenMP and Pthreads IDA examples
drreynolds Jul 3, 2023
3e38ae2
Initial draft of F2003 OpenMP example for IDA
drreynolds Jul 3, 2023
5162587
Tried to fix KINSOL serial F2003 example, edited documentation for ex…
danmm16 Jul 6, 2023
cf86eee
Tried to fix kinDiagon_kry_f2003.f90.
danmm16 Jul 6, 2023
0cc117f
Fixed so that it only uses right preconditioning
drreynolds Jul 6, 2023
ad18f7f
updates from our discussion
drreynolds Jul 6, 2023
b5efb6b
Additional updates from our discussion
drreynolds Jul 6, 2023
85016f8
Finished ida_heat2D_kry_bbd_f2003.f90 with occasional segmentation fa…
danmm16 Jul 8, 2023
d13a95c
Propagated example guide changes into its own branch
drreynolds Jul 10, 2023
afc7fb2
Finished CVODE sans deep dive files.
danmm16 Jul 24, 2023
ed093d1
Deleted the file danmm.lnk. Not sure how it got there.
danmm16 Jul 26, 2023
df8c04c
Signed-off-by: Daniel Margolis <[email protected]>
danmm16 Jul 27, 2023
f518337
Fixed merge conflicts.
danmm16 Jul 27, 2023
8d8a556
Mostly finished with CVODE documentation (Deep Dives). Two files left.
danmm16 Jul 29, 2023
adc1fed
Finished most of the CVODE documentation, including Deep dives.
danmm16 Jul 29, 2023
8a11db5
Finished updating CVODE documentation completely.
danmm16 Jul 31, 2023
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
18 changes: 9 additions & 9 deletions doc/arkode/examples/source/c_serial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The example routine solves this problem using a diagonally-implicit
Runge-Kutta method. Each stage is solved using the built-in modified
Newton iteration, but since the ODE is linear in :math:`y` these
should only require a single iteration per stage. Internally, Newton
will use the SUNLINSOL_DENSE linear solver via the ARKDLS interface,
will use the SUNLINSOL_DENSE linear solver via the ARKStep interface,
which in the case of this scalar-valued problem is just division. The
example file contains functions to evaluate both :math:`f(t,y)` and
:math:`J(t,y)=\lambda`.
Expand Down Expand Up @@ -181,8 +181,8 @@ Numerical method

This program solves the problem with the DIRK method, using a
Newton iteration with the SUNLINSOL_DENSE linear solver module via
the ARKDLS interface. Additionally, this example provides a routine
to ARKDLS to compute the dense Jacobian.
the ARKStep interface. Additionally, this example provides a routine
to ARKStep to compute the dense Jacobian.

The problem is run using scalar relative and absolute tolerances of
:math:`rtol=10^{-6}` and :math:`atol=10^{-10}`, respectively.
Expand Down Expand Up @@ -326,7 +326,7 @@ The problem implements the following testing scenario: :math:`u_0=1.2`,
Numerical method
----------------

This program solves the problem with the default thrid order method.
This program solves the problem with the default third order method.

The problem is run using a fixed slow step size :math:`hs=0.025` and fast step
size :math:`0.001`.
Expand Down Expand Up @@ -361,8 +361,8 @@ Numerical method

This program is constructed to solve the problem with the DIRK solver.
Implicit subsystems are solved using a Newton iteration with the
SUNLINSOL_DENSE dense linear solver module via the ARKDLS interface; a
routine is provided to ARKDLS to supply the Jacobian matrix.
SUNLINSOL_DENSE dense linear solver module via the ARKStep interface; a
routine is provided to ARKStep to supply the Jacobian matrix.

The problem is run using scalar relative and absolute tolerances of
:math:`rtol=10^{-4}` and :math:`atol=10^{-11}`, respectively.
Expand Down Expand Up @@ -436,7 +436,7 @@ Numerical method

This program solves the problem with the DIRK solver. Implicit
subsystems are solved using a Newton iteration with the
SUNLINSOL_DENSE linear solver module via the ARKDLS interface; a
SUNLINSOL_DENSE linear solver module via the ARKStep interface; a
routine is supplied to provide the dense Jacobian matrix.

The problem is run using scalar relative and vector absolute
Expand Down Expand Up @@ -536,7 +536,7 @@ relative and absolute solver tolerances of :math:`rtol=10^{-6}` and
:math:`atol=10^{-10}`, respectively.

This program solves the problem with a DIRK method, using a Newton
iteration with the SUNLINSOL_BAND linear solver module via the ARKDLS
iteration with the SUNLINSOL_BAND linear solver module via the ARKStep
interface; a routine is supplied to fill the banded Jacobian matrix.

100 outputs are printed at equal intervals, and run statistics
Expand Down Expand Up @@ -572,7 +572,7 @@ This problem is mathematically identical to the preceding problem,
banded matrix module and SUNLINSOL_BAND linear solver module, it uses
the SUNMATRIX_SPARSE sparse matrix module with the SUNLINSOL_KLU
linear solver module. These are still provided to ARKode using the
ARKDLS direct linear solver interface, and again a routine is provided
ARKStep direct linear solver interface, and again a routine is provided
to supply a compressed-sparse-column version of the Jacobian matrix.
Additionally, the solution is only output 10 times instead of 100.

Expand Down
252 changes: 252 additions & 0 deletions doc/arkode/examples/source/f2003_serial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
..
Programmer(s): Daniel R. Reynolds @ SMU
modified by Daniel M. Margolis @ SMU
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2023, 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
----------------------------------------------------------------

:tocdepth: 3


.. _serial_f2003:

====================================
Serial Fortran 2003 example problems
====================================



.. _fark_diurnal_kry_bp:

fark_diurnal_kry_bp
===================================================

This problem is an ARKode clone of the CVODE problem,
``fcv_diurnal_kry_bp``. As described in [HSR2017]_, this problem
models a two-species diurnal kinetics advection-diffusion PDE system
in two spatial dimensions,

.. math::

\frac{\partial c_i}{\partial t} =
K_h \frac{\partial^2 c_i}{\partial x^2} +
V \frac{\partial c_i}{\partial x} +
\frac{\partial}{\partial y}\left( K_v(y)
\frac{\partial c_i}{\partial y}\right) +
R_i(c_1,c_2,t),\quad i=1,2

where

.. math::

R_1(c_1,c_2,t) &= -q_1*c_1*c_3 - q_2*c_1*c_2 + 2*q_3(t)*c_3 + q_4(t)*c_2, \\
R_2(c_1,c_2,t) &= q_1*c_1*c_3 - q_2*c_1*c_2 - q_4(t)*c_2, \\
K_v(y) &= K_{v0} e^{y/5}.

Here :math:`K_h`, :math:`V`, :math:`K_{v0}`, :math:`q_1`, :math:`q_2`,
and :math:`c_3` are constants, and :math:`q_3(t)` and :math:`q_4(t)`
vary diurnally. The problem is posed on the square spatial domain
:math:`(x,y) \in [0,20]\times[30,50]`, with homogeneous Neumann
boundary conditions, and for time interval :math:`t\in [0,86400]` sec
(1 day).

We enforce the initial conditions

.. math::

c^1(x,y) &= 10^6 \chi(x)\eta(y) \\
c^2(x,y) &= 10^{12} \chi(x)\eta(y) \\
\chi(x) &= 1 - \sqrt{\frac{x - 10}{10}} + \frac12 \sqrt[4]{\frac{x - 10}{10}} \\
\eta(y) &= 1 - \sqrt{\frac{y - 40}{10}} + \frac12 \sqrt[4]{\frac{x - 10}{10}}.




Numerical method
----------------

We employ a method of lines approach, wherein we first semi-discretize
in space to convert the system of 2 PDEs into a larger system of ODEs.
To this end, the spatial derivatives are computed using second-order
centered differences, with the data distributed over :math:`Mx*My`
points on a uniform spatial grid. As a result, ARKode approaches the
problem as one involving :math:`2*Mx*My` coupled ODEs. In this
problem, we use a relatively coarse uniform mesh with
:math:`Mx=My=10`.

This program solves the problem with a DIRK method, using a Newton
iteration with the preconditioned SUNLINSOL_SPGMR iterative linear
solver module, and the ARKSPILS interface.

The left preconditioner used is a banded matrix, constructed using
the ARKBP module. The banded preconditioner matrix is generated using
difference quotients, with half-bandwidths ``mu = ml = 2``.

Performance data and sampled solution values are printed at
selected output times, and all performance counters are printed
on completion.






.. _fark_roberts_dnsL:

fark_roberts_dnsL
===================================================

This problem is an ARKode clone of the CVODE problem,
``fcv_roberts_dnsL``. As described in [HSR2017]_, this problem models
the kinetics of a three-species autocatalytic reaction. This is an
ODE system with 3 components, :math:`Y = [y_1,\, y_2,\, y_3]^T`,
satisfying the equations,

.. math::

\frac{d y_1}{dt} &= -0.04 y_1 + 10^4 y_2 y_3, \\
\frac{d y_2}{dt} &= 0.04 y_1 - 10^4 y_2 y_3 - 3\cdot10^7 y_2^2, \\
\frac{d y_3}{dt} &= 3\cdot10^7 y_2^2.

We integrate over the interval :math:`0\le t\le 4\cdot10^{10}`, with initial
conditions :math:`Y(0) = [1,\, 0,\, 0]^T`.

Additionally, we supply the following two root-finding equations:

.. math::

g_1(u) = u - 10^{-4}, \\
g_2(w) = w - 10^{-2}.

While these are not inherently difficult nonlinear equations, they
easily serve the purpose of determining the times at which our
solutions attain desired target values.


Numerical method
----------------

This program solves the problem with a DIRK method, using a Newton
iteration with the SUNLINSOL_LAPACKDENSE linear solver module and
ARKDLS interface.

As with the :ref:`ark_robertson_root` problem, we enable ARKode's
rootfinding module to find the times at which either :math:`u=10^{-4}`
or :math:`w=10^{-2}`.

Performance data and solution values are printed at
selected output times, along with additional output at rootfinding
events. All performance counters are printed on completion.






.. _ark_bruss:

ark_bruss
===================================================

<<<<<<< HEAD
This test problem is a Fortran 2003 version of the same brusselator
=======
This test problem is a Fortran-90 version of the same brusselator
>>>>>>> origin/develop
problem as before, :ref:`ark_brusselator`, in which the "test 1"
parameters are hard-coded into the solver. As with the previous test,
this problem has 3 dependent variables :math:`u`, :math:`v` and
:math:`w`, that depend on the independent variable :math:`t` via the
IVP system

.. math::

\frac{du}{dt} &= a - (w+1)u + v u^2, \\
\frac{dv}{dt} &= w u - v u^2, \\
\frac{dw}{dt} &= \frac{b-w}{\varepsilon} - w u.

We integrate over the interval :math:`0 \le t \le 10`, with the
initial conditions :math:`u(0) = 3.9`, :math:`v(0) = 1.1`,
:math:`w(0) = 2.8`, and parameters :math:`a=1.2`, :math:`b=2.5` and
:math:`\varepsilon=10^{-5}`. After each unit time interval, the
solution is output to the screen.


Numerical method
----------------

<<<<<<< HEAD
Since this driver and utility functions are written in Fortran 2003,
=======
Since this driver and utility functions are written in Fortran-90,
>>>>>>> origin/develop
this example demonstrates the use of the FARKODE interface for the
ARKode solver. For time integration, this example uses the
fourth-order additive Runge-Kutta IMEX method, where the right-hand
sides are broken up as

.. math::

f_E(t,u,v,w) = \left(\begin{array}{c} a - (w+1)u + v u^2 \\
w u - v u^2 \\ - w u \end{array}\right), \quad\text{and}\quad
f_I(t,u,v,w) = \left(\begin{array}{c} 0\\0\\
\frac{b-w}{\varepsilon}\end{array}\right).

The implicit systems are solved using the built-in modified Newton
iteration, with the SUNMATRIX_DENSE matrix module and accompanying
SUNLINSOL_DENSE linear solver module, through the ARKDLS interface.
Both the Jacobian routine and right-hand side functions are supplied
by functions provided in the example file.

The only non-default solver options are the tolerances
:math:`atol=10^{-10}` and :math:`rtol=10^{-6}`, adaptivity method 2 (I
controller), a maximum of 8 Newton iterations per step, a nonlinear
solver convergence coefficient :math:`nlscoef=10^{-8}`, and a maximum
of 1000 internal time steps.





Solutions
---------

With this setup, all three solution components exhibit a rapid
transient change during the first 0.2 time units, followed by a slow
and smooth evolution, as seen in the figure below. Note that these
results identically match those from the previous C example with the
same equations.

.. figure:: figs/plot-ark_bruss1.png
:scale: 70 %
:align: center





.. _ark_bruss1D_FEM_klu:

ark_bruss1D_FEM_klu
===================================================

This problem is mathematically identical to the C example problem
<<<<<<< HEAD
:ref:`ark_brusselator1D_FEM_slu`, but is written in Fortran 2003, stores
=======
:ref:`ark_brusselator1D_FEM_slu`, but is written in Fortran 90, stores
>>>>>>> origin/develop
the sparse Jacobian and mass matrices in compressed-sparse-row format,
and uses the KLU sparse-direct linear solver.




Loading