Skip to content

Commit ca32f7d

Browse files
committed
SUNDomEigEst_Destroy
1 parent cb60123 commit ca32f7d

File tree

16 files changed

+104
-135
lines changed

16 files changed

+104
-135
lines changed

doc/arkode/guide/source/Usage/LSRKStep/User_callable.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Allowable Method Families
263263

264264
**Return value:**
265265
* *ARK_SUCCESS* if successful
266-
* *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``.
266+
* *ARK_MEM_NULL* if ``arkode_mem`` was ``NULL``.
267267

268268
.. note:: If LSRKStepSetMaxNumStages routine is not called, then the default ``stage_max_limit`` is
269269
set to :math:`200`. Calling this function with ``stage_max_limit < 2`` resets the default value.
@@ -284,7 +284,7 @@ Allowable Method Families
284284

285285
**Return value:**
286286
* *ARK_SUCCESS* if successful
287-
* *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``.
287+
* *ARK_MEM_NULL* if ``arkode_mem`` was ``NULL``.
288288

289289
.. note:: If LSRKStepSetDomEigSafetyFactor routine is not called, then the default ``dom_eig_safety`` is
290290
set to :math:`1.01`. Calling this function with ``dom_eig_safety < 1`` resets the default value.
@@ -304,7 +304,7 @@ Allowable Method Families
304304

305305
**Return value:**
306306
* *ARK_SUCCESS* if successful
307-
* *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``.
307+
* *ARK_MEM_NULL* if ``arkode_mem`` was ``NULL``.
308308
* *ARK_ILL_INPUT* if an argument had an illegal value (e.g. SSP method is not declared)
309309

310310
.. note:: If LSRKStepSetNumSSPStages routine is not called, then the default ``num_of_stages`` is

doc/arkode/guide/source/sundomeigest/ARKODE_interface.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ the interested reader.
6363
+----------------------------------------------------+---------------------+---------------------+
6464
| :c:func:`SUNDomEigEst_PrintStats` | O | O |
6565
+----------------------------------------------------+---------------------+---------------------+
66-
| :c:func:`SUNDomEigEstFree`\ :sup:`4` | | |
66+
| :c:func:`SUNDomEigEst_Destroy`\ :sup:`4` | | |
6767
+----------------------------------------------------+---------------------+---------------------+
6868

6969

@@ -83,6 +83,6 @@ Notes:
8383
implemented by the ``SUNDomEigEstimator`` then ARKDEE will consider all
8484
estimates as requiring zero iterations.
8585

86-
4. Although ARKDEE does not call :c:func:`SUNDomEigEstFree()`
86+
4. Although ARKDEE does not call :c:func:`SUNDomEigEst_Destroy()`
8787
directly, this routine should be available for users to call when
8888
cleaning up from a simulation.

doc/shared/sundomeigest/SUNDomEigEst_API.rst

Lines changed: 48 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,38 @@ SUNDomEigEstimator core functions
3232
-----------------------------------------------------
3333

3434
The core dominant eigenvalue estimator functions consist of several **required**
35-
functions: :c:func:`SUNDomEigEst_SetATimes` provides a :c:type:`SUNATimesFn` function pointer,
35+
functions: :c:func:`SUNDomEigEst_NewEmpty` creates a new empty ``SUNDomEigEstimator``
36+
object, :c:func:`SUNDomEigEst_SetATimes` provides a :c:type:`SUNATimesFn` function pointer,
3637
as well as a ``void*`` pointer to a data structure used by this routine,
3738
:c:func:`SUNDomEigEst_Initialize` initializes the estimator object once all estimator-specific
3839
options have been set, :c:func:`SUNDomEigEst_ComputeHess` computes Hessenberg matrix
39-
(if the estimator requires), :c:func:`SUNDomEig_Estimate` estimates the dominant eigenvalue, and
40-
:c:func:`SUNDomEigEstFree` destroys an estimator object.
40+
(if the estimator requires), :c:func:`SUNDomEig_Estimate` estimates the dominant eigenvalue,
41+
:c:func:`SUNDomEigEst_FreeEmpty` an empty estimator and :c:func:`SUNDomEigEst_Destroy` destroys
42+
an estimator object.
4143

