diff --git a/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst b/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst index 08f30b9ff9..e8feb1b4ee 100644 --- a/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst @@ -1255,6 +1255,8 @@ Set additive RK tables via their names :c:func:`ARKStepSetTableName()` int pointers *fe* or *fi* passed to :c:func:`ARKStepCreate` are ``NULL``, but may be set directly by the user if desired. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.set_imex". .. c:function:: int ARKStepSetExplicit(void* arkode_mem) @@ -1279,6 +1281,8 @@ Set additive RK tables via their names :c:func:`ARKStepSetTableName()` int f(t,y)`, then we recommend that the ERKStep time-stepper module be used instead. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.set_explicit". .. c:function:: int ARKStepSetImplicit(void* arkode_mem) @@ -1298,6 +1302,9 @@ Set additive RK tables via their names :c:func:`ARKStepSetTableName()` int passed to :c:func:`ARKStepCreate` is ``NULL``, but may be set directly by the user if desired. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.set_implicit". + .. c:function:: int ARKStepSetTables(void* arkode_mem, int q, int p, ARKodeButcherTable Bi, ARKodeButcherTable Be) @@ -1437,6 +1444,10 @@ Set additive RK tables via their names :c:func:`ARKStepSetTableName()` int In all cases, error-checking is performed to ensure that the tables exist. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.table_names". + + **Warning:** This should not be used with :c:func:`ARKodeSetOrder`. diff --git a/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst b/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst index d5f7659863..bfcc710aec 100644 --- a/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst @@ -934,7 +934,10 @@ Optional inputs for IVP method selection **Warning:** This should not be used with :c:func:`ARKodeSetOrder`. + .. note:: + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.table_name". .. _ARKODE.Usage.ERKStep.ERKStepAdaptivityInput: diff --git a/doc/arkode/guide/source/Usage/LSRKStep/User_callable.rst b/doc/arkode/guide/source/Usage/LSRKStep/User_callable.rst index ac150cd8d5..5a143a5d5a 100644 --- a/doc/arkode/guide/source/Usage/LSRKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/LSRKStep/User_callable.rst @@ -156,6 +156,10 @@ Allowable Method Families * *ARK_SUCCESS* if successful * *ARK_ILL_INPUT* if an argument had an illegal value (e.g. typo in the method name). + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.sts_method". .. c:function:: int LSRKStepSetSSPMethodByName(void* arkode_mem, const char* emethod); @@ -171,6 +175,10 @@ Allowable Method Families * *ARK_SUCCESS* if successful * *ARK_ILL_INPUT* if an argument had an illegal value (e.g. typo in the method name). + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.ssp_method". .. c:function:: int LSRKStepSetDomEigFn(void* arkode_mem, ARKDomEigFn dom_eig); @@ -187,7 +195,9 @@ Allowable Method Families * *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``. * *ARK_ILL_INPUT* ``dom_eig = NULL`` and LSRKStep does not currently estimate this internally. - .. note:: This function is currently required when either the RKC or RKL methods are used. + .. note:: + + This function is currently required when either the RKC or RKL methods are used. .. c:function:: int LSRKStepSetDomEigFrequency(void* arkode_mem, long int nsteps); @@ -203,9 +213,16 @@ Allowable Method Families * *ARK_SUCCESS* if successful * *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``. -.. note:: If LSRKStepSetDomEigFrequency routine is not called, then the default ``nsteps`` is set to :math:`25` as recommended in :cite:p:`VSH:04`. - Calling this function with ``nsteps < 0`` resets the default value while ``nsteps = 0`` refers to constant dominant eigenvalue. + .. note:: + + If LSRKStepSetDomEigFrequency routine is not called, then the default ``nsteps`` + is set to :math:`25` as recommended in :cite:p:`VSH:04`. + + Calling this function with ``nsteps < 0`` resets the default value while + ``nsteps = 0`` refers to constant dominant eigenvalue. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.dom_eig_frequency". .. c:function:: int LSRKStepSetMaxNumStages(void* arkode_mem, int stage_max_limit); @@ -220,10 +237,18 @@ Allowable Method Families * *ARK_SUCCESS* if successful * *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``. -.. note:: If LSRKStepSetMaxNumStages routine is not called, then the default ``stage_max_limit`` is - set to :math:`200`. Calling this function with ``stage_max_limit < 2`` resets the default value. - This limit should be chosen with consideration of the following proportionality: :math:`s^2 \sim - h\lambda`, - where :math:`s` is the number of stages used, :math:`h` is the current step size and :math:`\lambda` is the dominant eigenvalue. + .. note:: + + If LSRKStepSetMaxNumStages routine is not called, then the default ``stage_max_limit`` + is set to :math:`200`. Calling this function with ``stage_max_limit < 2`` resets the + default value. + + This limit should be chosen with consideration of the following proportionality: + :math:`s^2 \sim - h\lambda`, where :math:`s` is the number of stages used, :math:`h` + is the current step size and :math:`\lambda` is the dominant eigenvalue. + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_num_stages". .. c:function:: int LSRKStepSetDomEigSafetyFactor(void* arkode_mem, sunrealtype dom_eig_safety); @@ -241,8 +266,14 @@ Allowable Method Families * *ARK_SUCCESS* if successful * *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``. -.. note:: If LSRKStepSetDomEigSafetyFactor routine is not called, then the default ``dom_eig_safety`` is - set to :math:`1.01`. Calling this function with ``dom_eig_safety < 1`` resets the default value. + .. note:: + + If LSRKStepSetDomEigSafetyFactor routine is not called, then the default + ``dom_eig_safety`` is set to :math:`1.01`. Calling this function with + ``dom_eig_safety < 1`` resets the default value. + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.dom_eig_safety_factor". .. c:function:: int LSRKStepSetNumSSPStages(void* arkode_mem, int num_of_stages); @@ -262,12 +293,17 @@ Allowable Method Families * *ARKLS_MEM_NULL* if ``arkode_mem`` was ``NULL``. * *ARK_ILL_INPUT* if an argument had an illegal value (e.g. SSP method is not declared) -.. note:: If LSRKStepSetNumSSPStages routine is not called, then the default ``num_of_stages`` is - set. Calling this function with ``num_of_stages <= 0`` resets the default values: + .. note:: + + If LSRKStepSetNumSSPStages routine is not called, then the default ``num_of_stages`` + is set. Calling this function with ``num_of_stages <= 0`` resets the default values: + + * ``num_of_stages = 10`` for :c:enumerator:`ARKODE_LSRK_SSP_S_2` + * ``num_of_stages = 9`` for :c:enumerator:`ARKODE_LSRK_SSP_S_3` + * ``num_of_stages = 10`` for :c:enumerator:`ARKODE_LSRK_SSP_10_4` - * ``num_of_stages = 10`` for :c:enumerator:`ARKODE_LSRK_SSP_S_2` - * ``num_of_stages = 9`` for :c:enumerator:`ARKODE_LSRK_SSP_S_3` - * ``num_of_stages = 10`` for :c:enumerator:`ARKODE_LSRK_SSP_10_4` + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.num_ssp_stages". .. _ARKODE.Usage.LSRKStep.OptionalOutputs: @@ -359,6 +395,7 @@ dependent variable vector. * *ARK_ILL_INPUT* if an argument had an illegal value. .. note:: + All previously set options are retained but may be updated by calling the appropriate "Set" functions. @@ -386,6 +423,7 @@ dependent variable vector. * *ARK_ILL_INPUT* if an argument had an illegal value. .. note:: + All previously set options are retained but may be updated by calling the appropriate "Set" functions. diff --git a/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst b/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst index 8514af3f71..2b12e86ace 100644 --- a/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst @@ -800,6 +800,11 @@ Optional inputs for IVP method selection For a description of the :c:type:`MRIStepCoupling` type and related functions for creating Butcher tables see :numref:`ARKODE.Usage.MRIStep.MRIStepCoupling`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.coupling_table", where *C* + is itself constructed by passing the command-line option to + :c:func:`MRIStepCoupling_LoadTableByName`. + .. warning:: This should not be used with :c:func:`ARKodeSetOrder`. diff --git a/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst b/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst index 13db1851e1..b239e5672e 100644 --- a/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst @@ -479,6 +479,11 @@ Optional inputs for IVP method selection :retval ARK_MEM_NULL: if the SPRKStep memory is ``NULL`` :retval ARK_ILL_INPUT: if an argument had an illegal value + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.method_name". + .. warning:: This should not be used with :c:func:`ARKodeSetOrder`. @@ -501,6 +506,11 @@ Optional inputs for IVP method selection :retval ARK_MEM_NULL: if the SPRKStep memory is ``NULL`` :retval ARK_ILL_INPUT: if an argument had an illegal value + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.use_compensated_sums". + .. _ARKODE.Usage.SPRKStep.SPRKStepRootfindingInput: diff --git a/doc/arkode/guide/source/Usage/User_callable.rst b/doc/arkode/guide/source/Usage/User_callable.rst index 27c41a5701..ad49d1c586 100644 --- a/doc/arkode/guide/source/Usage/User_callable.rst +++ b/doc/arkode/guide/source/Usage/User_callable.rst @@ -133,6 +133,11 @@ Alternatively, the user may supply a custom function to supply the :retval ARK_NO_MALLOC: ``arkode_mem`` was not allocated. :retval ARK_ILL_INPUT: an argument had an illegal value (e.g. a negative tolerance). + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.scalar_tolerances". + .. versionadded:: 6.1.0 @@ -882,6 +887,7 @@ Optional inputs for ARKODE ================================================ ======================================= ======================= Optional input Function name Default ================================================ ======================================= ======================= +Set ARKODE options from the command line :c:func:`ARKodeSetFromCommandLine` internal Return ARKODE parameters to their defaults :c:func:`ARKodeSetDefaults` internal Set integrator method order :c:func:`ARKodeSetOrder` 4 Set dense output interpolation type (SPRKStep) :c:func:`ARKodeSetInterpolantType` ``ARK_INTERP_LAGRANGE`` @@ -906,6 +912,39 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr +.. c:function:: int ARKodeSetFromCommandLine(void* arkode_mem, const char* arkid, int argc, char* argv[]) + + Passes command-line arguments to ARKODE to set options. + + :param arkode_mem: pointer to the ARKODE memory block. + :param arkid: String to use as prefix for ARKODE command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval ARK_SUCCESS: the function exited successfully. + :retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``. + :retval other: error return value from relevant ARKODE "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. These + are left unchanged by :c:func:`ARKodeSetFromCommandLine`. + + If the *arkid* argument is ``NULL`` then ``arkode.`` will be used for all ARKODE command-line + options, e.g., to set the integrator order of accuracy the default command-line option would be "arkode.order". + When using a combination of ARKODE integrators (e.g., via MRIStep, SplittingStep or + ForcingStep), it is recommended that users call :c:func:`ARKodeSetFromCommandLine` for each + ARKODE integrator using distinct *arkid* inputs, so that each ARKODE integrator can be controlled + separately. + + ARKODE options set via command-line arguments to :c:func:`ARKodeSetFromCommandLine` will overwrite + any previously-set values. + + The supported command-line options are documented within each ARKODE "set" routine. + + .. versionadded:: x.y.z + + .. c:function:: int ARKodeSetDefaults(void* arkode_mem) Resets all optional input parameters to ARKODE's original @@ -952,6 +991,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr ARKODE memory block, it cannot be changed after the first call to :c:func:`ARKodeEvolve`, unless ``*StepReInit`` is called. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.order". + .. versionadded:: 6.1.0 @@ -999,6 +1041,11 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr :retval ARK_ILL_INPUT: the *itype* argument is not recognized or the interpolation module has already been initialized. + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.interpolant_type". + .. versionchanged:: 6.1.0 This function replaces stepper specific versions in ARKStep, ERKStep, @@ -1046,6 +1093,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr obtained by the integrator are returned at the ends of the time interval. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.interpolant_degree". + .. versionadded:: 6.1.0 @@ -1102,6 +1152,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr routines will provide no useful information to the solver, and at worst they may interfere with the desired fixed step size. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.fixed_step". + .. versionadded:: 6.1.0 @@ -1114,7 +1167,7 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr selects forward integration, a negative value selects backward integration, and zero leaves the current direction unchanged. - + :retval ARK_SUCCESS: the function exited successfully. :retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``. @@ -1131,6 +1184,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr estimated at the next call to :c:func:`ARKodeEvolve` or can be specified with :c:func:`ARKodeSetInitStep`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.step_direction". + .. versionadded:: 6.2.0 @@ -1159,6 +1215,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr This routine will also reset the step size and error history. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.init_step". + .. versionadded:: 6.1.0 @@ -1187,6 +1246,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr A negative value indicates that no warning messages should be issued. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_hnil_warns". + .. versionadded:: 6.1.0 @@ -1211,6 +1273,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr Passing *mxsteps* < 0 disables the test (not recommended). + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_num_steps". + .. versionadded:: 6.1.0 @@ -1233,6 +1298,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr Pass *hmax* :math:`\le 0.0` to set the default value of :math:`\infty`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_step". + .. versionadded:: 6.1.0 @@ -1255,6 +1323,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr Pass *hmin* :math:`\le 0.0` to set the default value of 0. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.min_step". + .. versionadded:: 6.1.0 @@ -1282,6 +1353,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr :c:func:`ARKodeReset` will remain active but can be disabled by calling :c:func:`ARKodeClearStopTime`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.stop_time". + .. versionadded:: 6.1.0 @@ -1297,6 +1371,11 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr :retval ARK_SUCCESS: the function exited successfully. :retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``. + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.interpolate_stop_time". + .. versionadded:: 6.1.0 @@ -1314,6 +1393,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr The stop time can be re-enabled though a new call to :c:func:`ARKodeSetStopTime`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.clear_stop_time". + .. versionadded:: 6.1.0 @@ -1339,6 +1421,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr this function must be made *before* any calls to :c:func:`ARKodeSetLinearSolver` and/or :c:func:`ARKodeSetMassLinearSolver`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.linear". + .. versionadded:: 6.1.0 @@ -1363,6 +1448,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr The default value is 7; set *maxnef* :math:`\le 0` to specify this default. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_err_test_fails". + .. versionadded:: 6.1.0 @@ -1434,6 +1522,9 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr Passing *maxfails* <= 0 results in ARKODE using the default value (10). + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_num_constr_fails". + .. versionadded:: 6.1.0 @@ -1522,6 +1613,9 @@ Reset accumulated error :c:func:`ARKodeReset This should be called prior to calling :c:func:`ARKodeEvolve`, and can only be reset following a call to ``*StepReInit``. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.adaptivity_adjustment". + .. versionadded:: 6.1.0 @@ -1545,6 +1639,9 @@ Reset accumulated error :c:func:`ARKodeReset Any non-positive parameter will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.cfl_fraction". + .. versionadded:: 6.1.0 @@ -1573,6 +1670,9 @@ Reset accumulated error :c:func:`ARKodeReset :c:func:`ARKodeSetAdaptController` will be called, then this routine must be called *second*. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.error_bias". + .. versionadded:: 6.1.0 @@ -1596,6 +1696,9 @@ Reset accumulated error :c:func:`ARKodeReset Any interval *not* containing 1.0 will imply a reset to the default values. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.fixed_step_bounds". + .. versionadded:: 6.1.0 @@ -1621,6 +1724,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value outside the interval :math:`(0,1]` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_cfail_growth". + .. versionadded:: 6.1.0 @@ -1644,6 +1750,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value outside the interval :math:`(0,1]` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_efail_growth". + .. versionadded:: 6.1.0 @@ -1668,6 +1777,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value :math:`\le 1.0` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_first_growth". + .. versionadded:: 6.1.0 @@ -1692,6 +1804,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value :math:`\le 1.0` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_growth". + .. versionadded:: 6.1.0 @@ -1718,6 +1833,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value outside the interval :math:`(0,1)` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.min_reduction". + .. versionadded:: 6.1.0 @@ -1742,6 +1860,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value :math:`\le 0` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.safety_factor". + .. versionadded:: 6.1.0 @@ -1766,6 +1887,9 @@ Reset accumulated error :c:func:`ARKodeReset Any value :math:`\le 0` will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.small_num_efails". + .. versionadded:: 6.1.0 @@ -1850,6 +1974,10 @@ tolerance. A non-default error accumulation strategy can be disabled by calling :c:func:`ARKodeSetAccumulatedErrorType` with the argument ``ARK_ACCUMERROR_NONE``. + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.accum_error_type". :param arkode_mem: pointer to the ARKODE memory block. :param accum_type: accumulation strategy. @@ -1874,6 +2002,11 @@ tolerance. :retval ARK_STEPPER_UNSUPPORTED: temporal error estimation is not supported by the current time-stepping module. + .. note:: + + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.reset_accumulated_error". + .. versionadded:: 6.2.0 @@ -1967,6 +2100,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS :c:func:`ARKodeSetDeltaGammaMax` to reset the step size ratio threshold to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.nonlinear". + .. versionadded:: 6.1.0 @@ -2019,6 +2155,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS evaluation but instead evaluate the necessary quantities within the preconditioner setup function using the input values. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.autonomous". + .. versionadded:: 6.1.0 @@ -2054,6 +2193,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS The default value is 0. If *method* is set to an undefined value, this default predictor will be used. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.predictor_method". + .. versionadded:: 6.1.0 @@ -2132,6 +2274,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS The default value is 3; set *maxcor* :math:`\le 0` to specify this default. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_nonlin_iters". + .. versionadded:: 6.1.0 @@ -2156,6 +2301,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS The default value is 0.1; set *nlscoef* :math:`\le 0` to specify this default. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.nonlin_conv_coef". + .. versionadded:: 6.1.0 @@ -2178,6 +2326,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS Any non-positive parameter will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.nonlin_crdown". + .. versionadded:: 6.1.0 @@ -2202,6 +2353,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS Any non-positive parameter will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.nonlin_rdiv". + .. versionadded:: 6.1.0 @@ -2234,6 +2388,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS convergence failure still occurs, the time step size is reduced by the factor *etacf* (set within :c:func:`ARKodeSetMaxCFailGrowth`). + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.max_conv_fails". + .. versionadded:: 6.1.0 @@ -2257,6 +2414,9 @@ Specify if the implicit RHS is deduced after a nonlinear solve :c:func:`ARKodeS This is only compatible with time-stepping modules that support implicit algebraic solvers. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.deduce_implicit_rhs". + .. versionadded:: 6.1.0 @@ -2364,6 +2524,9 @@ is recomputed using the current :math:`\gamma` value. Any non-positive parameter will imply a reset to the default value. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.delta_gamma_max". + .. versionadded:: 6.1.0 .. index:: @@ -2392,6 +2555,9 @@ is recomputed using the current :math:`\gamma` value. step. If **msbp** is 0, the default value of 20 will be used. A negative value forces a linear solver step at each implicit stage. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.lsetup_frequency". + .. versionadded:: 6.1.0 @@ -2434,6 +2600,9 @@ is recomputed using the current :math:`\gamma` value. This function must be called *after* the ARKLS system solver interface has been initialized through a call to :c:func:`ARKodeSetLinearSolver`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.jac_eval_frequency". + .. versionadded:: 6.1.0 @@ -2621,6 +2790,9 @@ data in the program. The user data pointer may be specified through Linear solution scaling is enabled by default when a matrix-based linear solver is attached. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.linear_solution_scaling". + .. versionadded:: 6.1.0 @@ -2958,6 +3130,9 @@ the user through the :c:func:`ARKodeSetEpsLin` function. interface has been initialized through a call to :c:func:`ARKodeSetLinearSolver`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.eps_lin". + .. versionadded:: 6.1.0 @@ -2988,6 +3163,9 @@ the user through the :c:func:`ARKodeSetEpsLin` function. Passing a value *eplifac* :math:`\le 0` indicates to use the default value of 0.05. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.mass_eps_lin". + .. versionadded:: 6.1.0 @@ -3036,6 +3214,9 @@ allow for additional user control over these conversion factors. This function must be called *after* the ARKLS system solver interface has been initialized through a call to :c:func:`ARKodeSetLinearSolver`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.ls_norm_factor". + .. versionadded:: 6.1.0 @@ -3069,6 +3250,9 @@ allow for additional user control over these conversion factors. This function must be called *after* the ARKLS mass matrix solver interface has been initialized through a call to :c:func:`ARKodeSetMassLinearSolver`. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.mass_ls_norm_factor". + .. versionadded:: 6.1.0 @@ -3139,6 +3323,9 @@ Disable inactive root warnings :c:func:`ARKodeSetNoInactiveRootWarn` e first step), ARKODE will issue a warning which can be disabled with this optional input function. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.no_inactive_root_warn". + .. versionadded:: 6.1.0 @@ -4713,6 +4900,9 @@ Output all ARKODE solver parameters :c:func:`ARKodeWriteParameters` for this pointer, since parameters for all processes would be identical. + This routine will be called by :c:func:`ARKodeSetFromCommandLine` + when using the command-line option "arkid.write_parameters". + .. versionadded:: 6.1.0 diff --git a/doc/cvode/guide/source/Usage/index.rst b/doc/cvode/guide/source/Usage/index.rst index 33659bb628..460f09d042 100644 --- a/doc/cvode/guide/source/Usage/index.rst +++ b/doc/cvode/guide/source/Usage/index.rst @@ -386,6 +386,10 @@ the call to :c:func:`CVodeInit` * ``CV_NO_MALLOC`` -- The allocation function returned ``NULL`` * ``CV_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.scalar_tolerances". + .. c:function:: int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, N_Vector abstol) The function ``CVodeSVtolerances`` specifies scalar relative tolerance and vector absolute tolerances. @@ -825,6 +829,9 @@ Main solver optional input functions +-------------------------------+---------------------------------------------+----------------+ | **Optional input** | **Function name** | **Default** | +===============================+=============================================+================+ + | Set CVODE optional inputs | :c:func:`CVodeSetFromCommandLine` | | + | from the command line | | | + +-------------------------------+---------------------------------------------+----------------+ | User data | :c:func:`CVodeSetUserData` | ``NULL`` | +-------------------------------+---------------------------------------------+----------------+ | Maximum order for BDF method | :c:func:`CVodeSetMaxOrd` | 5 | @@ -865,6 +872,35 @@ Main solver optional input functions +-------------------------------+---------------------------------------------+----------------+ +.. c:function:: int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, int argc, char* argv[]) + + Passes command-line arguments to CVODE to set options. + + :param cvode_mem: pointer to the CVODE memory block. + :param cvid: String to use as prefix for CVODE command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval CV_SUCCESS: the function exited successfully. + :retval CV_MEM_NULL: ``cvode_mem`` was ``NULL``. + :retval other: error return value from relevant CVODE "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. + These are left unchanged by :c:func:`CVodeSetFromCommandLine`. + + If the *cvid* argument is ``NULL`` then ``cvode.`` will be used for all CVODE command-line + options, e.g., to set the maximum order of accuracy the default command-line option would + be "cvode.max_order". + + CVODE options set via command-line arguments to :c:func:`CVodeSetFromCommandLine` will + overwrite any previously-set values. + + The supported command-line options are documented within each CVODE "set" routine. + + .. versionadded:: x.y.z + .. c:function:: int CVodeSetUserData(void* cvode_mem, void * user_data) The function ``CVodeSetUserData`` specifies the user data block ``user_data`` and attaches it to the main CVODE memory block. @@ -918,6 +954,9 @@ Main solver optional input functions **Notes:** The monitor function that will be called can be set with ``CVodeSetMonitorFn``. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.monitor_frequency". + .. warning:: Modifying the solution in this function will result in undefined behavior. This function is only intended to be used for monitoring the integrator. SUNDIALS must be built with the CMake option ``SUNDIALS_BUILD_WITH_MONITORING``, to utilize this function. See :numref:`Installation` for more information. @@ -940,6 +979,9 @@ Main solver optional input functions An input value greater than the default will result in the default value. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_order". + .. c:function:: int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps) The function ``CVodeSetMaxNumSteps`` specifies the maximum number of steps to be taken by the solver in its attempt to reach the next output time. @@ -957,6 +999,9 @@ Main solver optional input functions Passing ``mxsteps`` < 0 disables the test (not recommended). + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_num_steps". + .. c:function:: int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil) The function ``CVodeSetMaxHnilWarns`` specifies the maximum number of messages issued by the solver warning that :math:`t+h=t` on the next internal step. @@ -972,6 +1017,9 @@ Main solver optional input functions **Notes:** The default value is 10. A negative value for ``mxhnil`` indicates that no warning messages should be issued. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_hnil_warns". + .. c:function:: int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype stldet) The function ``CVodeSetStabLimDet`` indicates if the BDF stability limit detection algorithm should be used. See :numref:`CVODE.Mathematics.stablimit` for further details. @@ -988,6 +1036,9 @@ Main solver optional input functions **Notes:** The default value is ``SUNFALSE``. If ``stldet = SUNTRUE`` when BDF is used and the method order is greater than or equal to 3, then an internal function, ``CVsldet``, is called to detect a possible stability limit. If such a limit is detected, then the order is reduced. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.stab_lim_det". + .. c:function:: int CVodeSetInitStep(void* cvode_mem, sunrealtype hin) The function ``CVodeSetInitStep`` specifies the initial step size. @@ -1003,6 +1054,9 @@ Main solver optional input functions **Notes:** By default, CVODE estimates the initial step size to be the solution :math:`h` of the equation :math:`0.5 h^2 \ddot{y} = 1`, where :math:`\ddot{y}` is an estimated second derivative of the solution at :math:`t_0`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.init_step". + .. c:function:: int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin) The function ``CVodeSetMinStep`` specifies a lower bound on the magnitude of the step size. @@ -1019,6 +1073,9 @@ Main solver optional input functions **Notes:** The default value is 0.0. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.min_step". + .. c:function:: int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax) The function ``CVodeSetMaxStep`` specifies an upper bound on the magnitude of the step size. @@ -1035,6 +1092,9 @@ Main solver optional input functions **Notes:** Pass ``hmax`` = 0.0 to obtain the default value :math:`\infty`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_step". + .. c:function:: int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop) The function ``CVodeSetStopTime`` specifies the value of the independent variable :math:`t` past which the solution is not to proceed. @@ -1056,6 +1116,9 @@ Main solver optional input functions A stop time not reached before a call to :c:func:`CVodeReInit` will remain active but can be disabled by calling :c:func:`CVodeClearStopTime`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.stop_time". + .. c:function:: int CVodeSetInterpolateStopTime(void* cvode_mem, sunbooleantype interp) The function ``CVodeSetInterpolateStopTime`` specifies that the output solution should be @@ -1070,6 +1133,11 @@ Main solver optional input functions * ``CV_SUCCESS`` -- The optional value has been successfully set. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.interpolate_stop_time". + + .. versionadded:: 6.6.0 .. c:function:: int CVodeClearStopTime(void* cvode_mem) @@ -1087,6 +1155,9 @@ Main solver optional input functions The stop time can be re-enabled though a new call to :c:func:`CVodeSetStopTime`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.clear_stop_time". + .. versionadded:: 6.5.1 .. c:function:: int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef) @@ -1104,6 +1175,9 @@ Main solver optional input functions **Notes:** The default value is 7. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_err_test_fails". + .. c:function:: int CVodeSetConstraints(void* cvode_mem, N_Vector constraints) The function ``CVodeSetConstraints`` specifies a vector defining inequality constraints for each component of the solution vector y. @@ -1139,9 +1213,12 @@ Main solver optional input functions * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. **Notes:** - SUNDIALS must be compiled appropriately for specialized kernels to be available. The CMake option ``SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS`` must be set to - ``ON`` when SUNDIALS is compiled. See the entry for this option in :numref:`Installation.Options` for more information. - Currently, the fused kernels are only supported when using CVODE with the :ref:`NVECTOR_CUDA ` and :ref:`NVECTOR_HIP ` implementations of the ``N_Vector``. + SUNDIALS must be compiled appropriately for specialized kernels to be available. The CMake option ``SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS`` must be set to + ``ON`` when SUNDIALS is compiled. See the entry for this option in :numref:`Installation.Options` for more information. + Currently, the fused kernels are only supported when using CVODE with the :ref:`NVECTOR_CUDA ` and :ref:`NVECTOR_HIP ` implementations of the ``N_Vector``. + + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.use_integrator_fused_kernels". .. _CVODE.Usage.CC.optional_input.optin_ls: @@ -1261,6 +1338,10 @@ difference approximation or a call to the :ref:`user-supplied Jacobian function * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.dgmax_lsetup". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, sunrealtype dgmax_jbad) @@ -1282,6 +1363,10 @@ difference approximation or a call to the :ref:`user-supplied Jacobian function * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.delta_gamma_max_bad_jac". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp) @@ -1300,6 +1385,9 @@ difference approximation or a call to the :ref:`user-supplied Jacobian function **Notes:** Positive values of ``msbp`` specify the linear solver setup frequency. For example, an input of ``1`` means the setup function will be called every time step while an input of ``2`` means it will be called called every other time step. If ``msbp = 0``, the default value of 20 will be used. Otherwise an error is returned. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.lsetup_frequency". + .. c:function:: int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj) The function ``CVodeSetJacEvalFrequency`` Specifies the number of steps after @@ -1334,6 +1422,9 @@ difference approximation or a call to the :ref:`user-supplied Jacobian function This function must be called after the CVLS linear solver interface has been initialized through a call to :c:func:`CVodeSetLinearSolver`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.jac_eval_frequency". + When using matrix-based linear solver modules, the CVLS solver interface needs a function to compute an approximation to the Jacobian matrix :math:`J(t,y)` or the linear system :math:`M = I - \gamma J`. The function to evaluate :math:`J(t,y)` must @@ -1435,6 +1526,9 @@ using the current :math:`\gamma` as part of the solve. By default scaling is enabled with matrix-based linear solvers when using BDF methods. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.linear_solution_scaling". + When using matrix-free linear solver modules, the CVLS solver interface requires a function to compute an approximation to the product between the Jacobian matrix :math:`J(t,y)` and a vector :math:`v`. The @@ -1590,6 +1684,9 @@ the :c:func:`CVodeSetEpsLin` function. If ``eplifac`` = 0.0 is passed, the default value is used. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_lin". + .. versionadded:: 4.0.0 Replaces the deprecated function ``CVSpilsSetEpsLin``. @@ -1616,6 +1713,9 @@ the :c:func:`CVodeSetEpsLin` function. Prior to the introduction of ``N_VGetLength`` in SUNDIALS v5.0.0 (CVODE v5.0.0) the value of ``nrmfac`` was computed using the vector dot product i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.ls_norm_factor". + .. _CVODE.Usage.CC.optional_input.optin_nls: @@ -1661,6 +1761,9 @@ nonlinear solver. **Notes:** The default value is 3. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_nonlin_iters". + .. c:function:: int CVodeSetMaxConvFails(void* cvode_mem, int maxncf) The function ``CVodeSetMaxConvFails`` specifies the maximum number of nonlinear solver convergence failures permitted during one step. @@ -1676,6 +1779,9 @@ nonlinear solver. **Notes:** The default value is 10. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_conv_fails". + .. c:function:: int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef) The function ``CVodeSetNonlinConvCoef`` specifies the safety factor used in the nonlinear convergence test (see :numref:`CVODE.Mathematics.ivp_sol`). @@ -1691,6 +1797,9 @@ nonlinear solver. **Notes:** The default value is 0.1. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.nonlin_conv_coef". + .. c:function:: int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f) The function ``CVodeSetNlsRhsFn`` specifies an alternative right-hand side function for use in nonlinear system function evaluations. @@ -1798,6 +1907,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_fixed_step_bounds". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs) @@ -1817,6 +1930,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max_first_step". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es) @@ -1847,6 +1964,9 @@ step size adaptivity. factor :math:`\eta_{\mathrm{max\_es}}` can be set with :c:func:`CVodeSetNumStepsEtaMaxEarlyStep`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.set_max_early_step". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst) @@ -1874,6 +1994,9 @@ step size adaptivity. The factor :math:`\eta_{\mathrm{max\_es}}` can be set with :c:func:`CVodeSetEtaMaxEarlyStep`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.num_steps_eta_max_early_step". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMax(void* cvode_mem, sunrealtype eta_max_gs) @@ -1901,6 +2024,9 @@ step size adaptivity. The factor for steps early in the integration is set by :c:func:`CVodeSetEtaMaxEarlyStep`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min) @@ -1920,6 +2046,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_min". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMinErrFail(void *cvode_mem, sunrealtype eta_min_ef) @@ -1940,6 +2070,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_min_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef) @@ -1966,6 +2100,12 @@ step size adaptivity. size factor :math:`\eta_{\mathrm{min\_ef}}` can be set with :c:func:`CVodeSetNumFailsEtaMaxErrFail`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.num_efails_eta_max_err_fail". + + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetNumFailsEtaMaxErrFail(void *cvode_mem, int small_nef) @@ -2013,6 +2153,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_conv_fail". + .. versionadded:: 6.2.0 @@ -2067,6 +2211,9 @@ the rootfinding algorithm. **Notes:** CVODE will not report the initial conditions as a possible zero-crossing (assuming that one or more components :math:`g_i` are zero at the initial time). However, if it appears that some :math:`g_i` is identically zero at the initial time (i.e., :math:`g_i` is zero at the initial time and after the first step), CVODE will issue a warning which can be disabled with this optional input function. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.no_inactive_root_warn". + .. _CVODE.Usage.CC.optional_input.optin_proj: @@ -2110,6 +2257,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_err_est". + .. versionadded:: 5.3.0 .. c:function:: int CVodeSetProjFrequency(void* cvode_mem, long int freq) @@ -2125,6 +2276,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_frequency". + .. versionadded:: 5.3.0 .. c:function:: int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails) @@ -2140,6 +2295,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_num_proj_fails". + .. versionadded:: 5.3.0 .. c:function:: int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps) @@ -2155,6 +2314,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_proj". + .. versionadded:: 5.3.0 .. c:function:: int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta) @@ -2170,6 +2333,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_fail_eta". + .. versionadded:: 5.3.0 diff --git a/doc/cvodes/guide/source/Usage/ADJ.rst b/doc/cvodes/guide/source/Usage/ADJ.rst index 178a8cbcc8..fd291c2202 100644 --- a/doc/cvodes/guide/source/Usage/ADJ.rst +++ b/doc/cvodes/guide/source/Usage/ADJ.rst @@ -584,6 +584,10 @@ call to :c:func:`CVodeInitB` or :c:func:`CVodeInitBS`. * ``CV_NO_ADJ`` -- The function :c:func:`CVodeAdjInit` has not been previously called. * ``CV_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.scalar_tolerances_b". + .. c:function:: int CVodeSVtolerancesB(void * cvode_mem, int which, sunrealtype reltolB, N_Vector abstolB) @@ -819,9 +823,9 @@ At any time during the integration of the forward problem, the user can disable the checkpointing of the forward sensitivities by calling the following function: -.. c:function:: int CVodeAdjSetNoSensi(void * cvode_mem) +.. c:function:: int CVodeSetAdjNoSensi(void * cvode_mem) - The function :c:func:`CVodeAdjSetNoSensi` instructs :c:func:`CVodeF` not to + The function :c:func:`CVodeSetAdjNoSensi` instructs :c:func:`CVodeF` not to save checkpointing data for forward sensitivities anymore. **Arguments:** @@ -832,6 +836,10 @@ function: * ``CV_MEM_NULL`` -- ``cvode_mem`` was ``NULL``. * ``CV_NO_ADJ`` -- The function :c:func:`CVodeAdjInit` has not been previously called. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.adj_no_sensi". + .. _CVODES.Usage.ADJ.user_callable.optional_input_b: @@ -877,7 +885,10 @@ The optional input functions defined for the backward problem are: Their return value ``flag`` (of type ``int``) can have any of the return values of their counterparts, but it can also be ``CV_NO_ADJ`` if :c:func:`CVodeAdjInit` has not been called, or ``CV_ILL_INPUT`` if ``which`` was -an invalid identifier. +an invalid identifier. The above routines may be controlled using command-line +options via :c:func:`CVodeSetFromCommandLine`, where the command-line argument is +appended with the suffix "_b", e.g., ``CVodeSetMaxOrdB`` can be controlled by the +command-line option "cvid.max_order_b". Linear solver interface optional input functions """""""""""""""""""""""""""""""""""""""""""""""" @@ -996,6 +1007,8 @@ disable solution scaling when using a matrix-based linear solver. By default scaling is enabled with matrix-based linear solvers when using BDF methods. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.linear_solution_scaling_b". .. c:function:: int CVodeSetJacTimesB(void * cvode_mem, int which, CVLsJacTimesSetupFnB jsetupB, CVLsJacTimesVecFnB jtvB) @@ -1160,6 +1173,9 @@ potentially non-differentiable factor. The default value is :math:`0.05`. Passing a value ``eplifacB = 0.0`` also indicates using the default value. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_lin_b". + .. versionadded:: 4.0.0 Replaces the deprecated function ``CVSpilsSetEpsLinB``. @@ -1192,6 +1208,9 @@ potentially non-differentiable factor. v5.0.0) the value of ``nrmfac`` was computed using the vector dot product i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.ls_norm_factor_b". + .. _CVODES.Usage.ADJ.user_callable.optional_output_b: @@ -1439,7 +1458,9 @@ optional values are specified. Their return value ``flag`` (of type ``int``) can have any of the return values of its counterparts, but it can also be ``CV_NO_ADJ`` if the function :c:func:`CVodeAdjInit` has not been previously called or ``CV_ILL_INPUT`` if the -parameter ``which`` was an invalid identifier. +parameter ``which`` was an invalid identifier. The first two routines above may +be controlled using command-line options "cvid.quad_err_con_b" and +"cvid.quad_scalar_tolerances_b" when using :c:func:`CVodeSetFromCommandLine`. Access to optional outputs related to backward quadrature integration can be obtained by calling the corresponding ``CVodeGetQuad*`` functions (see diff --git a/doc/cvodes/guide/source/Usage/FSA.rst b/doc/cvodes/guide/source/Usage/FSA.rst index 23f2a7d171..e3bb48b2a4 100644 --- a/doc/cvodes/guide/source/Usage/FSA.rst +++ b/doc/cvodes/guide/source/Usage/FSA.rst @@ -804,6 +804,9 @@ time and, if successful, takes effect immediately. The default value are ``DQtype == CV_CENTERED`` and ``DQrhomax=0.0``. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.sens_dq_method". + .. c:function:: int CVodeSetSensErrCon(void * cvode_mem, sunbooleantype errconS) @@ -825,6 +828,9 @@ time and, if successful, takes effect immediately. variables are excluded from the error tests. Note that, in any event, all variables are considered in the convergence tests. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.sens_err_con". + .. c:function:: int CVodeSetSensMaxNonlinIters(void * cvode_mem, int maxcorS) @@ -843,6 +849,9 @@ time and, if successful, takes effect immediately. **Notes:** The default value is 3. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.sens_max_nonlin_iters". + .. _CVODES.Usage.FSA.user_callable.optional_output: @@ -1595,6 +1604,9 @@ integration of sensitivity-dependent quadrature equations. **Notes:** By default, ``errconQS`` is set to ``SUNFALSE``. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.quad_sens_err_con". + .. warning:: It is illegal to call :c:func:`CVodeSetQuadSensErrCon` before a call to :c:func:`CVodeQuadSensInit`. diff --git a/doc/cvodes/guide/source/Usage/SIM.rst b/doc/cvodes/guide/source/Usage/SIM.rst index 658f269bb1..584692673a 100644 --- a/doc/cvodes/guide/source/Usage/SIM.rst +++ b/doc/cvodes/guide/source/Usage/SIM.rst @@ -389,6 +389,10 @@ the call to :c:func:`CVodeInit`. * ``CV_NO_MALLOC`` -- The allocation function returned ``NULL``. * ``CV_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.scalar_tolerances". + .. c:function:: int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, N_Vector abstol) The function ``CVodeSVtolerances`` specifies scalar relative tolerance and vector absolute tolerances. @@ -834,6 +838,9 @@ Main solver optional input functions +---------------------------------+---------------------------------------------+----------------+ | **Optional input** | **Function name** | **Default** | +=================================+=============================================+================+ + | Set CVODES optional inputs | :c:func:`CVodeSetFromCommandLine` | | + | from the command line | | | + +---------------------------------+---------------------------------------------+----------------+ | User data | :c:func:`CVodeSetUserData` | ``NULL`` | +---------------------------------+---------------------------------------------+----------------+ | Maximum order for BDF method | :c:func:`CVodeSetMaxOrd` | 5 | @@ -870,6 +877,36 @@ Main solver optional input functions +---------------------------------+---------------------------------------------+----------------+ +.. c:function:: int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, int argc, char* argv[]) + + Passes command-line arguments to CVODES to set options. + + :param cvode_mem: pointer to the CVODES memory block. + :param cvid: String to use as prefix for CVODES command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval CV_SUCCESS: the function exited successfully. + :retval CV_MEM_NULL: ``cvode_mem`` was ``NULL``. + :retval other: error return value from relevant CVODES "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. + These are left unchanged by :c:func:`CVodeSetFromCommandLine`. + + If the *cvid* argument is ``NULL`` then ``cvodes.`` will be used for all CVODES command-line + options, e.g., to set the maximum order of accuracy the default command-line option would + be "cvodes.max_order". + + CVODES options set via command-line arguments to :c:func:`CVodeSetFromCommandLine` will + overwrite any previously-set values. + + The supported command-line options are documented within each CVODES "set" routine. + + .. versionadded:: x.y.z + + .. c:function:: int CVodeSetUserData(void* cvode_mem, void * user_data) The function ``CVodeSetUserData`` specifies the user data block ``user_data`` and attaches it to the main CVODES memory block. @@ -923,6 +960,9 @@ Main solver optional input functions **Notes:** The monitor function that will be called can be set with ``CVodeSetMonitorFn``. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.monitor_frequency". + .. warning:: Modifying the solution in this function will result in undefined behavior. This function is only intended to be used for monitoring the integrator. SUNDIALS must be built with the CMake option ``SUNDIALS_BUILD_WITH_MONITORING``, to utilize this function. See :numref:`Installation` for more information. @@ -945,6 +985,9 @@ Main solver optional input functions An input value greater than the default will result in the default value. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_order". + .. c:function:: int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps) The function ``CVodeSetMaxNumSteps`` specifies the maximum number of steps to be taken by the solver in its attempt to reach the next output time. @@ -962,6 +1005,9 @@ Main solver optional input functions Passing ``mxsteps`` < 0 disables the test (not recommended). + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_num_steps". + .. c:function:: int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil) The function ``CVodeSetMaxHnilWarns`` specifies the maximum number of messages issued by the solver warning that :math:`t+h=t` on the next internal step. @@ -977,6 +1023,9 @@ Main solver optional input functions **Notes:** The default value is 10. A negative value for ``mxhnil`` indicates that no warning messages should be issued. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_hnil_warns". + .. c:function:: int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype stldet) The function ``CVodeSetStabLimDet`` indicates if the BDF stability limit detection algorithm should be used. See :numref:`CVODES.Mathematics.stablimit` for further details. @@ -993,6 +1042,9 @@ Main solver optional input functions **Notes:** The default value is ``SUNFALSE``. If ``stldet = SUNTRUE`` when BDF is used and the method order is greater than or equal to 3, then an internal function, ``CVsldet``, is called to detect a possible stability limit. If such a limit is detected, then the order is reduced. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.stab_lim_det". + .. c:function:: int CVodeSetInitStep(void* cvode_mem, sunrealtype hin) The function ``CVodeSetInitStep`` specifies the initial step size. @@ -1008,6 +1060,9 @@ Main solver optional input functions **Notes:** By default, CVODES estimates the initial step size to be the solution :math:`h` of the equation :math:`0.5 h^2 \ddot{y} = 1`, where :math:`\ddot{y}` is an estimated second derivative of the solution at :math:`t_0`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.init_step". + .. c:function:: int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin) The function ``CVodeSetMinStep`` specifies a lower bound on the magnitude of the step size. @@ -1024,6 +1079,9 @@ Main solver optional input functions **Notes:** The default value is 0.0. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.min_step". + .. c:function:: int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax) The function ``CVodeSetMaxStep`` specifies an upper bound on the magnitude of the step size. @@ -1040,6 +1098,9 @@ Main solver optional input functions **Notes:** Pass ``hmax`` = 0.0 to obtain the default value :math:`\infty`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_step". + .. c:function:: int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop) The function ``CVodeSetStopTime`` specifies the value of the independent variable :math:`t` past which the solution is not to proceed. @@ -1061,6 +1122,9 @@ Main solver optional input functions A stop time not reached before a call to :c:func:`CVodeReInit` will remain active but can be disabled by calling :c:func:`CVodeClearStopTime`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.stop_time". + .. c:function:: int CVodeSetInterpolateStopTime(void* cvode_mem, sunbooleantype interp) The function ``CVodeSetInterpolateStopTime`` specifies that the output solution should be @@ -1075,6 +1139,10 @@ Main solver optional input functions * ``CV_SUCCESS`` -- The optional value has been successfully set. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.interpolate_stop_time". + .. versionadded:: 6.6.0 .. c:function:: int CVodeClearStopTime(void* cvode_mem) @@ -1092,6 +1160,9 @@ Main solver optional input functions The stop time can be re-enabled though a new call to :c:func:`CVodeSetStopTime`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.clear_stop_time". + .. versionadded:: 6.5.1 .. c:function:: int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef) @@ -1109,6 +1180,9 @@ Main solver optional input functions **Notes:** The default value is 7. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_err_test_fails". + .. c:function:: int CVodeSetConstraints(void* cvode_mem, N_Vector constraints) The function ``CVodeSetConstraints`` specifies a vector defining inequality constraints for each component of the solution vector y. @@ -1258,6 +1332,10 @@ using the current :math:`\gamma` value. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.dgmax_lsetup". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, sunrealtype dgmax_jbad) @@ -1279,6 +1357,10 @@ using the current :math:`\gamma` value. * ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.delta_gamma_max_bad_jac". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp) @@ -1297,6 +1379,9 @@ using the current :math:`\gamma` value. **Notes:** Positive values of ``msbp`` specify the linear solver setup frequency. For example, an input of ``1`` means the setup function will be called every time step while an input of ``2`` means it will be called called every other time step. If ``msbp = 0``, the default value of 20 will be used. Otherwise an error is returned. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.lsetup_frequency". + .. c:function:: int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj) The function ``CVodeSetJacEvalFrequency`` Specifies the number of steps after @@ -1331,6 +1416,9 @@ using the current :math:`\gamma` value. This function must be called after the CVLS linear solver interface has been initialized through a call to :c:func:`CVodeSetLinearSolver`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.jac_eval_frequency". + When using matrix-based linear solver modules, the CVLS solver interface needs a function to compute an approximation to the Jacobian matrix :math:`J(t,y)` or the linear system :math:`M = I - \gamma J`. The function to evaluate :math:`J(t,y)` must @@ -1432,6 +1520,9 @@ using the current :math:`\gamma` as part of the solve. By default scaling is enabled with matrix-based linear solvers when using BDF methods. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.linear_solution_scaling". + When using matrix-free linear solver modules, the CVLS solver interface requires a function to compute an approximation to the product between the Jacobian matrix :math:`J(t,y)` and a vector :math:`v`. The @@ -1587,6 +1678,9 @@ the :c:func:`CVodeSetEpsLin` function. If ``eplifac`` = 0.0 is passed, the default value is used. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_lin". + .. versionadded:: 4.0.0 Replaces the deprecated function ``CVSpilsSetEpsLin``. @@ -1613,6 +1707,12 @@ the :c:func:`CVodeSetEpsLin` function. Prior to the introduction of ``N_VGetLength`` in SUNDIALS v5.0.0 (CVODES v5.0.0) the value of ``nrmfac`` was computed using the vector dot product i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.ls_norm_factor". + + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.ls_norm_factor". + .. _CVODES.Usage.SIM.optional_input.optin_nls: @@ -1658,6 +1758,9 @@ nonlinear solver. **Notes:** The default value is 3. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_nonlin_iters". + .. c:function:: int CVodeSetMaxConvFails(void* cvode_mem, int maxncf) The function ``CVodeSetMaxConvFails`` specifies the maximum number of nonlinear solver convergence failures permitted during one step. @@ -1673,6 +1776,9 @@ nonlinear solver. **Notes:** The default value is 10. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_conv_fails". + .. c:function:: int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef) The function ``CVodeSetNonlinConvCoef`` specifies the safety factor used in the nonlinear convergence test (see :numref:`CVODES.Mathematics.ivp_sol`). @@ -1688,6 +1794,9 @@ nonlinear solver. **Notes:** The default value is 0.1. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.nonlin_conv_coef". + .. c:function:: int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f) The function ``CVodeSetNlsRhsFn`` specifies an alternative right-hand side function for use in nonlinear system function evaluations. @@ -1795,6 +1904,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_fixed_step_bounds". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs) @@ -1814,6 +1927,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max_first_step". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es) @@ -1844,6 +1961,9 @@ step size adaptivity. factor :math:`\eta_{\mathrm{max\_es}}` can be set with :c:func:`CVodeSetNumStepsEtaMaxEarlyStep`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max_early_step". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst) @@ -1898,6 +2018,9 @@ step size adaptivity. The factor for steps early in the integration is set by :c:func:`CVodeSetEtaMaxEarlyStep`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min) @@ -1917,6 +2040,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_min". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMinErrFail(void *cvode_mem, sunrealtype eta_min_ef) @@ -1937,6 +2064,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_min_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef) @@ -1963,6 +2094,9 @@ step size adaptivity. size factor :math:`\eta_{\mathrm{min\_ef}}` can be set with :c:func:`CVodeSetNumFailsEtaMaxErrFail`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_max_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetNumFailsEtaMaxErrFail(void *cvode_mem, int small_nef) @@ -1990,6 +2124,9 @@ step size adaptivity. The factor :math:`\eta_{\mathrm{max\_ef}}` can be set with :c:func:`CVodeSetEtaMaxErrFail`. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.num_efails_eta_max_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEtaConvFail(void* cvode_mem, sunrealtype eta_cf) @@ -2010,6 +2147,10 @@ step size adaptivity. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eta_conv_fail". + .. versionadded:: 6.2.0 @@ -2062,8 +2203,15 @@ the rootfinding algorithm. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. **Notes:** - CVODES will not report the initial conditions as a possible zero-crossing (assuming that one or more components :math:`g_i` are zero at the initial time). However, if it appears that some :math:`g_i` is identically zero at the initial time (i.e., :math:`g_i` is zero at the initial time and after the first step), CVODES will issue a warning which can be disabled with this optional input function. + CVODES will not report the initial conditions as a possible zero-crossing + (assuming that one or more components :math:`g_i` are zero at the initial time). + However, if it appears that some :math:`g_i` is identically zero at the initial + time (i.e., :math:`g_i` is zero at the initial time and after the first step), + CVODES will issue a warning which can be disabled with this optional input + function. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.no_inactive_root_warn". .. _CVODES.Usage.SIM.optional_input.optin_proj: @@ -2107,6 +2255,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_err_est". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetProjFrequency(void* cvode_mem, long int freq) @@ -2122,6 +2274,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_frequency". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails) @@ -2137,6 +2293,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.max_num_proj_fails". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps) @@ -2152,6 +2312,13 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_lin". + + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.eps_proj". + .. versionadded:: 6.2.0 .. c:function:: int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta) @@ -2167,6 +2334,10 @@ the projection when solving an IVP with constraints. * ``CV_MEM_NULL`` -- The CVODES memory block was not initialized through a previous call to :c:func:`CVodeCreate`. * ``CV_PROJ_MEM_NULL`` -- The projection memory is ``NULL`` i.e., the projection functionality has not been enabled. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.proj_fail_eta". + .. versionadded:: 6.2.0 @@ -4071,6 +4242,9 @@ of quadrature equations. **Notes:** By default, ``errconQ`` is set to ``SUNFALSE``. + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.quad_err_con". + .. warning:: It is illegal to call ``CVodeSetQuadErrCon`` before a call to ``CVodeQuadInit``. @@ -4095,6 +4269,10 @@ integration tolerances for quadrature variables. * ``CV_MEM_NULL`` -- The ``cvode_mem`` pointer is ``NULL``. * ``CV_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`CVodeSetFromCommandLine` + when using the command-line option "cvid.quad_scalar_tolerances". + .. c:function:: int CVodeQuadSVtolerances(void * cvode_mem, sunrealtype reltolQ, N_Vector abstolQ) diff --git a/doc/ida/guide/source/Usage/index.rst b/doc/ida/guide/source/Usage/index.rst index c8b1ef09d7..d79a5da30a 100644 --- a/doc/ida/guide/source/Usage/index.rst +++ b/doc/ida/guide/source/Usage/index.rst @@ -383,6 +383,10 @@ norms). Note that this call must be made after the call to :c:func:`IDAInit`. called. * ``IDA_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.scalar_tolerances". + .. c:function:: int IDASVtolerances(void* ida_mem, sunrealtype reltol, N_Vector abstol) The function ``IDASVtolerances`` specifies scalar relative tolerance and @@ -906,6 +910,8 @@ Main solver optional input functions +--------------------------------------------------------------------+---------------------------------+----------------+ | **Optional input** | **Function name** | **Default** | +--------------------------------------------------------------------+---------------------------------+----------------+ + | Set IDA optional inputs from the command line | :c:func:`IDASetFromCommandLine` | | + +--------------------------------------------------------------------+---------------------------------+----------------+ | User data | :c:func:`IDASetUserData` | NULL | +--------------------------------------------------------------------+---------------------------------+----------------+ | Maximum order for BDF method | :c:func:`IDASetMaxOrd` | 5 | @@ -932,6 +938,35 @@ Main solver optional input functions +--------------------------------------------------------------------+---------------------------------+----------------+ +.. c:function:: int IDASetFromCommandLine(void* ida_mem, const char* idaid, int argc, char* argv[]) + + Passes command-line arguments to IDA to set options. + + :param ida_mem: pointer to the IDA solver objectd. + :param idaid: String to use as prefix for IDA command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval IDA_SUCCESS: the function exited successfully. + :retval IDA_MEM_NULL: ``ida_mem`` was ``NULL``. + :retval other: error return value from relevant IDA "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. + These are left unchanged by :c:func:`IDASetFromCommandLine`. + + If the *idaid* argument is ``NULL`` then ``ida.`` will be used for all IDA command-line + options, e.g., to set the maximum order of accuracy the default command-line option would + be "ida.max_order". + + IDA options set via command-line arguments to :c:func:`IDASetFromCommandLine` will + overwrite any previously-set values. + + The supported command-line options are documented within each IDA "set" routine. + + .. versionadded:: x.y.z + .. c:function:: int IDASetUserData(void * ida_mem, void * user_data) The function ``IDASetUserData`` attaches a user-defined data pointer to the @@ -977,6 +1012,9 @@ Main solver optional input functions requirements for the internal IDA memory block and its value cannot be increased past the value set when :c:func:`IDAInit` was called. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_order". + .. c:function:: int IDASetMaxNumSteps(void * ida_mem, long int mxsteps) The function ``IDASetMaxNumSteps`` specifies the maximum number of steps to @@ -994,6 +1032,9 @@ Main solver optional input functions Passing ``mxsteps`` = 0 results in IDA using the default value (500). Passing ``mxsteps`` < 0 disables the test (not recommended). + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_steps". + .. c:function:: int IDASetInitStep(void * ida_mem, sunrealtype hin) The function ``IDASetInitStep`` specifies the initial step size. @@ -1012,6 +1053,9 @@ Main solver optional input functions :math:`\|h \dot{y} \|_{{\scriptsize WRMS}} = 1/2`, with an added restriction that :math:`|h| \leq .001|t_{\text{out}} - t_0|`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.init_step". + .. c:function:: int IDASetMinStep(void * ida_mem, sunrealtype hmin) The function ``IDASetMinStep`` specifies the minimum absolute value of the @@ -1028,6 +1072,10 @@ Main solver optional input functions * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. * ``IDA_ILL_INPUT`` -- ``hmin`` is negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.min_step". + .. versionadded:: 6.2.0 .. c:function:: int IDASetMaxStep(void * ida_mem, sunrealtype hmax) @@ -1048,6 +1096,9 @@ Main solver optional input functions **Notes:** Pass ``hmax = 0`` to obtain the default value :math:`\infty`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_step". + .. c:function:: int IDASetStopTime(void * ida_mem, sunrealtype tstop) The function ``IDASetStopTime`` specifies the value of the independent @@ -1073,6 +1124,9 @@ Main solver optional input functions A stop time not reached before a call to :c:func:`IDAReInit` will remain active but can be disabled by calling :c:func:`IDAClearStopTime`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.stop_time". + .. c:function:: int IDAClearStopTime(void* ida_mem) Disables the stop time set with :c:func:`IDASetStopTime`. @@ -1088,6 +1142,9 @@ Main solver optional input functions The stop time can be re-enabled though a new call to :c:func:`IDASetStopTime`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.clear_stop_time". + .. versionadded:: 6.5.1 .. c:function:: int IDASetMaxErrTestFails(void * ida_mem, int maxnef) @@ -1107,6 +1164,9 @@ Main solver optional input functions **Notes:** The default value is 10. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_err_test_fails". + .. c:function:: int IDASetSuppressAlg(void * ida_mem, sunbooleantype suppressalg) The function ``IDASetSuppressAlg`` indicates whether or not to suppress @@ -1129,6 +1189,9 @@ Main solver optional input functions 1, whereas it is generally *encouraged* for systems of index 2 or more. See pp. 146-147 of :cite:p:`BCP:96` for more on this issue. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.suppress_alg". + .. c:function:: int IDASetId(void * ida_mem, N_Vector id) The function ``IDASetId`` specifies algebraic/differential components in the @@ -1288,6 +1351,10 @@ that updates the matrix using the current :math:`\alpha` as part of the solve. * ``IDA_SUCCESS`` -- The flag value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.delta_cj_lsetup". + .. versionadded:: 6.2.0 .. c:function:: int IDASetLinearSolutionScaling(void * ida_mem, sunbooleantype onoff) @@ -1312,6 +1379,9 @@ that updates the matrix using the current :math:`\alpha` as part of the solve. initialized through a call to :c:func:`IDASetLinearSolver`. By default scaling is enabled with matrix-based linear solvers. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.linear_solution_scaling". + When using matrix-free linear solver modules, the IDALS solver interface requires a function to compute an approximation to the product between the @@ -1402,6 +1472,9 @@ finite-difference approximation, via a call to :c:func:`IDASetIncrementFactor`. linear solver interface has been initialized through a call to :c:func:`IDASetLinearSolver`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.increment_factor". + .. versionadded:: 4.0.0 Replaces the deprecated function ``IDASpilsSetIncrementFactor``. @@ -1522,6 +1595,9 @@ where :math:`\epsilon` is the nonlinear solver tolerance, and the default :c:func:`IDASetLinearSolver`. If ``eplifac`` :math:`= 0.0` is passed, the default value is used. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eps_lin". + .. versionadded:: 4.0.0 Replaces the deprecated function ``IDASpilsSetEpsLin``. @@ -1555,6 +1631,9 @@ where :math:`\epsilon` is the nonlinear solver tolerance, and the default value of ``nrmfac`` was computed using :c:func:`N_VDotProd` i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.ls_norm_factor". + .. _IDA.Usage.CC.optional_input.optin_nls: @@ -1598,6 +1677,9 @@ nonlinear solver. **Notes:** The default value is 4. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_nonlin_iters". + .. c:function:: int IDASetMaxConvFails(void * ida_mem, int maxncf) @@ -1616,6 +1698,9 @@ nonlinear solver. **Notes:** The default value is 10. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_conv_fails". + .. c:function:: int IDASetNonlinConvCoef(void * ida_mem, sunrealtype nlscoef) @@ -1634,6 +1719,9 @@ nonlinear solver. **Notes:** The default value is 0.33. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.nonlin_conv_coef". + .. c:function:: int IDASetNlsResFn(void * ida_mem, IDAResFn res) @@ -1710,6 +1798,9 @@ to set optional inputs controlling the initial condition calculation. :math:`J^{-1}F(t_0, y, \dot{y})` must be :math:`\leq \mathtt{epiccon}`, where :math:`J` is the system Jacobian. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.nonlin_conv_coef_ic". + .. c:function:: int IDASetMaxNumStepsIC(void * ida_mem, int maxnh) The function ``IDASetMaxNumStepsIC`` specifies the maximum number of steps @@ -1729,6 +1820,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`5`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_steps_ic". + .. c:function:: int IDASetMaxNumJacsIC(void * ida_mem, int maxnj) The function ``IDASetMaxNumJacsIC`` specifies the maximum number of the @@ -1748,6 +1842,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`4`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_jacs_ic". + .. c:function:: int IDASetMaxNumItersIC(void * ida_mem, int maxnit) The function ``IDASetMaxNumItersIC`` specifies the maximum number of Newton @@ -1766,6 +1863,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`10`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_iters_ic". + .. c:function:: int IDASetMaxBacksIC(void * ida_mem, int maxbacks) The function ``IDASetMaxBacksIC`` specifies the maximum number of linesearch @@ -1784,6 +1884,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`100`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_backs_ic". + .. c:function:: int IDASetLineSearchOffIC(void * ida_mem, sunbooleantype lsoff) The function ``IDASetLineSearchOffIC`` specifies whether to turn on or off @@ -1799,8 +1902,10 @@ to set optional inputs controlling the initial condition calculation. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. **Notes:** + The default value is ``SUNFALSE``. - The default value is ``SUNFALSE``. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.linesearch_off_ic". .. c:function:: int IDASetStepToleranceIC(void * ida_mem, int steptol) @@ -1819,6 +1924,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`(\text{unit roundoff})^{2/3}`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.step_tolerance_ic". + .. _IDA.Usage.CC.optional_input.optin_step_adapt: @@ -1886,6 +1994,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_fixed_step_bounds". + .. versionadded:: 6.2.0 .. c:function:: int IDASetEtaMax(void* ida_mem, sunrealtype eta_max) @@ -1903,6 +2015,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_max". + .. versionadded:: 6.2.0 .. c:function:: int IDASetEtaMin(void* ida_mem, sunrealtype eta_min) @@ -1923,6 +2039,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_min". + .. versionadded:: 6.2.0 .. c:function:: int IDASetEtaLow(void* ida_mem, sunrealtype eta_low) @@ -1943,6 +2063,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_low". + .. versionadded:: 6.2.0 .. c:function:: int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef) @@ -1963,6 +2087,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_min_err_fail". + .. versionadded:: 6.2.0 .. c:function:: int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf) @@ -1983,6 +2111,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_conv_fail". + .. versionadded:: 6.2.0 @@ -2055,6 +2187,9 @@ rootfinding algorithm. first step), IDA will issue a warning which can be disabled with this optional input function. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.no_inactive_root_warn". + .. _IDA.Usage.CC.optional_dky: diff --git a/doc/idas/guide/source/Usage/ADJ.rst b/doc/idas/guide/source/Usage/ADJ.rst index 0368cf958d..104816c3a6 100644 --- a/doc/idas/guide/source/Usage/ADJ.rst +++ b/doc/idas/guide/source/Usage/ADJ.rst @@ -398,6 +398,10 @@ function: * ``IDA_MEM_NULL`` -- The ``ida_mem`` was ``NULL``. * ``IDA_NO_ADJ`` -- The function :c:func:`IDAAdjInit` has not been previously called. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.adj_no_sensi". + .. _IDAS.Usage.ADJ.user_callable.idasolvef: @@ -626,6 +630,10 @@ call to :c:func:`IDAInitB` or :c:func:`IDAInitBS`. * ``IDA_NO_ADJ`` -- The function :c:func:`IDAAdjInit` has not been previously called. * ``IDA_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.scalar_tolerances_b". + .. c:function:: int IDASVtolerancesB(void * ida_mem, int which, sunrealtype reltolB, N_Vector abstolB) @@ -963,7 +971,11 @@ The optional input functions defined for the backward problem are: Their return value ``flag`` (of type ``int``) can have any of the return values of their counterparts, but it can also be ``IDA_NO_ADJ`` if :c:func:`IDAAdjInit` has -not been called, or ``IDA_ILL_INPUT`` if ``which`` was an invalid identifier. +not been called, or ``IDA_ILL_INPUT`` if ``which`` was an invalid identifier. The +above routines may be controlled using command-line options via +:c:func:`IDASetFromCommandLine`, where the command-line argument is +appended with the suffix "_b", e.g., ``IDASetMaxOrdB`` can be controlled by the +command-line option "idaid.max_order_b". Linear solver interface optional input functions """""""""""""""""""""""""""""""""""""""""""""""" @@ -1042,11 +1054,14 @@ disable solution scaling when using a matrix-based linear solver. **Notes:** - By default scaling is enabled with matrix-based linear solvers when using - BDF methods. + By default scaling is enabled with matrix-based linear solvers when using + BDF methods. - By default scaling is enabled with matrix-based linear solvers when using BDF - methods. + By default scaling is enabled with matrix-based linear solvers when using BDF + methods. + + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.linear_solution_scaling_b". When using a matrix-free linear solver module for the backward problem, the IDALS linear solver interface requires a function to compute an @@ -1132,6 +1147,9 @@ setting increments for the finite-difference approximation, via a call to **Notes:** The default value is :math:`1.0`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.increment_factor_b". + .. versionadded:: 3.0.0 Replaces the deprecated function ``IDASpilsSetIncrementFactorB``. @@ -1265,6 +1283,9 @@ These may be accomplished through calling the following functions: Passing a value ``eplifacB`` :math:`= 0.0` also indicates using the default value. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eps_lin_b". + .. versionadded:: 3.0.0 Replaces the deprecated function ``IDASpilsSetEpsLinB``. @@ -1301,6 +1322,9 @@ These may be accomplished through calling the following functions: v4.0.0) the value of ``nrmfac`` was computed using the vector dot product i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.ls_norm_factor_b". + .. _IDAS.Usage.ADJ.user_callable.optional_output_b: @@ -1591,7 +1615,9 @@ optional values are specified. Their return value ``flag`` (of type ``int``) can have any of the return values of its counterparts, but it can also be ``IDA_NO_ADJ`` if the function :c:func:`IDAAdjInit` has not been previously called or ``IDA_ILL_INPUT`` if the -parameter ``which`` was an invalid identifier. +parameter ``which`` was an invalid identifier. The first two routines above may +be controlled using command-line options "idaid.quad_err_con_b" and +"idaid.quad_scalar_tolerances_b" when using :c:func:`IDASetFromCommandLine`. Access to optional outputs related to backward quadrature integration can be obtained by calling the corresponding ``IDAGetQuad*`` functions (see diff --git a/doc/idas/guide/source/Usage/FSA.rst b/doc/idas/guide/source/Usage/FSA.rst index b89ea26bf6..47feb40d1f 100644 --- a/doc/idas/guide/source/Usage/FSA.rst +++ b/doc/idas/guide/source/Usage/FSA.rst @@ -353,6 +353,9 @@ function is provided: Since sensitivity-related memory is not deallocated, sensitivities can be reactivated at a later time (using :c:func:`IDASensReInit`). + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.sens_toggle_off". + Forward sensitivity tolerance specification functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -742,17 +745,20 @@ time and, if successful, takes effect immediately. **Notes:** - If ``DQrhomax`` :math:`= 0.0`, then no switching is performed. The - approximation is done simultaneously using either centered or forward finite - differences, depending on the value of ``DQtype``. For values of - ``DQrhomax`` :math:`\ge 1.0`, the simultaneous approximation is used whenever - the estimated finite difference perturbations for states and parameters are - within a factor of ``DQrhomax``, and the separate approximation is used - otherwise. Note that a value ``DQrhomax`` :math:`<1.0` will effectively - disable switching. See :numref:`IDAS.Mathematics.FSA` for more details. + If ``DQrhomax`` :math:`= 0.0`, then no switching is performed. The + approximation is done simultaneously using either centered or forward finite + differences, depending on the value of ``DQtype``. For values of + ``DQrhomax`` :math:`\ge 1.0`, the simultaneous approximation is used whenever + the estimated finite difference perturbations for states and parameters are + within a factor of ``DQrhomax``, and the separate approximation is used + otherwise. Note that a value ``DQrhomax`` :math:`<1.0` will effectively + disable switching. See :numref:`IDAS.Mathematics.FSA` for more details. + + The default value are ``DQtype == IDA_CENTERED`` and + ``DQrhomax``:math:`=0.0`. - The default value are ``DQtype == IDA_CENTERED`` and - ``DQrhomax``:math:`=0.0`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.sens_dq_method". .. c:function:: int IDASetSensErrCon(void * ida_mem, sunbooleantype errconS) @@ -775,6 +781,9 @@ time and, if successful, takes effect immediately. variables are excluded from the error tests. Note that, in any event, all variables are considered in the convergence tests. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idas.sens_err_con". + .. c:function:: int IDASetSensMaxNonlinIters(void * ida_mem, int maxcorS) @@ -793,6 +802,9 @@ time and, if successful, takes effect immediately. **Notes:** The default value is 3. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idas.sens_max_nonlin_iters". + .. _IDAS.Usage.FSA.user_callable.optional_output: @@ -1429,6 +1441,9 @@ of sensitivity-dependent quadrature equations. **Notes:** By default, ``errconQS`` is set to ``SUNFALSE``. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idas.quad_sens_err_con". + .. warning:: It is illegal to call :c:func:`IDASetQuadSensErrCon` before a call to :c:func:`IDAQuadSensInit`. diff --git a/doc/idas/guide/source/Usage/SIM.rst b/doc/idas/guide/source/Usage/SIM.rst index 55c057b2ce..44f31a427b 100644 --- a/doc/idas/guide/source/Usage/SIM.rst +++ b/doc/idas/guide/source/Usage/SIM.rst @@ -381,6 +381,10 @@ norms). Note that this call must be made after the call to :c:func:`IDAInit`. called. * ``IDA_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.scalar_tolerances". + .. c:function:: int IDASVtolerances(void* ida_mem, sunrealtype reltol, N_Vector abstol) The function :c:func:`IDASVtolerances` specifies scalar relative tolerance and @@ -910,6 +914,8 @@ Main solver optional input functions +--------------------------------------------------------------------+---------------------------------+----------------+ | **Optional input** | **Function name** | **Default** | + +====================================================================+=================================+================+ + | Set IDAS optional inputs from the command line | :c:func:`IDASetFromCommandLine` | | +--------------------------------------------------------------------+---------------------------------+----------------+ | User data | :c:func:`IDASetUserData` | NULL | +--------------------------------------------------------------------+---------------------------------+----------------+ @@ -937,6 +943,36 @@ Main solver optional input functions +--------------------------------------------------------------------+---------------------------------+----------------+ +.. c:function:: int IDASetFromCommandLine(void* ida_mem, const char* idaid, int argc, char* argv[]) + + Passes command-line arguments to IDAS to set options. + + :param ida_mem: pointer to the IDAS memory block. + :param idaid: String to use as prefix for IDAS command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval IDA_SUCCESS: the function exited successfully. + :retval IDA_MEM_NULL: ``ida_mem`` was ``NULL``. + :retval other: error return value from relevant IDAS "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. + These are left unchanged by :c:func:`IDASetFromCommandLine`. + + If the *idaid* argument is ``NULL`` then ``idas.`` will be used for all IDAS command-line + options, e.g., to set the maximum order of accuracy the default command-line option would + be "idaid.max_order". + + IDAS options set via command-line arguments to :c:func:`IDASetFromCommandLine` will + overwrite any previously-set values. + + The supported command-line options are documented within each IDAS "set" routine. + + .. versionadded:: x.y.z + + .. c:function:: int IDASetUserData(void * ida_mem, void * user_data) The function :c:func:`IDASetUserData` attaches a user-defined data pointer to the @@ -982,6 +1018,9 @@ Main solver optional input functions requirements for the internal IDAS memory block and its value cannot be increased past the value set when :c:func:`IDAInit` was called. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_order". + .. c:function:: int IDASetMaxNumSteps(void * ida_mem, long int mxsteps) The function :c:func:`IDASetMaxNumSteps` specifies the maximum number of steps to @@ -999,6 +1038,9 @@ Main solver optional input functions Passing ``mxsteps`` = 0 results in IDAS using the default value (500). Passing ``mxsteps`` < 0 disables the test (not recommended). + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_steps". + .. c:function:: int IDASetInitStep(void * ida_mem, sunrealtype hin) The function :c:func:`IDASetInitStep` specifies the initial step size. @@ -1017,6 +1059,9 @@ Main solver optional input functions :math:`\|h \dot{y} \|_{{\scriptsize WRMS}} = 1/2`, with an added restriction that :math:`|h| \leq .001|t_{\text{out}} - t_0|`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.init_step". + .. c:function:: int IDASetMinStep(void * ida_mem, sunrealtype hmin) The function :c:func:`IDASetMinStep` specifies the minimum absolute value of @@ -1033,6 +1078,10 @@ Main solver optional input functions * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. * ``IDA_ILL_INPUT`` -- ``hmin`` is negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.min_step". + .. versionadded:: 5.2.0 .. c:function:: int IDASetMaxStep(void * ida_mem, sunrealtype hmax) @@ -1053,6 +1102,9 @@ Main solver optional input functions **Notes:** Pass ``hmax = 0`` to obtain the default value :math:`\infty`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_step". + .. c:function:: int IDASetStopTime(void * ida_mem, sunrealtype tstop) The function :c:func:`IDASetStopTime` specifies the value of the independent @@ -1078,6 +1130,9 @@ Main solver optional input functions A stop time not reached before a call to :c:func:`IDAReInit` will remain active but can be disabled by calling :c:func:`IDAClearStopTime`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.stop_time". + .. c:function:: int IDAClearStopTime(void* ida_mem) Disables the stop time set with :c:func:`IDASetStopTime`. @@ -1093,6 +1148,9 @@ Main solver optional input functions The stop time can be re-enabled though a new call to :c:func:`IDASetStopTime`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.clear_stop_time". + .. versionadded:: 6.5.1 .. c:function:: int IDASetMaxErrTestFails(void * ida_mem, int maxnef) @@ -1112,6 +1170,9 @@ Main solver optional input functions **Notes:** The default value is 10. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_err_test_fails". + .. c:function:: int IDASetSuppressAlg(void * ida_mem, sunbooleantype suppressalg) The function :c:func:`IDASetSuppressAlg` indicates whether or not to suppress @@ -1134,6 +1195,9 @@ Main solver optional input functions 1, whereas it is generally *encouraged* for systems of index 2 or more. See pp. 146-147 of :cite:p:`BCP:96` for more on this issue. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.suppress_alg". + .. c:function:: int IDASetId(void * ida_mem, N_Vector id) The function :c:func:`IDASetId` specifies algebraic/differential components in the @@ -1300,6 +1364,10 @@ that updates the matrix using the current :math:`\alpha` as part of the solve. * ``IDA_SUCCESS`` -- The flag value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.delta_cj_lsetup". + .. versionadded:: 5.2.0 .. c:function:: int IDASetLinearSolutionScaling(void * ida_mem, sunbooleantype onoff) @@ -1324,6 +1392,9 @@ that updates the matrix using the current :math:`\alpha` as part of the solve. initialized through a call to :c:func:`IDASetLinearSolver`. By default scaling is enabled with matrix-based linear solvers. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.linear_solution_scaling". + When using matrix-free linear solver modules, the IDALS solver interface requires a function to compute an approximation to the product between the @@ -1414,6 +1485,9 @@ finite-difference approximation, via a call to :c:func:`IDASetIncrementFactor`. linear solver interface has been initialized through a call to :c:func:`IDASetLinearSolver`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.increment_factor". + .. versionadded:: 3.0.0 Replaces the deprecated function ``IDASpilsSetIncrementFactor``. @@ -1534,6 +1608,9 @@ where :math:`\epsilon` is the nonlinear solver tolerance, and the default :c:func:`IDASetLinearSolver`. If ``eplifac`` :math:`= 0.0` is passed, the default value is used. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eps_lin". + .. versionadded:: 3.0.0 Replaces the deprecated function ``IDASpilsSetEpsLin``. @@ -1567,6 +1644,9 @@ where :math:`\epsilon` is the nonlinear solver tolerance, and the default value of ``nrmfac`` was computed using :c:func:`N_VDotProd` i.e., the ``nrmfac < 0`` case. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.ls_norm_factor". + .. _IDAS.Usage.SIM.user_callable.optional_input.nls: @@ -1610,6 +1690,9 @@ nonlinear solver. **Notes:** The default value is 4. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_nonlin_iters". + .. c:function:: int IDASetMaxConvFails(void * ida_mem, int maxncf) @@ -1628,6 +1711,9 @@ nonlinear solver. **Notes:** The default value is 10. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_conv_fails". + .. c:function:: int IDASetNonlinConvCoef(void * ida_mem, sunrealtype nlscoef) @@ -1646,6 +1732,9 @@ nonlinear solver. **Notes:** The default value is 0.33. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.nonlin_conv_coef". + .. c:function:: int IDASetNlsResFn(void * ida_mem, IDAResFn res) @@ -1726,6 +1815,9 @@ to set optional inputs controlling the initial condition calculation. :math:`J^{-1}F(t_0, y, \dot{y})` must be :math:`\leq \mathtt{epiccon}`, where :math:`J` is the system Jacobian. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.nonlin_conv_coef_ic". + .. c:function:: int IDASetMaxNumStepsIC(void * ida_mem, int maxnh) The function :c:func:`IDASetMaxNumStepsIC` specifies the maximum number of steps @@ -1745,6 +1837,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`5`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_steps_ic". + .. c:function:: int IDASetMaxNumJacsIC(void * ida_mem, int maxnj) The function :c:func:`IDASetMaxNumJacsIC` specifies the maximum number of the @@ -1764,6 +1859,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`4`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_jacs_ic". + .. c:function:: int IDASetMaxNumItersIC(void * ida_mem, int maxnit) The function :c:func:`IDASetMaxNumItersIC` specifies the maximum number of Newton @@ -1782,6 +1880,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`10`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_num_iters_ic". + .. c:function:: int IDASetMaxBacksIC(void * ida_mem, int maxbacks) The function :c:func:`IDASetMaxBacksIC` specifies the maximum number of linesearch @@ -1804,6 +1905,9 @@ to set optional inputs controlling the initial condition calculation. the limit ``maxbacks`` applies in the calculation of both the initial state values and the initial sensitivities. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.max_backs_ic". + .. c:function:: int IDASetLineSearchOffIC(void * ida_mem, sunbooleantype lsoff) @@ -1821,7 +1925,10 @@ to set optional inputs controlling the initial condition calculation. **Notes:** - The default value is ``SUNFALSE``. + The default value is ``SUNFALSE``. + + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.linesearch_off_ic". .. c:function:: int IDASetStepToleranceIC(void * ida_mem, int steptol) @@ -1840,6 +1947,9 @@ to set optional inputs controlling the initial condition calculation. **Notes:** The default value is :math:`(\text{unit roundoff})^{2/3}`. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.step_tolerance_ic". + .. _IDAS.Usage.SIM.user_callable.optional_input.step_adapt: @@ -1907,6 +2017,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_fixed_step_bounds". + .. versionadded:: 5.2.0 .. c:function:: int IDASetEtaMax(void* ida_mem, sunrealtype eta_max) @@ -1924,6 +2038,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_max". + .. versionadded:: 5.2.0 .. c:function:: int IDASetEtaMin(void* ida_mem, sunrealtype eta_min) @@ -1944,6 +2062,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_min". + .. versionadded:: 5.2.0 .. c:function:: int IDASetEtaLow(void* ida_mem, sunrealtype eta_low) @@ -1964,6 +2086,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_low". + .. versionadded:: 5.2.0 .. c:function:: int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef) @@ -1984,6 +2110,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_min_err_fail". + .. versionadded:: 5.2.0 .. c:function:: int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf) @@ -2004,6 +2134,10 @@ step size adaptivity. * ``IDA_SUCCESS`` -- The optional value has been successfully set. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.eta_conv_fail". + .. versionadded:: 5.2.0 @@ -2076,6 +2210,9 @@ rootfinding algorithm. first step), IDAS will issue a warning which can be disabled with this optional input function. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.no_inactive_root_warn". + .. _IDAS.Usage.SIM.user_callable.optional_dky: @@ -3876,6 +4013,9 @@ of quadrature equations. **Notes:** By default, ``errconQ`` is set to ``SUNFALSE``. + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.quad_err_con". + .. warning:: It is illegal to call :c:func:`IDASetQuadErrCon` before a call to :c:func:`IDAQuadInit`. @@ -3898,6 +4038,10 @@ quadrature variables. * ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``. * ``IDA_ILL_INPUT`` -- One of the input tolerances was negative. + **Notes:** + This routine will be called by :c:func:`IDASetFromCommandLine` + when using the command-line option "idaid.quad_scalar_tolerances". + .. c:function:: int IDAQuadSVtolerances(void * ida_mem, sunrealtype reltolQ, N_Vector abstolQ) diff --git a/doc/kinsol/guide/source/Usage/index.rst b/doc/kinsol/guide/source/Usage/index.rst index f87f60fd1b..a6e984f6db 100644 --- a/doc/kinsol/guide/source/Usage/index.rst +++ b/doc/kinsol/guide/source/Usage/index.rst @@ -456,6 +456,8 @@ negative, so a test ``retval`` :math:`<0` will catch any error. +========================================================+==================================+==============================+ | **KINSOL main solver** | | | +--------------------------------------------------------+----------------------------------+------------------------------+ + | Set KINSOL optional inputs from the command line | :c:func:`KINSetFromCommandLine` | | + +--------------------------------------------------------+----------------------------------+------------------------------+ | Data for problem-defining function | :c:func:`KINSetUserData` | ``NULL`` | +--------------------------------------------------------+----------------------------------+------------------------------+ | Max. number of nonlinear iterations | :c:func:`KINSetNumMaxIters` | 200 | @@ -519,6 +521,35 @@ negative, so a test ``retval`` :math:`<0` will catch any error. +--------------------------------------------------------+----------------------------------+------------------------------+ +.. c:function:: int KINSetFromCommandLine(void* kin_mem, const char* kinid, int argc, char* argv[]) + + Passes command-line arguments to KINSOL to set options. + + :param kin_mem: pointer to the KINSOL memory block. + :param kinid: String to use as prefix for KINSOL command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :retval KIN_SUCCESS: the function exited successfully. + :retval KIN_MEM_NULL: ``kin_mem`` was ``NULL``. + :retval other: error return value from relevant KINSOL "set" routine. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. + These are left unchanged by :c:func:`KINSetFromCommandLine`. + + If the *kinid* argument is ``NULL`` then ``kinsol.`` will be used for all KINSOL command-line + options, e.g., to set the maximum order of accuracy the default command-line option would + be "kinsol.max_order". + + KINSOL options set via command-line arguments to :c:func:`KINSetFromCommandLine` will + overwrite any previously-set values. + + The supported command-line options are documented within each KINSOL "set" routine. + + .. versionadded:: x.y.z + .. c:function:: int KINSetUserData(void * kin_mem, void * user_data) The function :c:func:`KINSetUserData` specifies the pointer to user-defined @@ -560,6 +591,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value for ``mxiter`` is ``MXITER_DEFAULT`` :math:`=200`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.num_max_iters". + .. c:function:: int KINSetNoInitSetup(void * kin_mem, sunbooleantype noInitSetup) @@ -583,6 +617,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. problems, in which the final preconditioner or Jacobian value from one problem is to be used initially for the next problem. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.no_init_setup". + .. c:function:: int KINSetNoResMon(void * kin_mem, sunbooleantype noNNIResMon) @@ -602,6 +639,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. When using a direct solver, the default value for ``noNNIResMon`` is ``SUNFALSE``, meaning that the nonlinear residual will be monitored. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.no_res_mon". + .. warning:: Residual monitoring is only available for use with matrix-based linear solver modules. @@ -647,6 +687,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. The value of ``msbset`` (see :c:func:`KINSetMaxSetupCalls`) should be a multiple of ``msbsetsub``. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.max_sub_setup_calls". + .. warning:: Residual monitoring is only available for use with matrix-based linear solver modules. @@ -699,6 +742,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. where :math:`\eta_{\text{min}} = 10^{-4}` and :math:`\eta_{\text{max}} = 0.9`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.eta_form". + .. c:function:: int KINSetEtaConstValue(void * kin_mem, sunrealtype eta) @@ -718,6 +764,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. The default value for ``eta`` is :math:`0.1`. The legal values are :math:`0.0 <` ``eta`` :math:`\le 1.0`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.eta_const_value". + .. c:function:: int KINSetEtaParams(void * kin_mem, sunrealtype egamma, sunrealtype ealpha) @@ -740,6 +789,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. :math:`2.0`, respectively. The legal values are :math:`0.0 <` ``egamma`` :math:`\le 1.0` and :math:`1.0<` ``ealpha`` :math:`\le 2.0`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.eta_params". + .. c:function:: int KINSetResMonConstValue(void * kin_mem, sunrealtype omegaconst) @@ -759,6 +811,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. The default value for ``omegaconst`` is :math:`0.9`. The legal values are :math:`0.0 <` ``omegaconst`` :math:`< 1.0`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.res_mon_const_value". + .. c:function:: int KINSetResMonParams(void * kin_mem, sunrealtype omegamin, sunrealtype omegamax) @@ -781,6 +836,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. and :math:`0.9`, respectively. The legal values are :math:`0.0 <` ``omegamin`` :math:`<` ``omegamax`` :math:`< 1.0`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.res_mon_params". + .. warning:: Residual monitoring is only available for use with matrix-based linear solver modules. @@ -805,6 +863,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. positive minimum value, equal to :math:`0.01`*``fnormtol``, is applied to :math:`\epsilon` (see :c:func:`KINSetFuncNormTol` below). + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.no_min_eps". + .. c:function:: int KINSetMaxNewtonStep(void * kin_mem, sunrealtype mxnewtstep) @@ -825,6 +886,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. The default value of ``mxnewtstep`` is :math:`1000\, \| u_0 \|_{D_u}`, where :math:`u_0` is the initial guess. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.max_newton_step". + .. c:function:: int KINSetMaxBetaFails(void * kin_mem, sunrealtype mxnbcf) @@ -844,6 +908,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value of ``mxnbcf`` is ``MXNBCF_DEFAULT`` :math:`=10`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.max_beta_fails". + .. c:function:: int KINSetRelErrFunc(void * kin_mem, sunrealtype relfunc) @@ -866,6 +933,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value for ``relfunc`` is :math:`U` = unit roundoff. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.rel_err_func". + .. c:function:: int KINSetFuncNormTol(void * kin_mem, sunrealtype fnormtol) @@ -886,6 +956,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value for ``fnormtol`` is (unit roundoff) :math:`^{1/3}`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.func_norm_tol". + .. c:function:: int KINSetScaledStepTol(void * kin_mem, sunrealtype scsteptol) @@ -905,6 +978,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value for ``scsteptol`` is (unit roundoff) :math:`^{2/3}`. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.scaled_step_tol". + .. c:function:: int KINSetConstraints(void * kin_mem, N_Vector constraints) @@ -974,6 +1050,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value of ``ret_newest`` is ``SUNFALSE``. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.return_newest". + .. c:function:: int KINSetDamping(void * kin_mem, sunrealtype beta) @@ -1001,6 +1080,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. ``beta`` is extremely small (close to zero), this can lead to an excessively tight tolerance. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.damping". + .. c:function:: int KINSetMAA(void * kin_mem, long int maa) @@ -1026,6 +1108,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. call should be made before the call to KINSetMAA, as the latter uses the value of ``mxiter``. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.m_aa". + .. c:function:: int KINSetDampingAA(void * kin_mem, sunrealtype beta) @@ -1052,6 +1137,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. value provided to :c:func:`KINSetDampingAA` is applied to all iterations and any value provided to :c:func:`KINSetDamping` is ignored. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.damping_aa". + .. c:function:: int KINSetDelayAA(void * kin_mem, long int delay) @@ -1070,6 +1158,9 @@ negative, so a test ``retval`` :math:`<0` will catch any error. **Notes:** The default value of ``delay`` is 0, indicating no delay. + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.delay_aa". + .. c:function:: int KINSetOrthAA(void* kin_mem, int orthaa) @@ -1101,6 +1192,8 @@ negative, so a test ``retval`` :math:`<0` will catch any error. An example of how to use this function can be found in ``examples/kinsol/serial/kinAnalytic_fp.c`` + This routine will be called by :c:func:`KINSetFromCommandLine` + when using the command-line option "kinid.orth_aa". .. _KINSOL.Usage.CC.optional_inputs.optin_ls: @@ -1457,7 +1550,7 @@ functions are described next. .. versionadded:: 6.3.0 -.. c:function:: int KINPrintAllStats(void* cvode_mem, FILE* outfile, SUNOutputFormat fmt) +.. c:function:: int KINPrintAllStats(void* kin_mem, FILE* outfile, SUNOutputFormat fmt) The function :c:func:`KINPrintAllStats` outputs all of the nonlinear solver, linear solver, and other statistics. diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst index 2e61c89673..935f35822a 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_Description.rst @@ -93,6 +93,12 @@ The virtual table structure is defined as The function implementing :c:func:`SUNAdaptController_Reset` + .. c:member:: SUNErrCode (*setfromcommandline)(SUNAdaptController C, const char* Cid, int argc, char* argv[]) + + The function implementing :c:func:`SUNAdaptController_SetFromCommandLine` + + .. versionadded:: x.y.z + .. c:member:: SUNErrCode (*setdefaults)(SUNAdaptController C) The function implementing :c:func:`SUNAdaptController_SetDefaults` @@ -261,6 +267,35 @@ note these requirements below. Additionally, we note the behavior of the base SU :return: :c:type:`SUNErrCode` indicating success or failure. +.. c:function:: SUNErrCode SUNAdaptController_SetFromCommandLine(SUNAdaptController C, const char* Cid, int argc, char* argv[]) + + Passes command-line arguments to SUNAdaptController implementations. + + :param C: the :c:type:`SUNAdaptController` object. + :param Cid: String to use as prefix for command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :return: :c:type:`SUNErrCode` indicating success or failure. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. These + are left unchanged by :c:func:`SUNAdaptController_SetFromCommandLine`. + + If the *Cid* argument is ``NULL`` then an implementation-specific prefix will be used for the + relevant command-line options -- see each implementation for its default prefix value. + When using a combination of SUNAdaptController objects (e.g., within MRIStep, SplittingStep or + ForcingStep), it is recommended that users call :c:func:`SUNAdaptController_SetFromCommandLine` + for each controller using distinct *Cid* inputs, so that each controller can be configured + separately. + + SUNAdaptController options set via command-line arguments to + :c:func:`SUNAdaptController_SetFromCommandLine` will overwrite any previously-set values. + + .. versionadded:: x.y.z + + .. c:function:: SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C) Sets the controller parameters to their default values. @@ -268,6 +303,11 @@ note these requirements below. Additionally, we note the behavior of the base SU :param C: the :c:type:`SUNAdaptController` object. :return: :c:type:`SUNErrCode` indicating success or failure. + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.defaults". + .. c:function:: SUNErrCode SUNAdaptController_Write(SUNAdaptController C, FILE* fptr) @@ -277,6 +317,11 @@ note these requirements below. Additionally, we note the behavior of the base SU :param fptr: the output stream to write the parameters to. :return: :c:type:`SUNErrCode` indicating success or failure. + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.write_parameters". + .. c:function:: SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, sunrealtype bias) @@ -289,6 +334,11 @@ note these requirements below. Additionally, we note the behavior of the base SU the default value for the controller. :return: :c:type:`SUNErrCode` indicating success or failure. + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.error_bias". + .. c:function:: SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, sunrealtype dsm) diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst index 54ba98a836..08f60a9199 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_ImExGus.rst @@ -106,6 +106,12 @@ routines: SUNAdaptController C = SUNAdaptController_ImExGus(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_imexgus". + .. c:function:: SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, sunrealtype k2e, sunrealtype k1i, sunrealtype k2i) This user-callable function provides control over the relevant parameters @@ -124,3 +130,8 @@ routines: .. code-block:: c retval = SUNAdaptController_SetParams_ImExGus(C, 0.4, 0.3, -1.0, 1.0); + + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst index 4a49424222..7eaac23bcc 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst @@ -142,6 +142,12 @@ also provides the following additional user-callable routines: :returns: if successful, a usable :c:type:`SUNAdaptController` object; otherwise it will return ``NULL``. + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_mrihtol". + .. c:function:: SUNErrCode SUNAdaptController_SetParams_MRIHTol(SUNAdaptController C, sunrealtype inner_max_relch, sunrealtype inner_min_tolfac, sunrealtype inner_max_tolfac) @@ -157,6 +163,11 @@ also provides the following additional user-callable routines: :returns: :c:type:`SUNErrCode` indicating success or failure. + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + Usage ----- diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst index a1ff1404d1..4901ebcc32 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_Soderlind.rst @@ -100,6 +100,12 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_Soderlind(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_soderlind". + .. c:function:: SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3, sunrealtype k4, sunrealtype k5) This user-callable function provides control over the relevant parameters @@ -121,6 +127,11 @@ also provides the following additional user-callable routines: /* Specify parameters for Soderlind's H_{0}312 controller */ retval = SUNAdaptController_SetParams_Soderlind(C, 0.25, 0.5, 0.25, -0.75, -0.25); + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + .. c:function:: SUNAdaptController SUNAdaptController_PID(SUNContext sunctx) @@ -138,6 +149,12 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_PID(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_pid". + .. c:function:: SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, sunrealtype k2, sunrealtype k3) This user-callable function provides control over the relevant parameters @@ -156,6 +173,11 @@ also provides the following additional user-callable routines: retval = SUNAdaptController_SetParams_PID(C, 0.58, -0.21, 0.1); + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + .. c:function:: SUNAdaptController SUNAdaptController_PI(SUNContext sunctx) @@ -173,6 +195,13 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_PI(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_pi". + + .. c:function:: SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, sunrealtype k2) This user-callable function provides control over the relevant parameters @@ -190,6 +219,11 @@ also provides the following additional user-callable routines: retval = SUNAdaptController_SetParams_PI(C, 0.8, -0.31); + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + .. c:function:: SUNAdaptController SUNAdaptController_I(SUNContext sunctx) @@ -207,6 +241,13 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_I(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_i". + + .. c:function:: SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) This user-callable function provides control over the relevant parameters @@ -223,6 +264,11 @@ also provides the following additional user-callable routines: retval = SUNAdaptController_SetParams_I(C, 1.0); + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + .. c:function:: SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx) @@ -241,10 +287,17 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_ExpGus(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_expgus". + + .. c:function:: SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) This user-callable function provides control over the relevant parameters - above for the explicit Gustafsson controller, setting :math:`k_3 = k_4 = k_5 = 0`. + above for the explicit Gustafsson controller, setting :math:`k_3 = k_4 = k_5 = 0`. This should be called *before* the time integrator is called to evolve the problem. .. note:: @@ -269,6 +322,11 @@ also provides the following additional user-callable routines: retval = SUNAdaptController_SetParams_ExpGus(C, 0.367, 0.268); + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". + .. c:function:: SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx) @@ -287,6 +345,13 @@ also provides the following additional user-callable routines: SUNAdaptController C = SUNAdaptController_ImpGus(sunctx); + .. note:: + + This SUNAdaptController implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNAdaptController_SetFromCommandLine` + to be "sunadaptcontroller_impgus". + + .. c:function:: SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, sunrealtype k1_hat, sunrealtype k2_hat) This user-callable function provides control over the relevant parameters @@ -314,3 +379,8 @@ also provides the following additional user-callable routines: .. code-block:: c retval = SUNAdaptController_SetParams_ImpGus(C, 0.98, 0.95); + + .. note:: + + This routine will be called by :c:func:`SUNAdaptController_SetFromCommandLine` + when using the command-line option "Cid.params". diff --git a/doc/shared/sunlinsol/SUNLinSol_API.rst b/doc/shared/sunlinsol/SUNLinSol_API.rst index 155ebb571e..b73b1a013c 100644 --- a/doc/shared/sunlinsol/SUNLinSol_API.rst +++ b/doc/shared/sunlinsol/SUNLinSol_API.rst @@ -240,6 +240,35 @@ the functionality for any optional routine should leave the corresponding function pointer ``NULL`` instead of supplying a dummy routine. +.. c:function:: SUNErrCode SUNLinSolSetFromCommandLine(SUNLinearSolver S, const char* LSid, int argc, char* argv[]) + + This *optional* routine allows command-line control over various options within a SUNLinearSolver implementation. + + :param S: the :c:type:`SUNLinearSolver` object. + :param LSid: String to use as prefix for command-line options. + :param argc: Number of command-line options provided to executable. + :param argv: Array of strings containing command-line options provided to executable. + + :return: :c:type:`SUNErrCode` indicating success or failure. + + .. note:: + + The *argc* and *argv* arguments should be those supplied to the user's ``main`` routine. These + are left unchanged by :c:func:`SUNLinSolSetFromCommandLine`. + + If the *LSid* argument is ``NULL`` then an implementation-specific prefix will be used for the + relevant command-line options -- see each implementation for its default prefix value. + When using a combination of SUNLinearSolver objects (e.g., for system and mass matrices within + ARKStep), it is recommended that users call :c:func:`SUNLinSolSetFromCommandLine` + for each controller using distinct *LSid* inputs, so that each solver can be configured + separately. + + SUNLinearSolver options set via command-line arguments to + :c:func:`SUNLinSolSetFromCommandLine` will overwrite any previously-set values. + + .. versionadded:: x.y.z + + .. c:function:: SUNErrCode SUNLinSolSetATimes(SUNLinearSolver LS, void* A_data, SUNATimesFn ATimes) *Required for matrix-free linear solvers* (otherwise optional). @@ -328,6 +357,11 @@ function pointer ``NULL`` instead of supplying a dummy routine. each call to :c:func:`SUNLinSolSolve`. + If supported by the SUNLinearSolver implementation, this routine will be called + by :c:func:`SUNLinSolSetFromCommandLine` when using the command-line option + "LSid.zero_guess". + + .. _SUNLinSol.GetFn: SUNLinearSolver "get" functions diff --git a/doc/shared/sunlinsol/SUNLinSol_KLU.rst b/doc/shared/sunlinsol/SUNLinSol_KLU.rst index c5a9679676..29b8ee5b02 100644 --- a/doc/shared/sunlinsol/SUNLinSol_KLU.rst +++ b/doc/shared/sunlinsol/SUNLinSol_KLU.rst @@ -60,6 +60,10 @@ user-callable routines: SUNDIALS, these will be included within this compatibility check. + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "klu". + .. c:function:: SUNErrCode SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, int reinit_type) @@ -114,6 +118,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.ordering". + .. c:function:: sun_klu_symbolic* SUNLinSol_KLUGetSymbolic(SUNLinearSolver S) diff --git a/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst b/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst index f9c0806c07..0b7459be6b 100644 --- a/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst +++ b/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst @@ -83,6 +83,11 @@ In addition, the module provides the following user-callable routines: the input matrix and vector to determine the linear system size and to assess compatibility with the solver. + **Notes:** + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "magmadense". + .. c:function:: SUNErrCode SUNLinSol_MagmaDense_SetAsync(SUNLinearSolver LS, sunbooleantype onoff) This function can be used to toggle the linear solver between asynchronous @@ -97,6 +102,11 @@ In addition, the module provides the following user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.async". + SUNLinearSolver_MagmaDense Content ----------------------------------- diff --git a/doc/shared/sunlinsol/SUNLinSol_PCG.rst b/doc/shared/sunlinsol/SUNLinSol_PCG.rst index c2e0bad2c4..7f373bf41a 100644 --- a/doc/shared/sunlinsol/SUNLinSol_PCG.rst +++ b/doc/shared/sunlinsol/SUNLinSol_PCG.rst @@ -135,6 +135,11 @@ The module SUNLinSol_PCG provides the following user-callable routines: preconditioning should work appropriately even for packages designed with one-sided preconditioning in mind. + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "pcg". + + .. c:function:: SUNErrCode SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype) This function updates the flag indicating use of preconditioning. @@ -156,6 +161,8 @@ The module SUNLinSol_PCG provides the following user-callable routines: ``SUN_PREC_RIGHT``, or ``SUN_PREC_BOTH`` will enable preconditioning; ``SUN_PREC_NONE`` disables preconditioning. + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.prec_type". .. c:function:: SUNErrCode SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl) @@ -170,6 +177,11 @@ The module SUNLinSol_PCG provides the following user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.maxl". + .. _SUNLinSol.PCG.Description: diff --git a/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst b/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst index 35a676d7ba..e206991bef 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst @@ -79,11 +79,13 @@ user-callable routines: preconditioning options with these solvers, this use mode is not supported and may result in inferior performance. - .. note:: - With ``SUN_PREC_RIGHT`` or ``SUN_PREC_BOTH`` the initial guess must be zero (use :c:func:`SUNLinSolSetZeroGuess` to indicate the initial guess is zero). + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "spbcgs". + .. c:function:: SUNErrCode SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, int pretype) @@ -101,6 +103,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.prec_type". + .. c:function:: SUNErrCode SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl) @@ -114,6 +121,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.maxl". + .. _SUNLinSol.SPBCGS.Description: diff --git a/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst index 86b26fdd29..0c0f447c00 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst @@ -84,6 +84,11 @@ user-callable routines: these packages, this use mode is not supported and may result in inferior performance. + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "spfgmr". + + .. c:function:: SUNErrCode SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype) This function updates the flag indicating use of preconditioning. @@ -107,6 +112,9 @@ user-callable routines: will result in use of ``SUN_PREC_RIGHT``; any other integer input will result in the default (no preconditioning). + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.prec_type". + .. c:function:: SUNErrCode SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, int gstype) @@ -122,6 +130,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.gs_type". + .. c:function:: SUNErrCode SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) @@ -135,6 +148,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.max_restarts". + .. _SUNLinSol.SPFGMR.Description: diff --git a/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst index e35e9ce213..6991da9db2 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst @@ -77,6 +77,9 @@ user-callable routines: with these solvers, this use mode is not supported and may result in inferior performance. + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "spgmr". .. c:function:: SUNErrCode SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, int pretype) @@ -94,6 +97,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.prec_type". + .. c:function:: SUNErrCode SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, int gstype) @@ -109,6 +117,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.gs_type". + .. c:function:: SUNErrCode SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) @@ -122,6 +135,11 @@ user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.max_restarts". + .. _SUNLinSol.SPGMR.Description: diff --git a/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst index 1f4468b9b3..a8c1e4f8d4 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst @@ -78,11 +78,12 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: with these solvers, this use mode is not supported and may result in inferior performance. - .. note:: - With ``SUN_PREC_RIGHT`` or ``SUN_PREC_BOTH`` the initial guess must be zero (use :c:func:`SUNLinSolSetZeroGuess` to indicate the initial guess is zero). + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "sptfqmr". .. c:function:: SUNErrCode SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, int pretype) @@ -101,6 +102,11 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.prec_type". + .. c:function:: SUNErrCode SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl) @@ -114,6 +120,11 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.maxl". + .. _SUNLinSol.SPTFQMR.Description: diff --git a/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst b/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst index 3fae265146..ff8d72e014 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst @@ -72,6 +72,10 @@ The module SUNLinSol_SuperLUMT provides the following user-callable routines: The ``num_threads`` argument is not checked and is passed directly to SuperLU_MT routines. + This SUNLinearSolver implementation sets the default prefix for command-line + arguments processed by :c:func:`SUNLinSolSetFromCommandLine` + to be "superlumt.". + .. c:function:: SUNErrCode SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, int ordering_choice) @@ -95,6 +99,11 @@ The module SUNLinSol_SuperLUMT provides the following user-callable routines: **Return value:** * A :c:type:`SUNErrCode` + **Notes:** + + This routine will be called by :c:func:`SUNLinSolSetFromCommandLine` + when using the command-line option "LSid.ordering". + .. _SUNLinSol.SuperLUMT.Description: diff --git a/examples/arkode/CXX_serial/ark_heat2D_lsrk.cpp b/examples/arkode/CXX_serial/ark_heat2D_lsrk.cpp index f7de7638fe..4ad89f1747 100644 --- a/examples/arkode/CXX_serial/ark_heat2D_lsrk.cpp +++ b/examples/arkode/CXX_serial/ark_heat2D_lsrk.cpp @@ -61,6 +61,7 @@ #include "nvector/nvector_serial.h" // access to the serial N_Vector #include "sunadaptcontroller/sunadaptcontroller_imexgus.h" #include "sunadaptcontroller/sunadaptcontroller_soderlind.h" +#include "sundials/sundials_adaptcontroller.h" // Macros for problem constants #define PI SUN_RCONST(3.141592653589793238462643383279502884197169) @@ -303,6 +304,12 @@ int main(int argc, char* argv[]) case (ARK_ADAPT_IMP_GUS): C = SUNAdaptController_ImpGus(ctx); break; case (ARK_ADAPT_IMEX_GUS): C = SUNAdaptController_ImExGus(ctx); break; } + flag = SUNAdaptController_SetFromCommandLine(C, "sunadaptcontroller", argc, + argv); + if (check_flag(&flag, "SUNAdaptControllerSetFromCommandLine", 1)) + { + return 1; + } flag = ARKodeSetAdaptController(arkode_mem, C); if (check_flag(&flag, "ARKodeSetAdaptController", 1)) { return 1; } } @@ -656,13 +663,6 @@ static int ReadInputs(int* argc, char*** argv, UserData* udata) InputHelp(); return -1; } - // Unknown input - else - { - cerr << "ERROR: Invalid input " << arg << endl; - InputHelp(); - return -1; - } } // Recompute total number of nodes diff --git a/examples/arkode/C_serial/ark_analytic.c b/examples/arkode/C_serial/ark_analytic.c index d226f2a00b..cd88fb3ba0 100644 --- a/examples/arkode/C_serial/ark_analytic.c +++ b/examples/arkode/C_serial/ark_analytic.c @@ -62,7 +62,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype atol); /* Main Program */ -int main(void) +int main(int argc, char* argv[]) { /* general problem parameters */ sunrealtype T0 = SUN_RCONST(0.0); /* initial time */ @@ -130,6 +130,10 @@ int main(void) flag = ARKodeSetLinear(arkode_mem, 0); if (check_flag(&flag, "ARKodeSetLinear", 1)) { return 1; } + /* Override any current settings with command-line options */ + flag = ARKodeSetFromCommandLine(arkode_mem, "", argc, argv); + if (check_flag(&flag, "ARKodeSetFromCommandLine", 1)) { return 1; } + /* Open output stream for results, output comment line */ UFID = fopen("solution.txt", "w"); fprintf(UFID, "# t u\n"); diff --git a/examples/arkode/C_serial/ark_heat1D.c b/examples/arkode/C_serial/ark_heat1D.c index 55280ec256..7369e8010a 100644 --- a/examples/arkode/C_serial/ark_heat1D.c +++ b/examples/arkode/C_serial/ark_heat1D.c @@ -71,7 +71,7 @@ static int Jac(N_Vector v, N_Vector Jv, sunrealtype t, N_Vector y, N_Vector fy, static int check_flag(void* flagvalue, const char* funcname, int opt); /* Main Program */ -int main(void) +int main(int argc, char* argv[]) { /* general problem parameters */ sunrealtype T0 = SUN_RCONST(0.0); /* initial time */ @@ -150,6 +150,12 @@ int main(void) flag = ARKodeSetLinear(arkode_mem, 0); if (check_flag(&flag, "ARKodeSetLinear", 1)) { return 1; } + /* Override any current settings with command-line options */ + flag = ARKodeSetFromCommandLine(arkode_mem, "", argc, argv); + if (check_flag(&flag, "ARKodeSetFromCommandLine", 1)) { return 1; } + flag = SUNLinSolSetFromCommandLine(LS, "", argc, argv); + if (check_flag(&flag, "ARKodeSetFromCommandLine", 1)) { return 1; } + /* output mesh to disk */ FID = fopen("heat_mesh.txt", "w"); for (i = 0; i < N; i++) { fprintf(FID, " %.16" ESYM "\n", udata->dx * i); } diff --git a/examples/arkode/C_serial/ark_kpr_mri.c b/examples/arkode/C_serial/ark_kpr_mri.c index af68b96c0d..8bc6b54594 100644 --- a/examples/arkode/C_serial/ark_kpr_mri.c +++ b/examples/arkode/C_serial/ark_kpr_mri.c @@ -529,6 +529,11 @@ int main(int argc, char* argv[]) retval = ARKodeSetFixedStep(inner_arkode_mem, hf); if (check_retval(&retval, "ARKodeSetFixedStep", 1)) { return 1; } + /* Override any current settings with command-line options -- enforce + the prefix "inner" */ + retval = ARKodeSetFromCommandLine(inner_arkode_mem, "inner", argc, argv); + if (check_retval(&retval, "ARKodeSetFromCommandLine", 1)) { return 1; } + /* Create inner stepper */ retval = ARKodeCreateMRIStepInnerStepper(inner_arkode_mem, &inner_stepper); if (check_retval(&retval, "ARKodeCreateMRIStepInnerStepper", 1)) { return 1; } @@ -679,6 +684,11 @@ int main(int argc, char* argv[]) retval = ARKodeSetFixedStep(arkode_mem, hs); if (check_retval(&retval, "ARKodeSetFixedStep", 1)) { return 1; } + /* Override any current settings with command-line options -- enforce + the prefix "outer" */ + retval = ARKodeSetFromCommandLine(arkode_mem, "outer", argc, argv); + if (check_retval(&retval, "ARKodeSetFromCommandLine", 1)) { return 1; } + /* * Integrate ODE */ diff --git a/examples/cvode/CXX_serial/cv_kpr.cpp b/examples/cvode/CXX_serial/cv_kpr.cpp index 3d36ddaf5c..628be80d9c 100644 --- a/examples/cvode/CXX_serial/cv_kpr.cpp +++ b/examples/cvode/CXX_serial/cv_kpr.cpp @@ -110,6 +110,10 @@ int main(int argc, char* argv[]) flag = CVodeSetUserData(cvode_mem, udata); if (check_flag(flag, "CVodeSetUserData")) { return 1; } + // Override any current settings with command-line options + flag = CVodeSetFromCommandLine(cvode_mem, "", argc, argv); + if (check_flag(flag, "CVodeSetFromCommandLine")) { return 1; } + // Initial time and fist output time sunrealtype tret = ZERO; sunrealtype tout = tret + opts.dtout; diff --git a/examples/cvodes/serial/cvsAnalytic_mels.c b/examples/cvodes/serial/cvsAnalytic_mels.c index 87d89c5459..b660180c6f 100644 --- a/examples/cvodes/serial/cvsAnalytic_mels.c +++ b/examples/cvodes/serial/cvsAnalytic_mels.c @@ -66,7 +66,7 @@ static int check_retval(void* returnvalue, const char* funcname, int opt); static SUNContext sunctx; /* Main Program */ -int main(void) +int main(int argc, char* argv[]) { /* general problem parameters */ sunrealtype T0 = SUN_RCONST(0.0); /* initial time */ @@ -127,6 +127,10 @@ int main(void) retval = CVodeSetLinearSolver(cvode_mem, LS, NULL); if (check_retval(&retval, "CVodeSetLinearSolver", 1)) { return 1; } + /* Override any current settings with command-line options */ + retval = CVodeSetFromCommandLine(cvode_mem, "", argc, argv); + if (check_retval(&retval, "CVodeSetFromCommandLine", 1)) { return (1); } + /* In loop, call CVode, print results, and test for error. Break out of loop when NOUT preset output times have been reached. */ t = T0; diff --git a/examples/ida/serial/idaAnalytic_mels.c b/examples/ida/serial/idaAnalytic_mels.c index 2cd01d06c5..37ee3c54ad 100644 --- a/examples/ida/serial/idaAnalytic_mels.c +++ b/examples/ida/serial/idaAnalytic_mels.c @@ -64,7 +64,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype atol); /* Main Program */ -int main(void) +int main(int argc, char* argv[]) { /* SUNDIALS context object */ SUNContext ctx; @@ -124,6 +124,10 @@ int main(void) retval = IDASetLinearSolver(ida_mem, LS, NULL); if (check_retval(&retval, "IDASetLinearSolver", 1)) { return (1); } + /* Override any current settings with command-line options */ + retval = IDASetFromCommandLine(ida_mem, "", argc, argv); + if (check_retval(&retval, "IDASetFromCommandLine", 1)) { return 1; } + /* In loop, call IDASolve, print results, and test for error. Stops when the final time has been reached. */ t = T0; diff --git a/examples/idas/serial/idasAnalytic_mels.c b/examples/idas/serial/idasAnalytic_mels.c index c15314b9e9..de8ad645d2 100644 --- a/examples/idas/serial/idasAnalytic_mels.c +++ b/examples/idas/serial/idasAnalytic_mels.c @@ -64,7 +64,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype atol); /* Main Program */ -int main(void) +int main(int argc, char* argv[]) { /* SUNDIALS context object */ SUNContext ctx; @@ -124,6 +124,10 @@ int main(void) retval = IDASetLinearSolver(ida_mem, LS, NULL); if (check_retval(&retval, "IDASetLinearSolver", 1)) { return (1); } + /* Override any current settings with command-line options */ + retval = IDASetFromCommandLine(ida_mem, "", argc, argv); + if (check_retval(&retval, "IDASetFromCommandLine", 1)) { return 1; } + /* In loop, call IDASolve, print results, and test for error. Stops when the final time has been reached. */ t = T0; diff --git a/examples/kinsol/serial/kinRoberts_fp.c b/examples/kinsol/serial/kinRoberts_fp.c index 37172c118b..2294549c4f 100644 --- a/examples/kinsol/serial/kinRoberts_fp.c +++ b/examples/kinsol/serial/kinRoberts_fp.c @@ -82,7 +82,7 @@ static int check_ans(N_Vector u, sunrealtype rtol, sunrealtype atol); *-------------------------------------------------------------------- */ -int main(void) +int main(int argc, char* argv[]) { SUNContext sunctx; sunrealtype fnormtol, fnorm; @@ -147,6 +147,11 @@ int main(void) retval = KINSetFuncNormTol(kmem, fnormtol); if (check_retval(&retval, "KINSetFuncNormTol", 1)) { return (1); } + /* Override any current settings with command-line options */ + + retval = KINSetFromCommandLine(kmem, "", argc, argv); + if (check_retval(&retval, "KINSetFromCommandLine", 1)) { return (1); } + /* ------------- * Initial guess * ------------- */ diff --git a/include/arkode/arkode.h b/include/arkode/arkode.h index 5843b6c077..0b4a20eefa 100644 --- a/include/arkode/arkode.h +++ b/include/arkode/arkode.h @@ -214,6 +214,10 @@ typedef enum * Shared API routines * -------------------------- */ +/* Command-line control over ARKODE options */ +SUNDIALS_EXPORT int ARKodeSetFromCommandLine(void* arkode_mem, const char* arkid, + int argc, char* argv[]); + /* Resize and Reset functions */ SUNDIALS_EXPORT int ARKodeResize(void* arkode_mem, N_Vector ynew, sunrealtype hscale, sunrealtype t0, diff --git a/include/cvode/cvode.h b/include/cvode/cvode.h index 8a4baf6387..2faa4e2441 100644 --- a/include/cvode/cvode.h +++ b/include/cvode/cvode.h @@ -116,6 +116,8 @@ SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun); /* Optional input functions */ +SUNDIALS_EXPORT int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, + int argc, char* argv[]); SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints); SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, sunrealtype dgmax_lsetup); diff --git a/include/cvodes/cvodes.h b/include/cvodes/cvodes.h index 551aeee6e6..6b11d36a8b 100644 --- a/include/cvodes/cvodes.h +++ b/include/cvodes/cvodes.h @@ -187,6 +187,8 @@ SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun); /* Optional input functions */ +SUNDIALS_EXPORT int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, + int argc, char* argv[]); SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints); SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, sunrealtype dgmax_lsetup); diff --git a/include/ida/ida.h b/include/ida/ida.h index b8e34a0e7c..ab4d54431d 100644 --- a/include/ida/ida.h +++ b/include/ida/ida.h @@ -114,6 +114,10 @@ SUNDIALS_EXPORT int IDAWFtolerances(void* ida_mem, IDAEwtFn efun); /* Initial condition calculation function */ SUNDIALS_EXPORT int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1); +/* Command-line control over scalar-valued set routines */ +SUNDIALS_EXPORT int IDASetFromCommandLine(void* ida_mem, const char* idaid, + int argc, char* argv[]); + /* Initial condition calculation optional input functions */ SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon); SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void* ida_mem, int maxnh); diff --git a/include/idas/idas.h b/include/idas/idas.h index 7dac9722a1..6e51761c51 100644 --- a/include/idas/idas.h +++ b/include/idas/idas.h @@ -178,6 +178,10 @@ SUNDIALS_EXPORT int IDAWFtolerances(void* ida_mem, IDAEwtFn efun); /* Initial condition calculation function */ SUNDIALS_EXPORT int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1); +/* Command-line control over scalar-valued set routines */ +SUNDIALS_EXPORT int IDASetFromCommandLine(void* ida_mem, const char* idaid, + int argc, char* argv[]); + /* Initial condition calculation optional input functions */ SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon); SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void* ida_mem, int maxnh); diff --git a/include/kinsol/kinsol.h b/include/kinsol/kinsol.h index 638cb665a7..e9eb8c7e39 100644 --- a/include/kinsol/kinsol.h +++ b/include/kinsol/kinsol.h @@ -100,6 +100,8 @@ SUNDIALS_EXPORT int KINSol(void* kinmem, N_Vector uu, int strategy, N_Vector u_scale, N_Vector f_scale); /* Optional input functions */ +SUNDIALS_EXPORT int KINSetFromCommandLine(void* kinmem, const char* kinid, + int argc, char* argv[]); SUNDIALS_EXPORT int KINSetUserData(void* kinmem, void* user_data); SUNDIALS_EXPORT int KINSetDamping(void* kinmem, sunrealtype beta); SUNDIALS_EXPORT int KINSetMAA(void* kinmem, long int maa); diff --git a/include/sunadaptcontroller/sunadaptcontroller_imexgus.h b/include/sunadaptcontroller/sunadaptcontroller_imexgus.h index f9effd653b..394cd82726 100644 --- a/include/sunadaptcontroller/sunadaptcontroller_imexgus.h +++ b/include/sunadaptcontroller/sunadaptcontroller_imexgus.h @@ -51,10 +51,16 @@ typedef struct _SUNAdaptControllerContent_ImExGus* SUNAdaptControllerContent_ImE SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController C, + const char* Cid, + int argc, char* argv[]); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, sunrealtype k1e, sunrealtype k2e, sunrealtype k1i, sunrealtype k2i); + SUNDIALS_EXPORT SUNAdaptController_Type SUNAdaptController_GetType_ImExGus(SUNAdaptController C); @@ -63,6 +69,7 @@ SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, sunrealtype h, int p, sunrealtype dsm, sunrealtype* hnew); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C); diff --git a/include/sunadaptcontroller/sunadaptcontroller_mrihtol.h b/include/sunadaptcontroller/sunadaptcontroller_mrihtol.h index 223c5a5353..1942b4bf70 100644 --- a/include/sunadaptcontroller/sunadaptcontroller_mrihtol.h +++ b/include/sunadaptcontroller/sunadaptcontroller_mrihtol.h @@ -47,36 +47,52 @@ SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_MRIHTol(SUNAdaptController HControl, SUNAdaptController TolControl, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController C, + const char* Cid, + int argc, char* argv[]); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_SetParams_MRIHTol(SUNAdaptController C, sunrealtype inner_max_relch, sunrealtype inner_min_tolfac, sunrealtype inner_max_tolfac); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_GetSlowController_MRIHTol(SUNAdaptController C, SUNAdaptController* Cslow); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_GetFastController_MRIHTol(SUNAdaptController C, SUNAdaptController* Cfast); + SUNDIALS_EXPORT SUNAdaptController_Type SUNAdaptController_GetType_MRIHTol(SUNAdaptController C); + SUNDIALS_EXPORT int SUNAdaptController_EstimateStepTol_MRIHTol( SUNAdaptController C, sunrealtype H, sunrealtype tolfac, int P, sunrealtype DSM, sunrealtype dsm, sunrealtype* Hnew, sunrealtype* tolfacnew); + SUNDIALS_EXPORT int SUNAdaptController_Reset_MRIHTol(SUNAdaptController C); + SUNDIALS_EXPORT int SUNAdaptController_SetDefaults_MRIHTol(SUNAdaptController C); + SUNDIALS_EXPORT int SUNAdaptController_Write_MRIHTol(SUNAdaptController C, FILE* fptr); + SUNDIALS_EXPORT int SUNAdaptController_SetErrorBias_MRIHTol(SUNAdaptController C, sunrealtype bias); + SUNDIALS_EXPORT int SUNAdaptController_UpdateMRIHTol_MRIHTol(SUNAdaptController C, sunrealtype H, sunrealtype tolfac, sunrealtype DSM, sunrealtype dsm); + SUNDIALS_DEPRECATED_EXPORT_MSG( "Work space functions will be removed in version 8.0.0") int SUNAdaptController_Space_MRIHTol(SUNAdaptController C, long int* lenrw, diff --git a/include/sunadaptcontroller/sunadaptcontroller_soderlind.h b/include/sunadaptcontroller/sunadaptcontroller_soderlind.h index 7651de6d78..302ea91baf 100644 --- a/include/sunadaptcontroller/sunadaptcontroller_soderlind.h +++ b/include/sunadaptcontroller/sunadaptcontroller_soderlind.h @@ -56,6 +56,12 @@ typedef struct _SUNAdaptControllerContent_Soderlind* SUNAdaptControllerContent_S SUNDIALS_EXPORT SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController C, + const char* Cid, + int argc, + char* argv[]); + SUNDIALS_EXPORT SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, sunrealtype k1, sunrealtype k2, diff --git a/include/sundials/sundials_adaptcontroller.h b/include/sundials/sundials_adaptcontroller.h index 44eced0bc1..82bf500773 100644 --- a/include/sundials/sundials_adaptcontroller.h +++ b/include/sundials/sundials_adaptcontroller.h @@ -73,6 +73,8 @@ struct _generic_SUNAdaptController_Ops /* OPTIONAL for all SUNAdaptController implementations. */ SUNErrCode (*destroy)(SUNAdaptController C); SUNErrCode (*reset)(SUNAdaptController C); + SUNErrCode (*setfromcommandline)(SUNAdaptController C, const char* Cid, + int argc, char* argv[]); SUNErrCode (*setdefaults)(SUNAdaptController C); SUNErrCode (*write)(SUNAdaptController C, FILE* fptr); SUNErrCode (*seterrorbias)(SUNAdaptController C, sunrealtype bias); @@ -147,6 +149,12 @@ SUNErrCode SUNAdaptController_EstimateStepTol(SUNAdaptController C, SUNDIALS_EXPORT SUNErrCode SUNAdaptController_Reset(SUNAdaptController C); +/* Function to update internal controller parameters from the command line. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetFromCommandLine(SUNAdaptController C, + const char* Cid, int argc, + char* argv[]); + /* Function to set the controller parameters to their default values. */ SUNDIALS_EXPORT SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C); diff --git a/include/sundials/sundials_linearsolver.h b/include/sundials/sundials_linearsolver.h index 43b9dca3d4..48fbdda109 100644 --- a/include/sundials/sundials_linearsolver.h +++ b/include/sundials/sundials_linearsolver.h @@ -118,6 +118,8 @@ struct _generic_SUNLinearSolver_Ops SUNErrCode (*setpreconditioner)(SUNLinearSolver, void*, SUNPSetupFn, SUNPSolveFn); SUNErrCode (*setscalingvectors)(SUNLinearSolver, N_Vector, N_Vector); + SUNErrCode (*setfromcommandline)(SUNLinearSolver, const char* Cid, int argc, + char* argv[]); SUNErrCode (*setzeroguess)(SUNLinearSolver, sunbooleantype); SUNErrCode (*initialize)(SUNLinearSolver); int (*setup)(SUNLinearSolver, SUNMatrix); @@ -168,6 +170,10 @@ SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, N_Vector s2); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetFromCommandLine(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]); + SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess(SUNLinearSolver S, sunbooleantype onoff); diff --git a/include/sunlinsol/sunlinsol_klu.h b/include/sunlinsol/sunlinsol_klu.h index 35591bc398..7c679b90cf 100644 --- a/include/sunlinsol/sunlinsol_klu.h +++ b/include/sunlinsol/sunlinsol_klu.h @@ -131,6 +131,10 @@ SUNDIALS_EXPORT sun_klu_common* SUNLinSol_KLUGetCommon(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_KLU(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_KLU(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_KLU(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_KLU(SUNLinearSolver S, + const char* LSid, + int argc, + char* argv[]); SUNDIALS_EXPORT int SUNLinSolSetup_KLU(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); diff --git a/include/sunlinsol/sunlinsol_magmadense.h b/include/sunlinsol/sunlinsol_magmadense.h index f36ea680cc..1bcfe6125e 100644 --- a/include/sunlinsol/sunlinsol_magmadense.h +++ b/include/sunlinsol/sunlinsol_magmadense.h @@ -65,6 +65,8 @@ SUNDIALS_EXPORT int SUNLinSol_MagmaDense_SetAsync(SUNLinearSolver S, SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_MagmaDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_MagmaDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_MagmaDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_MagmaDense( + SUNLinearSolver S, const char* LSid, int argc, char* argv[]); SUNDIALS_EXPORT int SUNLinSolSetup_MagmaDense(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_MagmaDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, diff --git a/include/sunlinsol/sunlinsol_pcg.h b/include/sunlinsol/sunlinsol_pcg.h index bef14ab107..e68e11b4b8 100644 --- a/include/sunlinsol/sunlinsol_pcg.h +++ b/include/sunlinsol/sunlinsol_pcg.h @@ -87,6 +87,10 @@ SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetFromCommandLine_PCG(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]); + SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, SUNATimesFn ATimes); diff --git a/include/sunlinsol/sunlinsol_spbcgs.h b/include/sunlinsol/sunlinsol_spbcgs.h index dbebee6567..d3513bbd9c 100644 --- a/include/sunlinsol/sunlinsol_spbcgs.h +++ b/include/sunlinsol/sunlinsol_spbcgs.h @@ -83,6 +83,10 @@ SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver S, + const char* LSid, + int argc, + char* argv[]); SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* A_data, SUNATimesFn ATimes); diff --git a/include/sunlinsol/sunlinsol_spfgmr.h b/include/sunlinsol/sunlinsol_spfgmr.h index f9ba1929ad..0da7e7b97e 100644 --- a/include/sunlinsol/sunlinsol_spfgmr.h +++ b/include/sunlinsol/sunlinsol_spfgmr.h @@ -84,6 +84,10 @@ typedef struct _SUNLinearSolverContent_SPFGMR* SUNLinearSolverContent_SPFGMR; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver S, + const char* LSid, + int argc, + char* argv[]); SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, diff --git a/include/sunlinsol/sunlinsol_spgmr.h b/include/sunlinsol/sunlinsol_spgmr.h index 827afb0055..e0a54648de 100644 --- a/include/sunlinsol/sunlinsol_spgmr.h +++ b/include/sunlinsol/sunlinsol_spgmr.h @@ -93,6 +93,10 @@ SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver S, + const char* LSid, + int argc, + char* argv[]); SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data, SUNATimesFn ATimes); diff --git a/include/sunlinsol/sunlinsol_sptfqmr.h b/include/sunlinsol/sunlinsol_sptfqmr.h index 437874fd15..59eec3ceb1 100644 --- a/include/sunlinsol/sunlinsol_sptfqmr.h +++ b/include/sunlinsol/sunlinsol_sptfqmr.h @@ -85,6 +85,10 @@ SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl) SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver S, + const char* LSid, + int argc, + char* argv[]); SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* A_data, SUNATimesFn ATimes); diff --git a/include/sunlinsol/sunlinsol_superlumt.h b/include/sunlinsol/sunlinsol_superlumt.h index 4bdb08ef04..42220dff6c 100644 --- a/include/sunlinsol/sunlinsol_superlumt.h +++ b/include/sunlinsol/sunlinsol_superlumt.h @@ -95,6 +95,8 @@ typedef struct _SUNLinearSolverContent_SuperLUMT* SUNLinearSolverContent_SuperLU SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, SUNMatrix A, int num_threads, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetFromCommandLine_SuperLUMT( + SUNLinearSolver S, const char* LSid, int argc, char* argv[]); SUNDIALS_EXPORT SUNErrCode SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, int ordering_choice); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUMT(SUNLinearSolver S); diff --git a/src/arkode/CMakeLists.txt b/src/arkode/CMakeLists.txt index 3e3634f7b1..1a55755ef2 100644 --- a/src/arkode/CMakeLists.txt +++ b/src/arkode/CMakeLists.txt @@ -27,6 +27,7 @@ set(arkode_SOURCES arkode_butcher_dirk.c arkode_butcher_erk.c arkode_butcher.c + arkode_cli.c arkode_erkstep_io.c arkode_erkstep.c arkode_forcingstep.c diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index 957d99f904..a6727e86f2 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -1545,6 +1545,7 @@ ARKodeMem arkCreate(SUNContext sunctx) ark_mem->step_setstagepredictfn = NULL; ark_mem->step_getnumrhsevals = NULL; ark_mem->step_setstepdirection = NULL; + ark_mem->step_setfromcommandline = NULL; ark_mem->step_getnumlinsolvsetups = NULL; ark_mem->step_setadaptcontroller = NULL; ark_mem->step_getestlocalerrors = NULL; diff --git a/src/arkode/arkode_arkstep.c b/src/arkode/arkode_arkstep.c index 0093728575..b61638c5ac 100644 --- a/src/arkode/arkode_arkstep.c +++ b/src/arkode/arkode_arkstep.c @@ -105,6 +105,7 @@ void* ARKStepCreate(ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0, N_Vector y0, ark_mem->step_printmem = arkStep_PrintMem; ark_mem->step_setdefaults = arkStep_SetDefaults; ark_mem->step_computestate = arkStep_ComputeState; + ark_mem->step_setfromcommandline = arkStep_SetFromCommandLine; ark_mem->step_setrelaxfn = arkStep_SetRelaxFn; ark_mem->step_setorder = arkStep_SetOrder; ark_mem->step_setnonlinearsolver = arkStep_SetNonlinearSolver; diff --git a/src/arkode/arkode_arkstep_impl.h b/src/arkode/arkode_arkstep_impl.h index 9dcc375bbf..23a40b0798 100644 --- a/src/arkode/arkode_arkstep_impl.h +++ b/src/arkode/arkode_arkstep_impl.h @@ -190,6 +190,8 @@ int arkStep_GetGammas(ARKodeMem ark_mem, sunrealtype* gamma, sunrealtype* gamrat int arkStep_FullRHS(ARKodeMem ark_mem, sunrealtype t, N_Vector y, N_Vector f, int mode); int arkStep_TakeStep_Z(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); +int arkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used); int arkStep_SetUserData(ARKodeMem ark_mem, void* user_data); int arkStep_SetDefaults(ARKodeMem ark_mem); int arkStep_SetOrder(ARKodeMem ark_mem, int ord); diff --git a/src/arkode/arkode_arkstep_io.c b/src/arkode/arkode_arkstep_io.c index 5b382fc949..ad707655f6 100644 --- a/src/arkode/arkode_arkstep_io.c +++ b/src/arkode/arkode_arkstep_io.c @@ -25,6 +25,7 @@ #include #include "arkode_arkstep_impl.h" +#include "sundials_cli.h" /*=============================================================== Exported optional input functions. @@ -628,6 +629,63 @@ int ARKStepGetTimestepperStats(void* arkode_mem, long int* expsteps, Private functions attached to ARKODE ===============================================================*/ +/*--------------------------------------------------------------- + arkStep_SetFromCommandLine: + + Provides command-line control over ARKStep-specific "set" routines. + ---------------------------------------------------------------*/ +int arkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used) +{ + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyTwoCharPair twochar_pairs[] = { + {"table_names", ARKStepSetTableName}}; + static const int num_twochar_keys = sizeof(twochar_pairs) / + sizeof(*twochar_pairs); + + static struct sunKeyActionPair action_pairs[] = {{"set_explicit", + ARKStepSetExplicit}, + {"set_implicit", + ARKStepSetImplicit}, + {"set_imex", ARKStepSetImEx}}; + static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + + /* check all "twochar" command-line options */ + int j, retval; + for (j = 0; j < num_twochar_keys; j++) + { + retval = sunCheckAndSetTwoCharArg((void*)ark_mem, i, argv, offset, + twochar_pairs[j].key, + twochar_pairs[j].set, arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + twochar_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg((void*)ark_mem, i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + return (ARK_SUCCESS); +} + /*--------------------------------------------------------------- arkStep_SetRelaxFn: diff --git a/src/arkode/arkode_cli.c b/src/arkode/arkode_cli.c new file mode 100644 index 0000000000..97fa64e06d --- /dev/null +++ b/src/arkode/arkode_cli.c @@ -0,0 +1,318 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to ARKODE. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "arkode/arkode.h" +#include "arkode/arkode_ls.h" +#include "arkode_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + ARKodeSetFromCommandLine: + + Parses the command line to control scalar-valued ARKODE options. + ---------------------------------------------------------------*/ + +int ARKodeSetFromCommandLine(void* arkode_mem, const char* arkid, int argc, + char* argv[]) +{ + ARKodeMem ark_mem; + if (arkode_mem == NULL) + { + arkProcessError(NULL, ARK_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_ARK_NO_MEM); + return (ARK_MEM_NULL); + } + ark_mem = (ARKodeMem)arkode_mem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = + {{"order", ARKodeSetOrder}, + {"interpolant_degree", ARKodeSetInterpolantDegree}, + {"linear", ARKodeSetLinear}, + {"autonomous", ARKodeSetAutonomous}, + {"deduce_implicit_rhs", ARKodeSetDeduceImplicitRhs}, + {"lsetup_frequency", ARKodeSetLSetupFrequency}, + {"predictor_method", ARKodeSetPredictorMethod}, + {"max_nonlin_iters", ARKodeSetMaxNonlinIters}, + {"max_hnil_warns", ARKodeSetMaxHnilWarns}, + {"interpolate_stop_time", ARKodeSetInterpolateStopTime}, + {"max_num_constr_fails", ARKodeSetMaxNumConstrFails}, + {"adaptivity_adjustment", ARKodeSetAdaptivityAdjustment}, + {"small_num_efails", ARKodeSetSmallNumEFails}, + {"max_err_test_fails", ARKodeSetMaxErrTestFails}, + {"max_conv_fails", ARKodeSetMaxConvFails}, + {"linear_solution_scaling", ARKodeSetLinearSolutionScaling}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = {{"max_num_steps", + ARKodeSetMaxNumSteps}, + {"jac_eval_frequency", + ARKodeSetJacEvalFrequency}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"nonlin_crdown", ARKodeSetNonlinCRDown}, + {"nonlin_rdiv", ARKodeSetNonlinRDiv}, + {"delta_gamma_max", ARKodeSetDeltaGammaMax}, + {"nonlin_conv_coef", ARKodeSetNonlinConvCoef}, + {"init_step", ARKodeSetInitStep}, + {"min_step", ARKodeSetMinStep}, + {"max_step", ARKodeSetMaxStep}, + {"stop_time", ARKodeSetStopTime}, + {"fixed_step", ARKodeSetFixedStep}, + {"step_direction", ARKodeSetStepDirection}, + {"cfl_fraction", ARKodeSetCFLFraction}, + {"safety_factor", ARKodeSetSafetyFactor}, + {"error_bias", ARKodeSetErrorBias}, + {"max_growth", ARKodeSetMaxGrowth}, + {"min_reduction", ARKodeSetMinReduction}, + {"max_first_growth", ARKodeSetMaxFirstGrowth}, + {"max_efail_growth", ARKodeSetMaxEFailGrowth}, + {"max_cfail_growth", ARKodeSetMaxCFailGrowth}, + {"eps_lin", ARKodeSetEpsLin}, + {"mass_eps_lin", ARKodeSetMassEpsLin}, + {"ls_norm_factor", ARKodeSetLSNormFactor}, + {"mass_ls_norm_factor", ARKodeSetMassLSNormFactor}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = {{"scalar_tolerances", + ARKodeSStolerances}, + {"fixed_step_bounds", + ARKodeSetFixedStepBounds}}; + static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + + static struct sunKeyActionPair action_pairs[] = + {{"nonlinear", ARKodeSetNonlinear}, + {"clear_stop_time", ARKodeClearStopTime}, + {"no_inactive_root_warn", ARKodeSetNoInactiveRootWarn}, + {"reset_accumulated_error", ARKodeResetAccumulatedError}}; + static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + + int i, j, retval; + sunbooleantype write_parameters = SUNFALSE; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if arkid is supplied, skip command-line arguments that do not begin with arkid; + else, skip command-line arguments that do not begin with "arkode." */ + size_t offset; + if (strlen(arkid) > 0) + { + if (strncmp(argv[i], arkid, strlen(arkid)) != 0) { continue; } + offset = strlen(arkid) + 1; + } + else + { + static const char* prefix = "arkode."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(arkode_mem, &i, argv, offset, + int_pairs[j].key, int_pairs[j].set, + &arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(arkode_mem, &i, argv, offset, + long_pairs[j].key, long_pairs[j].set, + &arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(arkode_mem, &i, argv, offset, + real_pairs[j].key, real_pairs[j].set, + &arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(arkode_mem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg(arkode_mem, &i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + &arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /*** handle all remaining command-line options ***/ + + if (strcmp(argv[i] + offset, "interpolant_type") == 0) + { + i++; + retval = ARK_ILL_INPUT; + if (strcmp(argv[i], "ARK_INTERP_HERMITE") == 0) + { + retval = ARKodeSetInterpolantType(arkode_mem, ARK_INTERP_HERMITE); + } + else if (strcmp(argv[i], "ARK_INTERP_LAGRANGE") == 0) + { + retval = ARKodeSetInterpolantType(arkode_mem, ARK_INTERP_LAGRANGE); + } + else if (strcmp(argv[i], "ARK_INTERP_NONE") == 0) + { + retval = ARKodeSetInterpolantType(arkode_mem, ARK_INTERP_NONE); + } + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s %s", + argv[i - 1], argv[i]); + return retval; + } + arg_used = SUNTRUE; + continue; + } + + if (strcmp(argv[i] + offset, "accum_error_type") == 0) + { + i++; + retval = ARK_ILL_INPUT; + if (strcmp(argv[i], "ARK_ACCUMERROR_NONE") == 0) + { + retval = ARKodeSetAccumulatedErrorType(arkode_mem, ARK_ACCUMERROR_NONE); + } + else if (strcmp(argv[i], "ARK_ACCUMERROR_MAX") == 0) + { + retval = ARKodeSetAccumulatedErrorType(arkode_mem, ARK_ACCUMERROR_MAX); + } + else if (strcmp(argv[i], "ARK_ACCUMERROR_SUM") == 0) + { + retval = ARKodeSetAccumulatedErrorType(arkode_mem, ARK_ACCUMERROR_SUM); + } + else if (strcmp(argv[i], "ARK_ACCUMERROR_AVG") == 0) + { + retval = ARKodeSetAccumulatedErrorType(arkode_mem, ARK_ACCUMERROR_AVG); + } + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s %s", + argv[i - 1], argv[i]); + return retval; + } + arg_used = SUNTRUE; + continue; + } + + if (strcmp(argv[i] + offset, "write_parameters") == 0) + { + write_parameters = SUNTRUE; + arg_used = SUNTRUE; + continue; + } + + /* Call stepper-specific SetFromCommandLine routine (if supplied) to + process this command-line argument */ + if (ark_mem->step_setfromcommandline) + { + retval = ark_mem->step_setfromcommandline(ark_mem, &i, argv, offset, + &arg_used); + if (retval != ARK_SUCCESS) { return retval; } + if (arg_used) { continue; } + } + + /* warn for uninterpreted arkid.X arguments */ + arkProcessError(ark_mem, ARK_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); + } + + /* Call ARKodeWriteParameters (if requested) now that all + command-line options have been set -- WARNING: this knows + nothing about MPI, so it could be redundantly written by all + processes if requested. */ + if (write_parameters) + { + retval = ARKodeWriteParameters(arkode_mem, stdout); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error writing parameters to stdout"); + return retval; + } + } + + return (ARK_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/arkode/arkode_erkstep.c b/src/arkode/arkode_erkstep.c index ab2f150b63..1ea4d2e916 100644 --- a/src/arkode/arkode_erkstep.c +++ b/src/arkode/arkode_erkstep.c @@ -89,6 +89,7 @@ void* ERKStepCreate(ARKRhsFn f, sunrealtype t0, N_Vector y0, SUNContext sunctx) ark_mem->step_resize = erkStep_Resize; ark_mem->step_free = erkStep_Free; ark_mem->step_printmem = erkStep_PrintMem; + ark_mem->step_setfromcommandline = erkStep_SetFromCommandLine; ark_mem->step_setdefaults = erkStep_SetDefaults; ark_mem->step_setrelaxfn = erkStep_SetRelaxFn; ark_mem->step_setorder = erkStep_SetOrder; diff --git a/src/arkode/arkode_erkstep_impl.h b/src/arkode/arkode_erkstep_impl.h index 8c6de3b7d4..7cae0be9d1 100644 --- a/src/arkode/arkode_erkstep_impl.h +++ b/src/arkode/arkode_erkstep_impl.h @@ -81,6 +81,8 @@ int erkStep_Init(ARKodeMem ark_mem, sunrealtype tout, int init_type); int erkStep_FullRHS(ARKodeMem ark_mem, sunrealtype t, N_Vector y, N_Vector f, int mode); int erkStep_TakeStep(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); +int erkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used); int erkStep_SetDefaults(ARKodeMem ark_mem); int erkStep_SetOrder(ARKodeMem ark_mem, int ord); int erkStep_PrintAllStats(ARKodeMem ark_mem, FILE* outfile, SUNOutputFormat fmt); diff --git a/src/arkode/arkode_erkstep_io.c b/src/arkode/arkode_erkstep_io.c index 1edda14763..b777769817 100644 --- a/src/arkode/arkode_erkstep_io.c +++ b/src/arkode/arkode_erkstep_io.c @@ -25,6 +25,7 @@ #include #include "arkode_erkstep_impl.h" +#include "sundials_cli.h" /*=============================================================== Exported optional input functions. @@ -255,6 +256,39 @@ int ERKStepGetTimestepperStats(void* arkode_mem, long int* expsteps, Private functions attached to ARKODE ===============================================================*/ +/*--------------------------------------------------------------- + erkStep_SetFromCommandLine: + + Provides command-line control over ERKStep-specific "set" routines. + ---------------------------------------------------------------*/ +int erkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used) +{ + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyCharPair char_pairs[] = { + {"table_name", ERKStepSetTableName}}; + static const int num_char_keys = sizeof(char_pairs) / sizeof(*char_pairs); + + /* check all "char" command-line options */ + int j, retval; + for (j = 0; j < num_char_keys; j++) + { + retval = sunCheckAndSetCharArg((void*)ark_mem, i, argv, offset, + char_pairs[j].key, char_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + char_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + return (ARK_SUCCESS); +} + /*--------------------------------------------------------------- erkStep_SetRelaxFn: diff --git a/src/arkode/arkode_impl.h b/src/arkode/arkode_impl.h index 4ef09d44c4..6dca949bfc 100644 --- a/src/arkode/arkode_impl.h +++ b/src/arkode/arkode_impl.h @@ -224,6 +224,9 @@ typedef int (*ARKTimestepGetNumRhsEvals)(ARKodeMem ark_mem, int partition_index, long int* num_rhs_evals); typedef int (*ARKTimestepSetStepDirection)(ARKodeMem ark_mem, sunrealtype stepdir); +typedef int (*ARKTimestepSetFromCommandLine)(ARKodeMem ark_mem, int* i, + char* argv[], const size_t offset, + sunbooleantype* arg_used); /* time stepper interface functions -- temporal adaptivity */ typedef int (*ARKTimestepGetEstLocalErrors)(ARKodeMem ark_mem, N_Vector ele); @@ -414,6 +417,7 @@ struct ARKodeMemRec ARKTimestepSetOrder step_setorder; ARKTimestepGetNumRhsEvals step_getnumrhsevals; ARKTimestepSetStepDirection step_setstepdirection; + ARKTimestepSetFromCommandLine step_setfromcommandline; /* Time stepper module -- temporal adaptivity */ sunbooleantype step_supports_adaptive; diff --git a/src/arkode/arkode_io.c b/src/arkode/arkode_io.c index de8ecb128f..76de15ea77 100644 --- a/src/arkode/arkode_io.c +++ b/src/arkode/arkode_io.c @@ -12,10 +12,7 @@ * SUNDIALS Copyright End *--------------------------------------------------------------- * This is the implementation file for the optional input and - * output functions for the ARKODE infrastructure; these routines - * should not be called directly by the user; instead they are - * provided as utility routines for ARKODE time-step modules - * to use. + * output functions for the ARKODE infrastructure. *--------------------------------------------------------------*/ #include @@ -1390,7 +1387,7 @@ int ARKodeSetNoInactiveRootWarn(void* arkode_mem) if (ark_mem->root_mem == NULL) { arkProcessError(ark_mem, ARK_MEM_NULL, __LINE__, __func__, __FILE__, - MSG_ARK_NO_MEM); + MSG_ARK_NO_ROOT); return (ARK_MEM_NULL); } ark_root_mem = (ARKodeRootMem)ark_mem->root_mem; diff --git a/src/arkode/arkode_lsrkstep.c b/src/arkode/arkode_lsrkstep.c index d86af26b87..01519c0543 100644 --- a/src/arkode/arkode_lsrkstep.c +++ b/src/arkode/arkode_lsrkstep.c @@ -166,18 +166,19 @@ void* lsrkStep_Create_Commons(ARKRhsFn rhs, sunrealtype t0, N_Vector y0, } /* Attach step_mem structure and function pointers to ark_mem */ - ark_mem->step_init = lsrkStep_Init; - ark_mem->step_fullrhs = lsrkStep_FullRHS; - ark_mem->step = lsrkStep_TakeStepRKC; - ark_mem->step_printallstats = lsrkStep_PrintAllStats; - ark_mem->step_writeparameters = lsrkStep_WriteParameters; - ark_mem->step_free = lsrkStep_Free; - ark_mem->step_printmem = lsrkStep_PrintMem; - ark_mem->step_setdefaults = lsrkStep_SetDefaults; - ark_mem->step_getnumrhsevals = lsrkStep_GetNumRhsEvals; - ark_mem->step_getestlocalerrors = lsrkStep_GetEstLocalErrors; - ark_mem->step_mem = (void*)step_mem; - ark_mem->step_supports_adaptive = SUNTRUE; + ark_mem->step_init = lsrkStep_Init; + ark_mem->step_fullrhs = lsrkStep_FullRHS; + ark_mem->step = lsrkStep_TakeStepRKC; + ark_mem->step_printallstats = lsrkStep_PrintAllStats; + ark_mem->step_writeparameters = lsrkStep_WriteParameters; + ark_mem->step_free = lsrkStep_Free; + ark_mem->step_printmem = lsrkStep_PrintMem; + ark_mem->step_setfromcommandline = lsrkStep_SetFromCommandLine; + ark_mem->step_setdefaults = lsrkStep_SetDefaults; + ark_mem->step_getnumrhsevals = lsrkStep_GetNumRhsEvals; + ark_mem->step_getestlocalerrors = lsrkStep_GetEstLocalErrors; + ark_mem->step_mem = (void*)step_mem; + ark_mem->step_supports_adaptive = SUNTRUE; /* Set default values for optional inputs */ retval = lsrkStep_SetDefaults((void*)ark_mem); diff --git a/src/arkode/arkode_lsrkstep_impl.h b/src/arkode/arkode_lsrkstep_impl.h index 98dba553be..d0866dc5bb 100644 --- a/src/arkode/arkode_lsrkstep_impl.h +++ b/src/arkode/arkode_lsrkstep_impl.h @@ -186,6 +186,8 @@ int lsrkStep_TakeStepSSPs3(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr int lsrkStep_TakeStepSSP43(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); int lsrkStep_TakeStepSSP104(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); +int lsrkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used); int lsrkStep_SetDefaults(ARKodeMem ark_mem); int lsrkStep_PrintAllStats(ARKodeMem ark_mem, FILE* outfile, SUNOutputFormat fmt); int lsrkStep_WriteParameters(ARKodeMem ark_mem, FILE* fp); diff --git a/src/arkode/arkode_lsrkstep_io.c b/src/arkode/arkode_lsrkstep_io.c index 4ae0d494fa..c096f0002e 100644 --- a/src/arkode/arkode_lsrkstep_io.c +++ b/src/arkode/arkode_lsrkstep_io.c @@ -22,6 +22,7 @@ #include #include "arkode_lsrkstep_impl.h" +#include "sundials_cli.h" /*=============================================================== Exported optional input functions. @@ -264,10 +265,10 @@ int LSRKStepSetDomEigFrequency(void* arkode_mem, long int nsteps) /*--------------------------------------------------------------- LSRKStepSetMaxNumStages sets the maximum number of stages allowed. - If the combination of the maximum number of stages and the current - time step size in the LSRKStep module does not allow for a stable - step, the step routine returns to ARKODE for an updated (refined) - step size. The number of such returns is tracked in a counter, + If the combination of the maximum number of stages and the current + time step size in the LSRKStep module does not allow for a stable + step, the step routine returns to ARKODE for an updated (refined) + step size. The number of such returns is tracked in a counter, which can be accessed using ARKodeGetNumExpSteps. ---------------------------------------------------------------*/ int LSRKStepSetMaxNumStages(void* arkode_mem, int stage_max_limit) @@ -385,8 +386,8 @@ int LSRKStepSetNumSSPStages(void* arkode_mem, int num_of_stages) break; case ARKODE_LSRK_SSP_S_3: - /* The SSP3 method differs significantly when s = 4. Therefore, the case - where num_of_stages = 4 is considered separately to avoid unnecessary + /* The SSP3 method differs significantly when s = 4. Therefore, the case + where num_of_stages = 4 is considered separately to avoid unnecessary boolean checks and improve computational efficiency. */ /* We check that num_of_stages is a perfect square. Note the call to sqrt @@ -491,6 +492,102 @@ int LSRKStepGetMaxNumStages(void* arkode_mem, int* stage_max) Private functions attached to ARKODE ===============================================================*/ +/*--------------------------------------------------------------- + lsrkStep_SetFromCommandLine: + + Provides command-line control over LSRKStep-specific "set" routines. + ---------------------------------------------------------------*/ +int lsrkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used) +{ + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyCharPair char_pairs[] = {{"sts_method", + LSRKStepSetSTSMethodByName}, + {"ssp_method", + LSRKStepSetSSPMethodByName}}; + static const int num_char_keys = sizeof(char_pairs) / sizeof(*char_pairs); + + static struct sunKeyLongPair long_pairs[] = { + {"dom_eig_frequency", LSRKStepSetDomEigFrequency}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyIntPair int_pairs[] = {{"max_num_stages", + LSRKStepSetMaxNumStages}, + {"num_ssp_stages", + LSRKStepSetNumSSPStages}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyRealPair real_pairs[] = { + {"dom_eig_safety_factor", LSRKStepSetDomEigSafetyFactor}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + /* check all "char" command-line options */ + int j, retval; + for (j = 0; j < num_char_keys; j++) + { + retval = sunCheckAndSetCharArg((void*)ark_mem, i, argv, offset, + char_pairs[j].key, char_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + char_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + /* check all "long int" command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg((void*)ark_mem, i, argv, offset, + long_pairs[j].key, long_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg((void*)ark_mem, i, argv, offset, + int_pairs[j].key, int_pairs[j].set, arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + /* check all "real" command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg((void*)ark_mem, i, argv, offset, + real_pairs[j].key, real_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + return (ARK_SUCCESS); +} + /*--------------------------------------------------------------- lsrkStep_SetDefaults: diff --git a/src/arkode/arkode_mristep.c b/src/arkode/arkode_mristep.c index 3eb4a3e72d..dde5ebda17 100644 --- a/src/arkode/arkode_mristep.c +++ b/src/arkode/arkode_mristep.c @@ -110,6 +110,7 @@ void* MRIStepCreate(ARKRhsFn fse, ARKRhsFn fsi, sunrealtype t0, N_Vector y0, ark_mem->step_printmem = mriStep_PrintMem; ark_mem->step_setdefaults = mriStep_SetDefaults; ark_mem->step_computestate = mriStep_ComputeState; + ark_mem->step_setfromcommandline = mriStep_SetFromCommandLine; ark_mem->step_setorder = mriStep_SetOrder; ark_mem->step_setnonlinearsolver = mriStep_SetNonlinearSolver; ark_mem->step_setlinear = mriStep_SetLinear; diff --git a/src/arkode/arkode_mristep_impl.h b/src/arkode/arkode_mristep_impl.h index 3385ddae2b..7eeae7da4a 100644 --- a/src/arkode/arkode_mristep_impl.h +++ b/src/arkode/arkode_mristep_impl.h @@ -230,6 +230,8 @@ int mriStep_TakeStepMRIGARK(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); int mriStep_TakeStepMRISR(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); int mriStep_TakeStepMERK(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); +int mriStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used); int mriStep_SetAdaptController(ARKodeMem ark_mem, SUNAdaptController C); int mriStep_SetUserData(ARKodeMem ark_mem, void* user_data); int mriStep_SetDefaults(ARKodeMem ark_mem); diff --git a/src/arkode/arkode_mristep_io.c b/src/arkode/arkode_mristep_io.c index d272508c7a..09b1daa0e6 100644 --- a/src/arkode/arkode_mristep_io.c +++ b/src/arkode/arkode_mristep_io.c @@ -22,6 +22,7 @@ #include #include "arkode_mristep_impl.h" +#include "sundials_cli.h" /*=============================================================== Exported optional input functions. @@ -248,6 +249,46 @@ int MRIStepGetNumInnerStepperFails(void* arkode_mem, long int* inner_fails) Private functions attached to ARKODE ===============================================================*/ +/*--------------------------------------------------------------- + mriStep_SetFromCommandLine: + + Provides command-line control over MRIStep-specific "set" routines. + ---------------------------------------------------------------*/ +int mriStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used) +{ + /* The only MRIStep-specific "Set" routine takes a custom MRIStepCoupling + table; however, these may be specified by name, so here we'll support + a command-line argument to specify the MRIStepCoupling table name, + create the table with that name, attach it to MRIStep (who copies its + values), and then free the table. */ + if (strcmp(argv[*i] + offset, "mristep_coupling_table") == 0) + { + (*i)++; + MRIStepCoupling Coupling = MRIStepCoupling_LoadTableByName(argv[*i]); + if (Coupling == NULL) + { + arkProcessError(ark_mem, ARK_ILL_INPUT, __LINE__, __func__, + __FILE__, "error setting command-line argument %s %s (invalid table name)", + argv[(*i) - 1], argv[*i]); + return ARK_ILL_INPUT; + } + int retval = MRIStepSetCoupling(ark_mem, Coupling); + MRIStepCoupling_Free(Coupling); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, + __FILE__, "error setting command-line argument %s %s (SetCoupling failed)", + argv[(*i) - 1], argv[*i]); + return retval; + } + *arg_used = SUNTRUE; + return ARK_SUCCESS; + } + + return ARK_SUCCESS; +} + /*--------------------------------------------------------------- mriStep_SetAdaptController: diff --git a/src/arkode/arkode_sprkstep.c b/src/arkode/arkode_sprkstep.c index b81728f976..84a941191b 100644 --- a/src/arkode/arkode_sprkstep.c +++ b/src/arkode/arkode_sprkstep.c @@ -108,17 +108,18 @@ void* SPRKStepCreate(ARKRhsFn f1, ARKRhsFn f2, sunrealtype t0, N_Vector y0, N_VConst(ZERO, step_mem->yerr); } else { step_mem->yerr = NULL; } - ark_mem->step_init = sprkStep_Init; - ark_mem->step_fullrhs = sprkStep_FullRHS; - ark_mem->step = sprkStep_TakeStep; - ark_mem->step_printallstats = sprkStep_PrintAllStats; - ark_mem->step_writeparameters = sprkStep_WriteParameters; - ark_mem->step_resize = sprkStep_Resize; - ark_mem->step_free = sprkStep_Free; - ark_mem->step_setdefaults = sprkStep_SetDefaults; - ark_mem->step_setorder = sprkStep_SetOrder; - ark_mem->step_getnumrhsevals = sprkStep_GetNumRhsEvals; - ark_mem->step_mem = (void*)step_mem; + ark_mem->step_init = sprkStep_Init; + ark_mem->step_fullrhs = sprkStep_FullRHS; + ark_mem->step = sprkStep_TakeStep; + ark_mem->step_printallstats = sprkStep_PrintAllStats; + ark_mem->step_writeparameters = sprkStep_WriteParameters; + ark_mem->step_resize = sprkStep_Resize; + ark_mem->step_free = sprkStep_Free; + ark_mem->step_setfromcommandline = sprkStep_SetFromCommandLine; + ark_mem->step_setdefaults = sprkStep_SetDefaults; + ark_mem->step_setorder = sprkStep_SetOrder; + ark_mem->step_getnumrhsevals = sprkStep_GetNumRhsEvals; + ark_mem->step_mem = (void*)step_mem; /* Set default values for optional inputs */ retval = sprkStep_SetDefaults((void*)ark_mem); diff --git a/src/arkode/arkode_sprkstep_impl.h b/src/arkode/arkode_sprkstep_impl.h index 4c5a39326a..a67ffc29e8 100644 --- a/src/arkode/arkode_sprkstep_impl.h +++ b/src/arkode/arkode_sprkstep_impl.h @@ -73,6 +73,8 @@ int sprkStep_FullRHS(ARKodeMem ark_mem, sunrealtype t, N_Vector y, N_Vector f, int sprkStep_TakeStep(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); int sprkStep_TakeStep_Compensated(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr); +int sprkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used); int sprkStep_SetUserData(ARKodeMem ark_mem, void* user_data); int sprkStep_SetDefaults(ARKodeMem ark_mem); int sprkStep_SetOrder(ARKodeMem ark_mem, int ord); diff --git a/src/arkode/arkode_sprkstep_io.c b/src/arkode/arkode_sprkstep_io.c index f67b802ce5..4c164683a5 100644 --- a/src/arkode/arkode_sprkstep_io.c +++ b/src/arkode/arkode_sprkstep_io.c @@ -27,6 +27,7 @@ #include "arkode/arkode.h" #include "arkode/arkode_sprk.h" #include "arkode_sprkstep_impl.h" +#include "sundials_cli.h" /*=============================================================== Exported optional input functions. @@ -208,6 +209,58 @@ int SPRKStepGetNumRhsEvals(void* arkode_mem, long int* nf1, long int* nf2) Private functions attached to ARKODE ===============================================================*/ +/*--------------------------------------------------------------- + sprkStep_SetFromCommandLine: + + Provides command-line control over SPRKStep-specific "set" routines. + ---------------------------------------------------------------*/ +int sprkStep_SetFromCommandLine(ARKodeMem ark_mem, int* i, char* argv[], + const size_t offset, sunbooleantype* arg_used) +{ + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyCharPair char_pairs[] = { + {"method_name", SPRKStepSetMethodName}}; + static const int num_char_keys = sizeof(char_pairs) / sizeof(*char_pairs); + + static struct sunKeyIntPair int_pairs[] = { + {"use_compensated_sums", SPRKStepSetUseCompensatedSums}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + /* check all "char" command-line options */ + int j, retval; + for (j = 0; j < num_char_keys; j++) + { + retval = sunCheckAndSetCharArg((void*)ark_mem, i, argv, offset, + char_pairs[j].key, char_pairs[j].set, + arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + char_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg((void*)ark_mem, i, argv, offset, + int_pairs[j].key, int_pairs[j].set, arg_used); + if (retval != ARK_SUCCESS) + { + arkProcessError(ark_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (*arg_used) { return ARK_SUCCESS; } + } + + return (ARK_SUCCESS); +} + /*--------------------------------------------------------------- sprkStep_SetDefaults: diff --git a/src/arkode/fmod_int32/farkode_mod.c b/src/arkode/fmod_int32/farkode_mod.c index cf23905ff6..fd7662a5b5 100644 --- a/src/arkode/fmod_int32/farkode_mod.c +++ b/src/arkode/fmod_int32/farkode_mod.c @@ -267,9 +267,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -284,6 +281,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -315,6 +315,25 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { } } +SWIGEXPORT int _wrap_FARKodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "ARKodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)ARKodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FARKodeResize(void *farg1, N_Vector farg2, double const *farg3, double const *farg4, ARKVecResizeFn farg5, void *farg6) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/arkode/fmod_int32/farkode_mod.f90 b/src/arkode/fmod_int32/farkode_mod.f90 index c7f65b633e..02d9213bce 100644 --- a/src/arkode/fmod_int32/farkode_mod.f90 +++ b/src/arkode/fmod_int32/farkode_mod.f90 @@ -115,6 +115,22 @@ module farkode_mod end enum integer, parameter, public :: ARKAccumError = kind(ARK_ACCUMERROR_NONE) public :: ARK_ACCUMERROR_NONE, ARK_ACCUMERROR_MAX, ARK_ACCUMERROR_SUM, ARK_ACCUMERROR_AVG + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FARKodeSetFromCommandLine public :: FARKodeResize public :: FARKodeReset public :: FARKodeCreateMRIStepInnerStepper @@ -192,10 +208,6 @@ module farkode_mod public :: FARKodeGetRootInfo public :: FARKodeGetUserData public :: FARKodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FARKodeGetReturnFlagName public :: FARKodeWriteParameters public :: FARKodeGetNumExpSteps @@ -268,14 +280,6 @@ module farkode_mod public :: FARKBBDPrecReInit public :: FARKBBDPrecGetWorkSpace public :: FARKBBDPrecGetNumGfnEvals - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct struct ARKodeButcherTableMem type, public :: ARKodeButcherTableMem type(SwigClassWrapper), public :: swigdata @@ -482,6 +486,19 @@ module farkode_mod ! WRAPPER DECLARATIONS interface +function swigc_FARKodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FARKodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FARKodeResize(farg1, farg2, farg3, farg4, farg5, farg6) & bind(C, name="_wrap_FARKodeResize") & result(fresult) @@ -2465,6 +2482,47 @@ function swigc_FARKodeSetLinSysFn(farg1, farg2) & contains ! MODULE SUBPROGRAMS + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FARKodeSetFromCommandLine(arkode_mem, arkid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: arkode_mem +character(kind=C_CHAR, len=*), target :: arkid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = arkode_mem +call SWIG_string_to_chararray(arkid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FARKodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FARKodeResize(arkode_mem, ynew, hscale, t0, resize, resize_data) & result(swig_result) use, intrinsic :: ISO_C_BINDING @@ -5355,24 +5413,6 @@ function FARKodeButcherTable_LoadDIRK(imethod) & swig_result = fresult end function - -subroutine SWIG_string_to_chararray(string, chars, wrap) - use, intrinsic :: ISO_C_BINDING - character(kind=C_CHAR, len=*), intent(IN) :: string - character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars - type(SwigArrayWrapper), intent(OUT) :: wrap - integer :: i - - allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) - do i=1,len(string) - chars(i) = string(i:i) - end do - i = len(string) + 1 - chars(i) = C_NULL_CHAR ! C string compatibility - wrap%data = c_loc(chars) - wrap%size = len(string) -end subroutine - function FARKodeButcherTable_LoadDIRKByName(imethod) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/arkode/fmod_int64/farkode_mod.c b/src/arkode/fmod_int64/farkode_mod.c index 0c4024af1f..6a1d14181e 100644 --- a/src/arkode/fmod_int64/farkode_mod.c +++ b/src/arkode/fmod_int64/farkode_mod.c @@ -267,9 +267,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -284,6 +281,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -315,6 +315,25 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { } } +SWIGEXPORT int _wrap_FARKodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "ARKodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)ARKodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FARKodeResize(void *farg1, N_Vector farg2, double const *farg3, double const *farg4, ARKVecResizeFn farg5, void *farg6) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/arkode/fmod_int64/farkode_mod.f90 b/src/arkode/fmod_int64/farkode_mod.f90 index c01ee2cb3e..1d057dc665 100644 --- a/src/arkode/fmod_int64/farkode_mod.f90 +++ b/src/arkode/fmod_int64/farkode_mod.f90 @@ -115,6 +115,22 @@ module farkode_mod end enum integer, parameter, public :: ARKAccumError = kind(ARK_ACCUMERROR_NONE) public :: ARK_ACCUMERROR_NONE, ARK_ACCUMERROR_MAX, ARK_ACCUMERROR_SUM, ARK_ACCUMERROR_AVG + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FARKodeSetFromCommandLine public :: FARKodeResize public :: FARKodeReset public :: FARKodeCreateMRIStepInnerStepper @@ -192,10 +208,6 @@ module farkode_mod public :: FARKodeGetRootInfo public :: FARKodeGetUserData public :: FARKodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FARKodeGetReturnFlagName public :: FARKodeWriteParameters public :: FARKodeGetNumExpSteps @@ -268,14 +280,6 @@ module farkode_mod public :: FARKBBDPrecReInit public :: FARKBBDPrecGetWorkSpace public :: FARKBBDPrecGetNumGfnEvals - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct struct ARKodeButcherTableMem type, public :: ARKodeButcherTableMem type(SwigClassWrapper), public :: swigdata @@ -482,6 +486,19 @@ module farkode_mod ! WRAPPER DECLARATIONS interface +function swigc_FARKodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FARKodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FARKodeResize(farg1, farg2, farg3, farg4, farg5, farg6) & bind(C, name="_wrap_FARKodeResize") & result(fresult) @@ -2465,6 +2482,47 @@ function swigc_FARKodeSetLinSysFn(farg1, farg2) & contains ! MODULE SUBPROGRAMS + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FARKodeSetFromCommandLine(arkode_mem, arkid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: arkode_mem +character(kind=C_CHAR, len=*), target :: arkid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = arkode_mem +call SWIG_string_to_chararray(arkid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FARKodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FARKodeResize(arkode_mem, ynew, hscale, t0, resize, resize_data) & result(swig_result) use, intrinsic :: ISO_C_BINDING @@ -5355,24 +5413,6 @@ function FARKodeButcherTable_LoadDIRK(imethod) & swig_result = fresult end function - -subroutine SWIG_string_to_chararray(string, chars, wrap) - use, intrinsic :: ISO_C_BINDING - character(kind=C_CHAR, len=*), intent(IN) :: string - character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars - type(SwigArrayWrapper), intent(OUT) :: wrap - integer :: i - - allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) - do i=1,len(string) - chars(i) = string(i:i) - end do - i = len(string) + 1 - chars(i) = C_NULL_CHAR ! C string compatibility - wrap%data = c_loc(chars) - wrap%size = len(string) -end subroutine - function FARKodeButcherTable_LoadDIRKByName(imethod) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/cvode/CMakeLists.txt b/src/cvode/CMakeLists.txt index 6f94b3b085..7a7b6ecb89 100644 --- a/src/cvode/CMakeLists.txt +++ b/src/cvode/CMakeLists.txt @@ -22,6 +22,7 @@ set(cvode_SOURCES cvode.c cvode_bandpre.c cvode_bbdpre.c + cvode_cli.c cvode_diag.c cvode_io.c cvode_ls.c diff --git a/src/cvode/cvode_cli.c b/src/cvode/cvode_cli.c new file mode 100644 index 0000000000..5081ef6990 --- /dev/null +++ b/src/cvode/cvode_cli.c @@ -0,0 +1,218 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to CVODE. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "cvode/cvode.h" +#include "cvode/cvode_ls.h" +#include "cvode/cvode_proj.h" +#include "cvode_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + CVodeSetFromCommandLine: + + Parses the command line to control scalar-valued CVODE options. + ---------------------------------------------------------------*/ + +int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, int argc, + char* argv[]) +{ + CVodeMem cv_mem; + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + cv_mem = (CVodeMem)cvode_mem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = + {{"max_conv_fails", CVodeSetMaxConvFails}, + {"max_err_test_fails", CVodeSetMaxErrTestFails}, + {"max_hnil_warns", CVodeSetMaxHnilWarns}, + {"max_nonlin_iters", CVodeSetMaxNonlinIters}, + {"max_order", CVodeSetMaxOrd}, + {"stab_lim_det", CVodeSetStabLimDet}, + {"interpolate_stop_time", CVodeSetInterpolateStopTime}, + {"use_integrator_fused_kernels", CVodeSetUseIntegratorFusedKernels}, + {"num_efails_eta_max_err_fail", CVodeSetNumFailsEtaMaxErrFail}, + {"linear_solution_scaling", CVodeSetLinearSolutionScaling}, + {"proj_err_est", CVodeSetProjErrEst}, + {"max_num_proj_fails", CVodeSetMaxNumProjFails}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = + {{"lsetup_frequency", CVodeSetLSetupFrequency}, + {"max_num_steps", CVodeSetMaxNumSteps}, + {"monitor_frequency", CVodeSetMonitorFrequency}, + {"num_steps_eta_max_early_step", CVodeSetNumStepsEtaMaxEarlyStep}, + {"jac_eval_frequency", CVodeSetJacEvalFrequency}, + {"proj_frequency", CVodeSetProjFrequency}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"dgmax_lsetup", CVodeSetDeltaGammaMaxLSetup}, + {"init_step", CVodeSetInitStep}, + {"max_step", CVodeSetMaxStep}, + {"min_step", CVodeSetMinStep}, + {"stop_time", CVodeSetStopTime}, + {"nonlin_conv_coef", CVodeSetNonlinConvCoef}, + {"eta_max_first_step", CVodeSetEtaMaxFirstStep}, + {"eta_max_early_step", CVodeSetEtaMaxEarlyStep}, + {"eta_max", CVodeSetEtaMax}, + {"eta_min", CVodeSetEtaMin}, + {"eta_min_err_fail", CVodeSetEtaMinErrFail}, + {"eta_max_err_fail", CVodeSetEtaMaxErrFail}, + {"eta_conv_fail", CVodeSetEtaConvFail}, + {"delta_gamma_max_bad_jac", CVodeSetDeltaGammaMaxBadJac}, + {"eps_lin", CVodeSetEpsLin}, + {"ls_norm_factor", CVodeSetLSNormFactor}, + {"eps_proj", CVodeSetEpsProj}, + {"proj_fail_eta", CVodeSetProjFailEta}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = {{"eta_fixed_step_bounds", + CVodeSetEtaFixedStepBounds}, + {"scalar_tolerances", + CVodeSStolerances}}; + static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + + static struct sunKeyActionPair action_pairs[] = {{"clear_stop_time", + CVodeClearStopTime}, + {"no_inactive_root_warn", + CVodeSetNoInactiveRootWarn}}; + static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + + int i, j, retval; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if cvid is supplied, skip command-line arguments that do not begin with cvid; + else, skip command-line arguments that do not begin with "cvode." */ + size_t offset; + if (strlen(cvid) > 0) + { + if (strncmp(argv[i], cvid, strlen(cvid)) != 0) { continue; } + offset = strlen(cvid) + 1; + } + else + { + static const char* prefix = "cvode."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(cvode_mem, &i, argv, offset, int_pairs[j].key, + int_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(cvode_mem, &i, argv, offset, + long_pairs[j].key, long_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(cvode_mem, &i, argv, offset, + real_pairs[j].key, real_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(cvode_mem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg(cvode_mem, &i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* warn for uninterpreted cvid.X arguments */ + cvProcessError(cv_mem, CV_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); + } + + return (CV_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/cvode/fmod_int32/fcvode_mod.c b/src/cvode/fmod_int32/fcvode_mod.c index 68f9ba20f1..c7d0f2efee 100644 --- a/src/cvode/fmod_int32/fcvode_mod.c +++ b/src/cvode/fmod_int32/fcvode_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -236,6 +252,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FCVodeCreate(int const *farg1, void *farg2) { @@ -332,6 +362,25 @@ SWIGEXPORT int _wrap_FCVodeWFtolerances(void *farg1, CVEwtFn farg2) { } +SWIGEXPORT int _wrap_FCVodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "CVodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)CVodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FCVodeSetConstraints(void *farg1, N_Vector farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/cvode/fmod_int32/fcvode_mod.f90 b/src/cvode/fmod_int32/fcvode_mod.f90 index 2e53b4bb9e..0040b0e6eb 100644 --- a/src/cvode/fmod_int32/fcvode_mod.f90 +++ b/src/cvode/fmod_int32/fcvode_mod.f90 @@ -69,6 +69,22 @@ module fcvode_mod public :: FCVodeSStolerances public :: FCVodeSVtolerances public :: FCVodeWFtolerances + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FCVodeSetFromCommandLine public :: FCVodeSetConstraints public :: FCVodeSetDeltaGammaMaxLSetup public :: FCVodeSetInitStep @@ -135,10 +151,6 @@ module fcvode_mod public :: FCVodeGetNumStepSolveFails public :: FCVodeGetUserData public :: FCVodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FCVodeGetReturnFlagName public :: FCVodeFree public :: FCVodeSetJacTimesRhsFn @@ -267,6 +279,19 @@ function swigc_FCVodeWFtolerances(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FCVodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FCVodeSetConstraints(farg1, farg2) & bind(C, name="_wrap_FCVodeSetConstraints") & result(fresult) @@ -1460,6 +1485,47 @@ function FCVodeWFtolerances(cvode_mem, efun) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FCVodeSetFromCommandLine(cvode_mem, cvid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: cvode_mem +character(kind=C_CHAR, len=*), target :: cvid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = cvode_mem +call SWIG_string_to_chararray(cvid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FCVodeSetConstraints(cvode_mem, constraints) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/cvode/fmod_int64/fcvode_mod.c b/src/cvode/fmod_int64/fcvode_mod.c index a42a5d51e8..c48adf0678 100644 --- a/src/cvode/fmod_int64/fcvode_mod.c +++ b/src/cvode/fmod_int64/fcvode_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -236,6 +252,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FCVodeCreate(int const *farg1, void *farg2) { @@ -332,6 +362,25 @@ SWIGEXPORT int _wrap_FCVodeWFtolerances(void *farg1, CVEwtFn farg2) { } +SWIGEXPORT int _wrap_FCVodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "CVodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)CVodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FCVodeSetConstraints(void *farg1, N_Vector farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/cvode/fmod_int64/fcvode_mod.f90 b/src/cvode/fmod_int64/fcvode_mod.f90 index 9aba027f07..0d2dfa7e34 100644 --- a/src/cvode/fmod_int64/fcvode_mod.f90 +++ b/src/cvode/fmod_int64/fcvode_mod.f90 @@ -69,6 +69,22 @@ module fcvode_mod public :: FCVodeSStolerances public :: FCVodeSVtolerances public :: FCVodeWFtolerances + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FCVodeSetFromCommandLine public :: FCVodeSetConstraints public :: FCVodeSetDeltaGammaMaxLSetup public :: FCVodeSetInitStep @@ -135,10 +151,6 @@ module fcvode_mod public :: FCVodeGetNumStepSolveFails public :: FCVodeGetUserData public :: FCVodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FCVodeGetReturnFlagName public :: FCVodeFree public :: FCVodeSetJacTimesRhsFn @@ -267,6 +279,19 @@ function swigc_FCVodeWFtolerances(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FCVodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FCVodeSetConstraints(farg1, farg2) & bind(C, name="_wrap_FCVodeSetConstraints") & result(fresult) @@ -1460,6 +1485,47 @@ function FCVodeWFtolerances(cvode_mem, efun) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FCVodeSetFromCommandLine(cvode_mem, cvid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: cvode_mem +character(kind=C_CHAR, len=*), target :: cvid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = cvode_mem +call SWIG_string_to_chararray(cvid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FCVodeSetConstraints(cvode_mem, constraints) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/cvodes/CMakeLists.txt b/src/cvodes/CMakeLists.txt index 9888aebfbe..9a0c3079ec 100644 --- a/src/cvodes/CMakeLists.txt +++ b/src/cvodes/CMakeLists.txt @@ -24,6 +24,7 @@ set(cvodes_SOURCES cvodes.c cvodes_bandpre.c cvodes_bbdpre.c + cvodes_cli.c cvodes_diag.c cvodes_io.c cvodes_ls.c diff --git a/src/cvodes/cvodes_cli.c b/src/cvodes/cvodes_cli.c new file mode 100644 index 0000000000..ecf9362836 --- /dev/null +++ b/src/cvodes/cvodes_cli.c @@ -0,0 +1,317 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to CVODE. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "cvodes/cvodes.h" +#include "cvodes/cvodes_ls.h" +#include "cvodes/cvodes_proj.h" +#include "cvodes_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + CVodeSetFromCommandLine: + + Parses the command line to control scalar-valued CVODE options. + ---------------------------------------------------------------*/ + +int CVodeSetFromCommandLine(void* cvode_mem, const char* cvid, int argc, + char* argv[]) +{ + CVodeMem cv_mem; + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + cv_mem = (CVodeMem)cvode_mem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = + {{"max_conv_fails", CVodeSetMaxConvFails}, + {"max_err_test_fails", CVodeSetMaxErrTestFails}, + {"max_hnil_warns", CVodeSetMaxHnilWarns}, + {"max_nonlin_iters", CVodeSetMaxNonlinIters}, + {"max_order", CVodeSetMaxOrd}, + {"stab_lim_det", CVodeSetStabLimDet}, + {"interpolate_stop_time", CVodeSetInterpolateStopTime}, + {"num_efails_eta_max_err_fail", CVodeSetNumFailsEtaMaxErrFail}, + {"quad_err_con", CVodeSetQuadErrCon}, + {"sens_err_con", CVodeSetSensErrCon}, + {"sens_max_nonlin_iters", CVodeSetSensMaxNonlinIters}, + {"quad_sens_err_con", CVodeSetQuadSensErrCon}, + {"linear_solution_scaling", CVodeSetLinearSolutionScaling}, + {"proj_err_est", CVodeSetProjErrEst}, + {"max_num_proj_fails", CVodeSetMaxNumProjFails}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = + {{"lsetup_frequency", CVodeSetLSetupFrequency}, + {"max_num_steps", CVodeSetMaxNumSteps}, + {"monitor_frequency", CVodeSetMonitorFrequency}, + {"jac_eval_frequency", CVodeSetJacEvalFrequency}, + {"proj_frequency", CVodeSetProjFrequency}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"dgmax_lsetup", CVodeSetDeltaGammaMaxLSetup}, + {"init_step", CVodeSetInitStep}, + {"max_step", CVodeSetMaxStep}, + {"min_step", CVodeSetMinStep}, + {"nonlin_conv_coef", CVodeSetNonlinConvCoef}, + {"stop_time", CVodeSetStopTime}, + {"eta_max_first_step", CVodeSetEtaMaxFirstStep}, + {"eta_max_early_step", CVodeSetEtaMaxEarlyStep}, + {"eta_max", CVodeSetEtaMax}, + {"eta_min", CVodeSetEtaMin}, + {"eta_min_err_fail", CVodeSetEtaMinErrFail}, + {"eta_max_err_fail", CVodeSetEtaMaxErrFail}, + {"eta_conv_fail", CVodeSetEtaConvFail}, + {"delta_gamma_max_bad_jac", CVodeSetDeltaGammaMaxBadJac}, + {"eps_lin", CVodeSetEpsLin}, + {"ls_norm_factor", CVodeSetLSNormFactor}, + {"eps_proj", CVodeSetEpsProj}, + {"proj_fail_eta", CVodeSetProjFailEta}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = + {{"eta_fixed_step_bounds", CVodeSetEtaFixedStepBounds}, + {"scalar_tolerances", CVodeSStolerances}, + {"quad_scalar_tolerances", CVodeQuadSStolerances}}; + static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + + static struct sunKeyTwoIntPair twoint_pairs[] = + {{"max_order_b", CVodeSetMaxOrdB}, + {"stab_lim_det_b", CVodeSetStabLimDetB}, + {"quad_err_con_b", CVodeSetQuadErrConB}, + {"linear_solution_scaling_b", CVodeSetLinearSolutionScalingB}}; + static const int num_twoint_keys = sizeof(twoint_pairs) / sizeof(*twoint_pairs); + + static struct sunKeyActionPair action_pairs[] = + {{"clear_stop_time", CVodeClearStopTime}, + {"adj_no_sensi", CVodeSetAdjNoSensi}, + {"no_inactive_root_warn", CVodeSetNoInactiveRootWarn}}; + static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + + static struct sunKeyIntRealPair int_real_pairs[] = + {{"sens_dq_method", CVodeSetSensDQMethod}, + {"init_step_b", CVodeSetInitStepB}, + {"min_step_b", CVodeSetMinStepB}, + {"max_step_b", CVodeSetMaxStepB}, + {"eps_lin_b", CVodeSetEpsLinB}, + {"ls_norm_factor_b", CVodeSetLSNormFactorB}}; + static const int num_int_real_keys = sizeof(int_real_pairs) / + sizeof(*int_real_pairs); + + static struct sunKeyIntRealRealPair int_real_real_pairs[] = + {{"scalar_tolerances_b", CVodeSStolerancesB}, + {"quad_scalar_tolerances_b", CVodeQuadSStolerancesB}}; + static const int num_int_real_real_keys = sizeof(int_real_real_pairs) / + sizeof(*int_real_real_pairs); + + static struct sunKeyIntLongPair int_long_pairs[] = { + {"max_num_steps_b", CVodeSetMaxNumStepsB}}; + static const int num_int_long_keys = sizeof(int_long_pairs) / + sizeof(*int_long_pairs); + + int i, j, retval; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if cvid is supplied, skip command-line arguments that do not begin with cvid; + else, skip command-line arguments that do not begin with "cvodes." */ + size_t offset; + if (strlen(cvid) > 0) + { + if (strncmp(argv[i], cvid, strlen(cvid)) != 0) { continue; } + offset = strlen(cvid) + 1; + } + else + { + static const char* prefix = "cvodes."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(cvode_mem, &i, argv, offset, int_pairs[j].key, + int_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(cvode_mem, &i, argv, offset, + long_pairs[j].key, long_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(cvode_mem, &i, argv, offset, + real_pairs[j].key, real_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-int command-line options */ + for (j = 0; j < num_twoint_keys; j++) + { + retval = sunCheckAndSetTwoIntArg(cvode_mem, &i, argv, offset, + twoint_pairs[j].key, twoint_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + twoint_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(cvode_mem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg(cvode_mem, &i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+real command-line options */ + for (j = 0; j < num_int_real_keys; j++) + { + retval = sunCheckAndSetIntRealArg(cvode_mem, &i, argv, offset, + int_real_pairs[j].key, + int_real_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+long command-line options */ + for (j = 0; j < num_int_long_keys; j++) + { + retval = sunCheckAndSetIntLongArg(cvode_mem, &i, argv, offset, + int_long_pairs[j].key, + int_long_pairs[j].set, &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+real+real command-line options */ + for (j = 0; j < num_int_real_real_keys; j++) + { + retval = sunCheckAndSetIntRealRealArg(cvode_mem, &i, argv, offset, + int_real_real_pairs[j].key, + int_real_real_pairs[j].set, + &arg_used); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_real_real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* warn for uninterpreted cvid.X arguments */ + cvProcessError(cv_mem, CV_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); + } + + return (CV_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/cvodes/fmod_int32/fcvodes_mod.c b/src/cvodes/fmod_int32/fcvodes_mod.c index 473678dc27..41b1c4bfd7 100644 --- a/src/cvodes/fmod_int32/fcvodes_mod.c +++ b/src/cvodes/fmod_int32/fcvodes_mod.c @@ -264,9 +264,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -281,6 +278,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -406,6 +406,25 @@ SWIGEXPORT int _wrap_FCVodeWFtolerances(void *farg1, CVEwtFn farg2) { } +SWIGEXPORT int _wrap_FCVodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "CVodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)CVodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FCVodeSetConstraints(void *farg1, N_Vector farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/cvodes/fmod_int32/fcvodes_mod.f90 b/src/cvodes/fmod_int32/fcvodes_mod.f90 index a288b74705..b54d0fba2e 100644 --- a/src/cvodes/fmod_int32/fcvodes_mod.f90 +++ b/src/cvodes/fmod_int32/fcvodes_mod.f90 @@ -100,6 +100,22 @@ module fcvodes_mod public :: FCVodeSStolerances public :: FCVodeSVtolerances public :: FCVodeWFtolerances + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FCVodeSetFromCommandLine public :: FCVodeSetConstraints public :: FCVodeSetDeltaGammaMaxLSetup public :: FCVodeSetInitStep @@ -170,10 +186,6 @@ module fcvodes_mod public :: FCVodeGetNumStepSolveFails public :: FCVodeGetUserData public :: FCVodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FCVodeGetReturnFlagName public :: FCVodeFree public :: FCVodeSetJacTimesRhsFn @@ -268,14 +280,6 @@ module fcvodes_mod public :: FCVodeGetQuadB public :: FCVodeGetAdjCVodeBmem public :: FCVodeGetAdjY - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct CVadjCheckPointRec type, public :: CVadjCheckPointRec type(SwigClassWrapper), public :: swigdata @@ -442,6 +446,19 @@ function swigc_FCVodeWFtolerances(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FCVodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FCVodeSetConstraints(farg1, farg2) & bind(C, name="_wrap_FCVodeSetConstraints") & result(fresult) @@ -2867,6 +2884,47 @@ function FCVodeWFtolerances(cvode_mem, efun) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FCVodeSetFromCommandLine(cvode_mem, cvid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: cvode_mem +character(kind=C_CHAR, len=*), target :: cvid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = cvode_mem +call SWIG_string_to_chararray(cvid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FCVodeSetConstraints(cvode_mem, constraints) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/cvodes/fmod_int64/fcvodes_mod.c b/src/cvodes/fmod_int64/fcvodes_mod.c index d3cbbca1d6..bcd330a87c 100644 --- a/src/cvodes/fmod_int64/fcvodes_mod.c +++ b/src/cvodes/fmod_int64/fcvodes_mod.c @@ -264,9 +264,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -281,6 +278,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -406,6 +406,25 @@ SWIGEXPORT int _wrap_FCVodeWFtolerances(void *farg1, CVEwtFn farg2) { } +SWIGEXPORT int _wrap_FCVodeSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "CVodeSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)CVodeSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FCVodeSetConstraints(void *farg1, N_Vector farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/cvodes/fmod_int64/fcvodes_mod.f90 b/src/cvodes/fmod_int64/fcvodes_mod.f90 index c2cdf3a0a3..21154ea34b 100644 --- a/src/cvodes/fmod_int64/fcvodes_mod.f90 +++ b/src/cvodes/fmod_int64/fcvodes_mod.f90 @@ -100,6 +100,22 @@ module fcvodes_mod public :: FCVodeSStolerances public :: FCVodeSVtolerances public :: FCVodeWFtolerances + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FCVodeSetFromCommandLine public :: FCVodeSetConstraints public :: FCVodeSetDeltaGammaMaxLSetup public :: FCVodeSetInitStep @@ -170,10 +186,6 @@ module fcvodes_mod public :: FCVodeGetNumStepSolveFails public :: FCVodeGetUserData public :: FCVodePrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FCVodeGetReturnFlagName public :: FCVodeFree public :: FCVodeSetJacTimesRhsFn @@ -268,14 +280,6 @@ module fcvodes_mod public :: FCVodeGetQuadB public :: FCVodeGetAdjCVodeBmem public :: FCVodeGetAdjY - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct CVadjCheckPointRec type, public :: CVadjCheckPointRec type(SwigClassWrapper), public :: swigdata @@ -442,6 +446,19 @@ function swigc_FCVodeWFtolerances(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FCVodeSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FCVodeSetConstraints(farg1, farg2) & bind(C, name="_wrap_FCVodeSetConstraints") & result(fresult) @@ -2867,6 +2884,47 @@ function FCVodeWFtolerances(cvode_mem, efun) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FCVodeSetFromCommandLine(cvode_mem, cvid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: cvode_mem +character(kind=C_CHAR, len=*), target :: cvid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = cvode_mem +call SWIG_string_to_chararray(cvid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FCVodeSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FCVodeSetConstraints(cvode_mem, constraints) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/ida/CMakeLists.txt b/src/ida/CMakeLists.txt index 53902e76ac..ddf07f9312 100644 --- a/src/ida/CMakeLists.txt +++ b/src/ida/CMakeLists.txt @@ -18,7 +18,14 @@ install(CODE "MESSAGE(\"\nInstall IDA\n\")") # Add variable ida_SOURCES with the sources for the IDA library -set(ida_SOURCES ida.c ida_bbdpre.c ida_ic.c ida_io.c ida_ls.c ida_nls.c) +set(ida_SOURCES + ida.c + ida_bbdpre.c + ida_cli.c + ida_ic.c + ida_io.c + ida_ls.c + ida_nls.c) # Add variable ida_HEADERS with the exported IDA header files set(ida_HEADERS ida.h ida_bbdpre.h ida_ls.h) diff --git a/src/ida/fmod_int32/fida_mod.c b/src/ida/fmod_int32/fida_mod.c index 68dfeea91f..1323ccbb78 100644 --- a/src/ida/fmod_int32/fida_mod.c +++ b/src/ida/fmod_int32/fida_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -233,6 +249,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FIDACreate(void *farg1) { @@ -347,6 +377,25 @@ SWIGEXPORT int _wrap_FIDACalcIC(void *farg1, int const *farg2, double const *far } +SWIGEXPORT int _wrap_FIDASetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "IDASetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)IDASetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FIDASetNonlinConvCoefIC(void *farg1, double const *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/ida/fmod_int32/fida_mod.f90 b/src/ida/fmod_int32/fida_mod.f90 index 136521893f..aa002698ee 100644 --- a/src/ida/fmod_int32/fida_mod.f90 +++ b/src/ida/fmod_int32/fida_mod.f90 @@ -68,6 +68,22 @@ module fida_mod public :: FIDASVtolerances public :: FIDAWFtolerances public :: FIDACalcIC + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FIDASetFromCommandLine public :: FIDASetNonlinConvCoefIC public :: FIDASetMaxNumStepsIC public :: FIDASetMaxNumJacsIC @@ -135,10 +151,6 @@ module fida_mod public :: FIDAGetNumStepSolveFails public :: FIDAGetUserData public :: FIDAPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FIDAGetReturnFlagName public :: FIDAFree public :: FIDASetJacTimesResFn @@ -252,6 +264,19 @@ function swigc_FIDACalcIC(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FIDASetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FIDASetNonlinConvCoefIC(farg1, farg2) & bind(C, name="_wrap_FIDASetNonlinConvCoefIC") & result(fresult) @@ -1307,6 +1332,47 @@ function FIDACalcIC(ida_mem, icopt, tout1) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FIDASetFromCommandLine(ida_mem, idaid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: ida_mem +character(kind=C_CHAR, len=*), target :: idaid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = ida_mem +call SWIG_string_to_chararray(idaid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FIDASetNonlinConvCoefIC(ida_mem, epiccon) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/ida/fmod_int64/fida_mod.c b/src/ida/fmod_int64/fida_mod.c index 02def580d4..e5048513ef 100644 --- a/src/ida/fmod_int64/fida_mod.c +++ b/src/ida/fmod_int64/fida_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -233,6 +249,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FIDACreate(void *farg1) { @@ -347,6 +377,25 @@ SWIGEXPORT int _wrap_FIDACalcIC(void *farg1, int const *farg2, double const *far } +SWIGEXPORT int _wrap_FIDASetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "IDASetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)IDASetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FIDASetNonlinConvCoefIC(void *farg1, double const *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/ida/fmod_int64/fida_mod.f90 b/src/ida/fmod_int64/fida_mod.f90 index 5e3fee8ae6..a19bfdc511 100644 --- a/src/ida/fmod_int64/fida_mod.f90 +++ b/src/ida/fmod_int64/fida_mod.f90 @@ -68,6 +68,22 @@ module fida_mod public :: FIDASVtolerances public :: FIDAWFtolerances public :: FIDACalcIC + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FIDASetFromCommandLine public :: FIDASetNonlinConvCoefIC public :: FIDASetMaxNumStepsIC public :: FIDASetMaxNumJacsIC @@ -135,10 +151,6 @@ module fida_mod public :: FIDAGetNumStepSolveFails public :: FIDAGetUserData public :: FIDAPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FIDAGetReturnFlagName public :: FIDAFree public :: FIDASetJacTimesResFn @@ -252,6 +264,19 @@ function swigc_FIDACalcIC(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FIDASetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FIDASetNonlinConvCoefIC(farg1, farg2) & bind(C, name="_wrap_FIDASetNonlinConvCoefIC") & result(fresult) @@ -1307,6 +1332,47 @@ function FIDACalcIC(ida_mem, icopt, tout1) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FIDASetFromCommandLine(ida_mem, idaid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: ida_mem +character(kind=C_CHAR, len=*), target :: idaid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = ida_mem +call SWIG_string_to_chararray(idaid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FIDASetNonlinConvCoefIC(ida_mem, epiccon) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/ida/ida_cli.c b/src/ida/ida_cli.c new file mode 100644 index 0000000000..7ffd889ea8 --- /dev/null +++ b/src/ida/ida_cli.c @@ -0,0 +1,210 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to IDA. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "ida/ida.h" +#include "ida/ida_ls.h" +#include "ida_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + IDASetFromCommandLine: + + Parses the command line to control scalar-valued IDA options. + ---------------------------------------------------------------*/ + +int IDASetFromCommandLine(void* ida_mem, const char* idaid, int argc, + char* argv[]) +{ + IDAMem IDA_mem; + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = + {{"max_num_steps_ic", IDASetMaxNumStepsIC}, + {"max_num_jacs_ic", IDASetMaxNumJacsIC}, + {"max_num_iters_ic", IDASetMaxNumItersIC}, + {"linesearch_off_ic", IDASetLineSearchOffIC}, + {"max_backs_ic", IDASetMaxBacksIC}, + {"max_order", IDASetMaxOrd}, + {"max_err_test_fails", IDASetMaxErrTestFails}, + {"suppress_alg", IDASetSuppressAlg}, + {"max_conv_fails", IDASetMaxConvFails}, + {"max_nonlin_iters", IDASetMaxNonlinIters}, + {"linear_solution_scaling", IDASetLinearSolutionScaling}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = { + {"max_num_steps", IDASetMaxNumSteps}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"nonlin_conv_coef_ic", IDASetNonlinConvCoefIC}, + {"step_tolerance_ic", IDASetStepToleranceIC}, + {"delta_cj_lsetup", IDASetDeltaCjLSetup}, + {"init_step", IDASetInitStep}, + {"max_step", IDASetMaxStep}, + {"min_step", IDASetMinStep}, + {"stop_time", IDASetStopTime}, + {"eta_min", IDASetEtaMin}, + {"eta_max", IDASetEtaMax}, + {"eta_low", IDASetEtaLow}, + {"eta_min_err_fail", IDASetEtaMinErrFail}, + {"eta_conv_fail", IDASetEtaConvFail}, + {"nonlin_conv_coef", IDASetNonlinConvCoef}, + {"eps_lin", IDASetEpsLin}, + {"ls_norm_factor", IDASetLSNormFactor}, + {"increment_factor", IDASetIncrementFactor}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = {"eta_fixed_step_bounds", + IDASetEtaFixedStepBounds}, + { + "scalar_tolerances", IDASStolerances + } +}; + +static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + +static struct sunKeyActionPair action_pairs[] = {{"clear_stop_time", + IDAClearStopTime}, + {"no_inactive_root_warn", + IDASetNoInactiveRootWarn}}; +static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + +int i, j, retval; +for (i = 1; i < argc; i++) +{ + sunbooleantype arg_used = SUNFALSE; + + /* if idaid is supplied, skip command-line arguments that do not begin with idaid; + else, skip command-line arguments that do not begin with "ida." */ + size_t offset; + if (strlen(idaid) > 0) + { + if (strncmp(argv[i], idaid, strlen(idaid)) != 0) { continue; } + offset = strlen(idaid) + 1; + } + else + { + static const char* prefix = "ida."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(ida_mem, &i, argv, offset, int_pairs[j].key, + int_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(ida_mem, &i, argv, offset, long_pairs[j].key, + long_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(ida_mem, &i, argv, offset, real_pairs[j].key, + real_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(ida_mem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg(ida_mem, &i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* warn for uninterpreted idaid.X arguments */ + IDAProcessError(IDA_mem, IDA_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); +} + +return (IDA_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/idas/CMakeLists.txt b/src/idas/CMakeLists.txt index 7b9f71f92b..f6a502c514 100644 --- a/src/idas/CMakeLists.txt +++ b/src/idas/CMakeLists.txt @@ -21,6 +21,7 @@ install(CODE "MESSAGE(\"\nInstall IDAS\n\")") set(idas_SOURCES idas.c idaa.c + idas_cli.c idas_io.c idas_ic.c idaa_io.c diff --git a/src/idas/fmod_int32/fidas_mod.c b/src/idas/fmod_int32/fidas_mod.c index c39dff4a1f..f7df16c727 100644 --- a/src/idas/fmod_int32/fidas_mod.c +++ b/src/idas/fmod_int32/fidas_mod.c @@ -262,9 +262,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -279,6 +276,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -422,6 +422,25 @@ SWIGEXPORT int _wrap_FIDACalcIC(void *farg1, int const *farg2, double const *far } +SWIGEXPORT int _wrap_FIDASetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "IDASetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)IDASetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FIDASetNonlinConvCoefIC(void *farg1, double const *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/idas/fmod_int32/fidas_mod.f90 b/src/idas/fmod_int32/fidas_mod.f90 index db6f376bfc..55c79bc554 100644 --- a/src/idas/fmod_int32/fidas_mod.f90 +++ b/src/idas/fmod_int32/fidas_mod.f90 @@ -93,6 +93,22 @@ module fidas_mod public :: FIDASVtolerances public :: FIDAWFtolerances public :: FIDACalcIC + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FIDASetFromCommandLine public :: FIDASetNonlinConvCoefIC public :: FIDASetMaxNumStepsIC public :: FIDASetMaxNumJacsIC @@ -165,10 +181,6 @@ module fidas_mod public :: FIDAGetNumStepSolveFails public :: FIDAGetUserData public :: FIDAPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FIDAGetReturnFlagName public :: FIDAFree public :: FIDASetJacTimesResFn @@ -261,14 +273,6 @@ module fidas_mod public :: FIDAGetAdjIDABmem public :: FIDAGetConsistentICB public :: FIDAGetAdjY - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct IDAadjCheckPointRec type, public :: IDAadjCheckPointRec type(SwigClassWrapper), public :: swigdata @@ -424,6 +428,19 @@ function swigc_FIDACalcIC(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FIDASetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FIDASetNonlinConvCoefIC(farg1, farg2) & bind(C, name="_wrap_FIDASetNonlinConvCoefIC") & result(fresult) @@ -2756,6 +2773,47 @@ function FIDACalcIC(ida_mem, icopt, tout1) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FIDASetFromCommandLine(ida_mem, idaid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: ida_mem +character(kind=C_CHAR, len=*), target :: idaid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = ida_mem +call SWIG_string_to_chararray(idaid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FIDASetNonlinConvCoefIC(ida_mem, epiccon) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/idas/fmod_int64/fidas_mod.c b/src/idas/fmod_int64/fidas_mod.c index 196fd9f52b..ecffd9bcd4 100644 --- a/src/idas/fmod_int64/fidas_mod.c +++ b/src/idas/fmod_int64/fidas_mod.c @@ -262,9 +262,6 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } -#include - - typedef struct { void* cptr; int cmemflags; @@ -279,6 +276,9 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { } +#include + + SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { if (self->cptr == NULL) { /* LHS is unassigned */ @@ -422,6 +422,25 @@ SWIGEXPORT int _wrap_FIDACalcIC(void *farg1, int const *farg2, double const *far } +SWIGEXPORT int _wrap_FIDASetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "IDASetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)IDASetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FIDASetNonlinConvCoefIC(void *farg1, double const *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/idas/fmod_int64/fidas_mod.f90 b/src/idas/fmod_int64/fidas_mod.f90 index b379e13d36..16ea7332c7 100644 --- a/src/idas/fmod_int64/fidas_mod.f90 +++ b/src/idas/fmod_int64/fidas_mod.f90 @@ -93,6 +93,22 @@ module fidas_mod public :: FIDASVtolerances public :: FIDAWFtolerances public :: FIDACalcIC + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FIDASetFromCommandLine public :: FIDASetNonlinConvCoefIC public :: FIDASetMaxNumStepsIC public :: FIDASetMaxNumJacsIC @@ -165,10 +181,6 @@ module fidas_mod public :: FIDAGetNumStepSolveFails public :: FIDAGetUserData public :: FIDAPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FIDAGetReturnFlagName public :: FIDAFree public :: FIDASetJacTimesResFn @@ -261,14 +273,6 @@ module fidas_mod public :: FIDAGetAdjIDABmem public :: FIDAGetConsistentICB public :: FIDAGetAdjY - - integer, parameter :: swig_cmem_own_bit = 0 - integer, parameter :: swig_cmem_rvalue_bit = 1 - integer, parameter :: swig_cmem_const_bit = 2 - type, bind(C) :: SwigClassWrapper - type(C_PTR), public :: cptr = C_NULL_PTR - integer(C_INT), public :: cmemflags = 0 - end type ! struct IDAadjCheckPointRec type, public :: IDAadjCheckPointRec type(SwigClassWrapper), public :: swigdata @@ -424,6 +428,19 @@ function swigc_FIDACalcIC(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FIDASetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FIDASetNonlinConvCoefIC(farg1, farg2) & bind(C, name="_wrap_FIDASetNonlinConvCoefIC") & result(fresult) @@ -2756,6 +2773,47 @@ function FIDACalcIC(ida_mem, icopt, tout1) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FIDASetFromCommandLine(ida_mem, idaid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: ida_mem +character(kind=C_CHAR, len=*), target :: idaid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = ida_mem +call SWIG_string_to_chararray(idaid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FIDASetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FIDASetNonlinConvCoefIC(ida_mem, epiccon) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/idas/idas_cli.c b/src/idas/idas_cli.c new file mode 100644 index 0000000000..57c54fb460 --- /dev/null +++ b/src/idas/idas_cli.c @@ -0,0 +1,309 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to IDA. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "idas/idas.h" +#include "idas/idas_ls.h" +#include "idas_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + IDASetFromCommandLine: + + Parses the command line to control scalar-valued IDA options. + ---------------------------------------------------------------*/ + +int IDASetFromCommandLine(void* ida_mem, const char* idaid, int argc, + char* argv[]) +{ + IDAMem IDA_mem; + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = + {{"max_num_steps_ic", IDASetMaxNumStepsIC}, + {"max_num_jacs_ic", IDASetMaxNumJacsIC}, + {"max_num_iters_ic", IDASetMaxNumItersIC}, + {"linesearch_off_ic", IDASetLineSearchOffIC}, + {"max_backs_ic", IDASetMaxBacksIC}, + {"max_order", IDASetMaxOrd}, + {"max_err_test_fails", IDASetMaxErrTestFails}, + {"suppress_alg", IDASetSuppressAlg}, + {"max_conv_fails", IDASetMaxConvFails}, + {"max_nonlin_iters", IDASetMaxNonlinIters}, + {"quad_err_con", IDASetQuadErrCon}, + {"sens_err_con", IDASetSensErrCon}, + {"sens_max_nonlin_iters", IDASetSensMaxNonlinIters}, + {"quad_sens_err_con", IDASetQuadSensErrCon}, + {"linear_solution_scaling", IDASetLinearSolutionScaling}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = { + {"max_num_steps", IDASetMaxNumSteps}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"nonlin_conv_coef_ic", IDASetNonlinConvCoefIC}, + {"step_tolerance_ic", IDASetStepToleranceIC}, + {"delta_cj_lsetup", IDASetDeltaCjLSetup}, + {"init_step", IDASetInitStep}, + {"max_step", IDASetMaxStep}, + {"min_step", IDASetMinStep}, + {"stop_time", IDASetStopTime}, + {"eta_min", IDASetEtaMin}, + {"eta_max", IDASetEtaMax}, + {"eta_low", IDASetEtaLow}, + {"eta_min_err_fail", IDASetEtaMinErrFail}, + {"eta_conv_fail", IDASetEtaConvFail}, + {"nonlin_conv_coef", IDASetNonlinConvCoef}, + {"eps_lin", IDASetEpsLin}, + {"ls_norm_factor", IDASetLSNormFactor}, + {"increment_factor", IDASetIncrementFactor}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = + {{"eta_fixed_step_bounds", IDASetEtaFixedStepBounds}, + {"scalar_tolerances", IDASStolerances}, + {"quad_scalar_tolerances", IDAQuadSStolerances}}; + static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + + static struct sunKeyTwoIntPair twoint_pairs[] = + {{"max_order_b", IDASetMaxOrdB}, + {"suppress_alg_b", IDASetSuppressAlgB}, + {"quad_err_con_b", IDASetQuadErrConB}, + {"linear_solution_scaling_b", IDASetLinearSolutionScalingB}}; + static const int num_twoint_keys = sizeof(twoint_pairs) / sizeof(*twoint_pairs); + + static struct sunKeyActionPair action_pairs[] = + {{"clear_stop_time", IDAClearStopTime}, + {"no_inactive_root_warn", IDASetNoInactiveRootWarn}, + {"sens_toggle_off", IDASensToggleOff}, + {"adj_no_sensi", IDAAdjSetNoSensi}}; + static const int num_action_keys = sizeof(action_pairs) / sizeof(*action_pairs); + + static struct sunKeyIntRealPair int_real_pairs[] = + {{"sens_dq_method", IDASetSensDQMethod}, + {"init_step_b", IDASetInitStepB}, + {"max_step_b", IDASetMaxStepB}, + {"eps_lin_b", IDASetEpsLinB}, + {"ls_norm_factor_b", IDASetLSNormFactorB}, + {"increment_factor_b", IDASetIncrementFactorB}}; + static const int num_int_real_keys = sizeof(int_real_pairs) / + sizeof(*int_real_pairs); + + static struct sunKeyIntRealRealPair int_real_real_pairs[] = + {{"scalar_tolerances_b", IDASStolerancesB}, + {"quad_scalar_tolerances_b", IDAQuadSStolerancesB}}; + static const int num_int_real_real_keys = sizeof(int_real_real_pairs) / + sizeof(*int_real_real_pairs); + + static struct sunKeyIntLongPair int_long_pairs[] = { + {"max_num_steps_b", IDASetMaxNumStepsB}}; + static const int num_int_long_keys = sizeof(int_long_pairs) / + sizeof(*int_long_pairs); + + int i, j, retval; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if idaid is supplied, skip command-line arguments that do not begin with idaid; + else, skip command-line arguments that do not begin with "idas." */ + size_t offset; + if (strlen(idaid) > 0) + { + if (strncmp(argv[i], idaid, strlen(idaid)) != 0) { continue; } + offset = strlen(idaid) + 1; + } + else + { + static const char* prefix = "idas."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(ida_mem, &i, argv, offset, int_pairs[j].key, + int_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(ida_mem, &i, argv, offset, long_pairs[j].key, + long_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(ida_mem, &i, argv, offset, real_pairs[j].key, + real_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-int command-line options */ + for (j = 0; j < num_twoint_keys; j++) + { + retval = sunCheckAndSetTwoIntArg(ida_mem, &i, argv, offset, + twoint_pairs[j].key, twoint_pairs[j].set, + &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + twoint_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(ida_mem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all action command-line options */ + for (j = 0; j < num_action_keys; j++) + { + retval = sunCheckAndSetActionArg(ida_mem, &i, argv, offset, + action_pairs[j].key, action_pairs[j].set, + &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + action_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+real command-line options */ + for (j = 0; j < num_int_real_keys; j++) + { + retval = sunCheckAndSetIntRealArg(ida_mem, &i, argv, offset, + int_real_pairs[j].key, + int_real_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+long command-line options */ + for (j = 0; j < num_int_long_keys; j++) + { + retval = sunCheckAndSetIntLongArg(ida_mem, &i, argv, offset, + int_long_pairs[j].key, + int_long_pairs[j].set, &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all int+real+real command-line options */ + for (j = 0; j < num_int_real_real_keys; j++) + { + retval = sunCheckAndSetIntRealRealArg(ida_mem, &i, argv, offset, + int_real_real_pairs[j].key, + int_real_real_pairs[j].set, + &arg_used); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_real_real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* warn for uninterpreted idaid.X arguments */ + IDAProcessError(IDA_mem, IDA_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); + } + + return (IDA_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/kinsol/CMakeLists.txt b/src/kinsol/CMakeLists.txt index e3c8a8bb77..27554b2f3e 100644 --- a/src/kinsol/CMakeLists.txt +++ b/src/kinsol/CMakeLists.txt @@ -18,7 +18,8 @@ install(CODE "MESSAGE(\"\nInstall KINSOL\n\")") # Add variable kinsol_SOURCES with the sources for the KINSOL library -set(kinsol_SOURCES kinsol.c kinsol_bbdpre.c kinsol_io.c kinsol_ls.c) +set(kinsol_SOURCES kinsol.c kinsol_bbdpre.c kinsol_cli.c kinsol_io.c + kinsol_ls.c) # Add variable kinsol_HEADERS with the exported KINSOL header files set(kinsol_HEADERS kinsol.h kinsol_bbdpre.h kinsol_ls.h) diff --git a/src/kinsol/fmod_int32/fkinsol_mod.c b/src/kinsol/fmod_int32/fkinsol_mod.c index 28e47ca143..9f2d8124a7 100644 --- a/src/kinsol/fmod_int32/fkinsol_mod.c +++ b/src/kinsol/fmod_int32/fkinsol_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -233,6 +249,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FKINCreate(void *farg1) { @@ -283,6 +313,25 @@ SWIGEXPORT int _wrap_FKINSol(void *farg1, N_Vector farg2, int const *farg3, N_Ve } +SWIGEXPORT int _wrap_FKINSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "KINSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)KINSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FKINSetUserData(void *farg1, void *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/kinsol/fmod_int32/fkinsol_mod.f90 b/src/kinsol/fmod_int32/fkinsol_mod.f90 index b536144611..2ad3ef01ce 100644 --- a/src/kinsol/fmod_int32/fkinsol_mod.f90 +++ b/src/kinsol/fmod_int32/fkinsol_mod.f90 @@ -60,6 +60,22 @@ module fkinsol_mod public :: FKINCreate public :: FKINInit public :: FKINSol + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FKINSetFromCommandLine public :: FKINSetUserData public :: FKINSetDamping public :: FKINSetMAA @@ -94,10 +110,6 @@ module fkinsol_mod public :: FKINGetStepLength public :: FKINGetUserData public :: FKINPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FKINGetReturnFlagName public :: FKINFree public :: FKINSetJacTimesVecSysFn @@ -165,6 +177,19 @@ function swigc_FKINSol(farg1, farg2, farg3, farg4, farg5) & integer(C_INT) :: fresult end function +function swigc_FKINSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FKINSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FKINSetUserData(farg1, farg2) & bind(C, name="_wrap_FKINSetUserData") & result(fresult) @@ -748,6 +773,47 @@ function FKINSol(kinmem, uu, strategy, u_scale, f_scale) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FKINSetFromCommandLine(kinmem, kinid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: kinmem +character(kind=C_CHAR, len=*), target :: kinid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = kinmem +call SWIG_string_to_chararray(kinid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FKINSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FKINSetUserData(kinmem, user_data) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/kinsol/fmod_int64/fkinsol_mod.c b/src/kinsol/fmod_int64/fkinsol_mod.c index 59cc57d5b2..b510edc23c 100644 --- a/src/kinsol/fmod_int64/fkinsol_mod.c +++ b/src/kinsol/fmod_int64/fkinsol_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -233,6 +249,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { } +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include SWIGEXPORT void * _wrap_FKINCreate(void *farg1) { @@ -283,6 +313,25 @@ SWIGEXPORT int _wrap_FKINSol(void *farg1, N_Vector farg2, int const *farg3, N_Ve } +SWIGEXPORT int _wrap_FKINSetFromCommandLine(void *farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + void *arg1 = (void *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "KINSetFromCommandLine(void *,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (int)KINSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FKINSetUserData(void *farg1, void *farg2) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/kinsol/fmod_int64/fkinsol_mod.f90 b/src/kinsol/fmod_int64/fkinsol_mod.f90 index 12ca4ddc6e..e9ae8316d6 100644 --- a/src/kinsol/fmod_int64/fkinsol_mod.f90 +++ b/src/kinsol/fmod_int64/fkinsol_mod.f90 @@ -60,6 +60,22 @@ module fkinsol_mod public :: FKINCreate public :: FKINInit public :: FKINSol + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FKINSetFromCommandLine public :: FKINSetUserData public :: FKINSetDamping public :: FKINSetMAA @@ -94,10 +110,6 @@ module fkinsol_mod public :: FKINGetStepLength public :: FKINGetUserData public :: FKINPrintAllStats - type, bind(C) :: SwigArrayWrapper - type(C_PTR), public :: data = C_NULL_PTR - integer(C_SIZE_T), public :: size = 0 - end type public :: FKINGetReturnFlagName public :: FKINFree public :: FKINSetJacTimesVecSysFn @@ -165,6 +177,19 @@ function swigc_FKINSol(farg1, farg2, farg3, farg4, farg5) & integer(C_INT) :: fresult end function +function swigc_FKINSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FKINSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FKINSetUserData(farg1, farg2) & bind(C, name="_wrap_FKINSetUserData") & result(fresult) @@ -748,6 +773,47 @@ function FKINSol(kinmem, uu, strategy, u_scale, f_scale) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FKINSetFromCommandLine(kinmem, kinid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: kinmem +character(kind=C_CHAR, len=*), target :: kinid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = kinmem +call SWIG_string_to_chararray(kinid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FKINSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FKINSetUserData(kinmem, user_data) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/kinsol/kinsol_cli.c b/src/kinsol/kinsol_cli.c new file mode 100644 index 0000000000..865c6f5489 --- /dev/null +++ b/src/kinsol/kinsol_cli.c @@ -0,0 +1,172 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to KINSOL. + *--------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "kinsol/kinsol.h" +#include "kinsol/kinsol_ls.h" +#include "kinsol_impl.h" +#include "sundials_cli.h" + +/*--------------------------------------------------------------- + KINSetFromCommandLine: + + Parses the command line to control scalar-valued KINSOL options. + ---------------------------------------------------------------*/ + +int KINSetFromCommandLine(void* kinmem, const char* kinid, int argc, char* argv[]) +{ + KINMem kin_mem; + if (kinmem == NULL) + { + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (KIN_MEM_NULL); + } + kin_mem = (KINMem)kinmem; + + /* Set lists of command-line arguments, and the corresponding set routines */ + static struct sunKeyIntPair int_pairs[] = {{"orth_aa", KINSetOrthAA}, + {"return_newest", KINSetReturnNewest}, + {"no_init_setup", KINSetNoInitSetup}, + {"no_res_mon", KINSetNoResMon}, + {"eta_form", KINSetEtaForm}, + {"no_min_eps", KINSetNoMinEps}}; + static const int num_int_keys = sizeof(int_pairs) / sizeof(*int_pairs); + + static struct sunKeyLongPair long_pairs[] = + {{"m_aa", KINSetMAA}, + {"delay_aa", KINSetDelayAA}, + {"num_max_iters", KINSetNumMaxIters}, + {"max_setup_calls", KINSetMaxSetupCalls}, + {"max_sub_setup_calls", KINSetMaxSubSetupCalls}, + {"max_beta_fails", KINSetMaxBetaFails}}; + static const int num_long_keys = sizeof(long_pairs) / sizeof(*long_pairs); + + static struct sunKeyRealPair real_pairs[] = + {{"damping", KINSetDamping}, + {"damping_aa", KINSetDampingAA}, + {"eta_const_value", KINSetEtaConstValue}, + {"res_mon_const_value", KINSetResMonConstValue}, + {"max_newton_step", KINSetMaxNewtonStep}, + {"rel_err_func", KINSetRelErrFunc}, + {"func_norm_tol", KINSetFuncNormTol}, + {"scaled_step_tol", KINSetScaledStepTol}}; + static const int num_real_keys = sizeof(real_pairs) / sizeof(*real_pairs); + + static struct sunKeyTwoRealPair tworeal_pairs[] = + {{"eta_params", KINSetEtaParams}, {"res_mon_params", KINSetResMonParams}}; + static const int num_tworeal_keys = sizeof(tworeal_pairs) / + sizeof(*tworeal_pairs); + + int i, j, retval; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if kinid is supplied, skip command-line arguments that do not begin with kinid; + else, skip command-line arguments that do not begin with "kinsol." */ + size_t offset; + if (strlen(kinid) > 0) + { + if (strncmp(argv[i], kinid, strlen(kinid)) != 0) { continue; } + offset = strlen(kinid) + 1; + } + else + { + static const char* prefix = "kinsol."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* check all "int" command-line options */ + for (j = 0; j < num_int_keys; j++) + { + retval = sunCheckAndSetIntArg(kinmem, &i, argv, offset, int_pairs[j].key, + int_pairs[j].set, &arg_used); + if (retval != KIN_SUCCESS) + { + KINProcessError(kin_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + int_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all long int command-line options */ + for (j = 0; j < num_long_keys; j++) + { + retval = sunCheckAndSetLongArg(kinmem, &i, argv, offset, long_pairs[j].key, + long_pairs[j].set, &arg_used); + if (retval != KIN_SUCCESS) + { + KINProcessError(kin_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + long_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all real command-line options */ + for (j = 0; j < num_real_keys; j++) + { + retval = sunCheckAndSetRealArg(kinmem, &i, argv, offset, real_pairs[j].key, + real_pairs[j].set, &arg_used); + if (retval != KIN_SUCCESS) + { + KINProcessError(kin_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + real_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* check all pair-of-real command-line options */ + for (j = 0; j < num_tworeal_keys; j++) + { + retval = sunCheckAndSetTwoRealArg(kinmem, &i, argv, offset, + tworeal_pairs[j].key, + tworeal_pairs[j].set, &arg_used); + if (retval != KIN_SUCCESS) + { + KINProcessError(kin_mem, retval, __LINE__, __func__, __FILE__, + "error setting command-line argument: %s", + tworeal_pairs[j].key); + return retval; + } + if (arg_used) break; + } + if (arg_used) continue; + + /* warn for uninterpreted kinid.X arguments */ + KINProcessError(kin_mem, KIN_WARNING, __LINE__, __func__, __FILE__, + "WARNING: argument %s was not handled\n", argv[i]); + } + + return (KIN_SUCCESS); +} + +/*=============================================================== + EOF + ===============================================================*/ diff --git a/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.c b/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.c index 9d4e4a3afd..5f08ac9e61 100644 --- a/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.c +++ b/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunadaptcontroller/sunadaptcontroller_imexgus.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_ImExGus(void *farg1) { SUNAdaptController fresult ; SUNContext arg1 = (SUNContext) 0 ; @@ -220,6 +275,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_ImExGus(void *farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_ImExGus(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_ImExGus(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4, double const *farg5) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.f90 b/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.f90 index 4dc30dc6a1..4fa583355f 100644 --- a/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.f90 +++ b/src/sunadaptcontroller/imexgus/fmod_int32/fsunadaptcontroller_imexgus_mod.f90 @@ -26,6 +26,22 @@ module fsunadaptcontroller_imexgus_mod ! DECLARATION CONSTRUCTS public :: FSUNAdaptController_ImExGus + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_ImExGus public :: FSUNAdaptController_SetParams_ImExGus public :: FSUNAdaptController_GetType_ImExGus public :: FSUNAdaptController_EstimateStep_ImExGus @@ -46,6 +62,19 @@ function swigc_FSUNAdaptController_ImExGus(farg1) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_ImExGus(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_ImExGus") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_ImExGus(farg1, farg2, farg3, farg4, farg5) & bind(C, name="_wrap_FSUNAdaptController_SetParams_ImExGus") & result(fresult) @@ -150,6 +179,47 @@ function FSUNAdaptController_ImExGus(sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_ImExGus(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_ImExGus(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_ImExGus(c, k1e, k2e, k1i, k2i) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.c b/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.c index 9d4e4a3afd..5f08ac9e61 100644 --- a/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.c +++ b/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunadaptcontroller/sunadaptcontroller_imexgus.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_ImExGus(void *farg1) { SUNAdaptController fresult ; SUNContext arg1 = (SUNContext) 0 ; @@ -220,6 +275,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_ImExGus(void *farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_ImExGus(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_ImExGus(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4, double const *farg5) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.f90 b/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.f90 index 4dc30dc6a1..4fa583355f 100644 --- a/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.f90 +++ b/src/sunadaptcontroller/imexgus/fmod_int64/fsunadaptcontroller_imexgus_mod.f90 @@ -26,6 +26,22 @@ module fsunadaptcontroller_imexgus_mod ! DECLARATION CONSTRUCTS public :: FSUNAdaptController_ImExGus + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_ImExGus public :: FSUNAdaptController_SetParams_ImExGus public :: FSUNAdaptController_GetType_ImExGus public :: FSUNAdaptController_EstimateStep_ImExGus @@ -46,6 +62,19 @@ function swigc_FSUNAdaptController_ImExGus(farg1) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_ImExGus(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_ImExGus") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_ImExGus(farg1, farg2, farg3, farg4, farg5) & bind(C, name="_wrap_FSUNAdaptController_SetParams_ImExGus") & result(fresult) @@ -150,6 +179,47 @@ function FSUNAdaptController_ImExGus(sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_ImExGus(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_ImExGus(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_ImExGus(c, k1e, k2e, k1i, k2i) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c index 33a9cc3549..73ae26dc9c 100644 --- a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c +++ b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c @@ -17,12 +17,14 @@ #include #include +#include #include #include #include #include +#include "sundials_cli.h" #include "sundials_macros.h" /* --------------- @@ -70,14 +72,15 @@ SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) SUNCheckLastErrNull(); /* Attach operations */ - C->ops->gettype = SUNAdaptController_GetType_ImExGus; - C->ops->estimatestep = SUNAdaptController_EstimateStep_ImExGus; - C->ops->reset = SUNAdaptController_Reset_ImExGus; - C->ops->setdefaults = SUNAdaptController_SetDefaults_ImExGus; - C->ops->write = SUNAdaptController_Write_ImExGus; - C->ops->seterrorbias = SUNAdaptController_SetErrorBias_ImExGus; - C->ops->updateh = SUNAdaptController_UpdateH_ImExGus; - C->ops->space = SUNAdaptController_Space_ImExGus; + C->ops->gettype = SUNAdaptController_GetType_ImExGus; + C->ops->estimatestep = SUNAdaptController_EstimateStep_ImExGus; + C->ops->reset = SUNAdaptController_Reset_ImExGus; + C->ops->setfromcommandline = SUNAdaptController_SetFromCommandLine_ImExGus; + C->ops->setdefaults = SUNAdaptController_SetDefaults_ImExGus; + C->ops->write = SUNAdaptController_Write_ImExGus; + C->ops->seterrorbias = SUNAdaptController_SetErrorBias_ImExGus; + C->ops->updateh = SUNAdaptController_UpdateH_ImExGus; + C->ops->space = SUNAdaptController_Space_ImExGus; /* Create content */ content = NULL; @@ -94,6 +97,92 @@ SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) return (C); } +/* ----------------------------------------------------------------- + * Function to control ImExGus parameters from the command line + */ + +SUNErrCode SUNAdaptController_SetFromCommandLine_ImExGus(SUNAdaptController C, + const char* Cid, + int argc, char* argv[]) +{ + SUNFunctionBegin(C->sunctx); + + int i; + SUNErrCode retval; + sunbooleantype write_parameters = SUNFALSE; + for (i = 1; i < argc; i++) + { + /* if Cid is supplied, skip command-line arguments that do not begin with Cid; + else, skip command-line arguments that do not begin with "sunadaptcontroller." */ + size_t offset; + if (strlen(Cid) > 0) + { + if (strncmp(argv[i], Cid, strlen(Cid)) != 0) { continue; } + offset = strlen(Cid) + 1; + } + else + { + static const char* prefix = "sunadaptcontroller_imexgus."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over SetParams function */ + if (strcmp(argv[i] + offset, "params") == 0) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + i += 1; + sunrealtype rarg3 = atof(argv[i]); + i += 1; + sunrealtype rarg4 = atof(argv[i]); + retval = SUNAdaptController_SetParams_ImExGus(C, rarg1, rarg2, rarg3, + rarg4); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetDefaults function */ + if (strcmp(argv[i] + offset, "defaults") == 0) + { + retval = SUNAdaptController_SetDefaults_ImExGus(C); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetErrorBias function */ + if (strcmp(argv[i] + offset, "error_bias") == 0) + { + i += 1; + sunrealtype rarg = atof(argv[i]); + retval = SUNAdaptController_SetErrorBias_ImExGus(C, rarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* check whether it was requested that all parameters be printed to screen */ + if (strcmp(argv[i] + offset, "write_parameters") == 0) + { + write_parameters = SUNTRUE; + continue; + } + } + + /* Call SUNAdaptController_Write_ImExGus (if requested) now that all + command-line options have been set -- WARNING: this knows + nothing about MPI, so it could be redundantly written by all + processes if requested. */ + if (write_parameters) + { + retval = SUNAdaptController_Write_ImExGus(C, stdout); + if (retval != SUN_SUCCESS) { return retval; } + } + + return SUN_SUCCESS; +} + /* ----------------------------------------------------------------- * Function to set ImExGus parameters */ diff --git a/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.c b/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.c index 41ec1e1d1c..05bea32a6c 100644 --- a/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.c +++ b/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.c @@ -297,6 +297,20 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { } } + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + SWIGEXPORT void _wrap_SUNAdaptControllerContent_MRIHTol__HControl_set(SwigClassWrapper const *farg1, SUNAdaptController farg2) { struct SUNAdaptControllerContent_MRIHTol_ *arg1 = (struct SUNAdaptControllerContent_MRIHTol_ *) 0 ; SUNAdaptController arg2 = (SUNAdaptController) 0 ; @@ -464,6 +478,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_MRIHTol(SUNAdaptControll } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_MRIHTol(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_MRIHTol(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.f90 b/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.f90 index e7afddd833..1f0fe2fbb0 100644 --- a/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.f90 +++ b/src/sunadaptcontroller/mrihtol/fmod_int32/fsunadaptcontroller_mrihtol_mod.f90 @@ -55,6 +55,14 @@ module fsunadaptcontroller_mrihtol_mod module procedure swigf_create_SUNAdaptControllerContent_MRIHTol_ end interface public :: FSUNAdaptController_MRIHTol + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_MRIHTol public :: FSUNAdaptController_SetParams_MRIHTol public :: FSUNAdaptController_GetSlowController_MRIHTol public :: FSUNAdaptController_GetFastController_MRIHTol @@ -187,6 +195,19 @@ function swigc_FSUNAdaptController_MRIHTol(farg1, farg2, farg3) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_MRIHTol(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_MRIHTol") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_MRIHTol(farg1, farg2, farg3, farg4) & bind(C, name="_wrap_FSUNAdaptController_SetParams_MRIHTol") & result(fresult) @@ -481,6 +502,47 @@ function FSUNAdaptController_MRIHTol(hcontrol, tolcontrol, sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_MRIHTol(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_MRIHTol(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_MRIHTol(c, inner_max_relch, inner_min_tolfac, inner_max_tolfac) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.c b/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.c index 41ec1e1d1c..05bea32a6c 100644 --- a/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.c +++ b/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.c @@ -297,6 +297,20 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) { } } + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + SWIGEXPORT void _wrap_SUNAdaptControllerContent_MRIHTol__HControl_set(SwigClassWrapper const *farg1, SUNAdaptController farg2) { struct SUNAdaptControllerContent_MRIHTol_ *arg1 = (struct SUNAdaptControllerContent_MRIHTol_ *) 0 ; SUNAdaptController arg2 = (SUNAdaptController) 0 ; @@ -464,6 +478,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_MRIHTol(SUNAdaptControll } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_MRIHTol(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_MRIHTol(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.f90 b/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.f90 index e7afddd833..1f0fe2fbb0 100644 --- a/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.f90 +++ b/src/sunadaptcontroller/mrihtol/fmod_int64/fsunadaptcontroller_mrihtol_mod.f90 @@ -55,6 +55,14 @@ module fsunadaptcontroller_mrihtol_mod module procedure swigf_create_SUNAdaptControllerContent_MRIHTol_ end interface public :: FSUNAdaptController_MRIHTol + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_MRIHTol public :: FSUNAdaptController_SetParams_MRIHTol public :: FSUNAdaptController_GetSlowController_MRIHTol public :: FSUNAdaptController_GetFastController_MRIHTol @@ -187,6 +195,19 @@ function swigc_FSUNAdaptController_MRIHTol(farg1, farg2, farg3) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_MRIHTol(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_MRIHTol") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_MRIHTol(farg1, farg2, farg3, farg4) & bind(C, name="_wrap_FSUNAdaptController_SetParams_MRIHTol") & result(fresult) @@ -481,6 +502,47 @@ function FSUNAdaptController_MRIHTol(hcontrol, tolcontrol, sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_MRIHTol(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_MRIHTol(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_MRIHTol(c, inner_max_relch, inner_min_tolfac, inner_max_tolfac) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c b/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c index 24d8c4bf07..3b26199c6d 100644 --- a/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c +++ b/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c @@ -17,12 +17,14 @@ #include #include +#include #include #include #include "sundials/priv/sundials_errors_impl.h" #include "sundials/sundials_errors.h" +#include "sundials_cli.h" #include "sundials_macros.h" /* ------------------ @@ -76,14 +78,15 @@ SUNAdaptController SUNAdaptController_MRIHTol(SUNAdaptController HControl, SUNCheckLastErrNull(); /* Attach operations */ - C->ops->gettype = SUNAdaptController_GetType_MRIHTol; - C->ops->estimatesteptol = SUNAdaptController_EstimateStepTol_MRIHTol; - C->ops->reset = SUNAdaptController_Reset_MRIHTol; - C->ops->setdefaults = SUNAdaptController_SetDefaults_MRIHTol; - C->ops->write = SUNAdaptController_Write_MRIHTol; - C->ops->seterrorbias = SUNAdaptController_SetErrorBias_MRIHTol; - C->ops->updatemrihtol = SUNAdaptController_UpdateMRIHTol_MRIHTol; - C->ops->space = SUNAdaptController_Space_MRIHTol; + C->ops->gettype = SUNAdaptController_GetType_MRIHTol; + C->ops->estimatesteptol = SUNAdaptController_EstimateStepTol_MRIHTol; + C->ops->reset = SUNAdaptController_Reset_MRIHTol; + C->ops->setfromcommandline = SUNAdaptController_SetFromCommandLine_MRIHTol; + C->ops->setdefaults = SUNAdaptController_SetDefaults_MRIHTol; + C->ops->write = SUNAdaptController_Write_MRIHTol; + C->ops->seterrorbias = SUNAdaptController_SetErrorBias_MRIHTol; + C->ops->updatemrihtol = SUNAdaptController_UpdateMRIHTol_MRIHTol; + C->ops->space = SUNAdaptController_Space_MRIHTol; /* Create content */ content = NULL; @@ -105,6 +108,89 @@ SUNAdaptController SUNAdaptController_MRIHTol(SUNAdaptController HControl, return C; } +/* ----------------------------------------------------------------- + * Function to control MRIHTol parameters from the command line + */ + +SUNErrCode SUNAdaptController_SetFromCommandLine_MRIHTol(SUNAdaptController C, + const char* Cid, + int argc, char* argv[]) +{ + SUNFunctionBegin(C->sunctx); + + int i; + SUNErrCode retval; + sunbooleantype write_parameters = SUNFALSE; + for (i = 1; i < argc; i++) + { + /* if Cid is supplied, skip command-line arguments that do not begin with Cid; + else, skip command-line arguments that do not begin with "sunadaptcontroller." */ + size_t offset; + if (strlen(Cid) > 0) + { + if (strncmp(argv[i], Cid, strlen(Cid)) != 0) { continue; } + offset = strlen(Cid) + 1; + } + else + { + static const char* prefix = "sunadaptcontroller_mrihtol."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over SetParams function */ + if (strcmp(argv[i] + offset, "params") == 0) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + i += 1; + sunrealtype rarg3 = atof(argv[i]); + retval = SUNAdaptController_SetParams_MRIHTol(C, rarg1, rarg2, rarg3); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetDefaults function */ + if (strcmp(argv[i] + offset, "defaults") == 0) + { + retval = SUNAdaptController_SetDefaults_MRIHTol(C); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetErrorBias function */ + if (strcmp(argv[i] + offset, "error_bias") == 0) + { + i += 1; + sunrealtype rarg = atof(argv[i]); + retval = SUNAdaptController_SetErrorBias_MRIHTol(C, rarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* check whether it was requested that all parameters be printed to screen */ + if (strcmp(argv[i] + offset, "write_parameters") == 0) + { + write_parameters = SUNTRUE; + continue; + } + } + + /* Call SUNAdaptController_Write_MRIHTol (if requested) now that all + command-line options have been set -- WARNING: this knows + nothing about MPI, so it could be redundantly written by all + processes if requested. */ + if (write_parameters) + { + retval = SUNAdaptController_Write_MRIHTol(C, stdout); + if (retval != SUN_SUCCESS) { return retval; } + } + + return SUN_SUCCESS; +} + /* ----------------------------------------------------------------- * Function to set MRIHTol parameters */ diff --git a/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.c b/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.c index 20bcb023cb..9d8424928b 100644 --- a/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.c +++ b/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunadaptcontroller/sunadaptcontroller_soderlind.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_Soderlind(void *farg1) { SUNAdaptController fresult ; SUNContext arg1 = (SUNContext) 0 ; @@ -220,6 +275,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_Soderlind(void *farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_Soderlind(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_Soderlind(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4, double const *farg5, double const *farg6) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.f90 b/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.f90 index 67d65f5068..27bcb0cf4a 100644 --- a/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.f90 +++ b/src/sunadaptcontroller/soderlind/fmod_int32/fsunadaptcontroller_soderlind_mod.f90 @@ -26,6 +26,22 @@ module fsunadaptcontroller_soderlind_mod ! DECLARATION CONSTRUCTS public :: FSUNAdaptController_Soderlind + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_Soderlind public :: FSUNAdaptController_SetParams_Soderlind public :: FSUNAdaptController_GetType_Soderlind public :: FSUNAdaptController_EstimateStep_Soderlind @@ -56,6 +72,19 @@ function swigc_FSUNAdaptController_Soderlind(farg1) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_Soderlind(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_Soderlind") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_Soderlind(farg1, farg2, farg3, farg4, farg5, farg6) & bind(C, name="_wrap_FSUNAdaptController_SetParams_Soderlind") & result(fresult) @@ -251,6 +280,47 @@ function FSUNAdaptController_Soderlind(sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_Soderlind(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_Soderlind(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_Soderlind(c, k1, k2, k3, k4, k5) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.c b/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.c index 20bcb023cb..9d8424928b 100644 --- a/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.c +++ b/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunadaptcontroller/sunadaptcontroller_soderlind.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_Soderlind(void *farg1) { SUNAdaptController fresult ; SUNContext arg1 = (SUNContext) 0 ; @@ -220,6 +275,25 @@ SWIGEXPORT SUNAdaptController _wrap_FSUNAdaptController_Soderlind(void *farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine_Soderlind(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetParams_Soderlind(SUNAdaptController farg1, double const *farg2, double const *farg3, double const *farg4, double const *farg5, double const *farg6) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.f90 b/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.f90 index 67d65f5068..27bcb0cf4a 100644 --- a/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.f90 +++ b/src/sunadaptcontroller/soderlind/fmod_int64/fsunadaptcontroller_soderlind_mod.f90 @@ -26,6 +26,22 @@ module fsunadaptcontroller_soderlind_mod ! DECLARATION CONSTRUCTS public :: FSUNAdaptController_Soderlind + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNAdaptController_SetFromCommandLine_Soderlind public :: FSUNAdaptController_SetParams_Soderlind public :: FSUNAdaptController_GetType_Soderlind public :: FSUNAdaptController_EstimateStep_Soderlind @@ -56,6 +72,19 @@ function swigc_FSUNAdaptController_Soderlind(farg1) & type(C_PTR) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine_Soderlind(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine_Soderlind") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetParams_Soderlind(farg1, farg2, farg3, farg4, farg5, farg6) & bind(C, name="_wrap_FSUNAdaptController_SetParams_Soderlind") & result(fresult) @@ -251,6 +280,47 @@ function FSUNAdaptController_Soderlind(sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNAdaptController_SetFromCommandLine_Soderlind(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine_Soderlind(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetParams_Soderlind(c, k1, k2, k3, k4, k5) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c index 78d38e4782..00d4795f5c 100644 --- a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c +++ b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c @@ -17,12 +17,14 @@ #include #include +#include #include #include #include #include +#include "sundials_cli.h" #include "sundials_macros.h" /* --------------- @@ -82,14 +84,15 @@ SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) SUNAdaptControllerContent_Soderlind content = NULL; /* Attach operations */ - C->ops->gettype = SUNAdaptController_GetType_Soderlind; - C->ops->estimatestep = SUNAdaptController_EstimateStep_Soderlind; - C->ops->reset = SUNAdaptController_Reset_Soderlind; - C->ops->setdefaults = SUNAdaptController_SetDefaults_Soderlind; - C->ops->write = SUNAdaptController_Write_Soderlind; - C->ops->seterrorbias = SUNAdaptController_SetErrorBias_Soderlind; - C->ops->updateh = SUNAdaptController_UpdateH_Soderlind; - C->ops->space = SUNAdaptController_Space_Soderlind; + C->ops->gettype = SUNAdaptController_GetType_Soderlind; + C->ops->estimatestep = SUNAdaptController_EstimateStep_Soderlind; + C->ops->reset = SUNAdaptController_Reset_Soderlind; + C->ops->setfromcommandline = SUNAdaptController_SetFromCommandLine_Soderlind; + C->ops->setdefaults = SUNAdaptController_SetDefaults_Soderlind; + C->ops->write = SUNAdaptController_Write_Soderlind; + C->ops->seterrorbias = SUNAdaptController_SetErrorBias_Soderlind; + C->ops->updateh = SUNAdaptController_UpdateH_Soderlind; + C->ops->space = SUNAdaptController_Space_Soderlind; /* Create content */ content = (SUNAdaptControllerContent_Soderlind)malloc(sizeof(*content)); @@ -103,6 +106,187 @@ SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) return (C); } +/* ----------------------------------------------------------------- + * Function to control Soderlind parameters from the command line + */ + +SUNErrCode SUNAdaptController_SetFromCommandLine_Soderlind(SUNAdaptController C, + const char* Cid, + int argc, char* argv[]) +{ + SUNFunctionBegin(C->sunctx); + + int i; + SUNErrCode retval; + sunbooleantype write_parameters = SUNFALSE; + for (i = 1; i < argc; i++) + { + /* if Cid is supplied, skip command-line arguments that do not begin with Cid; + else, skip command-line arguments that do not begin with "sunadaptcontroller." */ + size_t SOffset, PIDOffset, PIOffset, IOffset, ExpGusOffset, ImpGusOffset; + const char* SPrefix = (strlen(Cid) > 0) ? Cid + : "sunadaptcontroller_soderlind."; + const char* PIDPrefix = (strlen(Cid) > 0) ? Cid : "sunadaptcontroller_pid."; + const char* PIPrefix = (strlen(Cid) > 0) ? Cid : "sunadaptcontroller_pi."; + const char* IPrefix = (strlen(Cid) > 0) ? Cid : "sunadaptcontroller_i."; + const char* ExpGusPrefix = (strlen(Cid) > 0) ? Cid + : "sunadaptcontroller_expgus."; + const char* ImpGusPrefix = (strlen(Cid) > 0) ? Cid + : "sunadaptcontroller_impgus."; + if (strlen(Cid) > 0) + { + SOffset = PIDOffset = PIOffset = IOffset = ExpGusOffset = ImpGusOffset = + strlen(Cid) + 1; + } + else + { + SOffset = strlen(SPrefix); + PIDOffset = strlen(PIDPrefix); + PIOffset = strlen(PIPrefix); + IOffset = strlen(IPrefix); + ExpGusOffset = strlen(ExpGusPrefix); + ImpGusOffset = strlen(ImpGusPrefix); + } + + /* control over SetParams_Soderlind function */ + if ((strncmp(argv[i], SPrefix, strlen(SPrefix)) == 0) && + (strcmp(argv[i] + SOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + i += 1; + sunrealtype rarg3 = atof(argv[i]); + i += 1; + sunrealtype rarg4 = atof(argv[i]); + i += 1; + sunrealtype rarg5 = atof(argv[i]); + retval = SUNAdaptController_SetParams_Soderlind(C, rarg1, rarg2, rarg3, + rarg4, rarg5); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetParams_PID function */ + if ((strncmp(argv[i], PIDPrefix, strlen(PIDPrefix)) == 0) && + (strcmp(argv[i] + PIDOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + i += 1; + sunrealtype rarg3 = atof(argv[i]); + retval = SUNAdaptController_SetParams_PID(C, rarg1, rarg2, rarg3); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetParams_PI function */ + if ((strncmp(argv[i], PIPrefix, strlen(PIPrefix)) == 0) && + (strcmp(argv[i] + PIOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + retval = SUNAdaptController_SetParams_PI(C, rarg1, rarg2); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetParams_I function */ + if ((strncmp(argv[i], IPrefix, strlen(IPrefix)) == 0) && + (strcmp(argv[i] + IOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + retval = SUNAdaptController_SetParams_I(C, rarg1); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetParams_ExpGus function */ + if ((strncmp(argv[i], ExpGusPrefix, strlen(ExpGusPrefix)) == 0) && + (strcmp(argv[i] + ExpGusOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + retval = SUNAdaptController_SetParams_ExpGus(C, rarg1, rarg2); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetParams_ImpGus function */ + if ((strncmp(argv[i], ImpGusPrefix, strlen(ImpGusPrefix)) == 0) && + (strcmp(argv[i] + ImpGusOffset, "params") == 0)) + { + i += 1; + sunrealtype rarg1 = atof(argv[i]); + i += 1; + sunrealtype rarg2 = atof(argv[i]); + retval = SUNAdaptController_SetParams_ImpGus(C, rarg1, rarg2); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetDefaults_Soderlind function */ + if ((strcmp(argv[i] + SOffset, "defaults") == 0) || + (strcmp(argv[i] + PIDOffset, "defaults") == 0) || + (strcmp(argv[i] + PIOffset, "defaults") == 0) || + (strcmp(argv[i] + IOffset, "defaults") == 0) || + (strcmp(argv[i] + ExpGusOffset, "defaults") == 0) || + (strcmp(argv[i] + ImpGusOffset, "defaults") == 0)) + { + retval = SUNAdaptController_SetDefaults_Soderlind(C); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over SetErrorBias_Soderlind function */ + if ((strcmp(argv[i] + SOffset, "error_bias") == 0) || + (strcmp(argv[i] + PIDOffset, "error_bias") == 0) || + (strcmp(argv[i] + PIOffset, "error_bias") == 0) || + (strcmp(argv[i] + IOffset, "error_bias") == 0) || + (strcmp(argv[i] + ExpGusOffset, "error_bias") == 0) || + (strcmp(argv[i] + ImpGusOffset, "error_bias") == 0)) + { + i += 1; + sunrealtype rarg = atof(argv[i]); + retval = SUNAdaptController_SetErrorBias_Soderlind(C, rarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* check whether it was requested that all parameters be printed to screen */ + if ((strcmp(argv[i] + SOffset, "write_parameters") == 0) || + (strcmp(argv[i] + PIDOffset, "write_parameters") == 0) || + (strcmp(argv[i] + PIOffset, "write_parameters") == 0) || + (strcmp(argv[i] + IOffset, "write_parameters") == 0) || + (strcmp(argv[i] + ExpGusOffset, "write_parameters") == 0) || + (strcmp(argv[i] + ImpGusOffset, "write_parameters") == 0)) + { + write_parameters = SUNTRUE; + continue; + } + } + + /* Call SUNAdaptController_Write_Soderlind (if requested) now that all + command-line options have been set -- WARNING: this knows + nothing about MPI, so it could be redundantly written by all + processes if requested. */ + if (write_parameters) + { + retval = SUNAdaptController_Write_Soderlind(C, stdout); + if (retval != SUN_SUCCESS) { return retval; } + } + + return SUN_SUCCESS; +} + /* ----------------------------------------------------------------- * Function to set Soderlind parameters */ diff --git a/src/sundials/CMakeLists.txt b/src/sundials/CMakeLists.txt index a6b46b054a..b012026ef2 100644 --- a/src/sundials/CMakeLists.txt +++ b/src/sundials/CMakeLists.txt @@ -81,6 +81,7 @@ add_prefix(${SUNDIALS_SOURCE_DIR}/include/sundials/ sundials_HEADERS) set(sundials_SOURCES sundials_adaptcontroller.c sundials_band.c + sundials_cli.c sundials_context.c sundials_dense.c sundials_direct.c diff --git a/src/sundials/fmod_int32/fsundials_core_mod.c b/src/sundials/fmod_int32/fsundials_core_mod.c index 71d14a3c36..18a0a2faaa 100644 --- a/src/sundials/fmod_int32/fsundials_core_mod.c +++ b/src/sundials/fmod_int32/fsundials_core_mod.c @@ -193,6 +193,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -286,6 +302,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { #include "sundials/sundials_linearsolver.h" +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include "sundials/sundials_nonlinearsolver.h" @@ -2150,6 +2180,25 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors(SUNLinearSolver farg1, N_Vector } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess(SUNLinearSolver farg1, int const *farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; @@ -2598,6 +2647,25 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Reset(SUNAdaptController farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetDefaults(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sundials/fmod_int32/fsundials_core_mod.f90 b/src/sundials/fmod_int32/fsundials_core_mod.f90 index b56a9a040b..3b09a5b37b 100644 --- a/src/sundials/fmod_int32/fsundials_core_mod.f90 +++ b/src/sundials/fmod_int32/fsundials_core_mod.f90 @@ -411,6 +411,7 @@ module fsundials_core_mod type(C_FUNPTR), public :: setatimes type(C_FUNPTR), public :: setpreconditioner type(C_FUNPTR), public :: setscalingvectors + type(C_FUNPTR), public :: setfromcommandline type(C_FUNPTR), public :: setzeroguess type(C_FUNPTR), public :: initialize type(C_FUNPTR), public :: setup @@ -435,6 +436,18 @@ module fsundials_core_mod public :: FSUNLinSolSetATimes public :: FSUNLinSolSetPreconditioner public :: FSUNLinSolSetScalingVectors + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + public :: FSUNLinSolSetFromCommandLine public :: FSUNLinSolSetZeroGuess public :: FSUNLinSolInitialize public :: FSUNLinSolSetup @@ -522,6 +535,7 @@ module fsundials_core_mod type(C_FUNPTR), public :: estimatesteptol type(C_FUNPTR), public :: destroy type(C_FUNPTR), public :: reset + type(C_FUNPTR), public :: setfromcommandline type(C_FUNPTR), public :: setdefaults type(C_FUNPTR), public :: write type(C_FUNPTR), public :: seterrorbias @@ -542,6 +556,7 @@ module fsundials_core_mod public :: FSUNAdaptController_EstimateStep public :: FSUNAdaptController_EstimateStepTol public :: FSUNAdaptController_Reset + public :: FSUNAdaptController_SetFromCommandLine public :: FSUNAdaptController_SetDefaults public :: FSUNAdaptController_Write public :: FSUNAdaptController_SetErrorBias @@ -1756,6 +1771,19 @@ function swigc_FSUNLinSolSetScalingVectors(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetZeroGuess(farg1, farg2) & bind(C, name="_wrap_FSUNLinSolSetZeroGuess") & result(fresult) @@ -2044,6 +2072,19 @@ function swigc_FSUNAdaptController_Reset(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetDefaults(farg1) & bind(C, name="_wrap_FSUNAdaptController_SetDefaults") & result(fresult) @@ -4477,6 +4518,29 @@ function FSUNLinSolSetScalingVectors(s, s1, s2) & swig_result = fresult end function +function FSUNLinSolSetFromCommandLine(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetZeroGuess(s, onoff) & result(swig_result) use, intrinsic :: ISO_C_BINDING @@ -4993,6 +5057,29 @@ function FSUNAdaptController_Reset(c) & swig_result = fresult end function +function FSUNAdaptController_SetFromCommandLine(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetDefaults(c) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sundials/fmod_int64/fsundials_core_mod.c b/src/sundials/fmod_int64/fsundials_core_mod.c index b389504c8d..6557fbf760 100644 --- a/src/sundials/fmod_int64/fsundials_core_mod.c +++ b/src/sundials/fmod_int64/fsundials_core_mod.c @@ -193,6 +193,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -286,6 +302,20 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { #include "sundials/sundials_linearsolver.h" +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + + #include "sundials/sundials_nonlinearsolver.h" @@ -2150,6 +2180,25 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors(SUNLinearSolver farg1, N_Vector } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess(SUNLinearSolver farg1, int const *farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; @@ -2598,6 +2647,25 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Reset(SUNAdaptController farg1) { } +SWIGEXPORT int _wrap_FSUNAdaptController_SetFromCommandLine(SUNAdaptController farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNAdaptController arg1 = (SUNAdaptController) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNAdaptController)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNAdaptController_SetFromCommandLine(SUNAdaptController,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNAdaptController_SetFromCommandLine(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNAdaptController_SetDefaults(SUNAdaptController farg1) { int fresult ; SUNAdaptController arg1 = (SUNAdaptController) 0 ; diff --git a/src/sundials/fmod_int64/fsundials_core_mod.f90 b/src/sundials/fmod_int64/fsundials_core_mod.f90 index 30a58656d0..4509f697f6 100644 --- a/src/sundials/fmod_int64/fsundials_core_mod.f90 +++ b/src/sundials/fmod_int64/fsundials_core_mod.f90 @@ -411,6 +411,7 @@ module fsundials_core_mod type(C_FUNPTR), public :: setatimes type(C_FUNPTR), public :: setpreconditioner type(C_FUNPTR), public :: setscalingvectors + type(C_FUNPTR), public :: setfromcommandline type(C_FUNPTR), public :: setzeroguess type(C_FUNPTR), public :: initialize type(C_FUNPTR), public :: setup @@ -435,6 +436,18 @@ module fsundials_core_mod public :: FSUNLinSolSetATimes public :: FSUNLinSolSetPreconditioner public :: FSUNLinSolSetScalingVectors + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + public :: FSUNLinSolSetFromCommandLine public :: FSUNLinSolSetZeroGuess public :: FSUNLinSolInitialize public :: FSUNLinSolSetup @@ -522,6 +535,7 @@ module fsundials_core_mod type(C_FUNPTR), public :: estimatesteptol type(C_FUNPTR), public :: destroy type(C_FUNPTR), public :: reset + type(C_FUNPTR), public :: setfromcommandline type(C_FUNPTR), public :: setdefaults type(C_FUNPTR), public :: write type(C_FUNPTR), public :: seterrorbias @@ -542,6 +556,7 @@ module fsundials_core_mod public :: FSUNAdaptController_EstimateStep public :: FSUNAdaptController_EstimateStepTol public :: FSUNAdaptController_Reset + public :: FSUNAdaptController_SetFromCommandLine public :: FSUNAdaptController_SetDefaults public :: FSUNAdaptController_Write public :: FSUNAdaptController_SetErrorBias @@ -1756,6 +1771,19 @@ function swigc_FSUNLinSolSetScalingVectors(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetZeroGuess(farg1, farg2) & bind(C, name="_wrap_FSUNLinSolSetZeroGuess") & result(fresult) @@ -2044,6 +2072,19 @@ function swigc_FSUNAdaptController_Reset(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNAdaptController_SetFromCommandLine(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNAdaptController_SetFromCommandLine") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNAdaptController_SetDefaults(farg1) & bind(C, name="_wrap_FSUNAdaptController_SetDefaults") & result(fresult) @@ -4477,6 +4518,29 @@ function FSUNLinSolSetScalingVectors(s, s1, s2) & swig_result = fresult end function +function FSUNLinSolSetFromCommandLine(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetZeroGuess(s, onoff) & result(swig_result) use, intrinsic :: ISO_C_BINDING @@ -4993,6 +5057,29 @@ function FSUNAdaptController_Reset(c) & swig_result = fresult end function +function FSUNAdaptController_SetFromCommandLine(c, cid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNAdaptController), target, intent(inout) :: c +character(kind=C_CHAR, len=*), target :: cid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(c) +call SWIG_string_to_chararray(cid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNAdaptController_SetFromCommandLine(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNAdaptController_SetDefaults(c) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sundials/sundials_adaptcontroller.c b/src/sundials/sundials_adaptcontroller.c index 7758948675..463e822e52 100644 --- a/src/sundials/sundials_adaptcontroller.c +++ b/src/sundials/sundials_adaptcontroller.c @@ -47,17 +47,18 @@ SUNAdaptController SUNAdaptController_NewEmpty(SUNContext sunctx) SUNAssertNull(ops, SUN_ERR_MALLOC_FAIL); /* initialize operations to NULL */ - ops->gettype = NULL; - ops->destroy = NULL; - ops->reset = NULL; - ops->estimatestep = NULL; - ops->estimatesteptol = NULL; - ops->setdefaults = NULL; - ops->write = NULL; - ops->seterrorbias = NULL; - ops->updateh = NULL; - ops->updatemrihtol = NULL; - ops->space = NULL; + ops->gettype = NULL; + ops->destroy = NULL; + ops->reset = NULL; + ops->estimatestep = NULL; + ops->estimatesteptol = NULL; + ops->setfromcommandline = NULL; + ops->setdefaults = NULL; + ops->write = NULL; + ops->seterrorbias = NULL; + ops->updateh = NULL; + ops->updatemrihtol = NULL; + ops->space = NULL; /* attach ops and initialize content to NULL */ C->ops = ops; @@ -172,6 +173,20 @@ SUNErrCode SUNAdaptController_Reset(SUNAdaptController C) return (ier); } +SUNErrCode SUNAdaptController_SetFromCommandLine(SUNAdaptController C, + const char* Cid, int argc, + char* argv[]) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + if (C->ops->setfromcommandline) + { + ier = C->ops->setfromcommandline(C, Cid, argc, argv); + } + return (ier); +} + SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C) { SUNErrCode ier = SUN_SUCCESS; diff --git a/src/sundials/sundials_cli.c b/src/sundials/sundials_cli.c new file mode 100644 index 0000000000..ed5c5a9913 --- /dev/null +++ b/src/sundials/sundials_cli.c @@ -0,0 +1,211 @@ +/*--------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This file provides command-line control over optional inputs + * to ARKODE. + *--------------------------------------------------------------*/ + +#include "sundials_cli.h" +#include +#include +#include +#include + +/*=============================================================== + Command-line input utility routines + ===============================================================*/ + +int sunCheckAndSetIntArg(void* mem, int* i, char* argv[], const size_t offset, + const char* argtest, sunIntSetFn fname, + sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int iarg = atoi(argv[*i]); + int retval = fname(mem, iarg); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetTwoIntArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunTwoIntSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int iarg1 = atoi(argv[*i]); + (*i) += 1; + int iarg2 = atoi(argv[*i]); + int retval = fname(mem, iarg1, iarg2); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetLongArg(void* mem, int* i, char* argv[], const size_t offset, + const char* argtest, sunLongSetFn fname, + sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + long int iarg = atol(argv[*i]); + int retval = fname(mem, iarg); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetIntRealArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunIntRealSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int iarg = atoi(argv[*i]); + (*i) += 1; + sunrealtype rarg = atof(argv[*i]); + int retval = fname(mem, iarg, rarg); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetIntRealRealArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunIntRealRealSetFn fname, + sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int iarg = atoi(argv[*i]); + (*i) += 1; + sunrealtype rarg1 = atof(argv[*i]); + (*i) += 1; + sunrealtype rarg2 = atof(argv[*i]); + int retval = fname(mem, iarg, rarg1, rarg2); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetIntLongArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunIntLongSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int iarg = atoi(argv[*i]); + (*i) += 1; + long int large = atol(argv[*i]); + int retval = fname(mem, iarg, large); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetRealArg(void* mem, int* i, char* argv[], const size_t offset, + const char* argtest, sunRealSetFn fname, + sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + sunrealtype rarg = atof(argv[*i]); + int retval = fname(mem, rarg); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetTwoRealArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunTwoRealSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + sunrealtype rarg1 = atof(argv[*i]); + (*i) += 1; + sunrealtype rarg2 = atof(argv[*i]); + int retval = fname(mem, rarg1, rarg2); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetCharArg(void* mem, int* i, char* argv[], const size_t offset, + const char* argtest, sunCharSetFn fname, + sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + (*i) += 1; + int retval = fname(mem, argv[*i]); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetTwoCharArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunTwoCharSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + int retval = fname(mem, argv[*i + 1], argv[*i + 2]); + (*i) += 2; + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} + +int sunCheckAndSetActionArg(void* mem, int* i, char* argv[], + const size_t offset, const char* argtest, + sunActionSetFn fname, sunbooleantype* arg_used) +{ + *arg_used = SUNFALSE; + if (strcmp(argv[*i] + offset, argtest) == 0) + { + int retval = fname(mem); + if (retval != SUN_SUCCESS) { return retval; } + *arg_used = SUNTRUE; + } + return SUN_SUCCESS; +} diff --git a/src/sundials/sundials_cli.h b/src/sundials/sundials_cli.h new file mode 100644 index 0000000000..e2d7110010 --- /dev/null +++ b/src/sundials/sundials_cli.h @@ -0,0 +1,193 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds + * ----------------------------------------------------------------- + * 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 + * ----------------------------------------------------------------- + * SUNDIALS command-line utility definitions. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CLI_H +#define _SUNDIALS_CLI_H + +#include +#include "sundials/sundials_errors.h" +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* utilities for integer "set" routines */ +typedef int (*sunIntSetFn)(void*, int); + +struct sunKeyIntPair +{ + const char* key; + sunIntSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetIntArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, sunIntSetFn fname, + sunbooleantype* arg_used); + +/* utilities for pair-of-integer "set" routines */ +typedef int (*sunTwoIntSetFn)(void*, int, int); + +struct sunKeyTwoIntPair +{ + const char* key; + sunTwoIntSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetTwoIntArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunTwoIntSetFn fname, + sunbooleantype* arg_used); + +/* utilities for long int "set" routines */ +typedef int (*sunLongSetFn)(void*, long int); + +struct sunKeyLongPair +{ + const char* key; + sunLongSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetLongArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, sunLongSetFn fname, + sunbooleantype* arg_used); + +/* utilities for pair int/sunrealtype "set" routines */ +typedef int (*sunIntRealSetFn)(void*, int, sunrealtype); + +struct sunKeyIntRealPair +{ + const char* key; + sunIntRealSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetIntRealArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunIntRealSetFn fname, + sunbooleantype* arg_used); + +/* utilities for triplet int/sunrealtype/sunrealtype "set" routines */ +typedef int (*sunIntRealRealSetFn)(void*, int, sunrealtype, sunrealtype); + +struct sunKeyIntRealRealPair +{ + const char* key; + sunIntRealRealSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetIntRealRealArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunIntRealRealSetFn fname, + sunbooleantype* arg_used); + +/* utilities for pair int/long int "set" routines */ +typedef int (*sunIntLongSetFn)(void*, int, long int); + +struct sunKeyIntLongPair +{ + const char* key; + sunIntLongSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetIntLongArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunIntLongSetFn fname, + sunbooleantype* arg_used); + +/* utilities for sunrealtype "set" routines */ +typedef int (*sunRealSetFn)(void*, sunrealtype); + +struct sunKeyRealPair +{ + const char* key; + sunRealSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetRealArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, sunRealSetFn fname, + sunbooleantype* arg_used); + +/* utilities for pair-of-sunrealtype "set" routines */ +typedef int (*sunTwoRealSetFn)(void*, sunrealtype, sunrealtype); + +struct sunKeyTwoRealPair +{ + const char* key; + sunTwoRealSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetTwoRealArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunTwoRealSetFn fname, + sunbooleantype* arg_used); + +/* utilities for char* "set" routines */ +typedef int (*sunCharSetFn)(void*, const char*); + +struct sunKeyCharPair +{ + const char* key; + sunCharSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetCharArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, sunCharSetFn fname, + sunbooleantype* arg_used); + +/* utilities for pair-of-char* "set" routines */ +typedef int (*sunTwoCharSetFn)(void*, const char*, const char*); + +struct sunKeyTwoCharPair +{ + const char* key; + sunTwoCharSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetTwoCharArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunTwoCharSetFn fname, + sunbooleantype* arg_used); + +/* utilities for action "set" routines */ +typedef int (*sunActionSetFn)(void*); + +struct sunKeyActionPair +{ + const char* key; + sunActionSetFn set; +}; + +SUNDIALS_EXPORT int sunCheckAndSetActionArg(void* mem, int* i, char* argv[], + const size_t offset, + const char* argtest, + sunActionSetFn fname, + sunbooleantype* arg_used); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/sundials/sundials_linearsolver.c b/src/sundials/sundials_linearsolver.c index 7f54dfc983..cbe73f9c7d 100644 --- a/src/sundials/sundials_linearsolver.c +++ b/src/sundials/sundials_linearsolver.c @@ -57,21 +57,22 @@ SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx) SUNAssertNull(ops, SUN_ERR_MALLOC_FAIL); /* initialize operations to NULL */ - ops->gettype = NULL; - ops->getid = NULL; - ops->setatimes = NULL; - ops->setpreconditioner = NULL; - ops->setscalingvectors = NULL; - ops->setzeroguess = NULL; - ops->initialize = NULL; - ops->setup = NULL; - ops->solve = NULL; - ops->numiters = NULL; - ops->resnorm = NULL; - ops->resid = NULL; - ops->lastflag = NULL; - ops->space = NULL; - ops->free = NULL; + ops->gettype = NULL; + ops->getid = NULL; + ops->setatimes = NULL; + ops->setpreconditioner = NULL; + ops->setscalingvectors = NULL; + ops->setfromcommandline = NULL; + ops->setzeroguess = NULL; + ops->initialize = NULL; + ops->setup = NULL; + ops->solve = NULL; + ops->numiters = NULL; + ops->resnorm = NULL; + ops->resid = NULL; + ops->lastflag = NULL; + ops->space = NULL; + ops->free = NULL; /* attach ops and initialize content and context to NULL */ LS->ops = ops; @@ -147,6 +148,19 @@ SUNErrCode SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, N_Vector s return (ier); } +SUNErrCode SUNLinSolSetFromCommandLine(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNErrCode ier = SUN_SUCCESS; + if (S == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(S->sunctx); + if (S->ops->setfromcommandline) + { + return (S->ops->setfromcommandline(S, LSid, argc, argv)); + } + return (ier); +} + SUNErrCode SUNLinSolSetZeroGuess(SUNLinearSolver S, sunbooleantype onoff) { if (S->ops->setzeroguess) { return (S->ops->setzeroguess(S, onoff)); } diff --git a/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.c b/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.c index 504612c0e0..34783ed3d3 100644 --- a/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.c +++ b/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.c @@ -185,6 +185,15 @@ enum { }; +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -229,6 +238,31 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { return result; } + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_KLU(N_Vector farg1, SUNMatrix farg2, void *farg3) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -352,6 +386,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_KLU(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_KLU(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_KLU(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_KLU(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetup_KLU(SUNLinearSolver farg1, SUNMatrix farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.f90 b/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.f90 index bbd312f674..ce7c7cccb2 100644 --- a/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.f90 +++ b/src/sunlinsol/klu/fmod_int32/fsunlinsol_klu_mod.f90 @@ -54,6 +54,14 @@ module fsunlinsol_klu_mod public :: FSUNLinSolGetType_KLU public :: FSUNLinSolGetID_KLU public :: FSUNLinSolInitialize_KLU + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_KLU public :: FSUNLinSolSetup_KLU public :: FSUNLinSolSolve_KLU public :: FSUNLinSolLastFlag_KLU @@ -143,6 +151,19 @@ function swigc_FSUNLinSolInitialize_KLU(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_KLU(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_KLU") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetup_KLU(farg1, farg2) & bind(C, name="_wrap_FSUNLinSolSetup_KLU") & result(fresult) @@ -330,6 +351,47 @@ function FSUNLinSolInitialize_KLU(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_KLU(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_KLU(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetup_KLU(s, a) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.c b/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.c index 3e7b8d0614..c3deeca4de 100644 --- a/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.c +++ b/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.c @@ -185,6 +185,15 @@ enum { }; +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -229,6 +238,31 @@ SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { return result; } + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_KLU(N_Vector farg1, SUNMatrix farg2, void *farg3) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -352,6 +386,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_KLU(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_KLU(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_KLU(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_KLU(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetup_KLU(SUNLinearSolver farg1, SUNMatrix farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.f90 b/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.f90 index f836c8b140..da1c859145 100644 --- a/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.f90 +++ b/src/sunlinsol/klu/fmod_int64/fsunlinsol_klu_mod.f90 @@ -54,6 +54,14 @@ module fsunlinsol_klu_mod public :: FSUNLinSolGetType_KLU public :: FSUNLinSolGetID_KLU public :: FSUNLinSolInitialize_KLU + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_KLU public :: FSUNLinSolSetup_KLU public :: FSUNLinSolSolve_KLU public :: FSUNLinSolLastFlag_KLU @@ -143,6 +151,19 @@ function swigc_FSUNLinSolInitialize_KLU(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_KLU(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_KLU") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetup_KLU(farg1, farg2) & bind(C, name="_wrap_FSUNLinSolSetup_KLU") & result(fresult) @@ -330,6 +351,47 @@ function FSUNLinSolInitialize_KLU(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_KLU(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_KLU(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetup_KLU(s, a) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/klu/sunlinsol_klu.c b/src/sunlinsol/klu/sunlinsol_klu.c index abcc8a5026..e5808ec050 100644 --- a/src/sunlinsol/klu/sunlinsol_klu.c +++ b/src/sunlinsol/klu/sunlinsol_klu.c @@ -19,11 +19,14 @@ #include #include #include +#include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_macros.h" #define ONE SUN_RCONST(1.0) @@ -79,14 +82,15 @@ SUNLinearSolver SUNLinSol_KLU(N_Vector y, SUNMatrix A, SUNContext sunctx) if (S == NULL) { return (NULL); } /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_KLU; - S->ops->getid = SUNLinSolGetID_KLU; - S->ops->initialize = SUNLinSolInitialize_KLU; - S->ops->setup = SUNLinSolSetup_KLU; - S->ops->solve = SUNLinSolSolve_KLU; - S->ops->lastflag = SUNLinSolLastFlag_KLU; - S->ops->space = SUNLinSolSpace_KLU; - S->ops->free = SUNLinSolFree_KLU; + S->ops->gettype = SUNLinSolGetType_KLU; + S->ops->getid = SUNLinSolGetID_KLU; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_KLU; + S->ops->initialize = SUNLinSolInitialize_KLU; + S->ops->setup = SUNLinSolSetup_KLU; + S->ops->solve = SUNLinSolSolve_KLU; + S->ops->lastflag = SUNLinSolLastFlag_KLU; + S->ops->space = SUNLinSolSpace_KLU; + S->ops->free = SUNLinSolFree_KLU; /* Create content */ content = NULL; @@ -168,6 +172,47 @@ SUNErrCode SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, return SUN_SUCCESS; } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_KLU(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "klu."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over SetOrdering function */ + if (strcmp(argv[i] + offset, "ordering") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_KLUSetOrdering(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the ordering type for a KLU linear solver */ diff --git a/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp b/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp index 2ac907ec54..b14774a022 100644 --- a/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp +++ b/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp @@ -14,9 +14,11 @@ #include #include +#include #include #include #include +#include "sundials_cli.h" /* Interfaces to match 'sunrealtype' with the correct MAGMA functions */ #if defined(SUNDIALS_DOUBLE_PRECISION) @@ -105,14 +107,15 @@ SUNLinearSolver SUNLinSol_MagmaDense(N_Vector y, SUNMatrix Amat, SUNContext sunc if (S == NULL) { return (NULL); } /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_MagmaDense; - S->ops->getid = SUNLinSolGetID_MagmaDense; - S->ops->initialize = SUNLinSolInitialize_MagmaDense; - S->ops->setup = SUNLinSolSetup_MagmaDense; - S->ops->solve = SUNLinSolSolve_MagmaDense; - S->ops->lastflag = SUNLinSolLastFlag_MagmaDense; - S->ops->space = SUNLinSolSpace_MagmaDense; - S->ops->free = SUNLinSolFree_MagmaDense; + S->ops->gettype = SUNLinSolGetType_MagmaDense; + S->ops->getid = SUNLinSolGetID_MagmaDense; + S->ops->initialize = SUNLinSolInitialize_MagmaDense; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_MagmaDense; + S->ops->setup = SUNLinSolSetup_MagmaDense; + S->ops->solve = SUNLinSolSolve_MagmaDense; + S->ops->lastflag = SUNLinSolLastFlag_MagmaDense; + S->ops->space = SUNLinSolSpace_MagmaDense; + S->ops->free = SUNLinSolFree_MagmaDense; /* Create content */ content = NULL; @@ -231,6 +234,47 @@ SUNErrCode SUNLinSolInitialize_MagmaDense(SUNLinearSolver S) return SUN_SUCCESS; } +SUNErrCode SUNLinSolSetFromCommandLine_MagmaDense(SUNLinearSolver S, + const char* LSid, int argc, + char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i, j; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + sunbooleantype arg_used = SUNFALSE; + + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "magmadense."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over SetAsync function */ + if (strcmp(argv[i] + offset, "async") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_MagmaDense_SetAsync(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + arg_used = SUNTRUE; + continue; + } + } + return SUN_SUCCESS; +} + int SUNLinSolSetup_MagmaDense(SUNLinearSolver S, SUNMatrix A) { /* Check for valid inputs */ diff --git a/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.c b/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.c index 9c2f9bcb44..21b6c5bc3f 100644 --- a/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.c +++ b/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_pcg.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_PCG(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_PCG(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_PCG(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_PCG(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_PCG(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_PCG(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.f90 b/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.f90 index 5a38ae2960..e6d03beb3e 100644 --- a/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.f90 +++ b/src/sunlinsol/pcg/fmod_int32/fsunlinsol_pcg_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_pcg_mod public :: FSUNLinSolGetType_PCG public :: FSUNLinSolGetID_PCG public :: FSUNLinSolInitialize_PCG + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_PCG public :: FSUNLinSolSetATimes_PCG public :: FSUNLinSolSetPreconditioner_PCG public :: FSUNLinSolSetScalingVectors_PCG @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_PCG(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_PCG(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_PCG") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_PCG(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_PCG") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_PCG(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_PCG(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_PCG(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_PCG(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.c b/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.c index 6173f11b75..e32266823b 100644 --- a/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.c +++ b/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_pcg.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_PCG(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_PCG(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_PCG(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_PCG(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_PCG(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_PCG(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.f90 b/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.f90 index b6f5851f0e..b0cc010b96 100644 --- a/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.f90 +++ b/src/sunlinsol/pcg/fmod_int64/fsunlinsol_pcg_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_pcg_mod public :: FSUNLinSolGetType_PCG public :: FSUNLinSolGetID_PCG public :: FSUNLinSolInitialize_PCG + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_PCG public :: FSUNLinSolSetATimes_PCG public :: FSUNLinSolSetPreconditioner_PCG public :: FSUNLinSolSetScalingVectors_PCG @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_PCG(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_PCG(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_PCG") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_PCG(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_PCG") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_PCG(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_PCG(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_PCG(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_PCG(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/pcg/sunlinsol_pcg.c b/src/sunlinsol/pcg/sunlinsol_pcg.c index 4f524e020e..153bd27915 100644 --- a/src/sunlinsol/pcg/sunlinsol_pcg.c +++ b/src/sunlinsol/pcg/sunlinsol_pcg.c @@ -18,11 +18,13 @@ #include #include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_logger_impl.h" #include "sundials_macros.h" @@ -69,21 +71,22 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc SUNCheckLastErrNull(); /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_PCG; - S->ops->getid = SUNLinSolGetID_PCG; - S->ops->setatimes = SUNLinSolSetATimes_PCG; - S->ops->setpreconditioner = SUNLinSolSetPreconditioner_PCG; - S->ops->setscalingvectors = SUNLinSolSetScalingVectors_PCG; - S->ops->setzeroguess = SUNLinSolSetZeroGuess_PCG; - S->ops->initialize = SUNLinSolInitialize_PCG; - S->ops->setup = SUNLinSolSetup_PCG; - S->ops->solve = SUNLinSolSolve_PCG; - S->ops->numiters = SUNLinSolNumIters_PCG; - S->ops->resnorm = SUNLinSolResNorm_PCG; - S->ops->resid = SUNLinSolResid_PCG; - S->ops->lastflag = SUNLinSolLastFlag_PCG; - S->ops->space = SUNLinSolSpace_PCG; - S->ops->free = SUNLinSolFree_PCG; + S->ops->gettype = SUNLinSolGetType_PCG; + S->ops->getid = SUNLinSolGetID_PCG; + S->ops->setatimes = SUNLinSolSetATimes_PCG; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_PCG; + S->ops->setpreconditioner = SUNLinSolSetPreconditioner_PCG; + S->ops->setscalingvectors = SUNLinSolSetScalingVectors_PCG; + S->ops->setzeroguess = SUNLinSolSetZeroGuess_PCG; + S->ops->initialize = SUNLinSolInitialize_PCG; + S->ops->setup = SUNLinSolSetup_PCG; + S->ops->solve = SUNLinSolSolve_PCG; + S->ops->numiters = SUNLinSolNumIters_PCG; + S->ops->resnorm = SUNLinSolResNorm_PCG; + S->ops->resid = SUNLinSolResid_PCG; + S->ops->lastflag = SUNLinSolLastFlag_PCG; + S->ops->space = SUNLinSolSpace_PCG; + S->ops->free = SUNLinSolFree_PCG; /* Create content */ content = NULL; @@ -127,6 +130,67 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_PCG(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "pcg."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "prec_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_PCGSetPrecType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over Maxl function */ + if (strcmp(argv[i] + offset, "maxl") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_PCGSetMaxl(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over ZeroGuess function */ + if (strcmp(argv[i] + offset, "zero_guess") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSolSetZeroGuess_PCG(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the type of preconditioning for PCG to use */ diff --git a/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.c b/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.c index 1a864f19a6..ec519caa5f 100644 --- a/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.c +++ b/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spbcgs.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPBCGS(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPBCGS(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPBCGS(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPBCGS(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.f90 b/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.f90 index b83fe50880..b7329e5729 100644 --- a/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.f90 +++ b/src/sunlinsol/spbcgs/fmod_int32/fsunlinsol_spbcgs_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_spbcgs_mod public :: FSUNLinSolGetType_SPBCGS public :: FSUNLinSolGetID_SPBCGS public :: FSUNLinSolInitialize_SPBCGS + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPBCGS public :: FSUNLinSolSetATimes_SPBCGS public :: FSUNLinSolSetPreconditioner_SPBCGS public :: FSUNLinSolSetScalingVectors_SPBCGS @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_SPBCGS(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPBCGS(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPBCGS") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPBCGS(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPBCGS") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_SPBCGS(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPBCGS(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPBCGS(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPBCGS(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.c b/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.c index 731012db16..7fff1a827a 100644 --- a/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.c +++ b/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spbcgs.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPBCGS(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPBCGS(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPBCGS(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPBCGS(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.f90 b/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.f90 index 3530bf5bf3..822c105b3a 100644 --- a/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.f90 +++ b/src/sunlinsol/spbcgs/fmod_int64/fsunlinsol_spbcgs_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_spbcgs_mod public :: FSUNLinSolGetType_SPBCGS public :: FSUNLinSolGetID_SPBCGS public :: FSUNLinSolInitialize_SPBCGS + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPBCGS public :: FSUNLinSolSetATimes_SPBCGS public :: FSUNLinSolSetPreconditioner_SPBCGS public :: FSUNLinSolSetScalingVectors_SPBCGS @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_SPBCGS(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPBCGS(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPBCGS") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPBCGS(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPBCGS") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_SPBCGS(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPBCGS(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPBCGS(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPBCGS(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c b/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c index 5c941c5e22..4c1c6b48c8 100644 --- a/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c +++ b/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c @@ -19,12 +19,14 @@ #include #include +#include #include #include #include #include "sundials/sundials_errors.h" +#include "sundials_cli.h" #include "sundials_logger_impl.h" #include "sundials_macros.h" @@ -78,21 +80,22 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, SUNCheckLastErrNull(); /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_SPBCGS; - S->ops->getid = SUNLinSolGetID_SPBCGS; - S->ops->setatimes = SUNLinSolSetATimes_SPBCGS; - S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPBCGS; - S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPBCGS; - S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPBCGS; - S->ops->initialize = SUNLinSolInitialize_SPBCGS; - S->ops->setup = SUNLinSolSetup_SPBCGS; - S->ops->solve = SUNLinSolSolve_SPBCGS; - S->ops->numiters = SUNLinSolNumIters_SPBCGS; - S->ops->resnorm = SUNLinSolResNorm_SPBCGS; - S->ops->resid = SUNLinSolResid_SPBCGS; - S->ops->lastflag = SUNLinSolLastFlag_SPBCGS; - S->ops->space = SUNLinSolSpace_SPBCGS; - S->ops->free = SUNLinSolFree_SPBCGS; + S->ops->gettype = SUNLinSolGetType_SPBCGS; + S->ops->getid = SUNLinSolGetID_SPBCGS; + S->ops->setatimes = SUNLinSolSetATimes_SPBCGS; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_SPBCGS; + S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPBCGS; + S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPBCGS; + S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPBCGS; + S->ops->initialize = SUNLinSolInitialize_SPBCGS; + S->ops->setup = SUNLinSolSetup_SPBCGS; + S->ops->solve = SUNLinSolSolve_SPBCGS; + S->ops->numiters = SUNLinSolNumIters_SPBCGS; + S->ops->resnorm = SUNLinSolResNorm_SPBCGS; + S->ops->resid = SUNLinSolResid_SPBCGS; + S->ops->lastflag = SUNLinSolLastFlag_SPBCGS; + S->ops->space = SUNLinSolSpace_SPBCGS; + S->ops->free = SUNLinSolFree_SPBCGS; /* Create content */ content = NULL; @@ -149,6 +152,67 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_SPBCGS(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "spbcgs."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "prec_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPBCGSSetPrecType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over Maxl function */ + if (strcmp(argv[i] + offset, "maxl") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPBCGSSetMaxl(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over ZeroGuess function */ + if (strcmp(argv[i] + offset, "zero_guess") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSolSetZeroGuess_SPBCGS(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the type of preconditioning for SPBCGS to use */ diff --git a/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.c b/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.c index 9cb339ae7c..e388a2613f 100644 --- a/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.c +++ b/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spfgmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPFGMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -226,6 +281,25 @@ SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPFGMR(N_Vector farg1, int const *fa } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPFGMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSol_SPFGMRSetPrecType(SUNLinearSolver farg1, int const *farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.f90 b/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.f90 index 6a8f7896e8..1952cd604c 100644 --- a/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.f90 +++ b/src/sunlinsol/spfgmr/fmod_int32/fsunlinsol_spfgmr_mod.f90 @@ -28,6 +28,22 @@ module fsunlinsol_spfgmr_mod integer(C_INT), parameter, public :: SUNSPFGMR_MAXL_DEFAULT = 5_C_INT integer(C_INT), parameter, public :: SUNSPFGMR_MAXRS_DEFAULT = 0_C_INT public :: FSUNLinSol_SPFGMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPFGMR public :: FSUNLinSol_SPFGMRSetPrecType public :: FSUNLinSol_SPFGMRSetGSType public :: FSUNLinSol_SPFGMRSetMaxRestarts @@ -60,6 +76,19 @@ function swigc_FSUNLinSol_SPFGMR(farg1, farg2, farg3, farg4) & type(C_PTR) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPFGMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPFGMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSol_SPFGMRSetPrecType(farg1, farg2) & bind(C, name="_wrap_FSUNLinSol_SPFGMRSetPrecType") & result(fresult) @@ -249,6 +278,47 @@ function FSUNLinSol_SPFGMR(y, pretype, maxl, sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPFGMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPFGMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSol_SPFGMRSetPrecType(s, pretype) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.c b/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.c index 7c30b5166d..b9f98a270d 100644 --- a/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.c +++ b/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spfgmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPFGMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -226,6 +281,25 @@ SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPFGMR(N_Vector farg1, int const *fa } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPFGMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSol_SPFGMRSetPrecType(SUNLinearSolver farg1, int const *farg2) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.f90 b/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.f90 index 88ae7451b5..30834e8051 100644 --- a/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.f90 +++ b/src/sunlinsol/spfgmr/fmod_int64/fsunlinsol_spfgmr_mod.f90 @@ -28,6 +28,22 @@ module fsunlinsol_spfgmr_mod integer(C_INT), parameter, public :: SUNSPFGMR_MAXL_DEFAULT = 5_C_INT integer(C_INT), parameter, public :: SUNSPFGMR_MAXRS_DEFAULT = 0_C_INT public :: FSUNLinSol_SPFGMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPFGMR public :: FSUNLinSol_SPFGMRSetPrecType public :: FSUNLinSol_SPFGMRSetGSType public :: FSUNLinSol_SPFGMRSetMaxRestarts @@ -60,6 +76,19 @@ function swigc_FSUNLinSol_SPFGMR(farg1, farg2, farg3, farg4) & type(C_PTR) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPFGMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPFGMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSol_SPFGMRSetPrecType(farg1, farg2) & bind(C, name="_wrap_FSUNLinSol_SPFGMRSetPrecType") & result(fresult) @@ -249,6 +278,47 @@ function FSUNLinSol_SPFGMR(y, pretype, maxl, sunctx) & call c_f_pointer(fresult, swig_result) end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPFGMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPFGMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSol_SPFGMRSetPrecType(s, pretype) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c b/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c index bc6b4576c1..e56ce0cf69 100644 --- a/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c +++ b/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c @@ -19,11 +19,13 @@ #include #include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_logger_impl.h" #include "sundials_macros.h" @@ -78,21 +80,22 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, SUNCheckLastErrNull(); /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_SPFGMR; - S->ops->getid = SUNLinSolGetID_SPFGMR; - S->ops->setatimes = SUNLinSolSetATimes_SPFGMR; - S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPFGMR; - S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPFGMR; - S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPFGMR; - S->ops->initialize = SUNLinSolInitialize_SPFGMR; - S->ops->setup = SUNLinSolSetup_SPFGMR; - S->ops->solve = SUNLinSolSolve_SPFGMR; - S->ops->numiters = SUNLinSolNumIters_SPFGMR; - S->ops->resnorm = SUNLinSolResNorm_SPFGMR; - S->ops->resid = SUNLinSolResid_SPFGMR; - S->ops->lastflag = SUNLinSolLastFlag_SPFGMR; - S->ops->space = SUNLinSolSpace_SPFGMR; - S->ops->free = SUNLinSolFree_SPFGMR; + S->ops->gettype = SUNLinSolGetType_SPFGMR; + S->ops->getid = SUNLinSolGetID_SPFGMR; + S->ops->setatimes = SUNLinSolSetATimes_SPFGMR; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_SPFGMR; + S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPFGMR; + S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPFGMR; + S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPFGMR; + S->ops->initialize = SUNLinSolInitialize_SPFGMR; + S->ops->setup = SUNLinSolSetup_SPFGMR; + S->ops->solve = SUNLinSolSolve_SPFGMR; + S->ops->numiters = SUNLinSolNumIters_SPFGMR; + S->ops->resnorm = SUNLinSolResNorm_SPFGMR; + S->ops->resid = SUNLinSolResid_SPFGMR; + S->ops->lastflag = SUNLinSolLastFlag_SPFGMR; + S->ops->space = SUNLinSolSpace_SPFGMR; + S->ops->free = SUNLinSolFree_SPFGMR; /* Create content */ content = NULL; @@ -137,6 +140,77 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_SPFGMR(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spfgmr." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "spfgmr."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "prec_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPFGMRSetPrecType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over GSType function */ + if (strcmp(argv[i] + offset, "gs_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPFGMRSetGSType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over MaxRestarts function */ + if (strcmp(argv[i] + offset, "max_restarts") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPFGMRSetMaxRestarts(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over ZeroGuess function */ + if (strcmp(argv[i] + offset, "zero_guess") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSolSetZeroGuess_SPFGMR(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to toggle preconditioning on/off -- turns on if pretype is any * one of SUN_PREC_LEFT, SUN_PREC_RIGHT or SUN_PREC_BOTH; otherwise turns off diff --git a/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.c b/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.c index 2be19f50fe..28c7e7503c 100644 --- a/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.c +++ b/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spgmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPGMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -304,6 +359,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPGMR(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPGMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPGMR(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.f90 b/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.f90 index b71379bbb2..b978afeecd 100644 --- a/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.f90 +++ b/src/sunlinsol/spgmr/fmod_int32/fsunlinsol_spgmr_mod.f90 @@ -34,6 +34,22 @@ module fsunlinsol_spgmr_mod public :: FSUNLinSolGetType_SPGMR public :: FSUNLinSolGetID_SPGMR public :: FSUNLinSolInitialize_SPGMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPGMR public :: FSUNLinSolSetATimes_SPGMR public :: FSUNLinSolSetPreconditioner_SPGMR public :: FSUNLinSolSetScalingVectors_SPGMR @@ -111,6 +127,19 @@ function swigc_FSUNLinSolInitialize_SPGMR(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPGMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPGMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPGMR(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPGMR") & result(fresult) @@ -336,6 +365,47 @@ function FSUNLinSolInitialize_SPGMR(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPGMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPGMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPGMR(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.c b/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.c index 8063348bb1..dbd3f9b108 100644 --- a/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.c +++ b/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_spgmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPGMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -304,6 +359,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPGMR(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPGMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPGMR(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.f90 b/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.f90 index 950e7ee8a7..5b8222fe8d 100644 --- a/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.f90 +++ b/src/sunlinsol/spgmr/fmod_int64/fsunlinsol_spgmr_mod.f90 @@ -34,6 +34,22 @@ module fsunlinsol_spgmr_mod public :: FSUNLinSolGetType_SPGMR public :: FSUNLinSolGetID_SPGMR public :: FSUNLinSolInitialize_SPGMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPGMR public :: FSUNLinSolSetATimes_SPGMR public :: FSUNLinSolSetPreconditioner_SPGMR public :: FSUNLinSolSetScalingVectors_SPGMR @@ -111,6 +127,19 @@ function swigc_FSUNLinSolInitialize_SPGMR(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPGMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPGMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPGMR(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPGMR") & result(fresult) @@ -336,6 +365,47 @@ function FSUNLinSolInitialize_SPGMR(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPGMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPGMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPGMR(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/spgmr/sunlinsol_spgmr.c b/src/sunlinsol/spgmr/sunlinsol_spgmr.c index 55a472987c..5290d53cc0 100644 --- a/src/sunlinsol/spgmr/sunlinsol_spgmr.c +++ b/src/sunlinsol/spgmr/sunlinsol_spgmr.c @@ -19,11 +19,13 @@ #include #include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_logger_impl.h" #include "sundials_macros.h" @@ -76,21 +78,22 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, SUNCheckLastErrNull(); /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_SPGMR; - S->ops->getid = SUNLinSolGetID_SPGMR; - S->ops->setatimes = SUNLinSolSetATimes_SPGMR; - S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPGMR; - S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPGMR; - S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPGMR; - S->ops->initialize = SUNLinSolInitialize_SPGMR; - S->ops->setup = SUNLinSolSetup_SPGMR; - S->ops->solve = SUNLinSolSolve_SPGMR; - S->ops->numiters = SUNLinSolNumIters_SPGMR; - S->ops->resnorm = SUNLinSolResNorm_SPGMR; - S->ops->resid = SUNLinSolResid_SPGMR; - S->ops->lastflag = SUNLinSolLastFlag_SPGMR; - S->ops->space = SUNLinSolSpace_SPGMR; - S->ops->free = SUNLinSolFree_SPGMR; + S->ops->gettype = SUNLinSolGetType_SPGMR; + S->ops->getid = SUNLinSolGetID_SPGMR; + S->ops->setatimes = SUNLinSolSetATimes_SPGMR; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_SPGMR; + S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPGMR; + S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPGMR; + S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPGMR; + S->ops->initialize = SUNLinSolInitialize_SPGMR; + S->ops->setup = SUNLinSolSetup_SPGMR; + S->ops->solve = SUNLinSolSolve_SPGMR; + S->ops->numiters = SUNLinSolNumIters_SPGMR; + S->ops->resnorm = SUNLinSolResNorm_SPGMR; + S->ops->resid = SUNLinSolResid_SPGMR; + S->ops->lastflag = SUNLinSolLastFlag_SPGMR; + S->ops->space = SUNLinSolSpace_SPGMR; + S->ops->free = SUNLinSolFree_SPGMR; /* Create content */ content = NULL; @@ -134,6 +137,77 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_SPGMR(SUNLinearSolver S, const char* LSid, + int argc, char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spgmr." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "spgmr."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "prec_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPGMRSetPrecType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over GSType function */ + if (strcmp(argv[i] + offset, "gs_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPGMRSetGSType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over MaxRestarts function */ + if (strcmp(argv[i] + offset, "max_restarts") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPGMRSetMaxRestarts(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over ZeroGuess function */ + if (strcmp(argv[i] + offset, "zero_guess") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSolSetZeroGuess_SPGMR(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the type of preconditioning for SPGMR to use */ diff --git a/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.c b/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.c index f16ec912e2..648b2c233f 100644 --- a/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.c +++ b/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_sptfqmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPTFQMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPTFQMR(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPTFQMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPTFQMR(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.f90 b/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.f90 index e34a320d20..2d2bd25ed5 100644 --- a/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.f90 +++ b/src/sunlinsol/sptfqmr/fmod_int32/fsunlinsol_sptfqmr_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_sptfqmr_mod public :: FSUNLinSolGetType_SPTFQMR public :: FSUNLinSolGetID_SPTFQMR public :: FSUNLinSolInitialize_SPTFQMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPTFQMR public :: FSUNLinSolSetATimes_SPTFQMR public :: FSUNLinSolSetPreconditioner_SPTFQMR public :: FSUNLinSolSetScalingVectors_SPTFQMR @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_SPTFQMR(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPTFQMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPTFQMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPTFQMR(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPTFQMR") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_SPTFQMR(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPTFQMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPTFQMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPTFQMR(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.c b/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.c index b5fee5a458..de16e81331 100644 --- a/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.c +++ b/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.c @@ -178,6 +178,22 @@ { printf("In " DECL ": " MSG); assert(0); RETURNNULL; } +enum { + SWIG_MEM_OWN = 0x01, + SWIG_MEM_RVALUE = 0x02, + SWIG_MEM_CONST = 0x04 +}; + + +#define SWIG_check_mutable(SWIG_CLASS_WRAPPER, TYPENAME, FNAME, FUNCNAME, RETURNNULL) \ + if ((SWIG_CLASS_WRAPPER).cmemflags & SWIG_MEM_CONST) { \ + SWIG_exception_impl(FUNCNAME, SWIG_TypeError, \ + "Cannot pass const " TYPENAME " (class " FNAME ") " \ + "as a mutable reference", \ + RETURNNULL); \ + } + + #include #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) # ifndef snprintf @@ -208,6 +224,45 @@ #include "sunlinsol/sunlinsol_sptfqmr.h" + +#include +#ifdef _MSC_VER +# ifndef strtoull +# define strtoull _strtoui64 +# endif +# ifndef strtoll +# define strtoll _strtoi64 +# endif +#endif + + +typedef struct { + void* data; + size_t size; +} SwigArrayWrapper; + + +SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { + SwigArrayWrapper result; + result.data = NULL; + result.size = 0; + return result; +} + + +typedef struct { + void* cptr; + int cmemflags; +} SwigClassWrapper; + + +SWIGINTERN SwigClassWrapper SwigClassWrapper_uninitialized() { + SwigClassWrapper result; + result.cptr = NULL; + result.cmemflags = 0; + return result; +} + SWIGEXPORT SUNLinearSolver _wrap_FSUNLinSol_SPTFQMR(N_Vector farg1, int const *farg2, int const *farg3, void *farg4) { SUNLinearSolver fresult ; N_Vector arg1 = (N_Vector) 0 ; @@ -290,6 +345,25 @@ SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPTFQMR(SUNLinearSolver farg1) { } +SWIGEXPORT int _wrap_FSUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver farg1, SwigArrayWrapper *farg2, int const *farg3, SwigClassWrapper const *farg4) { + int fresult ; + SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + char **arg4 ; + SUNErrCode result; + + arg1 = (SUNLinearSolver)(farg1); + arg2 = (char *)(farg2->data); + arg3 = (int)(*farg3); + SWIG_check_mutable(*farg4, "char **", "SWIGTYPE_p_p_char", "SUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver,char const *,int,char *[])", return 0); + arg4 = (char **)(farg4->cptr); + result = (SUNErrCode)SUNLinSolSetFromCommandLine_SPTFQMR(arg1,(char const *)arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPTFQMR(SUNLinearSolver farg1, void *farg2, SUNATimesFn farg3) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; diff --git a/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.f90 b/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.f90 index ffc1fc0626..6b87ed1ef8 100644 --- a/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.f90 +++ b/src/sunlinsol/sptfqmr/fmod_int64/fsunlinsol_sptfqmr_mod.f90 @@ -32,6 +32,22 @@ module fsunlinsol_sptfqmr_mod public :: FSUNLinSolGetType_SPTFQMR public :: FSUNLinSolGetID_SPTFQMR public :: FSUNLinSolInitialize_SPTFQMR + + integer, parameter :: swig_cmem_own_bit = 0 + integer, parameter :: swig_cmem_rvalue_bit = 1 + integer, parameter :: swig_cmem_const_bit = 2 + type, bind(C) :: SwigClassWrapper + type(C_PTR), public :: cptr = C_NULL_PTR + integer(C_INT), public :: cmemflags = 0 + end type + type, public :: SWIGTYPE_p_p_char + type(SwigClassWrapper), public :: swigdata + end type + type, bind(C) :: SwigArrayWrapper + type(C_PTR), public :: data = C_NULL_PTR + integer(C_SIZE_T), public :: size = 0 + end type + public :: FSUNLinSolSetFromCommandLine_SPTFQMR public :: FSUNLinSolSetATimes_SPTFQMR public :: FSUNLinSolSetPreconditioner_SPTFQMR public :: FSUNLinSolSetScalingVectors_SPTFQMR @@ -100,6 +116,19 @@ function swigc_FSUNLinSolInitialize_SPTFQMR(farg1) & integer(C_INT) :: fresult end function +function swigc_FSUNLinSolSetFromCommandLine_SPTFQMR(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNLinSolSetFromCommandLine_SPTFQMR") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +import :: swigarraywrapper +import :: swigclasswrapper +type(C_PTR), value :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT), intent(in) :: farg3 +type(SwigClassWrapper) :: farg4 +integer(C_INT) :: fresult +end function + function swigc_FSUNLinSolSetATimes_SPTFQMR(farg1, farg2, farg3) & bind(C, name="_wrap_FSUNLinSolSetATimes_SPTFQMR") & result(fresult) @@ -309,6 +338,47 @@ function FSUNLinSolInitialize_SPTFQMR(s) & swig_result = fresult end function + +subroutine SWIG_string_to_chararray(string, chars, wrap) + use, intrinsic :: ISO_C_BINDING + character(kind=C_CHAR, len=*), intent(IN) :: string + character(kind=C_CHAR), dimension(:), target, allocatable, intent(OUT) :: chars + type(SwigArrayWrapper), intent(OUT) :: wrap + integer :: i + + allocate(character(kind=C_CHAR) :: chars(len(string) + 1)) + do i=1,len(string) + chars(i) = string(i:i) + end do + i = len(string) + 1 + chars(i) = C_NULL_CHAR ! C string compatibility + wrap%data = c_loc(chars) + wrap%size = len(string) +end subroutine + +function FSUNLinSolSetFromCommandLine_SPTFQMR(s, lsid, argc, argv) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(SUNLinearSolver), target, intent(inout) :: s +character(kind=C_CHAR, len=*), target :: lsid +character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars +integer(C_INT), intent(in) :: argc +class(SWIGTYPE_p_p_char), intent(in) :: argv +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(SwigArrayWrapper) :: farg2 +integer(C_INT) :: farg3 +type(SwigClassWrapper) :: farg4 + +farg1 = c_loc(s) +call SWIG_string_to_chararray(lsid, farg2_chars, farg2) +farg3 = argc +farg4 = argv%swigdata +fresult = swigc_FSUNLinSolSetFromCommandLine_SPTFQMR(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + function FSUNLinSolSetATimes_SPTFQMR(s, a_data, atimes) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c b/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c index cc13ae7068..f3b4840a49 100644 --- a/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c +++ b/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c @@ -18,11 +18,13 @@ #include #include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_logger_impl.h" #include "sundials_macros.h" @@ -75,21 +77,22 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, SUNCheckLastErrNull(); /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_SPTFQMR; - S->ops->getid = SUNLinSolGetID_SPTFQMR; - S->ops->setatimes = SUNLinSolSetATimes_SPTFQMR; - S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPTFQMR; - S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPTFQMR; - S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPTFQMR; - S->ops->initialize = SUNLinSolInitialize_SPTFQMR; - S->ops->setup = SUNLinSolSetup_SPTFQMR; - S->ops->solve = SUNLinSolSolve_SPTFQMR; - S->ops->numiters = SUNLinSolNumIters_SPTFQMR; - S->ops->resnorm = SUNLinSolResNorm_SPTFQMR; - S->ops->resid = SUNLinSolResid_SPTFQMR; - S->ops->lastflag = SUNLinSolLastFlag_SPTFQMR; - S->ops->space = SUNLinSolSpace_SPTFQMR; - S->ops->free = SUNLinSolFree_SPTFQMR; + S->ops->gettype = SUNLinSolGetType_SPTFQMR; + S->ops->getid = SUNLinSolGetID_SPTFQMR; + S->ops->setatimes = SUNLinSolSetATimes_SPTFQMR; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_SPTFQMR; + S->ops->setpreconditioner = SUNLinSolSetPreconditioner_SPTFQMR; + S->ops->setscalingvectors = SUNLinSolSetScalingVectors_SPTFQMR; + S->ops->setzeroguess = SUNLinSolSetZeroGuess_SPTFQMR; + S->ops->initialize = SUNLinSolInitialize_SPTFQMR; + S->ops->setup = SUNLinSolSetup_SPTFQMR; + S->ops->solve = SUNLinSolSolve_SPTFQMR; + S->ops->numiters = SUNLinSolNumIters_SPTFQMR; + S->ops->resnorm = SUNLinSolResNorm_SPTFQMR; + S->ops->resid = SUNLinSolResid_SPTFQMR; + S->ops->lastflag = SUNLinSolLastFlag_SPTFQMR; + S->ops->space = SUNLinSolSpace_SPTFQMR; + S->ops->free = SUNLinSolFree_SPTFQMR; /* Create content */ content = NULL; @@ -149,6 +152,68 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_SPTFQMR(SUNLinearSolver S, + const char* LSid, int argc, + char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "sptfqmr."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "prec_type") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPTFQMRSetPrecType(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over Maxl function */ + if (strcmp(argv[i] + offset, "maxl") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SPTFQMRSetMaxl(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + + /* control over ZeroGuess function */ + if (strcmp(argv[i] + offset, "zero_guess") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSolSetZeroGuess_SPTFQMR(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the type of preconditioning for SPTFQMR to use */ diff --git a/src/sunlinsol/superlumt/sunlinsol_superlumt.c b/src/sunlinsol/superlumt/sunlinsol_superlumt.c index fc35e33735..26930dc956 100644 --- a/src/sunlinsol/superlumt/sunlinsol_superlumt.c +++ b/src/sunlinsol/superlumt/sunlinsol_superlumt.c @@ -20,11 +20,14 @@ #include #include +#include +#include #include #include #include +#include "sundials_cli.h" #include "sundials_macros.h" #define ZERO SUN_RCONST(0.0) @@ -91,14 +94,15 @@ SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, SUNMatrix A, int num_threads, if (S == NULL) { return (NULL); } /* Attach operations */ - S->ops->gettype = SUNLinSolGetType_SuperLUMT; - S->ops->getid = SUNLinSolGetID_SuperLUMT; - S->ops->initialize = SUNLinSolInitialize_SuperLUMT; - S->ops->setup = SUNLinSolSetup_SuperLUMT; - S->ops->solve = SUNLinSolSolve_SuperLUMT; - S->ops->lastflag = SUNLinSolLastFlag_SuperLUMT; - S->ops->space = SUNLinSolSpace_SuperLUMT; - S->ops->free = SUNLinSolFree_SuperLUMT; + S->ops->gettype = SUNLinSolGetType_SuperLUMT; + S->ops->getid = SUNLinSolGetID_SuperLUMT; + S->ops->initialize = SUNLinSolInitialize_SuperLUMT; + S->ops->setfromcommandline = SUNLinSolSetFromCommandLine_SuperLUMT; + S->ops->setup = SUNLinSolSetup_SuperLUMT; + S->ops->solve = SUNLinSolSolve_SuperLUMT; + S->ops->lastflag = SUNLinSolLastFlag_SuperLUMT; + S->ops->space = SUNLinSolSpace_SuperLUMT; + S->ops->free = SUNLinSolFree_SuperLUMT; /* Create content */ content = NULL; @@ -203,6 +207,48 @@ SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, SUNMatrix A, int num_threads, return (S); } +/* ---------------------------------------------------------------------------- + * Function to control set routines via the command line + */ + +SUNErrCode SUNLinSolSetFromCommandLine_SuperLUMT(SUNLinearSolver S, + const char* LSid, int argc, + char* argv[]) +{ + SUNFunctionBegin(S->sunctx); + + int i; + SUNErrCode retval; + for (i = 1; i < argc; i++) + { + /* if LSid is supplied, skip command-line arguments that do not begin with LSid; + else, skip command-line arguments that do not begin with "spbcgs." */ + size_t offset; + if (strlen(LSid) > 0) + { + if (strncmp(argv[i], LSid, strlen(LSid)) != 0) { continue; } + offset = strlen(LSid) + 1; + } + else + { + static const char* prefix = "superlumt."; + if (strncmp(argv[i], prefix, strlen(prefix)) != 0) { continue; } + offset = strlen(prefix); + } + + /* control over PrecType function */ + if (strcmp(argv[i] + offset, "ordering") == 0) + { + i += 1; + int iarg = atoi(argv[i]); + retval = SUNLinSol_SuperLUMTSetOrdering(S, iarg); + if (retval != SUN_SUCCESS) { return retval; } + continue; + } + } + return SUN_SUCCESS; +} + /* ---------------------------------------------------------------------------- * Function to set the ordering type for a SuperLUMT linear solver */