4244
The remaining **optional** function, :c:func:`SUNDomEigEst_PreProcess` preprocesses the estimator object
4345
to "warm-up" the estimator for a more appropriate initial vector before starting iterations.
4446

47+
48+
.. c:function:: SUNDomEigEstimator SUNDomEigEst_NewEmpty(SUNContext sunctx)
49+
50+
*Required.*
51+
52+
This function allocates a new ``SUNDomEigEstimator`` object and
53+
initializes its content pointer and the function pointers in the operations
54+
structure to ``NULL``.
55+
56+
**Arguments:**
57+
58+
* *sunctx* -- the :c:type:`SUNContext` object (see :numref:`SUNDIALS.SUNContext`)
59+
60+
**Return value:**
61+
62+
If successful, this function returns a ``SUNDomEigEstimator`` object.
63+
If an error occurs when allocating the object, then this routine will
64+
return ``NULL``.
65+
66+
4567
.. c:function:: SUNErrCode SUNDomEigEst_SetATimes(SUNDomEigEstimator DEE, void* A_data, SUNATimesFn ATimes)
4668
4769
*Required.*
@@ -104,10 +126,8 @@ to "warm-up" the estimator for a more appropriate initial vector before starting
104126
105127
**Return value:**
106128
107-
Zero for a successful call, a positive value for a recoverable failure,
108-
and a negative value for an unrecoverable failure. Ideally this should
109-
return one of the generic error codes listed in
110-
:numref:`SUNDomEigEst.ErrorCodes`.
129+
`SUN_SUCCESS` for a successful call, or a relevant error code from
130+
:numref:`SUNDomEigEst.ErrorCodes` upon failure.
111131
112132
**Usage:**
113133
@@ -147,20 +167,36 @@ to "warm-up" the estimator for a more appropriate initial vector before starting
147167
retval = SUNDomEig_Estimate(DEE, dom_eig);
148168
149169
170+
.. c:function:: SUNErrCode SUNDomEigEst_FreeEmpty(SUNDomEigEstimator DEE)
150171
151-
.. c:function:: SUNErrCode SUNDomEigEstFree(SUNDomEigEstimator DEE)
172+
This routine frees the ``SUNDomEigEstimator`` object, under the
173+
assumption that any implementation-specific data that was allocated
174+
within the underlying content structure has already been freed.
175+
It will additionally test whether the ops pointer is ``NULL``,
176+
and, if it is not, it will free it as well.
177+
178+
**Arguments:**
179+
180+
* *DEE* -- a SUNDomEigEstimator object
181+
182+
**Return value:**
183+
184+
A :c:type:`SUNErrCode`.
185+
186+
187+
.. c:function:: SUNErrCode SUNDomEigEst_Destroy(SUNDomEigEstimator* DEEptr)
152188
153189
Frees memory allocated by the dominant eigenvalue estimatimator.
154190
155191
**Arguments:**
156192
157-
* *DEE* -- a SUNDomEigEst object.
193+
* *DEEptr* -- a SUNDomEigEst object pointer.
158194
159195
**Usage:**
160196
161197
.. code-block:: c
162198
163-
retval = SUNDomEigEstFree(DEE);
199+
retval = SUNDomEigEst_Destroy(&DEE);
164200
165201
166202
.. _SUNDomEigEst.SetFn:
@@ -199,7 +235,7 @@ function pointer ``NULL`` instead of supplying a dummy routine.
199235
200236
.. c:function:: SUNErrCode SUNDomEigEst_SetTol(SUNDomEigEstimator DEE, sunrealtype tol)
201237
202-
This *optional* routine sets the estimator tolerance.
238+
This *optional* routine sets the estimator's :ref:`relative tolerance <pi_rel_tol>`.
203239
204240
**Arguments:**
205241
@@ -545,7 +581,7 @@ The virtual table structure is defined as
545581
546582
.. c:member:: SUNErrCode (*free)(SUNDomEigEstimator)
547583
548-
The function implementing :c:func:`SUNDomEigEstFree`
584+
The function implementing :c:func:`SUNDomEigEst_Destroy`
549585
550586
The generic SUNDomEigEst class defines and implements the dominant eigenvalue estimator
551587
operations defined in :numref:`SUNDomEigEst.CoreFn` -- :numref:`SUNDomEigEst.GetFn`.
@@ -566,75 +602,6 @@ operation:
566602
}
567603
568604
569-
.. _SUNDomEigEst.API.Custom:
570-
571-
Implementing a custom SUNDomEigEstimator module
572-
--------------------------------------------------
573-
574-
A particular implementation of the ``SUNDomEigEstimator`` module must:
575-
576-
* Specify the *content* field of the SUNDomEigEst module.
577-
578-
* Define and implement the required dominant eigenvalue estimator operations.
579-
580-
.. note::
581-
582-
The names of these routines should be unique to that
583-
implementation in order to permit using more than one
584-
SUNDomEigEst module (each with different ``SUNDomEigEstimator``
585-
internal data representations) in the same code.
586-
587-
* Define and implement user-callable constructor and destructor
588-
routines to create and free a ``SUNDomEigEstimator`` with
589-
the new *content* field and with *ops* pointing to the
590-
new dominant eigenvalue estimator operations.
591-
592-
We note that the function pointers for all unsupported optional
593-
routines should be set to ``NULL`` in the *ops* structure. This
594-
allows the SUNDIALS package that is using the SUNDomEigEst object
595-
to know whether the associated functionality is supported.
596-
597-
To aid in the creation of custom ``SUNDomEigEstimator`` modules the generic
598-
``SUNDomEigEstimator`` module provides the utility function
599-
:c:func:`SUNDomEigEst_NewEmpty`. When used in custom ``SUNDomEigEstimator``
600-
constructors this function will ease the introduction of any new optional dominant
601-
eigenvalue estimator operations to the ``SUNDomEigEstimator`` API by ensuring that only required
602-
operations need to be set.
603-
604-
.. c:function:: SUNDomEigEstimator SUNDomEigEst_NewEmpty(SUNContext sunctx)
605-
606-
This function allocates a new generic ``SUNDomEigEstimator`` object and
607-
initializes its content pointer and the function pointers in the operations
608-
structure to ``NULL``.
609-
610-
**Arguments:**
611-
612-
* *sunctx* -- the :c:type:`SUNContext` object (see :numref:`SUNDIALS.SUNContext`)
613-
614-
**Return value:**
615-
616-
If successful, this function returns a ``SUNDomEigEstimator`` object.
617-
If an error occurs when allocating the object, then this routine will
618-
return ``NULL``.
619-
620-
621-
.. c:function:: SUNErrCode SUNDomEigEst_FreeEmpty(SUNDomEigEstimator DEE)
622-
623-
This routine frees the generic ``SUNDomEigEstimator`` object, under the
624-
assumption that any implementation-specific data that was allocated
625-
within the underlying content structure has already been freed.
626-
It will additionally test whether the ops pointer is ``NULL``,
627-
and, if it is not, it will free it as well.
628-
629-
**Arguments:**
630-
631-
* *DEE* -- a SUNDomEigEstimator object
632-
633-
**Return value:**
634-
635-
A :c:type:`SUNErrCode`.
636-
637-
638605
Additionally, a ``SUNDomEigEstimator`` implementation *may* do the following:
639606
640607
* Define and implement additional user-callable "set" routines

doc/shared/sundomeigest/SUNDomEigEst_ARNI.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ This estimator is constructed to perform the following operations:
148148
that interfaces with SUNDomEigEst_ARNI to supply the ``ATimes``
149149
function pointer and the related data ``ATData``.
150150
* In the "initialize" call, the estimator parameters are checked
151-
for validity and ARNI estimator memory is allocated.
151+
for validity and the remaining ARNI estimator memory such as LAPACK
152+
workspace is allocated.
152153

153154
* In the "preprocess" call, the initial nonzero vector :math:`q_0` is warmed up
154155
:math:`k=` ``numwarmups`` times as
@@ -175,4 +176,4 @@ dominant eigenvalue estimator operations listed in
175176

176177
* ``SUNDomEig_Estimate_ArnI``
177178

178-
* ``SUNDomEigEstFree_ArnI``
179+
* ``SUNDomEigEst_Destroy_ArnI``

doc/shared/sundomeigest/SUNDomEigEst_Introduction.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ provide their own ``N_Vector`` and/or ``SUNMatrix`` modules.
3939
While Krylov-based estimators preset the number of Krylov subspace
4040
dimensions, resulting in a tolerance-free estimation, SUNDIALS requires
4141
that iterative estimators stop when the residual meets a prescribed
42-
tolerance, i.e.,
42+
tolerance, :math:`\tau`,
4343

4444
.. math::
45-
46-
||\lambda_{k+1} - \lambda_k|| < \text{tol}.
45+
:name: pi_rel_tol
46+
47+
\frac{\left|\lambda_k - \lambda_{k-1}\right|}{\left|\lambda_k \right|} < \tau.
4748
4849
For users interested in providing their own SUNDomEigEst module, the
4950
following section presents the SUNDomEigEst API and its implementation
@@ -53,11 +54,7 @@ the definition of functions supplied to an estimator implementation in
5354
:numref:`SUNDomEigEst.SUNSuppliedFn`. The estimator return codes are described
5455
in :numref:`SUNDomEigEst.ErrorCodes`. The ``SUNDomEigEstimator`` type and the
5556
generic SUNDomEigEst module are defined in :numref:`SUNDomEigEst.Generic`.
56-
:numref:`SUNDomEigEst.API.Custom` lists the requirements for supplying a custom
57-
SUNDomEigEst module and discusses some intended use cases. Users wishing to
58-
supply their own SUNDomEigEst module are encouraged to use the SUNDomEigEst
59-
implementations provided with SUNDIALS as a template for supplying custom
60-
dominant eigenvalue estimator modules. The section that then follows describes
57+
The section that then follows describes
6158
the SUNDomEigEst functions required by this SUNDIALS package, and provides
6259
additional package specific details. Then the remaining sections of this
6360
chapter present the SUNDomEigEst modules provided with SUNDIALS.

doc/shared/sundomeigest/SUNDomEigEst_PI.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ can be approximated using the Rayleigh quotient
4141
\lambda_k = \frac{\mathbf{v}_k^T A \mathbf{v}_k}{\|\mathbf{v}_k\|^2}.
4242
4343
The iteration continues until the two successive eigenvalue approximations are
44-
relatively close enough to one another. That is, for some relative tolerance
45-
:math:`\tau`,
46-
enough to one another. That is, for some relative tolerance :math:`\tau`,
47-
48-
.. math::
49-
50-
\frac{\left|\lambda_k - \lambda_{k-1}\right|}{\left|\lambda_k \right|} < \tau.
44+
relatively close enough to one another. That is, for some :ref:`relative tolerance <pi_rel_tol>`.
5145

5246
PI works for the matrices that have a **real** dominant eigenvalue. If it is strictly
5347
greater than all others (in magnitude), convergence is guaranteed. The speed of convergence
@@ -167,7 +161,7 @@ This estimator is constructed to perform the following operations:
167161
function pointer and the related data ``ATData``.
168162

169163
* In the "initialize" call, the estimator parameters are checked
170-
for validity and PI estimator memory is allocated.
164+
for validity and the initial eigenvector is normalized.
171165

172166
* In the "preprocess" call, the initial vector :math:`q_0` is warmed up
173167
:math:`k=` ``numwarmups`` times as
@@ -208,4 +202,4 @@ eigenvalue estimator operations listed in
208202

209203
* ``SUNDomEigEst_PrintStats_PI``
210204

211-
* ``SUNDomEigEstFree_PI``
205+
* ``SUNDomEigEst_Destroy_PI``

examples/arkode/CXX_serial/ark_heat2D_lsrk_internal_domeig.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,12 @@ int main(int argc, char* argv[])
451451
// Clean up and return
452452
// --------------------
453453

454-
ARKodeFree(&arkode_mem); // Free integrator memory
455-
N_VDestroy(u); // Free vectors
456-
SUNDomEigEstFree(DEE); /* Free DEE object */
457-
FreeUserData(udata); // Free user data
454+
ARKodeFree(&arkode_mem); // Free integrator memory
455+
N_VDestroy(u); // Free vectors
456+
SUNDomEigEst_Destroy(&DEE); /* Free DEE object */
457+
FreeUserData(udata); // Free user data
458458
delete udata;
459-
SUNContext_Free(&ctx); // Free context
459+
SUNContext_Free(&ctx); // Free context
460460

461461
return 0;
462462
}

examples/arkode/C_serial/ark_analytic_lsrk_internal_domeig.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ int main(void)
277277
flag = compute_error(y, t);
278278

279279
/* Clean up and return */
280-
N_VDestroy(y); /* Free y vector */
281-
ARKodeFree(&arkode_mem); /* Free integrator memory */
282-
SUNDomEigEstFree(DEE); /* Free DEE object */
283-
SUNContext_Free(&ctx); /* Free context */
280+
N_VDestroy(y); /* Free y vector */
281+
ARKodeFree(&arkode_mem); /* Free integrator memory */
282+
SUNDomEigEst_Destroy(&DEE); /* Free DEE object */
283+
SUNContext_Free(&ctx); /* Free context */
284284

285285
return flag;
286286
}

include/sundials/sundials_domeigestimator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef _SUNDOMEIGEST_H
1818
#define _SUNDOMEIGEST_H
1919

20-
/* TODO: Check to see if they are all required */
2120
#include <sundials/priv/sundials_errors_impl.h>
2221
#include <sundials/sundials_config.h>
2322
#include <sundials/sundials_context.h>
@@ -70,7 +69,7 @@ struct _generic_SUNDomEigEstimator_Ops
7069
SUNErrCode (*getminniters)(SUNDomEigEstimator, int*);
7170
SUNErrCode (*getnumatimescalls)(SUNDomEigEstimator, long int*);
7271
SUNErrCode (*printstats)(SUNDomEigEstimator, FILE*);
73-
SUNErrCode (*free)(SUNDomEigEstimator);
72+
SUNErrCode (*free)(SUNDomEigEstimator*);
7473
};
7574

7675
/* An estimator is a structure with an implementation-dependent
@@ -140,7 +139,7 @@ SUNDIALS_EXPORT
140139
SUNErrCode SUNDomEigEst_PrintStats(SUNDomEigEstimator DEE, FILE* outfile);
141140

142141
SUNDIALS_EXPORT
143-
SUNErrCode SUNDomEigEstFree(SUNDomEigEstimator DEE);
142+
SUNErrCode SUNDomEigEst_Destroy(SUNDomEigEstimator* DEEptr);
144143

145144
#ifdef __cplusplus
146145
}

include/sundomeigest/sundomeigest_arni.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ SUNDIALS_EXPORT
9292
SUNErrCode SUNDomEigEst_PrintStats_ArnI(SUNDomEigEstimator DEE, FILE* outfile);
9393

9494
SUNDIALS_EXPORT
95-
SUNErrCode SUNDomEigEstFree_ArnI(SUNDomEigEstimator DEE);
95+
SUNErrCode SUNDomEigEst_Destroy_ArnI(SUNDomEigEstimator* DEEptr);
9696

9797
#ifdef __cplusplus
9898
}

0 commit comments

Comments
 (0)