diff --git a/cleanup b/cleanup index c652a90..d762f2b 100755 --- a/cleanup +++ b/cleanup @@ -1,9 +1,10 @@ #! /bin/sh -rm -fr src/*.o src/*.so autom4te.cache config.log config.status inst/lib/*.a +rm -fr src/*.o src/*.so autom4te.cache config.log config.status inst/lib/*.a inst/*.a rm -fr src/sundials rm -fr inst/lib rm -f configure~ rm -f Makevars rm -f config.log rm -f config.status + diff --git a/cleanup.win b/cleanup.win new file mode 100644 index 0000000..a03d7ea --- /dev/null +++ b/cleanup.win @@ -0,0 +1,2 @@ +#! /bin/sh +./cleanup $* diff --git a/configure.win b/configure.win new file mode 100644 index 0000000..dfb10e8 --- /dev/null +++ b/configure.win @@ -0,0 +1,2 @@ +#! /bin/sh +./configure $* diff --git a/inst/include/arkode/arkode.h b/inst/include/arkode/arkode.h new file mode 100644 index 0000000..f4e0667 --- /dev/null +++ b/inst/include/arkode/arkode.h @@ -0,0 +1,419 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main ARKODE infrastructure. + * ----------------------------------------------------------------- + * ARKODE is used to numerically solve the ordinary initial value + * problems using one-step methods. Users do not call ARKODE + * infrastructure routines directly; they instead interact with + * one of the time stepping modules built on top of ARKODE. + * These time step modules define their supported problem types, + * solver options, etc. + * + * This file serves to define constants and provide function + * prototypes for use across ARKODE-based time integration + * modules. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_H +#define _ARKODE_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * ARKODE Constants + * ----------------- */ + +/* usage modes (itask) */ +#define ARK_NORMAL 1 +#define ARK_ONE_STEP 2 + +/* adaptivity module flags */ +#define ARK_ADAPT_CUSTOM -1 +#define ARK_ADAPT_PID 0 +#define ARK_ADAPT_PI 1 +#define ARK_ADAPT_I 2 +#define ARK_ADAPT_EXP_GUS 3 +#define ARK_ADAPT_IMP_GUS 4 +#define ARK_ADAPT_IMEX_GUS 5 + +/* Constants for evaluating the full RHS */ +#define ARK_FULLRHS_START 0 +#define ARK_FULLRHS_END 1 +#define ARK_FULLRHS_OTHER 2 + +/* interpolation module flags */ + +/* max allowed degree */ +#define ARK_INTERP_MAX_DEGREE 5 + +/* interpolation module types */ +#define ARK_INTERP_NONE -1 +#define ARK_INTERP_HERMITE 0 +#define ARK_INTERP_LAGRANGE 1 + +/* return values */ + +#define ARK_SUCCESS 0 +#define ARK_TSTOP_RETURN 1 +#define ARK_ROOT_RETURN 2 + +#define ARK_WARNING 99 + +#define ARK_TOO_MUCH_WORK -1 +#define ARK_TOO_MUCH_ACC -2 +#define ARK_ERR_FAILURE -3 +#define ARK_CONV_FAILURE -4 + +#define ARK_LINIT_FAIL -5 +#define ARK_LSETUP_FAIL -6 +#define ARK_LSOLVE_FAIL -7 +#define ARK_RHSFUNC_FAIL -8 +#define ARK_FIRST_RHSFUNC_ERR -9 +#define ARK_REPTD_RHSFUNC_ERR -10 +#define ARK_UNREC_RHSFUNC_ERR -11 +#define ARK_RTFUNC_FAIL -12 +#define ARK_LFREE_FAIL -13 +#define ARK_MASSINIT_FAIL -14 +#define ARK_MASSSETUP_FAIL -15 +#define ARK_MASSSOLVE_FAIL -16 +#define ARK_MASSFREE_FAIL -17 +#define ARK_MASSMULT_FAIL -18 + +#define ARK_CONSTR_FAIL -19 +#define ARK_MEM_FAIL -20 +#define ARK_MEM_NULL -21 +#define ARK_ILL_INPUT -22 +#define ARK_NO_MALLOC -23 +#define ARK_BAD_K -24 +#define ARK_BAD_T -25 +#define ARK_BAD_DKY -26 +#define ARK_TOO_CLOSE -27 + +#define ARK_VECTOROP_ERR -28 + +#define ARK_NLS_INIT_FAIL -29 +#define ARK_NLS_SETUP_FAIL -30 +#define ARK_NLS_SETUP_RECVR -31 +#define ARK_NLS_OP_ERR -32 + +#define ARK_INNERSTEP_ATTACH_ERR -33 +#define ARK_INNERSTEP_FAIL -34 +#define ARK_OUTERTOINNER_FAIL -35 +#define ARK_INNERTOOUTER_FAIL -36 + +/* ARK_POSTPROCESS_FAIL equals ARK_POSTPROCESS_STEP_FAIL + for backwards compatibility */ +#define ARK_POSTPROCESS_FAIL -37 +#define ARK_POSTPROCESS_STEP_FAIL -37 +#define ARK_POSTPROCESS_STAGE_FAIL -38 + +#define ARK_USER_PREDICT_FAIL -39 +#define ARK_INTERP_FAIL -40 + +#define ARK_INVALID_TABLE -41 + +#define ARK_CONTEXT_ERR -42 + +#define ARK_RELAX_FAIL -43 +#define ARK_RELAX_MEM_NULL -44 +#define ARK_RELAX_FUNC_FAIL -45 +#define ARK_RELAX_JAC_FAIL -46 + +#define ARK_CONTROLLER_ERR -47 + +#define ARK_STEPPER_UNSUPPORTED -48 + +#define ARK_UNRECOGNIZED_ERROR -99 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*ARKRhsFn)(sunrealtype t, N_Vector y, N_Vector ydot, + void* user_data); + +typedef int (*ARKRootFn)(sunrealtype t, N_Vector y, sunrealtype* gout, + void* user_data); + +typedef int (*ARKEwtFn)(N_Vector y, N_Vector ewt, void* user_data); + +typedef int (*ARKRwtFn)(N_Vector y, N_Vector rwt, void* user_data); + +typedef int (*ARKAdaptFn)(N_Vector y, sunrealtype t, sunrealtype h1, + sunrealtype h2, sunrealtype h3, sunrealtype e1, + sunrealtype e2, sunrealtype e3, int q, int p, + sunrealtype* hnew, void* user_data); + +typedef int (*ARKExpStabFn)(N_Vector y, sunrealtype t, sunrealtype* hstab, + void* user_data); + +typedef int (*ARKVecResizeFn)(N_Vector y, N_Vector ytemplate, void* user_data); + +typedef int (*ARKPostProcessFn)(sunrealtype t, N_Vector y, void* user_data); + +typedef int (*ARKStagePredictFn)(sunrealtype t, N_Vector zpred, void* user_data); + +typedef int (*ARKRelaxFn)(N_Vector y, sunrealtype* r, void* user_data); + +typedef int (*ARKRelaxJacFn)(N_Vector y, N_Vector J, void* user_data); + +/* ------------------------------------------------ + * MRIStep Inner Stepper Type (forward declaration) + * ------------------------------------------------ */ + +typedef _SUNDIALS_STRUCT_ _MRIStepInnerStepper* MRIStepInnerStepper; + +/* -------------------------- + * Relaxation Solver Options + * -------------------------- */ + +typedef enum +{ + ARK_RELAX_BRENT, + ARK_RELAX_NEWTON +} ARKRelaxSolver; + +/* -------------------------- + * Shared API routines + * -------------------------- */ + +/* Resize and Reset functions */ +SUNDIALS_EXPORT int ARKodeResize(void* arkode_mem, N_Vector ynew, + sunrealtype hscale, sunrealtype t0, + ARKVecResizeFn resize, void* resize_data); +SUNDIALS_EXPORT int ARKodeReset(void* arkode_mem, sunrealtype tR, N_Vector yR); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int ARKodeSStolerances(void* arkode_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int ARKodeSVtolerances(void* arkode_mem, sunrealtype reltol, + N_Vector abstol); +SUNDIALS_EXPORT int ARKodeWFtolerances(void* arkode_mem, ARKEwtFn efun); + +/* Residual tolerance input functions */ +SUNDIALS_EXPORT int ARKodeResStolerance(void* arkode_mem, sunrealtype rabstol); +SUNDIALS_EXPORT int ARKodeResVtolerance(void* arkode_mem, N_Vector rabstol); +SUNDIALS_EXPORT int ARKodeResFtolerance(void* arkode_mem, ARKRwtFn rfun); + +/* Rootfinding */ +SUNDIALS_EXPORT int ARKodeRootInit(void* arkode_mem, int nrtfn, ARKRootFn g); +SUNDIALS_EXPORT int ARKodeSetRootDirection(void* arkode_mem, int* rootdir); +SUNDIALS_EXPORT int ARKodeSetNoInactiveRootWarn(void* arkode_mem); + +/* Optional input functions (general) */ +SUNDIALS_EXPORT int ARKodeSetDefaults(void* arkode_mem); +SUNDIALS_EXPORT int ARKodeSetOrder(void* arkode_mem, int maxord); +SUNDIALS_EXPORT int ARKodeSetInterpolantType(void* arkode_mem, int itype); +SUNDIALS_EXPORT int ARKodeSetInterpolantDegree(void* arkode_mem, int degree); +SUNDIALS_EXPORT int ARKodeSetMaxNumSteps(void* arkode_mem, long int mxsteps); +SUNDIALS_EXPORT int ARKodeSetInterpolateStopTime(void* arkode_mem, + sunbooleantype interp); +SUNDIALS_EXPORT int ARKodeSetStopTime(void* arkode_mem, sunrealtype tstop); +SUNDIALS_EXPORT int ARKodeClearStopTime(void* arkode_mem); +SUNDIALS_EXPORT int ARKodeSetFixedStep(void* arkode_mem, sunrealtype hfixed); +SUNDIALS_EXPORT int ARKodeSetUserData(void* arkode_mem, void* user_data); +SUNDIALS_EXPORT int ARKodeSetPostprocessStepFn(void* arkode_mem, + ARKPostProcessFn ProcessStep); +SUNDIALS_EXPORT int ARKodeSetPostprocessStageFn(void* arkode_mem, + ARKPostProcessFn ProcessStage); + +/* Optional input functions (implicit solver) */ +SUNDIALS_EXPORT int ARKodeSetNonlinearSolver(void* arkode_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int ARKodeSetLinear(void* arkode_mem, int timedepend); +SUNDIALS_EXPORT int ARKodeSetNonlinear(void* arkode_mem); +SUNDIALS_EXPORT int ARKodeSetAutonomous(void* arkode_mem, + sunbooleantype autonomous); +SUNDIALS_EXPORT int ARKodeSetNlsRhsFn(void* arkode_mem, ARKRhsFn nls_fi); +SUNDIALS_EXPORT int ARKodeSetDeduceImplicitRhs(void* arkode_mem, + sunbooleantype deduce); +SUNDIALS_EXPORT int ARKodeSetNonlinCRDown(void* arkode_mem, sunrealtype crdown); +SUNDIALS_EXPORT int ARKodeSetNonlinRDiv(void* arkode_mem, sunrealtype rdiv); +SUNDIALS_EXPORT int ARKodeSetDeltaGammaMax(void* arkode_mem, sunrealtype dgmax); +SUNDIALS_EXPORT int ARKodeSetLSetupFrequency(void* arkode_mem, int msbp); +SUNDIALS_EXPORT int ARKodeSetPredictorMethod(void* arkode_mem, int method); +SUNDIALS_EXPORT int ARKodeSetMaxNonlinIters(void* arkode_mem, int maxcor); +SUNDIALS_EXPORT int ARKodeSetMaxConvFails(void* arkode_mem, int maxncf); +SUNDIALS_EXPORT int ARKodeSetNonlinConvCoef(void* arkode_mem, + sunrealtype nlscoef); +SUNDIALS_EXPORT int ARKodeSetStagePredictFn(void* arkode_mem, + ARKStagePredictFn PredictStage); + +/* Optional input functions (temporal adaptivity) */ +SUNDIALS_EXPORT int ARKodeSetAdaptController(void* arkode_mem, + SUNAdaptController C); +SUNDIALS_EXPORT int ARKodeSetAdaptivityAdjustment(void* arkode_mem, int adjust); +SUNDIALS_EXPORT int ARKodeSetCFLFraction(void* arkode_mem, sunrealtype cfl_frac); +SUNDIALS_EXPORT int ARKodeSetErrorBias(void* arkode_mem, sunrealtype bias); +SUNDIALS_EXPORT int ARKodeSetSafetyFactor(void* arkode_mem, sunrealtype safety); +SUNDIALS_EXPORT int ARKodeSetMaxGrowth(void* arkode_mem, sunrealtype mx_growth); +SUNDIALS_EXPORT int ARKodeSetMinReduction(void* arkode_mem, sunrealtype eta_min); +SUNDIALS_EXPORT int ARKodeSetFixedStepBounds(void* arkode_mem, sunrealtype lb, + sunrealtype ub); +SUNDIALS_EXPORT int ARKodeSetMaxFirstGrowth(void* arkode_mem, sunrealtype etamx1); +SUNDIALS_EXPORT int ARKodeSetMaxEFailGrowth(void* arkode_mem, sunrealtype etamxf); +SUNDIALS_EXPORT int ARKodeSetSmallNumEFails(void* arkode_mem, int small_nef); +SUNDIALS_EXPORT int ARKodeSetMaxCFailGrowth(void* arkode_mem, sunrealtype etacf); +SUNDIALS_EXPORT int ARKodeSetStabilityFn(void* arkode_mem, ARKExpStabFn EStab, + void* estab_data); +SUNDIALS_EXPORT int ARKodeSetMaxErrTestFails(void* arkode_mem, int maxnef); +SUNDIALS_EXPORT int ARKodeSetConstraints(void* arkode_mem, N_Vector constraints); +SUNDIALS_EXPORT int ARKodeSetMaxHnilWarns(void* arkode_mem, int mxhnil); +SUNDIALS_EXPORT int ARKodeSetInitStep(void* arkode_mem, sunrealtype hin); +SUNDIALS_EXPORT int ARKodeSetMinStep(void* arkode_mem, sunrealtype hmin); +SUNDIALS_EXPORT int ARKodeSetMaxStep(void* arkode_mem, sunrealtype hmax); +SUNDIALS_EXPORT int ARKodeSetMaxNumConstrFails(void* arkode_mem, int maxfails); + +/* Integrate the ODE over an interval in t */ +SUNDIALS_EXPORT int ARKodeEvolve(void* arkode_mem, sunrealtype tout, + N_Vector yout, sunrealtype* tret, int itask); + +/* Computes the kth derivative of the y function at time t */ +SUNDIALS_EXPORT int ARKodeGetDky(void* arkode_mem, sunrealtype t, int k, + N_Vector dky); + +/* Utility function to update/compute y based on zcor */ +SUNDIALS_EXPORT int ARKodeComputeState(void* arkode_mem, N_Vector zcor, + N_Vector z); + +/* Optional output functions (general) */ +SUNDIALS_EXPORT int ARKodeGetNumStepAttempts(void* arkode_mem, + long int* step_attempts); +SUNDIALS_EXPORT int ARKodeGetWorkSpace(void* arkode_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int ARKodeGetNumSteps(void* arkode_mem, long int* nsteps); +SUNDIALS_EXPORT int ARKodeGetLastStep(void* arkode_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int ARKodeGetCurrentStep(void* arkode_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int ARKodeGetErrWeights(void* arkode_mem, N_Vector eweight); +SUNDIALS_EXPORT int ARKodeGetNumGEvals(void* arkode_mem, long int* ngevals); +SUNDIALS_EXPORT int ARKodeGetRootInfo(void* arkode_mem, int* rootsfound); +SUNDIALS_EXPORT int ARKodeGetUserData(void* arkode_mem, void** user_data); +SUNDIALS_EXPORT int ARKodePrintAllStats(void* arkode_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* ARKodeGetReturnFlagName(long int flag); +SUNDIALS_EXPORT int ARKodeWriteParameters(void* arkode_mem, FILE* fp); + +/* Optional output functions (temporal adaptivity) */ +SUNDIALS_EXPORT int ARKodeGetNumExpSteps(void* arkode_mem, long int* expsteps); +SUNDIALS_EXPORT int ARKodeGetNumAccSteps(void* arkode_mem, long int* accsteps); +SUNDIALS_EXPORT int ARKodeGetNumErrTestFails(void* arkode_mem, + long int* netfails); +SUNDIALS_EXPORT int ARKodeGetEstLocalErrors(void* arkode_mem, N_Vector ele); +SUNDIALS_EXPORT int ARKodeGetActualInitStep(void* arkode_mem, + sunrealtype* hinused); +SUNDIALS_EXPORT int ARKodeGetTolScaleFactor(void* arkode_mem, + sunrealtype* tolsfac); +SUNDIALS_EXPORT int ARKodeGetNumConstrFails(void* arkode_mem, + long int* nconstrfails); +SUNDIALS_EXPORT int ARKodeGetStepStats(void* arkode_mem, long int* nsteps, + sunrealtype* hinused, sunrealtype* hlast, + sunrealtype* hcur, sunrealtype* tcur); + +/* Optional output functions (implicit solver) */ +SUNDIALS_EXPORT int ARKodeGetNumLinSolvSetups(void* arkode_mem, + long int* nlinsetups); +SUNDIALS_EXPORT int ARKodeGetCurrentTime(void* arkode_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int ARKodeGetCurrentState(void* arkode_mem, N_Vector* state); +SUNDIALS_EXPORT int ARKodeGetCurrentGamma(void* arkode_mem, sunrealtype* gamma); +SUNDIALS_EXPORT int ARKodeGetNonlinearSystemData( + void* arkode_mem, sunrealtype* tcur, N_Vector* zpred, N_Vector* z, + N_Vector* Fi, sunrealtype* gamma, N_Vector* sdata, void** user_data); +SUNDIALS_EXPORT int ARKodeGetNumNonlinSolvIters(void* arkode_mem, + long int* nniters); +SUNDIALS_EXPORT int ARKodeGetNumNonlinSolvConvFails(void* arkode_mem, + long int* nnfails); +SUNDIALS_EXPORT int ARKodeGetNonlinSolvStats(void* arkode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int ARKodeGetNumStepSolveFails(void* arkode_mem, + long int* nncfails); +SUNDIALS_EXPORT int ARKodeGetJac(void* arkode_mem, SUNMatrix* J); +SUNDIALS_EXPORT int ARKodeGetJacTime(void* arkode_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int ARKodeGetJacNumSteps(void* arkode_mem, long int* nst_J); +SUNDIALS_EXPORT int ARKodeGetLinWorkSpace(void* arkode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int ARKodeGetNumJacEvals(void* arkode_mem, long int* njevals); +SUNDIALS_EXPORT int ARKodeGetNumPrecEvals(void* arkode_mem, long int* npevals); +SUNDIALS_EXPORT int ARKodeGetNumPrecSolves(void* arkode_mem, long int* npsolves); +SUNDIALS_EXPORT int ARKodeGetNumLinIters(void* arkode_mem, long int* nliters); +SUNDIALS_EXPORT int ARKodeGetNumLinConvFails(void* arkode_mem, + long int* nlcfails); +SUNDIALS_EXPORT int ARKodeGetNumJTSetupEvals(void* arkode_mem, + long int* njtsetups); +SUNDIALS_EXPORT int ARKodeGetNumJtimesEvals(void* arkode_mem, long int* njvevals); +SUNDIALS_EXPORT int ARKodeGetNumLinRhsEvals(void* arkode_mem, + long int* nfevalsLS); +SUNDIALS_EXPORT int ARKodeGetLastLinFlag(void* arkode_mem, long int* flag); +SUNDIALS_EXPORT char* ARKodeGetLinReturnFlagName(long int flag); + +/* Optional output functions (non-identity mass matrices) */ +SUNDIALS_EXPORT int ARKodeGetCurrentMassMatrix(void* arkode_mem, SUNMatrix* M); +SUNDIALS_EXPORT int ARKodeGetResWeights(void* arkode_mem, N_Vector rweight); +SUNDIALS_EXPORT int ARKodeGetMassWorkSpace(void* arkode_mem, long int* lenrwMLS, + long int* leniwMLS); +SUNDIALS_EXPORT int ARKodeGetNumMassSetups(void* arkode_mem, long int* nmsetups); +SUNDIALS_EXPORT int ARKodeGetNumMassMultSetups(void* arkode_mem, + long int* nmvsetups); +SUNDIALS_EXPORT int ARKodeGetNumMassMult(void* arkode_mem, long int* nmvevals); +SUNDIALS_EXPORT int ARKodeGetNumMassSolves(void* arkode_mem, long int* nmsolves); +SUNDIALS_EXPORT int ARKodeGetNumMassPrecEvals(void* arkode_mem, + long int* nmpevals); +SUNDIALS_EXPORT int ARKodeGetNumMassPrecSolves(void* arkode_mem, + long int* nmpsolves); +SUNDIALS_EXPORT int ARKodeGetNumMassIters(void* arkode_mem, long int* nmiters); +SUNDIALS_EXPORT int ARKodeGetNumMassConvFails(void* arkode_mem, + long int* nmcfails); +SUNDIALS_EXPORT int ARKodeGetNumMTSetups(void* arkode_mem, long int* nmtsetups); +SUNDIALS_EXPORT int ARKodeGetLastMassFlag(void* arkode_mem, long int* flag); + +/* Free function */ +SUNDIALS_EXPORT void ARKodeFree(void** arkode_mem); + +/* Output the ARKODE memory structure (useful when debugging) */ +SUNDIALS_EXPORT void ARKodePrintMem(void* arkode_mem, FILE* outfile); + +/* Relaxation functions */ +SUNDIALS_EXPORT int ARKodeSetRelaxFn(void* arkode_mem, ARKRelaxFn rfn, + ARKRelaxJacFn rjac); +SUNDIALS_EXPORT int ARKodeSetRelaxEtaFail(void* arkode_mem, sunrealtype eta_rf); +SUNDIALS_EXPORT int ARKodeSetRelaxLowerBound(void* arkode_mem, sunrealtype lower); +SUNDIALS_EXPORT int ARKodeSetRelaxMaxFails(void* arkode_mem, int max_fails); +SUNDIALS_EXPORT int ARKodeSetRelaxMaxIters(void* arkode_mem, int max_iters); +SUNDIALS_EXPORT int ARKodeSetRelaxSolver(void* arkode_mem, ARKRelaxSolver solver); +SUNDIALS_EXPORT int ARKodeSetRelaxResTol(void* arkode_mem, sunrealtype res_tol); +SUNDIALS_EXPORT int ARKodeSetRelaxTol(void* arkode_mem, sunrealtype rel_tol, + sunrealtype abs_tol); +SUNDIALS_EXPORT int ARKodeSetRelaxUpperBound(void* arkode_mem, sunrealtype upper); +SUNDIALS_EXPORT int ARKodeGetNumRelaxFnEvals(void* arkode_mem, long int* r_evals); +SUNDIALS_EXPORT int ARKodeGetNumRelaxJacEvals(void* arkode_mem, + long int* J_evals); +SUNDIALS_EXPORT int ARKodeGetNumRelaxFails(void* arkode_mem, + long int* relax_fails); +SUNDIALS_EXPORT int ARKodeGetNumRelaxBoundFails(void* arkode_mem, + long int* fails); +SUNDIALS_EXPORT int ARKodeGetNumRelaxSolveFails(void* arkode_mem, + long int* fails); +SUNDIALS_EXPORT int ARKodeGetNumRelaxSolveIters(void* arkode_mem, + long int* iters); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_arkstep.h b/inst/include/arkode/arkode_arkstep.h new file mode 100644 index 0000000..f7a6f11 --- /dev/null +++ b/inst/include/arkode/arkode_arkstep.h @@ -0,0 +1,438 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKODE ARKStep module. + * -----------------------------------------------------------------*/ + +#ifndef _ARKSTEP_H +#define _ARKSTEP_H + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * ARKStep Constants + * ----------------- */ + +/* Default Butcher tables for each method/order */ + +/* explicit */ +static const int ARKSTEP_DEFAULT_ERK_1 = ARKODE_FORWARD_EULER_1_1; +static const int ARKSTEP_DEFAULT_ERK_2 = ARKODE_HEUN_EULER_2_1_2; +static const int ARKSTEP_DEFAULT_ERK_3 = ARKODE_BOGACKI_SHAMPINE_4_2_3; +static const int ARKSTEP_DEFAULT_ERK_4 = ARKODE_ZONNEVELD_5_3_4; +static const int ARKSTEP_DEFAULT_ERK_5 = ARKODE_CASH_KARP_6_4_5; +static const int ARKSTEP_DEFAULT_ERK_6 = ARKODE_VERNER_8_5_6; +static const int ARKSTEP_DEFAULT_ERK_7 = ARKODE_VERNER_10_6_7; +static const int ARKSTEP_DEFAULT_ERK_8 = ARKODE_FEHLBERG_13_7_8; +static const int ARKSTEP_DEFAULT_ERK_9 = ARKODE_VERNER_16_8_9; + +/* implicit */ +static const int ARKSTEP_DEFAULT_DIRK_1 = ARKODE_BACKWARD_EULER_1_1; +static const int ARKSTEP_DEFAULT_DIRK_2 = ARKODE_SDIRK_2_1_2; +static const int ARKSTEP_DEFAULT_DIRK_3 = ARKODE_ARK324L2SA_DIRK_4_2_3; +static const int ARKSTEP_DEFAULT_DIRK_4 = ARKODE_SDIRK_5_3_4; +static const int ARKSTEP_DEFAULT_DIRK_5 = ARKODE_ARK548L2SA_DIRK_8_4_5; + +/* ImEx */ +static const int ARKSTEP_DEFAULT_ARK_ETABLE_2 = ARKODE_ARK2_ERK_3_1_2; +static const int ARKSTEP_DEFAULT_ARK_ETABLE_3 = ARKODE_ARK324L2SA_ERK_4_2_3; +static const int ARKSTEP_DEFAULT_ARK_ETABLE_4 = ARKODE_ARK436L2SA_ERK_6_3_4; +static const int ARKSTEP_DEFAULT_ARK_ETABLE_5 = ARKODE_ARK548L2SA_ERK_8_4_5; +static const int ARKSTEP_DEFAULT_ARK_ITABLE_2 = ARKODE_ARK2_DIRK_3_1_2; +static const int ARKSTEP_DEFAULT_ARK_ITABLE_3 = ARKODE_ARK324L2SA_DIRK_4_2_3; +static const int ARKSTEP_DEFAULT_ARK_ITABLE_4 = ARKODE_ARK436L2SA_DIRK_6_3_4; +static const int ARKSTEP_DEFAULT_ARK_ITABLE_5 = ARKODE_ARK548L2SA_DIRK_8_4_5; + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Creation and Reinitialization functions */ +SUNDIALS_EXPORT void* ARKStepCreate(ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0, + N_Vector y0, SUNContext sunctx); +SUNDIALS_EXPORT int ARKStepReInit(void* arkode_mem, ARKRhsFn fe, ARKRhsFn fi, + sunrealtype t0, N_Vector y0); + +/* Optional input functions -- must be called AFTER ARKStepCreate */ +SUNDIALS_EXPORT int ARKStepSetExplicit(void* arkode_mem); +SUNDIALS_EXPORT int ARKStepSetImplicit(void* arkode_mem); +SUNDIALS_EXPORT int ARKStepSetImEx(void* arkode_mem); +SUNDIALS_EXPORT int ARKStepSetTables(void* arkode_mem, int q, int p, + ARKodeButcherTable Bi, + ARKodeButcherTable Be); +SUNDIALS_EXPORT int ARKStepSetTableNum(void* arkode_mem, + ARKODE_DIRKTableID itable, + ARKODE_ERKTableID etable); +SUNDIALS_EXPORT int ARKStepSetTableName(void* arkode_mem, const char* itable, + const char* etable); + +/* Optional output functions */ +SUNDIALS_EXPORT int ARKStepGetNumRhsEvals(void* arkode_mem, long int* nfe_evals, + long int* nfi_evals); +SUNDIALS_EXPORT int ARKStepGetCurrentButcherTables(void* arkode_mem, + ARKodeButcherTable* Bi, + ARKodeButcherTable* Be); +SUNDIALS_EXPORT int ARKStepGetTimestepperStats( + void* arkode_mem, long int* expsteps, long int* accsteps, + long int* step_attempts, long int* nfe_evals, long int* nfi_evals, + long int* nlinsetups, long int* netfails); + +/* MRIStep interface functions */ +SUNDIALS_EXPORT int ARKStepCreateMRIStepInnerStepper(void* arkode_mem, + MRIStepInnerStepper* stepper); + +/* -------------------------------------------------------------------------- + * Deprecated Functions -- all are superseded by shared ARKODE-level routines + * -------------------------------------------------------------------------- */ + +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResize instead") +int ARKStepResize(void* arkode_mem, N_Vector ynew, sunrealtype hscale, + sunrealtype t0, ARKVecResizeFn resize, void* resize_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeReset instead") +int ARKStepReset(void* arkode_mem, sunrealtype tR, N_Vector yR); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSStolerances instead") +int ARKStepSStolerances(void* arkode_mem, sunrealtype reltol, sunrealtype abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSVtolerances instead") +int ARKStepSVtolerances(void* arkode_mem, sunrealtype reltol, N_Vector abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWFtolerances instead") +int ARKStepWFtolerances(void* arkode_mem, ARKEwtFn efun); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResStolerance instead") +int ARKStepResStolerance(void* arkode_mem, sunrealtype rabstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResVtolerance instead") +int ARKStepResVtolerance(void* arkode_mem, N_Vector rabstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResFtolerance instead") +int ARKStepResFtolerance(void* arkode_mem, ARKRwtFn rfun); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinearSolver instead") +int ARKStepSetLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassLinearSolver instead") +int ARKStepSetMassLinearSolver(void* arkode_mem, SUNLinearSolver LS, + SUNMatrix M, sunbooleantype time_dep); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeRootInit instead") +int ARKStepRootInit(void* arkode_mem, int nrtfn, ARKRootFn g); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDefaults instead") +int ARKStepSetDefaults(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("adjust parameters individually instead") +int ARKStepSetOptimalParams(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetOrder instead") +int ARKStepSetOrder(void* arkode_mem, int maxord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantType instead") +int ARKStepSetInterpolantType(void* arkode_mem, int itype); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int ARKStepSetInterpolantDegree(void* arkode_mem, int degree); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int ARKStepSetDenseOrder(void* arkode_mem, int dord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinearSolver instead") +int ARKStepSetNonlinearSolver(void* arkode_mem, SUNNonlinearSolver NLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNlsRhsFn instead") +int ARKStepSetNlsRhsFn(void* arkode_mem, ARKRhsFn nls_fi); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinear instead") +int ARKStepSetLinear(void* arkode_mem, int timedepend); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinear instead") +int ARKStepSetNonlinear(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDeduceImplicitRhs instead") +int ARKStepSetDeduceImplicitRhs(void* arkode_mem, sunbooleantype deduce); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetAdaptController instead") +int ARKStepSetAdaptController(void* arkode_mem, SUNAdaptController C); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetAdaptivityAdjustment instead") +int ARKStepSetAdaptivityAdjustment(void* arkode_mem, int adjust); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetCFLFraction instead") +int ARKStepSetCFLFraction(void* arkode_mem, sunrealtype cfl_frac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetSafetyFactor instead") +int ARKStepSetSafetyFactor(void* arkode_mem, sunrealtype safety); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ARKStepSetErrorBias(void* arkode_mem, sunrealtype bias); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxGrowth instead") +int ARKStepSetMaxGrowth(void* arkode_mem, sunrealtype mx_growth); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMinReduction instead") +int ARKStepSetMinReduction(void* arkode_mem, sunrealtype eta_min); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetFixedStepBounds instead") +int ARKStepSetFixedStepBounds(void* arkode_mem, sunrealtype lb, sunrealtype ub); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ARKStepSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, + int pq, sunrealtype adapt_params[3]); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ARKStepSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxFirstGrowth instead") +int ARKStepSetMaxFirstGrowth(void* arkode_mem, sunrealtype etamx1); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxEFailGrowth instead") +int ARKStepSetMaxEFailGrowth(void* arkode_mem, sunrealtype etamxf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetSmallNumEFails instead") +int ARKStepSetSmallNumEFails(void* arkode_mem, int small_nef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxCFailGrowth instead") +int ARKStepSetMaxCFailGrowth(void* arkode_mem, sunrealtype etacf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinCRDown instead") +int ARKStepSetNonlinCRDown(void* arkode_mem, sunrealtype crdown); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinRDiv instead") +int ARKStepSetNonlinRDiv(void* arkode_mem, sunrealtype rdiv); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDeltaGammaMax instead") +int ARKStepSetDeltaGammaMax(void* arkode_mem, sunrealtype dgmax); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLSetupFrequency instead") +int ARKStepSetLSetupFrequency(void* arkode_mem, int msbp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPredictorMethod instead") +int ARKStepSetPredictorMethod(void* arkode_mem, int method); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStabilityFn instead") +int ARKStepSetStabilityFn(void* arkode_mem, ARKExpStabFn EStab, void* estab_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxErrTestFails instead") +int ARKStepSetMaxErrTestFails(void* arkode_mem, int maxnef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNonlinIters instead") +int ARKStepSetMaxNonlinIters(void* arkode_mem, int maxcor); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxConvFails instead") +int ARKStepSetMaxConvFails(void* arkode_mem, int maxncf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinConvCoef instead") +int ARKStepSetNonlinConvCoef(void* arkode_mem, sunrealtype nlscoef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetConstraints instead") +int ARKStepSetConstraints(void* arkode_mem, N_Vector constraints); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNumSteps instead") +int ARKStepSetMaxNumSteps(void* arkode_mem, long int mxsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxHnilWarns instead") +int ARKStepSetMaxHnilWarns(void* arkode_mem, int mxhnil); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInitStep instead") +int ARKStepSetInitStep(void* arkode_mem, sunrealtype hin); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMinStep instead") +int ARKStepSetMinStep(void* arkode_mem, sunrealtype hmin); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxStep instead") +int ARKStepSetMaxStep(void* arkode_mem, sunrealtype hmax); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolateStopTime instead") +int ARKStepSetInterpolateStopTime(void* arkode_mem, sunbooleantype interp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStopTime instead") +int ARKStepSetStopTime(void* arkode_mem, sunrealtype tstop); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeClearStopTime instead") +int ARKStepClearStopTime(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetFixedStep instead") +int ARKStepSetFixedStep(void* arkode_mem, sunrealtype hfixed); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNumConstrFails instead") +int ARKStepSetMaxNumConstrFails(void* arkode_mem, int maxfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRootDirection instead") +int ARKStepSetRootDirection(void* arkode_mem, int* rootdir); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNoInactiveRootWarn instead") +int ARKStepSetNoInactiveRootWarn(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetUserData instead") +int ARKStepSetUserData(void* arkode_mem, void* user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStepFn instead") +int ARKStepSetPostprocessStepFn(void* arkode_mem, ARKPostProcessFn ProcessStep); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStageFn instead") +int ARKStepSetPostprocessStageFn(void* arkode_mem, ARKPostProcessFn ProcessStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStagePredictFn instead") +int ARKStepSetStagePredictFn(void* arkode_mem, ARKStagePredictFn PredictStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacFn instead") +int ARKStepSetJacFn(void* arkode_mem, ARKLsJacFn jac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassFn instead") +int ARKStepSetMassFn(void* arkode_mem, ARKLsMassFn mass); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacEvalFrequency instead") +int ARKStepSetJacEvalFrequency(void* arkode_mem, long int msbj); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinearSolutionScaling instead") +int ARKStepSetLinearSolutionScaling(void* arkode_mem, sunbooleantype onoff); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetEpsLin instead") +int ARKStepSetEpsLin(void* arkode_mem, sunrealtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassEpsLin instead") +int ARKStepSetMassEpsLin(void* arkode_mem, sunrealtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLSNormFactor instead") +int ARKStepSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassLSNormFactor instead") +int ARKStepSetMassLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPreconditioner instead") +int ARKStepSetPreconditioner(void* arkode_mem, ARKLsPrecSetupFn psetup, + ARKLsPrecSolveFn psolve); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassPreconditioner instead") +int ARKStepSetMassPreconditioner(void* arkode_mem, ARKLsMassPrecSetupFn psetup, + ARKLsMassPrecSolveFn psolve); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacTimes instead") +int ARKStepSetJacTimes(void* arkode_mem, ARKLsJacTimesSetupFn jtsetup, + ARKLsJacTimesVecFn jtimes); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacTimesRhsFn instead") +int ARKStepSetJacTimesRhsFn(void* arkode_mem, ARKRhsFn jtimesRhsFn); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMassTimes instead") +int ARKStepSetMassTimes(void* arkode_mem, ARKLsMassTimesSetupFn msetup, + ARKLsMassTimesVecFn mtimes, void* mtimes_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinSysFn instead") +int ARKStepSetLinSysFn(void* arkode_mem, ARKLsLinSysFn linsys); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeEvolve instead") +int ARKStepEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetDky instead") +int ARKStepGetDky(void* arkode_mem, sunrealtype t, int k, N_Vector dky); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeComputeState instead") +int ARKStepComputeState(void* arkode_mem, N_Vector zcor, N_Vector z); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumExpSteps instead") +int ARKStepGetNumExpSteps(void* arkode_mem, long int* expsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumAccSteps instead") +int ARKStepGetNumAccSteps(void* arkode_mem, long int* accsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumStepAttempts instead") +int ARKStepGetNumStepAttempts(void* arkode_mem, long int* step_attempts); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinSolvSetups instead") +int ARKStepGetNumLinSolvSetups(void* arkode_mem, long int* nlinsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumErrTestFails instead") +int ARKStepGetNumErrTestFails(void* arkode_mem, long int* netfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetEstLocalErrors instead") +int ARKStepGetEstLocalErrors(void* arkode_mem, N_Vector ele); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetWorkSpace instead") +int ARKStepGetWorkSpace(void* arkode_mem, long int* lenrw, long int* leniw); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumSteps instead") +int ARKStepGetNumSteps(void* arkode_mem, long int* nsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetActualInitStep instead") +int ARKStepGetActualInitStep(void* arkode_mem, sunrealtype* hinused); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLastStep instead") +int ARKStepGetLastStep(void* arkode_mem, sunrealtype* hlast); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentStep instead") +int ARKStepGetCurrentStep(void* arkode_mem, sunrealtype* hcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentTime instead") +int ARKStepGetCurrentTime(void* arkode_mem, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentState instead") +int ARKStepGetCurrentState(void* arkode_mem, N_Vector* state); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentGamma instead") +int ARKStepGetCurrentGamma(void* arkode_mem, sunrealtype* gamma); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentMassMatrix instead") +int ARKStepGetCurrentMassMatrix(void* arkode_mem, SUNMatrix* M); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetTolScaleFactor instead") +int ARKStepGetTolScaleFactor(void* arkode_mem, sunrealtype* tolsfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetErrWeights instead") +int ARKStepGetErrWeights(void* arkode_mem, N_Vector eweight); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetResWeights instead") +int ARKStepGetResWeights(void* arkode_mem, N_Vector rweight); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumGEvals instead") +int ARKStepGetNumGEvals(void* arkode_mem, long int* ngevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetRootInfo instead") +int ARKStepGetRootInfo(void* arkode_mem, int* rootsfound); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumConstrFails instead") +int ARKStepGetNumConstrFails(void* arkode_mem, long int* nconstrfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetUserData instead") +int ARKStepGetUserData(void* arkode_mem, void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintAllStats instead") +int ARKStepPrintAllStats(void* arkode_mem, FILE* outfile, SUNOutputFormat fmt); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetReturnFlagName instead") +char* ARKStepGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWriteParameters instead") +int ARKStepWriteParameters(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG( + "use ARKStepGetCurrentButcherTables and ARKodeButcherTable_Write instead") +int ARKStepWriteButcher(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetStepStats instead") +int ARKStepGetStepStats(void* arkode_mem, long int* nsteps, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNonlinearSystemData instead") +int ARKStepGetNonlinearSystemData(void* arkode_mem, sunrealtype* tcur, + N_Vector* zpred, N_Vector* z, N_Vector* Fi, + sunrealtype* gamma, N_Vector* sdata, + void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumNonlinSolvIters instead") +int ARKStepGetNumNonlinSolvIters(void* arkode_mem, long int* nniters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumNonlinSolvConvFails instead") +int ARKStepGetNumNonlinSolvConvFails(void* arkode_mem, long int* nnfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNonlinSolvStats instead") +int ARKStepGetNonlinSolvStats(void* arkode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumStepSolveFails instead") +int ARKStepGetNumStepSolveFails(void* arkode_mem, long int* nncfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetJac instead") +int ARKStepGetJac(void* arkode_mem, SUNMatrix* J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetJacTime instead") +int ARKStepGetJacTime(void* arkode_mem, sunrealtype* t_J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetJacNumSteps instead") +int ARKStepGetJacNumSteps(void* arkode_mem, long int* nst_J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLinWorkSpace instead") +int ARKStepGetLinWorkSpace(void* arkode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJacEvals instead") +int ARKStepGetNumJacEvals(void* arkode_mem, long int* njevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumPrecEvals instead") +int ARKStepGetNumPrecEvals(void* arkode_mem, long int* npevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumPrecSolves instead") +int ARKStepGetNumPrecSolves(void* arkode_mem, long int* npsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinIters instead") +int ARKStepGetNumLinIters(void* arkode_mem, long int* nliters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinConvFails instead") +int ARKStepGetNumLinConvFails(void* arkode_mem, long int* nlcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJTSetupEvals instead") +int ARKStepGetNumJTSetupEvals(void* arkode_mem, long int* njtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJtimesEvals instead") +int ARKStepGetNumJtimesEvals(void* arkode_mem, long int* njvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinRhsEvals instead") +int ARKStepGetNumLinRhsEvals(void* arkode_mem, long int* nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLastLinFlag instead") +int ARKStepGetLastLinFlag(void* arkode_mem, long int* flag); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetMassWorkSpace instead") +int ARKStepGetMassWorkSpace(void* arkode_mem, long int* lenrwMLS, + long int* leniwMLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassSetups instead") +int ARKStepGetNumMassSetups(void* arkode_mem, long int* nmsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassMultSetups instead") +int ARKStepGetNumMassMultSetups(void* arkode_mem, long int* nmvsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassMult instead") +int ARKStepGetNumMassMult(void* arkode_mem, long int* nmvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassSolves instead") +int ARKStepGetNumMassSolves(void* arkode_mem, long int* nmsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassPrecEvals instead") +int ARKStepGetNumMassPrecEvals(void* arkode_mem, long int* nmpevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassPrecSolves instead") +int ARKStepGetNumMassPrecSolves(void* arkode_mem, long int* nmpsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassIters instead") +int ARKStepGetNumMassIters(void* arkode_mem, long int* nmiters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMassConvFails instead") +int ARKStepGetNumMassConvFails(void* arkode_mem, long int* nmcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumMTSetups instead") +int ARKStepGetNumMTSetups(void* arkode_mem, long int* nmtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLastMassFlag instead") +int ARKStepGetLastMassFlag(void* arkode_mem, long int* flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLinReturnFlagName instead") +char* ARKStepGetLinReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeFree instead") +void ARKStepFree(void** arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintMem instead") +void ARKStepPrintMem(void* arkode_mem, FILE* outfile); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxFn instead") +int ARKStepSetRelaxFn(void* arkode_mem, ARKRelaxFn rfn, ARKRelaxJacFn rjac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxEtaFail instead") +int ARKStepSetRelaxEtaFail(void* arkode_mem, sunrealtype eta_rf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxLowerBound instead") +int ARKStepSetRelaxLowerBound(void* arkode_mem, sunrealtype lower); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxMaxFails instead") +int ARKStepSetRelaxMaxFails(void* arkode_mem, int max_fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxMaxIters instead") +int ARKStepSetRelaxMaxIters(void* arkode_mem, int max_iters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxSolver instead") +int ARKStepSetRelaxSolver(void* arkode_mem, ARKRelaxSolver solver); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxResTol instead") +int ARKStepSetRelaxResTol(void* arkode_mem, sunrealtype res_tol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxTol instead") +int ARKStepSetRelaxTol(void* arkode_mem, sunrealtype rel_tol, + sunrealtype abs_tol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxUpperBound instead") +int ARKStepSetRelaxUpperBound(void* arkode_mem, sunrealtype upper); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxFnEvals instead") +int ARKStepGetNumRelaxFnEvals(void* arkode_mem, long int* r_evals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxJacEvals instead") +int ARKStepGetNumRelaxJacEvals(void* arkode_mem, long int* J_evals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxFails instead") +int ARKStepGetNumRelaxFails(void* arkode_mem, long int* relax_fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxBoundFails instead") +int ARKStepGetNumRelaxBoundFails(void* arkode_mem, long int* fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxSolveFails instead") +int ARKStepGetNumRelaxSolveFails(void* arkode_mem, long int* fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxSolveIters instead") +int ARKStepGetNumRelaxSolveIters(void* arkode_mem, long int* iters); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_bandpre.h b/inst/include/arkode/arkode_bandpre.h new file mode 100644 index 0000000..526c657 --- /dev/null +++ b/inst/include/arkode/arkode_bandpre.h @@ -0,0 +1,43 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKBANDPRE module, which provides + * a banded difference quotient Jacobian-based preconditioner. + * -----------------------------------------------------------------*/ + +#ifndef _ARKBANDPRE_H +#define _ARKBANDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* BandPrec inititialization function */ + +SUNDIALS_EXPORT int ARKBandPrecInit(void* arkode_mem, sunindextype N, + sunindextype mu, sunindextype ml); + +/* Optional output functions */ + +SUNDIALS_EXPORT int ARKBandPrecGetWorkSpace(void* arkode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int ARKBandPrecGetNumRhsEvals(void* arkode_mem, + long int* nfevalsBP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_bbdpre.h b/inst/include/arkode/arkode_bbdpre.h new file mode 100644 index 0000000..54eb36a --- /dev/null +++ b/inst/include/arkode/arkode_bbdpre.h @@ -0,0 +1,59 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKBBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _ARKBBDPRE_H +#define _ARKBBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* User-supplied function Types */ + +typedef int (*ARKLocalFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + N_Vector g, void* user_data); + +typedef int (*ARKCommFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int ARKBBDPrecInit(void* arkode_mem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dqrely, ARKLocalFn gloc, + ARKCommFn cfn); + +SUNDIALS_EXPORT int ARKBBDPrecReInit(void* arkode_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dqrely); + +/* Optional output functions */ + +SUNDIALS_EXPORT int ARKBBDPrecGetWorkSpace(void* arkode_mem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int ARKBBDPrecGetNumGfnEvals(void* arkode_mem, + long int* ngevalsBBDP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_butcher.h b/inst/include/arkode/arkode_butcher.h new file mode 100644 index 0000000..029b3d1 --- /dev/null +++ b/inst/include/arkode/arkode_butcher.h @@ -0,0 +1,71 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for ARKode Butcher table structures. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_BUTCHER_H +#define _ARKODE_BUTCHER_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*--------------------------------------------------------------- + Types : struct ARKodeButcherTableMem, ARKodeButcherTable + ---------------------------------------------------------------*/ +struct ARKodeButcherTableMem +{ + int q; /* method order of accuracy */ + int p; /* embedding order of accuracy */ + int stages; /* number of stages */ + sunrealtype** A; /* Butcher table coefficients */ + sunrealtype* c; /* canopy node coefficients */ + sunrealtype* b; /* root node coefficients */ + sunrealtype* d; /* embedding coefficients */ +}; + +typedef _SUNDIALS_STRUCT_ ARKodeButcherTableMem* ARKodeButcherTable; + +/* Utility routines to allocate/free/output Butcher table structures */ +SUNDIALS_EXPORT ARKodeButcherTable +ARKodeButcherTable_Alloc(int stages, sunbooleantype embedded); +SUNDIALS_EXPORT ARKodeButcherTable ARKodeButcherTable_Create(int s, int q, int p, + sunrealtype* c, + sunrealtype* A, + sunrealtype* b, + sunrealtype* d); +SUNDIALS_EXPORT ARKodeButcherTable ARKodeButcherTable_Copy(ARKodeButcherTable B); +SUNDIALS_EXPORT void ARKodeButcherTable_Space(ARKodeButcherTable B, + sunindextype* liw, + sunindextype* lrw); +SUNDIALS_EXPORT void ARKodeButcherTable_Free(ARKodeButcherTable B); +SUNDIALS_EXPORT void ARKodeButcherTable_Write(ARKodeButcherTable B, + FILE* outfile); +SUNDIALS_EXPORT sunbooleantype +ARKodeButcherTable_IsStifflyAccurate(ARKodeButcherTable B); +SUNDIALS_EXPORT int ARKodeButcherTable_CheckOrder(ARKodeButcherTable B, int* q, + int* p, FILE* outfile); +SUNDIALS_EXPORT int ARKodeButcherTable_CheckARKOrder(ARKodeButcherTable B1, + ARKodeButcherTable B2, + int* q, int* p, + FILE* outfile); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_butcher_dirk.h b/inst/include/arkode/arkode_butcher_dirk.h new file mode 100644 index 0000000..c89ea05 --- /dev/null +++ b/inst/include/arkode/arkode_butcher_dirk.h @@ -0,0 +1,75 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for ARKode's built-in DIRK Butcher tables. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_DIRK_TABLES_H +#define _ARKODE_DIRK_TABLES_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + ARKODE_DIRK_NONE = -1, /* ensure enum is signed int */ + ARKODE_MIN_DIRK_NUM = 100, + ARKODE_SDIRK_2_1_2 = ARKODE_MIN_DIRK_NUM, + ARKODE_BILLINGTON_3_3_2, + ARKODE_TRBDF2_3_3_2, + ARKODE_KVAERNO_4_2_3, + ARKODE_ARK324L2SA_DIRK_4_2_3, + ARKODE_CASH_5_2_4, + ARKODE_CASH_5_3_4, + ARKODE_SDIRK_5_3_4, + ARKODE_KVAERNO_5_3_4, + ARKODE_ARK436L2SA_DIRK_6_3_4, + ARKODE_KVAERNO_7_4_5, + ARKODE_ARK548L2SA_DIRK_8_4_5, + ARKODE_ARK437L2SA_DIRK_7_3_4, + ARKODE_ARK548L2SAb_DIRK_8_4_5, + ARKODE_ESDIRK324L2SA_4_2_3, + ARKODE_ESDIRK325L2SA_5_2_3, + ARKODE_ESDIRK32I5L2SA_5_2_3, + ARKODE_ESDIRK436L2SA_6_3_4, + ARKODE_ESDIRK43I6L2SA_6_3_4, + ARKODE_QESDIRK436L2SA_6_3_4, + ARKODE_ESDIRK437L2SA_7_3_4, + ARKODE_ESDIRK547L2SA_7_4_5, + ARKODE_ESDIRK547L2SA2_7_4_5, + ARKODE_ARK2_DIRK_3_1_2, + ARKODE_BACKWARD_EULER_1_1, + ARKODE_IMPLICIT_MIDPOINT_1_2, + ARKODE_IMPLICIT_TRAPEZOIDAL_2_2, + ARKODE_MAX_DIRK_NUM = ARKODE_IMPLICIT_TRAPEZOIDAL_2_2 +} ARKODE_DIRKTableID; + +/* Accessor routine to load built-in DIRK table */ +SUNDIALS_EXPORT ARKodeButcherTable +ARKodeButcherTable_LoadDIRK(ARKODE_DIRKTableID imethod); + +/* Accessor routine to load built-in DIRK table */ +SUNDIALS_EXPORT ARKodeButcherTable +ARKodeButcherTable_LoadDIRKByName(const char* imethod); + +SUNDIALS_EXPORT const char* ARKodeButcherTable_DIRKIDToName( + ARKODE_DIRKTableID imethod); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_butcher_erk.h b/inst/include/arkode/arkode_butcher_erk.h new file mode 100644 index 0000000..c6c0373 --- /dev/null +++ b/inst/include/arkode/arkode_butcher_erk.h @@ -0,0 +1,71 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for ARKode's built-in ERK Butcher tables. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_ERK_TABLES_H +#define _ARKODE_ERK_TABLES_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + ARKODE_ERK_NONE = -1, /* ensure enum is signed int */ + ARKODE_MIN_ERK_NUM = 0, + ARKODE_HEUN_EULER_2_1_2 = ARKODE_MIN_ERK_NUM, + ARKODE_BOGACKI_SHAMPINE_4_2_3, + ARKODE_ARK324L2SA_ERK_4_2_3, + ARKODE_ZONNEVELD_5_3_4, + ARKODE_ARK436L2SA_ERK_6_3_4, + ARKODE_SAYFY_ABURUB_6_3_4, + ARKODE_CASH_KARP_6_4_5, + ARKODE_FEHLBERG_6_4_5, + ARKODE_DORMAND_PRINCE_7_4_5, + ARKODE_ARK548L2SA_ERK_8_4_5, + ARKODE_VERNER_8_5_6, + ARKODE_FEHLBERG_13_7_8, + ARKODE_KNOTH_WOLKE_3_3, + ARKODE_ARK437L2SA_ERK_7_3_4, + ARKODE_ARK548L2SAb_ERK_8_4_5, + ARKODE_ARK2_ERK_3_1_2, + ARKODE_SOFRONIOU_SPALETTA_5_3_4, + ARKODE_SHU_OSHER_3_2_3, + ARKODE_VERNER_9_5_6, + ARKODE_VERNER_10_6_7, + ARKODE_VERNER_13_7_8, + ARKODE_VERNER_16_8_9, + ARKODE_FORWARD_EULER_1_1, + ARKODE_RALSTON_EULER_2_1_2, + ARKODE_EXPLICIT_MIDPOINT_EULER_2_1_2, + ARKODE_MAX_ERK_NUM = ARKODE_EXPLICIT_MIDPOINT_EULER_2_1_2 +} ARKODE_ERKTableID; + +/* Accessor routine to load built-in ERK table */ +SUNDIALS_EXPORT ARKodeButcherTable +ARKodeButcherTable_LoadERK(ARKODE_ERKTableID emethod); + +SUNDIALS_EXPORT ARKodeButcherTable +ARKodeButcherTable_LoadERKByName(const char* emethod); + +SUNDIALS_EXPORT const char* ARKodeButcherTable_ERKIDToName(ARKODE_ERKTableID emethod); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_erkstep.h b/inst/include/arkode/arkode_erkstep.h new file mode 100644 index 0000000..ed93a24 --- /dev/null +++ b/inst/include/arkode/arkode_erkstep.h @@ -0,0 +1,252 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKODE ERKStep module. + * -----------------------------------------------------------------*/ + +#ifndef _ERKSTEP_H +#define _ERKSTEP_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * ERKStep Constants + * ----------------- */ + +/* Default Butcher tables for each order */ + +static const int ERKSTEP_DEFAULT_1 = ARKODE_FORWARD_EULER_1_1; +static const int ERKSTEP_DEFAULT_2 = ARKODE_HEUN_EULER_2_1_2; +static const int ERKSTEP_DEFAULT_3 = ARKODE_BOGACKI_SHAMPINE_4_2_3; +static const int ERKSTEP_DEFAULT_4 = ARKODE_ZONNEVELD_5_3_4; +static const int ERKSTEP_DEFAULT_5 = ARKODE_CASH_KARP_6_4_5; +static const int ERKSTEP_DEFAULT_6 = ARKODE_VERNER_8_5_6; +static const int ERKSTEP_DEFAULT_7 = ARKODE_VERNER_10_6_7; +static const int ERKSTEP_DEFAULT_8 = ARKODE_FEHLBERG_13_7_8; +static const int ERKSTEP_DEFAULT_9 = ARKODE_VERNER_16_8_9; + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Creation and Reinitialization functions */ +SUNDIALS_EXPORT void* ERKStepCreate(ARKRhsFn f, sunrealtype t0, N_Vector y0, + SUNContext sunctx); +SUNDIALS_EXPORT int ERKStepReInit(void* arkode_mem, ARKRhsFn f, sunrealtype t0, + N_Vector y0); + +/* Optional input functions -- must be called AFTER ERKStepCreate */ +SUNDIALS_EXPORT int ERKStepSetTable(void* arkode_mem, ARKodeButcherTable B); +SUNDIALS_EXPORT int ERKStepSetTableNum(void* arkode_mem, + ARKODE_ERKTableID etable); +SUNDIALS_EXPORT int ERKStepSetTableName(void* arkode_mem, const char* etable); + +/* Optional output functions */ +SUNDIALS_EXPORT int ERKStepGetNumRhsEvals(void* arkode_mem, long int* nfevals); +SUNDIALS_EXPORT int ERKStepGetCurrentButcherTable(void* arkode_mem, + ARKodeButcherTable* B); + +/* Grouped optional output functions */ +SUNDIALS_EXPORT int ERKStepGetTimestepperStats( + void* arkode_mem, long int* expsteps, long int* accsteps, + long int* step_attempts, long int* nfevals, long int* netfails); + +/* -------------------------------------------------------------------------- + * Deprecated Functions -- all are superseded by shared ARKODE-level routines + * -------------------------------------------------------------------------- */ + +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResize instead") +int ERKStepResize(void* arkode_mem, N_Vector ynew, sunrealtype hscale, + sunrealtype t0, ARKVecResizeFn resize, void* resize_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeReset instead") +int ERKStepReset(void* arkode_mem, sunrealtype tR, N_Vector yR); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSStolerances instead") +int ERKStepSStolerances(void* arkode_mem, sunrealtype reltol, sunrealtype abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSVtolerances instead") +int ERKStepSVtolerances(void* arkode_mem, sunrealtype reltol, N_Vector abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWFtolerances instead") +int ERKStepWFtolerances(void* arkode_mem, ARKEwtFn efun); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeRootInit instead") +int ERKStepRootInit(void* arkode_mem, int nrtfn, ARKRootFn g); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDefaults instead") +int ERKStepSetDefaults(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetOrder instead") +int ERKStepSetOrder(void* arkode_mem, int maxord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantType instead") +int ERKStepSetInterpolantType(void* arkode_mem, int itype); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int ERKStepSetInterpolantDegree(void* arkode_mem, int degree); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int ERKStepSetDenseOrder(void* arkode_mem, int dord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetAdaptController instead") +int ERKStepSetAdaptController(void* arkode_mem, SUNAdaptController C); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetAdaptivityAdjustment instead") +int ERKStepSetAdaptivityAdjustment(void* arkode_mem, int adjust); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetCFLFraction instead") +int ERKStepSetCFLFraction(void* arkode_mem, sunrealtype cfl_frac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetSafetyFactor instead") +int ERKStepSetSafetyFactor(void* arkode_mem, sunrealtype safety); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ERKStepSetErrorBias(void* arkode_mem, sunrealtype bias); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxGrowth instead") +int ERKStepSetMaxGrowth(void* arkode_mem, sunrealtype mx_growth); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMinReduction instead") +int ERKStepSetMinReduction(void* arkode_mem, sunrealtype eta_min); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetFiARKodeBounds instead") +int ERKStepSetFixedStepBounds(void* arkode_mem, sunrealtype lb, sunrealtype ub); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ERKStepSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, + int pq, sunrealtype adapt_params[3]); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNAdaptController instead") +int ERKStepSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxFirstGrowth instead") +int ERKStepSetMaxFirstGrowth(void* arkode_mem, sunrealtype etamx1); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxEFailGrowth instead") +int ERKStepSetMaxEFailGrowth(void* arkode_mem, sunrealtype etamxf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetSmallNumEFails instead") +int ERKStepSetSmallNumEFails(void* arkode_mem, int small_nef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStabilityFn instead") +int ERKStepSetStabilityFn(void* arkode_mem, ARKExpStabFn EStab, void* estab_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxErrTestFails instead") +int ERKStepSetMaxErrTestFails(void* arkode_mem, int maxnef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetConstraints instead") +int ERKStepSetConstraints(void* arkode_mem, N_Vector constraints); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetMaxARKodes instead") +int ERKStepSetMaxNumSteps(void* arkode_mem, long int mxsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxHnilWarns instead") +int ERKStepSetMaxHnilWarns(void* arkode_mem, int mxhnil); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetIARKode instead") +int ERKStepSetInitStep(void* arkode_mem, sunrealtype hin); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetARKode instead") +int ERKStepSetMinStep(void* arkode_mem, sunrealtype hmin); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetARKode instead") +int ERKStepSetMaxStep(void* arkode_mem, sunrealtype hmax); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolateStopTime instead") +int ERKStepSetInterpolateStopTime(void* arkode_mem, sunbooleantype interp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStopTime instead") +int ERKStepSetStopTime(void* arkode_mem, sunrealtype tstop); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeClearStopTime instead") +int ERKStepClearStopTime(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetFiARKode instead") +int ERKStepSetFixedStep(void* arkode_mem, sunrealtype hfixed); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNumConstrFails instead") +int ERKStepSetMaxNumConstrFails(void* arkode_mem, int maxfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRootDirection instead") +int ERKStepSetRootDirection(void* arkode_mem, int* rootdir); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNoInactiveRootWarn instead") +int ERKStepSetNoInactiveRootWarn(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetUserData instead") +int ERKStepSetUserData(void* arkode_mem, void* user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepSetPostprocARKodeFn instead") +int ERKStepSetPostprocessStepFn(void* arkode_mem, ARKPostProcessFn ProcessStep); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStageFn instead") +int ERKStepSetPostprocessStageFn(void* arkode_mem, ARKPostProcessFn ProcessStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeEvolve instead") +int ERKStepEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetDky instead") +int ERKStepGetDky(void* arkode_mem, sunrealtype t, int k, N_Vector dky); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetNumARKodes instead") +int ERKStepGetNumExpSteps(void* arkode_mem, long int* expsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetNumARKodes instead") +int ERKStepGetNumAccSteps(void* arkode_mem, long int* accsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetARKodeAttempts instead") +int ERKStepGetNumStepAttempts(void* arkode_mem, long int* step_attempts); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumErrTestFails instead") +int ERKStepGetNumErrTestFails(void* arkode_mem, long int* netfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetEstLocalErrors instead") +int ERKStepGetEstLocalErrors(void* arkode_mem, N_Vector ele); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetWorkSpace instead") +int ERKStepGetWorkSpace(void* arkode_mem, long int* lenrw, long int* leniw); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetARKodes instead") +int ERKStepGetNumSteps(void* arkode_mem, long int* nsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetActualIARKode instead") +int ERKStepGetActualInitStep(void* arkode_mem, sunrealtype* hinused); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetLARKode instead") +int ERKStepGetLastStep(void* arkode_mem, sunrealtype* hlast); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepGetCurrARKode instead") +int ERKStepGetCurrentStep(void* arkode_mem, sunrealtype* hcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentTime instead") +int ERKStepGetCurrentTime(void* arkode_mem, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetTolScaleFactor instead") +int ERKStepGetTolScaleFactor(void* arkode_mem, sunrealtype* tolsfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetErrWeights instead") +int ERKStepGetErrWeights(void* arkode_mem, N_Vector eweight); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumGEvals instead") +int ERKStepGetNumGEvals(void* arkode_mem, long int* ngevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetRootInfo instead") +int ERKStepGetRootInfo(void* arkode_mem, int* rootsfound); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumConstrFails instead") +int ERKStepGetNumConstrFails(void* arkode_mem, long int* nconstrfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetUserData instead") +int ERKStepGetUserData(void* arkode_mem, void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintAllStats instead") +int ERKStepPrintAllStats(void* arkode_mem, FILE* outfile, SUNOutputFormat fmt); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetReturnFlagName instead") +char* ERKStepGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWriteParameters instead") +int ERKStepWriteParameters(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG( + "use ERKStepGetCurrentButcherTable and ARKodeButcherTable_Write instead") +int ERKStepWriteButcher(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ERKStepARKodeStats instead") +int ERKStepGetStepStats(void* arkode_mem, long int* nsteps, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeFree instead") +void ERKStepFree(void** arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintMem instead") +void ERKStepPrintMem(void* arkode_mem, FILE* outfile); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxFn instead") +int ERKStepSetRelaxFn(void* arkode_mem, ARKRelaxFn rfn, ARKRelaxJacFn rjac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxEtaFail instead") +int ERKStepSetRelaxEtaFail(void* arkode_mem, sunrealtype eta_rf); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxLowerBound instead") +int ERKStepSetRelaxLowerBound(void* arkode_mem, sunrealtype lower); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxMaxFails instead") +int ERKStepSetRelaxMaxFails(void* arkode_mem, int max_fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxMaxIters instead") +int ERKStepSetRelaxMaxIters(void* arkode_mem, int max_iters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxSolver instead") +int ERKStepSetRelaxSolver(void* arkode_mem, ARKRelaxSolver solver); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxResTol instead") +int ERKStepSetRelaxResTol(void* arkode_mem, sunrealtype res_tol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxTol instead") +int ERKStepSetRelaxTol(void* arkode_mem, sunrealtype rel_tol, + sunrealtype abs_tol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRelaxUpperBound instead") +int ERKStepSetRelaxUpperBound(void* arkode_mem, sunrealtype upper); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxFnEvals instead") +int ERKStepGetNumRelaxFnEvals(void* arkode_mem, long int* r_evals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxJacEvals instead") +int ERKStepGetNumRelaxJacEvals(void* arkode_mem, long int* J_evals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxFails instead") +int ERKStepGetNumRelaxFails(void* arkode_mem, long int* relax_fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxBoundFails instead") +int ERKStepGetNumRelaxBoundFails(void* arkode_mem, long int* fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxSolveFails instead") +int ERKStepGetNumRelaxSolveFails(void* arkode_mem, long int* fails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumRelaxSolveIters instead") +int ERKStepGetNumRelaxSolveIters(void* arkode_mem, long int* iters); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_ls.h b/inst/include/arkode/arkode_ls.h new file mode 100644 index 0000000..ce5a692 --- /dev/null +++ b/inst/include/arkode/arkode_ls.h @@ -0,0 +1,130 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for ARKode's linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _ARKLS_H +#define _ARKLS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================= + ARKLS Constants + =================================================================*/ + +#define ARKLS_SUCCESS 0 +#define ARKLS_MEM_NULL -1 +#define ARKLS_LMEM_NULL -2 +#define ARKLS_ILL_INPUT -3 +#define ARKLS_MEM_FAIL -4 +#define ARKLS_PMEM_NULL -5 +#define ARKLS_MASSMEM_NULL -6 +#define ARKLS_JACFUNC_UNRECVR -7 +#define ARKLS_JACFUNC_RECVR -8 +#define ARKLS_MASSFUNC_UNRECVR -9 +#define ARKLS_MASSFUNC_RECVR -10 +#define ARKLS_SUNMAT_FAIL -11 +#define ARKLS_SUNLS_FAIL -12 + +/*================================================================= + ARKLS user-supplied function prototypes + =================================================================*/ + +typedef int (*ARKLsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + void* user_data, N_Vector tmp1, N_Vector tmp2, + N_Vector tmp3); + +typedef int (*ARKLsMassFn)(sunrealtype t, SUNMatrix M, void* user_data, + N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); + +typedef int (*ARKLsPrecSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* user_data); + +typedef int (*ARKLsPrecSolveFn)(sunrealtype t, N_Vector y, N_Vector fy, + N_Vector r, N_Vector z, sunrealtype gamma, + sunrealtype delta, int lr, void* user_data); + +typedef int (*ARKLsJacTimesSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + void* user_data); + +typedef int (*ARKLsJacTimesVecFn)(N_Vector v, N_Vector Jv, sunrealtype t, + N_Vector y, N_Vector fy, void* user_data, + N_Vector tmp); + +typedef int (*ARKLsLinSysFn)(sunrealtype t, N_Vector y, N_Vector fy, + SUNMatrix A, SUNMatrix M, sunbooleantype jok, + sunbooleantype* jcur, sunrealtype gamma, + void* user_data, N_Vector tmp1, N_Vector tmp2, + N_Vector tmp3); + +typedef int (*ARKLsMassTimesSetupFn)(sunrealtype t, void* mtimes_data); + +typedef int (*ARKLsMassTimesVecFn)(N_Vector v, N_Vector Mv, sunrealtype t, + void* mtimes_data); + +typedef int (*ARKLsMassPrecSetupFn)(sunrealtype t, void* user_data); + +typedef int (*ARKLsMassPrecSolveFn)(sunrealtype t, N_Vector r, N_Vector z, + sunrealtype delta, int lr, void* user_data); + +/* Linear solver set functions */ +SUNDIALS_EXPORT int ARKodeSetLinearSolver(void* arkode_mem, SUNLinearSolver LS, + SUNMatrix A); +SUNDIALS_EXPORT int ARKodeSetMassLinearSolver(void* arkode_mem, + SUNLinearSolver LS, SUNMatrix M, + sunbooleantype time_dep); + +/* Linear solver interface optional input functions -- must be called + AFTER ARKodeSetLinearSolver and/or ARKodeSetMassLinearSolver */ +SUNDIALS_EXPORT int ARKodeSetJacFn(void* arkode_mem, ARKLsJacFn jac); +SUNDIALS_EXPORT int ARKodeSetMassFn(void* arkode_mem, ARKLsMassFn mass); +SUNDIALS_EXPORT int ARKodeSetJacEvalFrequency(void* arkode_mem, long int msbj); +SUNDIALS_EXPORT int ARKodeSetLinearSolutionScaling(void* arkode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int ARKodeSetEpsLin(void* arkode_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int ARKodeSetMassEpsLin(void* arkode_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int ARKodeSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int ARKodeSetMassLSNormFactor(void* arkode_mem, + sunrealtype nrmfac); +SUNDIALS_EXPORT int ARKodeSetPreconditioner(void* arkode_mem, + ARKLsPrecSetupFn psetup, + ARKLsPrecSolveFn psolve); +SUNDIALS_EXPORT int ARKodeSetMassPreconditioner(void* arkode_mem, + ARKLsMassPrecSetupFn psetup, + ARKLsMassPrecSolveFn psolve); +SUNDIALS_EXPORT int ARKodeSetJacTimes(void* arkode_mem, + ARKLsJacTimesSetupFn jtsetup, + ARKLsJacTimesVecFn jtimes); +SUNDIALS_EXPORT int ARKodeSetJacTimesRhsFn(void* arkode_mem, + ARKRhsFn jtimesRhsFn); +SUNDIALS_EXPORT int ARKodeSetMassTimes(void* arkode_mem, + ARKLsMassTimesSetupFn msetup, + ARKLsMassTimesVecFn mtimes, + void* mtimes_data); +SUNDIALS_EXPORT int ARKodeSetLinSysFn(void* arkode_mem, ARKLsLinSysFn linsys); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_mristep.h b/inst/include/arkode/arkode_mristep.h new file mode 100644 index 0000000..000bae1 --- /dev/null +++ b/inst/include/arkode/arkode_mristep.h @@ -0,0 +1,378 @@ +/* ----------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKODE MRIStep module. + * -----------------------------------------------------------------*/ + +#ifndef _MRISTEP_H +#define _MRISTEP_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * MRIStep Constants + * ----------------- */ + +/* MRIStep method types */ +typedef enum +{ + MRISTEP_EXPLICIT, + MRISTEP_IMPLICIT, + MRISTEP_IMEX +} MRISTEP_METHOD_TYPE; + +typedef enum +{ + ARKODE_MRI_NONE = -1, /* ensure enum is signed int */ + ARKODE_MIN_MRI_NUM = 200, + ARKODE_MIS_KW3 = ARKODE_MIN_MRI_NUM, + ARKODE_MRI_GARK_ERK33a, + ARKODE_MRI_GARK_ERK45a, + ARKODE_MRI_GARK_IRK21a, + ARKODE_MRI_GARK_ESDIRK34a, + ARKODE_MRI_GARK_ESDIRK46a, + ARKODE_IMEX_MRI_GARK3a, + ARKODE_IMEX_MRI_GARK3b, + ARKODE_IMEX_MRI_GARK4, + ARKODE_MRI_GARK_FORWARD_EULER, + ARKODE_MRI_GARK_RALSTON2, + ARKODE_MRI_GARK_ERK22a, + ARKODE_MRI_GARK_ERK22b, + ARKODE_MRI_GARK_RALSTON3, + ARKODE_MRI_GARK_BACKWARD_EULER, + ARKODE_MRI_GARK_IMPLICIT_MIDPOINT, + ARKODE_IMEX_MRI_GARK_EULER, + ARKODE_IMEX_MRI_GARK_TRAPEZOIDAL, + ARKODE_IMEX_MRI_GARK_MIDPOINT, + ARKODE_MAX_MRI_NUM = ARKODE_IMEX_MRI_GARK_MIDPOINT, +} ARKODE_MRITableID; + +/* Default MRI coupling tables for each order */ +static const int MRISTEP_DEFAULT_EXPL_1 = ARKODE_MRI_GARK_FORWARD_EULER; +static const int MRISTEP_DEFAULT_EXPL_2 = ARKODE_MRI_GARK_ERK22b; +static const int MRISTEP_DEFAULT_EXPL_3 = ARKODE_MIS_KW3; +static const int MRISTEP_DEFAULT_EXPL_4 = ARKODE_MRI_GARK_ERK45a; + +static const int MRISTEP_DEFAULT_IMPL_SD_1 = ARKODE_MRI_GARK_BACKWARD_EULER; +static const int MRISTEP_DEFAULT_IMPL_SD_2 = ARKODE_MRI_GARK_IRK21a; +static const int MRISTEP_DEFAULT_IMPL_SD_3 = ARKODE_MRI_GARK_ESDIRK34a; +static const int MRISTEP_DEFAULT_IMPL_SD_4 = ARKODE_MRI_GARK_ESDIRK46a; + +static const int MRISTEP_DEFAULT_IMEX_SD_1 = ARKODE_IMEX_MRI_GARK_EULER; +static const int MRISTEP_DEFAULT_IMEX_SD_2 = ARKODE_IMEX_MRI_GARK_TRAPEZOIDAL; +static const int MRISTEP_DEFAULT_IMEX_SD_3 = ARKODE_IMEX_MRI_GARK3b; +static const int MRISTEP_DEFAULT_IMEX_SD_4 = ARKODE_IMEX_MRI_GARK4; + +/* ------------------------------------ + * MRIStep Inner Stepper Function Types + * ------------------------------------ */ + +typedef int (*MRIStepInnerEvolveFn)(MRIStepInnerStepper stepper, sunrealtype t0, + sunrealtype tout, N_Vector y); + +typedef int (*MRIStepInnerFullRhsFn)(MRIStepInnerStepper stepper, sunrealtype t, + N_Vector y, N_Vector f, int mode); + +typedef int (*MRIStepInnerResetFn)(MRIStepInnerStepper stepper, sunrealtype tR, + N_Vector yR); + +/*--------------------------------------------------------------- + MRI coupling data structure and associated utility routines + ---------------------------------------------------------------*/ +struct MRIStepCouplingMem +{ + int nmat; /* number of MRI coupling matrices */ + int stages; /* size of coupling matrices (stages * stages) */ + int q; /* method order of accuracy */ + int p; /* embedding order of accuracy */ + sunrealtype* c; /* stage abscissae */ + sunrealtype*** W; /* explicit coupling matrices [nmat][stages][stages] */ + sunrealtype*** G; /* implicit coupling matrices [nmat][stages][stages] */ +}; + +typedef _SUNDIALS_STRUCT_ MRIStepCouplingMem* MRIStepCoupling; + +/* Accessor routine to load built-in MRI table */ +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_LoadTable(ARKODE_MRITableID method); + +/* Accessor routine to load built-in MRI table from string */ +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_LoadTableByName(const char* method); + +/* Utility routines to allocate/free/output coupling table structures */ +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_Alloc(int nmat, int stages, + MRISTEP_METHOD_TYPE type); +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_Create(int nmat, int stages, + int q, int p, + sunrealtype* W, + sunrealtype* G, + sunrealtype* c); +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_MIStoMRI(ARKodeButcherTable B, + int q, int p); +SUNDIALS_EXPORT MRIStepCoupling MRIStepCoupling_Copy(MRIStepCoupling MRIC); +SUNDIALS_EXPORT void MRIStepCoupling_Space(MRIStepCoupling MRIC, + sunindextype* liw, sunindextype* lrw); +SUNDIALS_EXPORT void MRIStepCoupling_Free(MRIStepCoupling MRIC); +SUNDIALS_EXPORT void MRIStepCoupling_Write(MRIStepCoupling MRIC, FILE* outfile); + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*MRIStepPreInnerFn)(sunrealtype t, N_Vector* f, int nvecs, + void* user_data); + +typedef int (*MRIStepPostInnerFn)(sunrealtype t, N_Vector y, void* user_data); + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Creation and Reinitialization functions */ +SUNDIALS_EXPORT void* MRIStepCreate(ARKRhsFn fse, ARKRhsFn fsi, sunrealtype t0, + N_Vector y0, MRIStepInnerStepper stepper, + SUNContext sunctx); +SUNDIALS_EXPORT int MRIStepReInit(void* arkode_mem, ARKRhsFn fse, ARKRhsFn fsi, + sunrealtype t0, N_Vector y0); + +/* Optional input functions -- must be called AFTER MRIStepCreate */ +SUNDIALS_EXPORT int MRIStepSetCoupling(void* arkode_mem, MRIStepCoupling MRIC); +SUNDIALS_EXPORT int MRIStepSetPreInnerFn(void* arkode_mem, + MRIStepPreInnerFn prefn); +SUNDIALS_EXPORT int MRIStepSetPostInnerFn(void* arkode_mem, + MRIStepPostInnerFn postfn); + +/* Optional output functions */ +SUNDIALS_EXPORT int MRIStepGetNumRhsEvals(void* arkode_mem, long int* nfse_evals, + long int* nfsi_evals); +SUNDIALS_EXPORT int MRIStepGetCurrentCoupling(void* arkode_mem, + MRIStepCoupling* MRIC); +SUNDIALS_EXPORT int MRIStepGetLastInnerStepFlag(void* arkode_mem, int* flag); + +/* Custom inner stepper functions */ +SUNDIALS_EXPORT int MRIStepInnerStepper_Create(SUNContext sunctx, + MRIStepInnerStepper* stepper); +SUNDIALS_EXPORT int MRIStepInnerStepper_Free(MRIStepInnerStepper* stepper); +SUNDIALS_EXPORT int MRIStepInnerStepper_SetContent(MRIStepInnerStepper stepper, + void* content); +SUNDIALS_EXPORT int MRIStepInnerStepper_GetContent(MRIStepInnerStepper stepper, + void** content); +SUNDIALS_EXPORT int MRIStepInnerStepper_SetEvolveFn(MRIStepInnerStepper stepper, + MRIStepInnerEvolveFn fn); +SUNDIALS_EXPORT int MRIStepInnerStepper_SetFullRhsFn(MRIStepInnerStepper stepper, + MRIStepInnerFullRhsFn fn); +SUNDIALS_EXPORT int MRIStepInnerStepper_SetResetFn(MRIStepInnerStepper stepper, + MRIStepInnerResetFn fn); +SUNDIALS_EXPORT int MRIStepInnerStepper_AddForcing(MRIStepInnerStepper stepper, + sunrealtype t, N_Vector f); +SUNDIALS_EXPORT int MRIStepInnerStepper_GetForcingData( + MRIStepInnerStepper stepper, sunrealtype* tshift, sunrealtype* tscale, + N_Vector** forcing, int* nforcing); + +/* -------------------------------------------------------------------------- + * Deprecated Functions -- all are superseded by shared ARKODE-level routines + * -------------------------------------------------------------------------- */ + +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeResize instead") +int MRIStepResize(void* arkode_mem, N_Vector ynew, sunrealtype t0, + ARKVecResizeFn resize, void* resize_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeReset instead") +int MRIStepReset(void* arkode_mem, sunrealtype tR, N_Vector yR); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSStolerances instead") +int MRIStepSStolerances(void* arkode_mem, sunrealtype reltol, sunrealtype abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSVtolerances instead") +int MRIStepSVtolerances(void* arkode_mem, sunrealtype reltol, N_Vector abstol); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWFtolerances instead") +int MRIStepWFtolerances(void* arkode_mem, ARKEwtFn efun); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinearSolver instead") +int MRIStepSetLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeRootInit instead") +int MRIStepRootInit(void* arkode_mem, int nrtfn, ARKRootFn g); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDefaults instead") +int MRIStepSetDefaults(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetOrder instead") +int MRIStepSetOrder(void* arkode_mem, int ord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantType instead") +int MRIStepSetInterpolantType(void* arkode_mem, int itype); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int MRIStepSetInterpolantDegree(void* arkode_mem, int degree); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int MRIStepSetDenseOrder(void* arkode_mem, int dord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinearSolver instead") +int MRIStepSetNonlinearSolver(void* arkode_mem, SUNNonlinearSolver NLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNlsRhsFn instead") +int MRIStepSetNlsRhsFn(void* arkode_mem, ARKRhsFn nls_fs); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinear instead") +int MRIStepSetLinear(void* arkode_mem, int timedepend); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinear instead") +int MRIStepSetNonlinear(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepSetMaxARKodes instead") +int MRIStepSetMaxNumSteps(void* arkode_mem, long int mxsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinCRDown instead") +int MRIStepSetNonlinCRDown(void* arkode_mem, sunrealtype crdown); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinRDiv instead") +int MRIStepSetNonlinRDiv(void* arkode_mem, sunrealtype rdiv); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDeltaGammaMax instead") +int MRIStepSetDeltaGammaMax(void* arkode_mem, sunrealtype dgmax); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLSetupFrequency instead") +int MRIStepSetLSetupFrequency(void* arkode_mem, int msbp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPredictorMethod instead") +int MRIStepSetPredictorMethod(void* arkode_mem, int method); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNonlinIters instead") +int MRIStepSetMaxNonlinIters(void* arkode_mem, int maxcor); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNonlinConvCoef instead") +int MRIStepSetNonlinConvCoef(void* arkode_mem, sunrealtype nlscoef); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxHnilWarns instead") +int MRIStepSetMaxHnilWarns(void* arkode_mem, int mxhnil); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolateStopTime instead") +int MRIStepSetInterpolateStopTime(void* arkode_mem, sunbooleantype interp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStopTime instead") +int MRIStepSetStopTime(void* arkode_mem, sunrealtype tstop); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeClearStopTime instead") +int MRIStepClearStopTime(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepSetFiARKode instead") +int MRIStepSetFixedStep(void* arkode_mem, sunrealtype hsfixed); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRootDirection instead") +int MRIStepSetRootDirection(void* arkode_mem, int* rootdir); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNoInactiveRootWarn instead") +int MRIStepSetNoInactiveRootWarn(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetUserData instead") +int MRIStepSetUserData(void* arkode_mem, void* user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepSetPostprocARKodeFn instead") +int MRIStepSetPostprocessStepFn(void* arkode_mem, ARKPostProcessFn ProcessStep); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStageFn instead") +int MRIStepSetPostprocessStageFn(void* arkode_mem, ARKPostProcessFn ProcessStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStagePredictFn instead") +int MRIStepSetStagePredictFn(void* arkode_mem, ARKStagePredictFn PredictStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDeduceImplicitRhs instead") +int MRIStepSetDeduceImplicitRhs(void* arkode_mem, sunbooleantype deduce); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacFn instead") +int MRIStepSetJacFn(void* arkode_mem, ARKLsJacFn jac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacEvalFrequency instead") +int MRIStepSetJacEvalFrequency(void* arkode_mem, long int msbj); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinearSolutionScaling instead") +int MRIStepSetLinearSolutionScaling(void* arkode_mem, sunbooleantype onoff); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetEpsLin instead") +int MRIStepSetEpsLin(void* arkode_mem, sunrealtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLSNormFactor instead") +int MRIStepSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPreconditioner instead") +int MRIStepSetPreconditioner(void* arkode_mem, ARKLsPrecSetupFn psetup, + ARKLsPrecSolveFn psolve); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacTimes instead") +int MRIStepSetJacTimes(void* arkode_mem, ARKLsJacTimesSetupFn jtsetup, + ARKLsJacTimesVecFn jtimes); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetJacTimesRhsFn instead") +int MRIStepSetJacTimesRhsFn(void* arkode_mem, ARKRhsFn jtimesRhsFn); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetLinSysFn instead") +int MRIStepSetLinSysFn(void* arkode_mem, ARKLsLinSysFn linsys); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeEvolve instead") +int MRIStepEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetDky instead") +int MRIStepGetDky(void* arkode_mem, sunrealtype t, int k, N_Vector dky); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeComputeState instead") +int MRIStepComputeState(void* arkode_mem, N_Vector zcor, N_Vector z); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinSolvSetups instead") +int MRIStepGetNumLinSolvSetups(void* arkode_mem, long int* nlinsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetWorkSpace instead") +int MRIStepGetWorkSpace(void* arkode_mem, long int* lenrw, long int* leniw); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepGetARKodes instead") +int MRIStepGetNumSteps(void* arkode_mem, long int* nssteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepGetLARKode instead") +int MRIStepGetLastStep(void* arkode_mem, sunrealtype* hlast); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentTime instead") +int MRIStepGetCurrentTime(void* arkode_mem, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentState instead") +int MRIStepGetCurrentState(void* arkode_mem, N_Vector* state); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentGamma instead") +int MRIStepGetCurrentGamma(void* arkode_mem, sunrealtype* gamma); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetTolScaleFactor instead") +int MRIStepGetTolScaleFactor(void* arkode_mem, sunrealtype* tolsfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetErrWeights instead") +int MRIStepGetErrWeights(void* arkode_mem, N_Vector eweight); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumGEvals instead") +int MRIStepGetNumGEvals(void* arkode_mem, long int* ngevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetRootInfo instead") +int MRIStepGetRootInfo(void* arkode_mem, int* rootsfound); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetUserData instead") +int MRIStepGetUserData(void* arkode_mem, void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintAllStats instead") +int MRIStepPrintAllStats(void* arkode_mem, FILE* outfile, SUNOutputFormat fmt); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetReturnFlagName instead") +char* MRIStepGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWriteParameters instead") +int MRIStepWriteParameters(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG( + "use MRIStepGetCurrentCoupling and MRIStepCoupling_Write instead") +int MRIStepWriteCoupling(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNonlinearSystemData instead") +int MRIStepGetNonlinearSystemData(void* arkode_mem, sunrealtype* tcur, + N_Vector* zpred, N_Vector* z, N_Vector* F, + sunrealtype* gamma, N_Vector* sdata, + void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumNonlinSolvIters instead") +int MRIStepGetNumNonlinSolvIters(void* arkode_mem, long int* nniters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumNonlinSolvConvFails instead") +int MRIStepGetNumNonlinSolvConvFails(void* arkode_mem, long int* nnfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNonlinSolvStats instead") +int MRIStepGetNonlinSolvStats(void* arkode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepGetARKodeSolveFails instead") +int MRIStepGetNumStepSolveFails(void* arkode_mem, long int* nncfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetJac instead") +int MRIStepGetJac(void* arkode_mem, SUNMatrix* J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetJacTime instead") +int MRIStepGetJacTime(void* arkode_mem, sunrealtype* t_J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use MRIStepGetJacARKodes instead") +int MRIStepGetJacNumSteps(void* arkode_mem, long* nst_J); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLinWorkSpace instead") +int MRIStepGetLinWorkSpace(void* arkode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJacEvals instead") +int MRIStepGetNumJacEvals(void* arkode_mem, long int* njevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumPrecEvals instead") +int MRIStepGetNumPrecEvals(void* arkode_mem, long int* npevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumPrecSolves instead") +int MRIStepGetNumPrecSolves(void* arkode_mem, long int* npsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinIters instead") +int MRIStepGetNumLinIters(void* arkode_mem, long int* nliters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinConvFails instead") +int MRIStepGetNumLinConvFails(void* arkode_mem, long int* nlcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJTSetupEvals instead") +int MRIStepGetNumJTSetupEvals(void* arkode_mem, long int* njtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumJtimesEvals instead") +int MRIStepGetNumJtimesEvals(void* arkode_mem, long int* njvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumLinRhsEvals instead") +int MRIStepGetNumLinRhsEvals(void* arkode_mem, long int* nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLastLinFlag instead") +int MRIStepGetLastLinFlag(void* arkode_mem, long int* flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLinReturnFlagName instead") +char* MRIStepGetLinReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeFree instead") +void MRIStepFree(void** arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintMem instead") +void MRIStepPrintMem(void* arkode_mem, FILE* outfile); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_sprk.h b/inst/include/arkode/arkode_sprk.h new file mode 100644 index 0000000..1c6263e --- /dev/null +++ b/inst/include/arkode/arkode_sprk.h @@ -0,0 +1,97 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file defines the ARKodeSPRKTable structure. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_SPRKTABLE_H +#define _ARKODE_SPRKTABLE_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + ARKODE_SPRK_NONE = -1, /* ensure enum is signed int */ + ARKODE_MIN_SPRK_NUM = 0, + ARKODE_SPRK_EULER_1_1 = ARKODE_MIN_SPRK_NUM, + ARKODE_SPRK_LEAPFROG_2_2, + ARKODE_SPRK_PSEUDO_LEAPFROG_2_2, + ARKODE_SPRK_RUTH_3_3, + ARKODE_SPRK_MCLACHLAN_2_2, + ARKODE_SPRK_MCLACHLAN_3_3, + ARKODE_SPRK_CANDY_ROZMUS_4_4, + ARKODE_SPRK_MCLACHLAN_4_4, + ARKODE_SPRK_MCLACHLAN_5_6, + ARKODE_SPRK_YOSHIDA_6_8, + ARKODE_SPRK_SUZUKI_UMENO_8_16, + ARKODE_SPRK_SOFRONIOU_10_36, + ARKODE_MAX_SPRK_NUM = ARKODE_SPRK_SOFRONIOU_10_36 +} ARKODE_SPRKMethodID; + +struct ARKodeSPRKTableMem +{ + /* method order of accuracy */ + int q; + /* number of stages */ + int stages; + /* the a_i coefficients generate the explicit Butcher table */ + sunrealtype* a; + /* the ahat_i coefficients generate the diagonally-implicit Butcher table */ + sunrealtype* ahat; +}; + +typedef _SUNDIALS_STRUCT_ ARKodeSPRKTableMem* ARKodeSPRKTable; + +/* Utility routines to allocate/free/output SPRK structures */ +SUNDIALS_EXPORT +ARKodeSPRKTable ARKodeSPRKTable_Create(int s, int q, const sunrealtype* a, + const sunrealtype* ahat); + +SUNDIALS_EXPORT +ARKodeSPRKTable ARKodeSPRKTable_Alloc(int stages); + +SUNDIALS_EXPORT +ARKodeSPRKTable ARKodeSPRKTable_Load(ARKODE_SPRKMethodID id); + +SUNDIALS_EXPORT +ARKodeSPRKTable ARKodeSPRKTable_LoadByName(const char* method); + +SUNDIALS_EXPORT +ARKodeSPRKTable ARKodeSPRKTable_Copy(ARKodeSPRKTable that_sprk_storage); + +SUNDIALS_EXPORT +void ARKodeSPRKTable_Write(ARKodeSPRKTable sprk_table, FILE* outfile); + +SUNDIALS_EXPORT +void ARKodeSPRKTable_Space(ARKodeSPRKTable sprk_storage, sunindextype* liw, + sunindextype* lrw); +SUNDIALS_EXPORT +void ARKodeSPRKTable_Free(ARKodeSPRKTable sprk_storage); + +SUNDIALS_EXPORT +int ARKodeSPRKTable_ToButcher(ARKodeSPRKTable sprk_storage, + ARKodeButcherTable* a_ptr, + ARKodeButcherTable* b_ptr); + +/* Different methods */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/arkode/arkode_sprkstep.h b/inst/include/arkode/arkode_sprkstep.h new file mode 100644 index 0000000..3e4519c --- /dev/null +++ b/inst/include/arkode/arkode_sprkstep.h @@ -0,0 +1,134 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the ARKODE SPRKStep module. + * -----------------------------------------------------------------*/ + +#ifndef _ARKODE_SPRKSTEP_H +#define _ARKODE_SPRKSTEP_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * SPRKStep Constants + * ----------------- */ + +static const int SPRKSTEP_DEFAULT_1 = ARKODE_SPRK_EULER_1_1; +static const int SPRKSTEP_DEFAULT_2 = ARKODE_SPRK_LEAPFROG_2_2; +static const int SPRKSTEP_DEFAULT_3 = ARKODE_SPRK_MCLACHLAN_3_3; +static const int SPRKSTEP_DEFAULT_4 = ARKODE_SPRK_MCLACHLAN_4_4; +static const int SPRKSTEP_DEFAULT_5 = ARKODE_SPRK_MCLACHLAN_5_6; +static const int SPRKSTEP_DEFAULT_6 = ARKODE_SPRK_YOSHIDA_6_8; +static const int SPRKSTEP_DEFAULT_8 = ARKODE_SPRK_SUZUKI_UMENO_8_16; +static const int SPRKSTEP_DEFAULT_10 = ARKODE_SPRK_SOFRONIOU_10_36; + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Creation and Reinitialization functions */ +SUNDIALS_EXPORT void* SPRKStepCreate(ARKRhsFn f1, ARKRhsFn f2, sunrealtype t0, + N_Vector y0, SUNContext sunctx); +SUNDIALS_EXPORT int SPRKStepReInit(void* arkode_mem, ARKRhsFn f1, ARKRhsFn f2, + sunrealtype t0, N_Vector y0); + +/* Optional input functions -- must be called AFTER SPRKStepCreate */ +SUNDIALS_EXPORT int SPRKStepSetUseCompensatedSums(void* arkode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int SPRKStepSetMethod(void* arkode_mem, + ARKodeSPRKTable sprk_storage); +SUNDIALS_EXPORT int SPRKStepSetMethodName(void* arkode_mem, const char* method); + +/* Optional output functions */ +SUNDIALS_EXPORT int SPRKStepGetCurrentMethod(void* arkode_mem, + ARKodeSPRKTable* sprk_storage); +SUNDIALS_EXPORT int SPRKStepGetNumRhsEvals(void* arkode_mem, long int* nf1, + long int* nf2); + +/* -------------------------------------------------------------------------- + * Deprecated Functions -- all are superseded by shared ARKODE-level routines + * -------------------------------------------------------------------------- */ + +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeReset instead") +int SPRKStepReset(void* arkode_mem, sunrealtype tR, N_Vector yR); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeRootInit instead") +int SPRKStepRootInit(void* arkode_mem, int nrtfn, ARKRootFn g); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetRootDirection instead") +int SPRKStepSetRootDirection(void* arkode_mem, int* rootdir); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetNoInactiveRootWarn instead") +int SPRKStepSetNoInactiveRootWarn(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetDefaults instead") +int SPRKStepSetDefaults(void* arkode_mem); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetOrder instead") +int SPRKStepSetOrder(void* arkode_mem, int maxord); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantType instead") +int SPRKStepSetInterpolantType(void* arkode_mem, int itype); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetInterpolantDegree instead") +int SPRKStepSetInterpolantDegree(void* arkode_mem, int degree); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetMaxNumSteps instead") +int SPRKStepSetMaxNumSteps(void* arkode_mem, long int mxsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetStopTime instead") +int SPRKStepSetStopTime(void* arkode_mem, sunrealtype tstop); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetFixedStep instead") +int SPRKStepSetFixedStep(void* arkode_mem, sunrealtype hfixed); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetUserData instead") +int SPRKStepSetUserData(void* arkode_mem, void* user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStepFn instead") +int SPRKStepSetPostprocessStepFn(void* arkode_mem, ARKPostProcessFn ProcessStep); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeSetPostprocessStageFn instead") +int SPRKStepSetPostprocessStageFn(void* arkode_mem, + ARKPostProcessFn ProcessStage); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeEvolve instead") +int SPRKStepEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetDky instead") +int SPRKStepGetDky(void* arkode_mem, sunrealtype t, int k, N_Vector dky); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetReturnFlagName instead") +char* SPRKStepGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentState instead") +int SPRKStepGetCurrentState(void* arkode_mem, N_Vector* state); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentStep instead") +int SPRKStepGetCurrentStep(void* arkode_mem, sunrealtype* hcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetCurrentTime instead") +int SPRKStepGetCurrentTime(void* arkode_mem, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetLastStep instead") +int SPRKStepGetLastStep(void* arkode_mem, sunrealtype* hlast); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumStepAttempts instead") +int SPRKStepGetNumStepAttempts(void* arkode_mem, long int* step_attempts); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetNumSteps instead") +int SPRKStepGetNumSteps(void* arkode_mem, long int* nsteps); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetRootInfo instead") +int SPRKStepGetRootInfo(void* arkode_mem, int* rootsfound); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetUserData instead") +int SPRKStepGetUserData(void* arkode_mem, void** user_data); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodePrintAllStats instead") +int SPRKStepPrintAllStats(void* arkode_mem, FILE* outfile, SUNOutputFormat fmt); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeWriteParameters instead") +int SPRKStepWriteParameters(void* arkode_mem, FILE* fp); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeGetStepStats instead") +int SPRKStepGetStepStats(void* arkode_mem, long int* nsteps, + sunrealtype* hinused, sunrealtype* hlast, + sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_DEPRECATED_EXPORT_MSG("use ARKodeFree instead") +void SPRKStepFree(void** arkode_mem); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode.h b/inst/include/cvode/cvode.h new file mode 100644 index 0000000..b5aad37 --- /dev/null +++ b/inst/include/cvode/cvode.h @@ -0,0 +1,244 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, + * and Dan Shumaker @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main CVODE integrator. + * -----------------------------------------------------------------*/ + +#ifndef _CVODE_H +#define _CVODE_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * CVODE Constants + * ----------------- */ + +/* lmm */ +#define CV_ADAMS 1 +#define CV_BDF 2 + +/* itask */ +#define CV_NORMAL 1 +#define CV_ONE_STEP 2 + +/* return values */ + +#define CV_SUCCESS 0 +#define CV_TSTOP_RETURN 1 +#define CV_ROOT_RETURN 2 + +#define CV_WARNING 99 + +#define CV_TOO_MUCH_WORK -1 +#define CV_TOO_MUCH_ACC -2 +#define CV_ERR_FAILURE -3 +#define CV_CONV_FAILURE -4 + +#define CV_LINIT_FAIL -5 +#define CV_LSETUP_FAIL -6 +#define CV_LSOLVE_FAIL -7 +#define CV_RHSFUNC_FAIL -8 +#define CV_FIRST_RHSFUNC_ERR -9 +#define CV_REPTD_RHSFUNC_ERR -10 +#define CV_UNREC_RHSFUNC_ERR -11 +#define CV_RTFUNC_FAIL -12 +#define CV_NLS_INIT_FAIL -13 +#define CV_NLS_SETUP_FAIL -14 +#define CV_CONSTR_FAIL -15 +#define CV_NLS_FAIL -16 + +#define CV_MEM_FAIL -20 +#define CV_MEM_NULL -21 +#define CV_ILL_INPUT -22 +#define CV_NO_MALLOC -23 +#define CV_BAD_K -24 +#define CV_BAD_T -25 +#define CV_BAD_DKY -26 +#define CV_TOO_CLOSE -27 +#define CV_VECTOROP_ERR -28 + +#define CV_PROJ_MEM_NULL -29 +#define CV_PROJFUNC_FAIL -30 +#define CV_REPTD_PROJFUNC_ERR -31 + +#define CV_CONTEXT_ERR -32 + +#define CV_UNRECOGNIZED_ERR -99 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*CVRhsFn)(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data); + +typedef int (*CVRootFn)(sunrealtype t, N_Vector y, sunrealtype* gout, + void* user_data); + +typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void* user_data); + +typedef int (*CVMonitorFn)(void* cvode_mem, void* user_data); + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT void* CVodeCreate(int lmm, SUNContext sunctx); + +SUNDIALS_EXPORT int CVodeInit(void* cvode_mem, CVRhsFn f, sunrealtype t0, + N_Vector y0); +SUNDIALS_EXPORT int CVodeReInit(void* cvode_mem, sunrealtype t0, N_Vector y0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int CVodeSStolerances(void* cvode_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, + N_Vector abstol); +SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun); + +/* Optional input functions */ + +SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, + sunrealtype dgmax_lsetup); +SUNDIALS_EXPORT int CVodeSetInitStep(void* cvode_mem, sunrealtype hin); +SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp); +SUNDIALS_EXPORT int CVodeSetMaxConvFails(void* cvode_mem, int maxncf); +SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef); +SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil); +SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void* cvode_mem, int maxcor); +SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps); +SUNDIALS_EXPORT int CVodeSetMaxOrd(void* cvode_mem, int maxord); +SUNDIALS_EXPORT int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax); +SUNDIALS_EXPORT int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin); +SUNDIALS_EXPORT int CVodeSetMonitorFn(void* cvode_mem, CVMonitorFn fn); +SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void* cvode_mem, long int nst); +SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef); +SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void* cvode_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype stldet); +SUNDIALS_EXPORT int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop); +SUNDIALS_EXPORT int CVodeSetInterpolateStopTime(void* cvode_mem, + sunbooleantype interp); +SUNDIALS_EXPORT int CVodeClearStopTime(void* cvode_mem); +SUNDIALS_EXPORT int CVodeSetUseIntegratorFusedKernels(void* cvode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetUserData(void* cvode_mem, void* user_data); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int CVodeSetEtaFixedStepBounds(void* cvode_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs); +SUNDIALS_EXPORT +int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es); +SUNDIALS_EXPORT +int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst); +SUNDIALS_EXPORT +int CVodeSetEtaMax(void* cvode_mem, sunrealtype eta_max_gs); +SUNDIALS_EXPORT +int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int CVodeSetEtaMinErrFail(void* cvode_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef); +SUNDIALS_EXPORT +int CVodeSetNumFailsEtaMaxErrFail(void* cvode_mem, int small_nef); +SUNDIALS_EXPORT +int CVodeSetEtaConvFail(void* cvode_mem, sunrealtype eta_cf); + +/* Rootfinding initialization function */ +SUNDIALS_EXPORT int CVodeRootInit(void* cvode_mem, int nrtfn, CVRootFn g); + +/* Rootfinding optional input functions */ +SUNDIALS_EXPORT int CVodeSetRootDirection(void* cvode_mem, int* rootdir); +SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void* cvode_mem); + +/* Solver function */ +SUNDIALS_EXPORT int CVode(void* cvode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); + +/* Utility functions to update/compute y based on ycor */ +SUNDIALS_EXPORT int CVodeComputeState(void* cvode_mem, N_Vector ycor, N_Vector y); + +/* Dense output function */ +SUNDIALS_EXPORT int CVodeGetDky(void* cvode_mem, sunrealtype t, int k, + N_Vector dky); + +/* Optional output functions */ +SUNDIALS_EXPORT int CVodeGetWorkSpace(void* cvode_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int CVodeGetNumSteps(void* cvode_mem, long int* nsteps); +SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void* cvode_mem, long int* nfevals); +SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void* cvode_mem, + long int* nlinsetups); +SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void* cvode_mem, long int* netfails); +SUNDIALS_EXPORT int CVodeGetLastOrder(void* cvode_mem, int* qlast); +SUNDIALS_EXPORT int CVodeGetCurrentOrder(void* cvode_mem, int* qcur); +SUNDIALS_EXPORT int CVodeGetCurrentGamma(void* cvode_mem, sunrealtype* gamma); +SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void* cvode_mem, + long int* nslred); +SUNDIALS_EXPORT int CVodeGetActualInitStep(void* cvode_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int CVodeGetLastStep(void* cvode_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int CVodeGetCurrentStep(void* cvode_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int CVodeGetCurrentState(void* cvode_mem, N_Vector* y); +SUNDIALS_EXPORT int CVodeGetCurrentTime(void* cvode_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void* cvode_mem, sunrealtype* tolsfac); +SUNDIALS_EXPORT int CVodeGetErrWeights(void* cvode_mem, N_Vector eweight); +SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void* cvode_mem, N_Vector ele); +SUNDIALS_EXPORT int CVodeGetNumGEvals(void* cvode_mem, long int* ngevals); +SUNDIALS_EXPORT int CVodeGetRootInfo(void* cvode_mem, int* rootsfound); +SUNDIALS_EXPORT int CVodeGetIntegratorStats( + void* cvode_mem, long int* nsteps, long int* nfevals, long int* nlinsetups, + long int* netfails, int* qlast, int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetNonlinearSystemData(void* cvode_mem, + sunrealtype* tcur, + N_Vector* ypred, N_Vector* yn, + N_Vector* fn, sunrealtype* gamma, + sunrealtype* rl1, N_Vector* zn1, + void** user_data); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void* cvode_mem, + long int* nniters); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void* cvode_mem, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void* cvode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNumStepSolveFails(void* cvode_mem, + long int* nncfails); +SUNDIALS_EXPORT int CVodeGetUserData(void* cvode_mem, void** user_data); +SUNDIALS_EXPORT int CVodePrintAllStats(void* cvode_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* CVodeGetReturnFlagName(long int flag); + +/* Free function */ +SUNDIALS_EXPORT void CVodeFree(void** cvode_mem); + +/* CVLS interface function that depends on CVRhsFn */ +SUNDIALS_EXPORT int CVodeSetJacTimesRhsFn(void* cvode_mem, CVRhsFn jtimesRhsFn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode_bandpre.h b/inst/include/cvode/cvode_bandpre.h new file mode 100644 index 0000000..bde2d10 --- /dev/null +++ b/inst/include/cvode/cvode_bandpre.h @@ -0,0 +1,44 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Alan C. Hindmarsh and Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVBANDPRE module, which provides + * a banded difference quotient Jacobian-based preconditioner. + * -----------------------------------------------------------------*/ + +#ifndef _CVBANDPRE_H +#define _CVBANDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* BandPrec inititialization function */ + +SUNDIALS_EXPORT int CVBandPrecInit(void* cvode_mem, sunindextype N, + sunindextype mu, sunindextype ml); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVBandPrecGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVBandPrecGetNumRhsEvals(void* cvode_mem, + long int* nfevalsBP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode_bbdpre.h b/inst/include/cvode/cvode_bbdpre.h new file mode 100644 index 0000000..bc9e11b --- /dev/null +++ b/inst/include/cvode/cvode_bbdpre.h @@ -0,0 +1,61 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Michael Wittman, Alan C. Hindmarsh and + * Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVBBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _CVBBDPRE_H +#define _CVBBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* User-supplied function Types */ + +typedef int (*CVLocalFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + N_Vector g, void* user_data); + +typedef int (*CVCommFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dqrely, CVLocalFn gloc, + CVCommFn cfn); + +SUNDIALS_EXPORT int CVBBDPrecReInit(void* cvode_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dqrely); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVBBDPrecGetWorkSpace(void* cvode_mem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int CVBBDPrecGetNumGfnEvals(void* cvode_mem, + long int* ngevalsBBDP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode_diag.h b/inst/include/cvode/cvode_diag.h new file mode 100644 index 0000000..7c7387e --- /dev/null +++ b/inst/include/cvode/cvode_diag.h @@ -0,0 +1,59 @@ +/* --------------------------------------------------------------------- + * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and + * Radu Serban @ LLNL + * --------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVODE diagonal linear solver, CVDIAG. + * ---------------------------------------------------------------------*/ + +#ifndef _CVDIAG_H +#define _CVDIAG_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* --------------------- + * CVDIAG return values + * --------------------- */ + +#define CVDIAG_SUCCESS 0 +#define CVDIAG_MEM_NULL -1 +#define CVDIAG_LMEM_NULL -2 +#define CVDIAG_ILL_INPUT -3 +#define CVDIAG_MEM_FAIL -4 + +/* Additional last_flag values */ + +#define CVDIAG_INV_FAIL -5 +#define CVDIAG_RHSFUNC_UNRECVR -6 +#define CVDIAG_RHSFUNC_RECVR -7 + +/* CVDiag initialization function */ + +SUNDIALS_EXPORT int CVDiag(void* cvode_mem); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVDiagGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVDiagGetNumRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVDiagGetLastFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVDiagGetReturnFlagName(long int flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode_ls.h b/inst/include/cvode/cvode_ls.h new file mode 100644 index 0000000..1847b07 --- /dev/null +++ b/inst/include/cvode/cvode_ls.h @@ -0,0 +1,129 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Scott D. Cohen, Alan C. Hindmarsh and + * Radu Serban @ LLNL + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for CVODE's linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _CVLS_H +#define _CVLS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================= + CVLS Constants + =================================================================*/ + +#define CVLS_SUCCESS 0 +#define CVLS_MEM_NULL -1 +#define CVLS_LMEM_NULL -2 +#define CVLS_ILL_INPUT -3 +#define CVLS_MEM_FAIL -4 +#define CVLS_PMEM_NULL -5 +#define CVLS_JACFUNC_UNRECVR -6 +#define CVLS_JACFUNC_RECVR -7 +#define CVLS_SUNMAT_FAIL -8 +#define CVLS_SUNLS_FAIL -9 + +/*================================================================= + CVLS user-supplied function prototypes + =================================================================*/ + +typedef int (*CVLsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + void* user_data, N_Vector tmp1, N_Vector tmp2, + N_Vector tmp3); + +typedef int (*CVLsPrecSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* user_data); + +typedef int (*CVLsPrecSolveFn)(sunrealtype t, N_Vector y, N_Vector fy, + N_Vector r, N_Vector z, sunrealtype gamma, + sunrealtype delta, int lr, void* user_data); + +typedef int (*CVLsJacTimesSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + void* user_data); + +typedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, sunrealtype t, + N_Vector y, N_Vector fy, void* user_data, + N_Vector tmp); + +typedef int (*CVLsLinSysFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix A, + sunbooleantype jok, sunbooleantype* jcur, + sunrealtype gamma, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); + +/*================================================================= + CVLS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, + SUNMatrix A); + +/*----------------------------------------------------------------- + Optional inputs to the CVLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int CVodeSetJacFn(void* cvode_mem, CVLsJacFn jac); +SUNDIALS_EXPORT int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj); +SUNDIALS_EXPORT int CVodeSetLinearSolutionScaling(void* cvode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, + sunrealtype dgmax_jbad); +SUNDIALS_EXPORT int CVodeSetEpsLin(void* cvode_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int CVodeSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn pset, + CVLsPrecSolveFn psolve); +SUNDIALS_EXPORT int CVodeSetJacTimes(void* cvode_mem, CVLsJacTimesSetupFn jtsetup, + CVLsJacTimesVecFn jtimes); +SUNDIALS_EXPORT int CVodeSetLinSysFn(void* cvode_mem, CVLsLinSysFn linsys); + +/*----------------------------------------------------------------- + Optional outputs from the CVLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int CVodeGetJac(void* cvode_mem, SUNMatrix* J); +SUNDIALS_EXPORT int CVodeGetJacTime(void* cvode_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int CVodeGetJacNumSteps(void* cvode_mem, long int* nst_J); +SUNDIALS_EXPORT int CVodeGetLinWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVodeGetNumJacEvals(void* cvode_mem, long int* njevals); +SUNDIALS_EXPORT int CVodeGetNumPrecEvals(void* cvode_mem, long int* npevals); +SUNDIALS_EXPORT int CVodeGetNumPrecSolves(void* cvode_mem, long int* npsolves); +SUNDIALS_EXPORT int CVodeGetNumLinIters(void* cvode_mem, long int* nliters); +SUNDIALS_EXPORT int CVodeGetNumLinConvFails(void* cvode_mem, long int* nlcfails); +SUNDIALS_EXPORT int CVodeGetNumJTSetupEvals(void* cvode_mem, long int* njtsetups); +SUNDIALS_EXPORT int CVodeGetNumJtimesEvals(void* cvode_mem, long int* njvevals); +SUNDIALS_EXPORT int CVodeGetNumLinRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVodeGetLinSolveStats(void* cvode_mem, long int* njevals, + long int* nfevalsLS, + long int* nliters, long int* nlcfails, + long int* npevals, long int* npsolves, + long int* njtsetups, long int* njtimes); +SUNDIALS_EXPORT int CVodeGetLastLinFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVodeGetLinReturnFlagName(long int flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvode/cvode_proj.h b/inst/include/cvode/cvode_proj.h new file mode 100644 index 0000000..8ff792e --- /dev/null +++ b/inst/include/cvode/cvode_proj.h @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------------------- + * Based on CPODES by Radu Serban @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for CVODE's projection interface. + * ---------------------------------------------------------------------------*/ + +#ifndef _CVPROJ_H +#define _CVPROJ_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * CVProj user-supplied function prototypes + * ---------------------------------------------------------------------------*/ + +typedef int (*CVProjFn)(sunrealtype t, N_Vector ycur, N_Vector corr, + sunrealtype epsProj, N_Vector err, void* user_data); + +/* ----------------------------------------------------------------------------- + * CVProj Exported functions + * ---------------------------------------------------------------------------*/ + +/* Projection initialization functions */ +SUNDIALS_EXPORT int CVodeSetProjFn(void* cvode_mem, CVProjFn pfun); + +/* Optional input functions */ +SUNDIALS_EXPORT int CVodeSetProjErrEst(void* cvode_mem, sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetProjFrequency(void* cvode_mem, long int proj_freq); +SUNDIALS_EXPORT int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails); +SUNDIALS_EXPORT int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps); +SUNDIALS_EXPORT int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta); + +/* Optional output functions */ +SUNDIALS_EXPORT int CVodeGetNumProjEvals(void* cvode_mem, long int* nproj); +SUNDIALS_EXPORT int CVodeGetNumProjFails(void* cvode_mem, long int* nprf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes.h b/inst/include/cvodes/cvodes.h new file mode 100644 index 0000000..8af98fc --- /dev/null +++ b/inst/include/cvodes/cvodes.h @@ -0,0 +1,624 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main CVODES integrator. + * -----------------------------------------------------------------*/ + +#ifndef _CVODES_H +#define _CVODES_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * CVODES Constants + * ----------------- */ + +/* lmm */ +#define CV_ADAMS 1 +#define CV_BDF 2 + +/* itask */ +#define CV_NORMAL 1 +#define CV_ONE_STEP 2 + +/* ism */ +#define CV_SIMULTANEOUS 1 +#define CV_STAGGERED 2 +#define CV_STAGGERED1 3 + +/* DQtype */ +#define CV_CENTERED 1 +#define CV_FORWARD 2 + +/* interp */ +#define CV_HERMITE 1 +#define CV_POLYNOMIAL 2 + +/* return values */ + +#define CV_SUCCESS 0 +#define CV_TSTOP_RETURN 1 +#define CV_ROOT_RETURN 2 + +#define CV_WARNING 99 + +#define CV_TOO_MUCH_WORK -1 +#define CV_TOO_MUCH_ACC -2 +#define CV_ERR_FAILURE -3 +#define CV_CONV_FAILURE -4 + +#define CV_LINIT_FAIL -5 +#define CV_LSETUP_FAIL -6 +#define CV_LSOLVE_FAIL -7 +#define CV_RHSFUNC_FAIL -8 +#define CV_FIRST_RHSFUNC_ERR -9 +#define CV_REPTD_RHSFUNC_ERR -10 +#define CV_UNREC_RHSFUNC_ERR -11 +#define CV_RTFUNC_FAIL -12 +#define CV_NLS_INIT_FAIL -13 +#define CV_NLS_SETUP_FAIL -14 +#define CV_CONSTR_FAIL -15 +#define CV_NLS_FAIL -16 + +#define CV_MEM_FAIL -20 +#define CV_MEM_NULL -21 +#define CV_ILL_INPUT -22 +#define CV_NO_MALLOC -23 +#define CV_BAD_K -24 +#define CV_BAD_T -25 +#define CV_BAD_DKY -26 +#define CV_TOO_CLOSE -27 +#define CV_VECTOROP_ERR -28 + +#define CV_NO_QUAD -30 +#define CV_QRHSFUNC_FAIL -31 +#define CV_FIRST_QRHSFUNC_ERR -32 +#define CV_REPTD_QRHSFUNC_ERR -33 +#define CV_UNREC_QRHSFUNC_ERR -34 + +#define CV_NO_SENS -40 +#define CV_SRHSFUNC_FAIL -41 +#define CV_FIRST_SRHSFUNC_ERR -42 +#define CV_REPTD_SRHSFUNC_ERR -43 +#define CV_UNREC_SRHSFUNC_ERR -44 + +#define CV_BAD_IS -45 + +#define CV_NO_QUADSENS -50 +#define CV_QSRHSFUNC_FAIL -51 +#define CV_FIRST_QSRHSFUNC_ERR -52 +#define CV_REPTD_QSRHSFUNC_ERR -53 +#define CV_UNREC_QSRHSFUNC_ERR -54 + +#define CV_CONTEXT_ERR -55 + +#define CV_PROJ_MEM_NULL -56 +#define CV_PROJFUNC_FAIL -57 +#define CV_REPTD_PROJFUNC_ERR -58 + +#define CV_BAD_TINTERP -59 + +#define CV_UNRECOGNIZED_ERR -99 + +/* adjoint return values */ + +#define CV_NO_ADJ -101 +#define CV_NO_FWD -102 +#define CV_NO_BCK -103 +#define CV_BAD_TB0 -104 +#define CV_REIFWD_FAIL -105 +#define CV_FWD_FAIL -106 +#define CV_GETY_BADT -107 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*CVRhsFn)(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data); + +typedef int (*CVRootFn)(sunrealtype t, N_Vector y, sunrealtype* gout, + void* user_data); + +typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void* user_data); + +typedef int (*CVMonitorFn)(void* cvode_mem, void* user_data); + +typedef int (*CVQuadRhsFn)(sunrealtype t, N_Vector y, N_Vector yQdot, + void* user_data); + +typedef int (*CVSensRhsFn)(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + N_Vector* yS, N_Vector* ySdot, void* user_data, + N_Vector tmp1, N_Vector tmp2); + +typedef int (*CVSensRhs1Fn)(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + int iS, N_Vector yS, N_Vector ySdot, + void* user_data, N_Vector tmp1, N_Vector tmp2); + +typedef int (*CVQuadSensRhsFn)(int Ns, sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yQdot, N_Vector* yQSdot, + void* user_data, N_Vector tmp, N_Vector tmpQ); + +typedef int (*CVRhsFnB)(sunrealtype t, N_Vector y, N_Vector yB, N_Vector yBdot, + void* user_dataB); + +typedef int (*CVRhsFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector yBdot, void* user_dataB); + +typedef int (*CVQuadRhsFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector qBdot, void* user_dataB); + +typedef int (*CVQuadRhsFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector qBdot, void* user_dataB); + +/* --------------------------------------- + * Exported Functions -- Forward Problems + * --------------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT void* CVodeCreate(int lmm, SUNContext sunctx); + +SUNDIALS_EXPORT int CVodeInit(void* cvode_mem, CVRhsFn f, sunrealtype t0, + N_Vector y0); +SUNDIALS_EXPORT int CVodeReInit(void* cvode_mem, sunrealtype t0, N_Vector y0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int CVodeSStolerances(void* cvode_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, + N_Vector abstol); +SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun); + +/* Optional input functions */ + +SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, + sunrealtype dgmax_lsetup); +SUNDIALS_EXPORT int CVodeSetInitStep(void* cvode_mem, sunrealtype hin); +SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp); +SUNDIALS_EXPORT int CVodeSetMaxConvFails(void* cvode_mem, int maxncf); +SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef); +SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil); +SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void* cvode_mem, int maxcor); +SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps); +SUNDIALS_EXPORT int CVodeSetMaxOrd(void* cvode_mem, int maxord); +SUNDIALS_EXPORT int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax); +SUNDIALS_EXPORT int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin); +SUNDIALS_EXPORT int CVodeSetMonitorFn(void* cvode_mem, CVMonitorFn fn); +SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void* cvode_mem, long int nst); +SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef); +SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void* cvode_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype stldet); +SUNDIALS_EXPORT int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop); +SUNDIALS_EXPORT int CVodeSetInterpolateStopTime(void* cvode_mem, + sunbooleantype interp); +SUNDIALS_EXPORT int CVodeClearStopTime(void* cvode_mem); +SUNDIALS_EXPORT int CVodeSetUserData(void* cvode_mem, void* user_data); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int CVodeSetEtaFixedStepBounds(void* cvode_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs); +SUNDIALS_EXPORT +int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es); +SUNDIALS_EXPORT +int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst); +SUNDIALS_EXPORT +int CVodeSetEtaMax(void* cvode_mem, sunrealtype eta_max_gs); +SUNDIALS_EXPORT +int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int CVodeSetEtaMinErrFail(void* cvode_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef); +SUNDIALS_EXPORT +int CVodeSetNumFailsEtaMaxErrFail(void* cvode_mem, int small_nef); +SUNDIALS_EXPORT +int CVodeSetEtaConvFail(void* cvode_mem, sunrealtype eta_cf); + +/* Rootfinding initialization function */ +SUNDIALS_EXPORT int CVodeRootInit(void* cvode_mem, int nrtfn, CVRootFn g); + +/* Rootfinding optional input functions */ +SUNDIALS_EXPORT int CVodeSetRootDirection(void* cvode_mem, int* rootdir); +SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void* cvode_mem); + +/* Solver function */ +SUNDIALS_EXPORT int CVode(void* cvode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); + +/* Utility functions to update/compute y based on ycor */ +SUNDIALS_EXPORT int CVodeComputeState(void* cvode_mem, N_Vector ycor, N_Vector y); +SUNDIALS_EXPORT int CVodeComputeStateSens(void* cvode_mem, N_Vector* yScor, + N_Vector* yS); +SUNDIALS_EXPORT int CVodeComputeStateSens1(void* cvode_mem, int idx, + N_Vector yScor1, N_Vector yS1); + +/* Dense output function */ +SUNDIALS_EXPORT int CVodeGetDky(void* cvode_mem, sunrealtype t, int k, + N_Vector dky); + +/* Optional output functions */ +SUNDIALS_EXPORT int CVodeGetWorkSpace(void* cvode_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int CVodeGetNumSteps(void* cvode_mem, long int* nsteps); +SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void* cvode_mem, long int* nfevals); +SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void* cvode_mem, + long int* nlinsetups); +SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void* cvode_mem, long int* netfails); +SUNDIALS_EXPORT int CVodeGetLastOrder(void* cvode_mem, int* qlast); +SUNDIALS_EXPORT int CVodeGetCurrentOrder(void* cvode_mem, int* qcur); +SUNDIALS_EXPORT int CVodeGetCurrentGamma(void* cvode_mem, sunrealtype* gamma); +SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void* cvode_mem, + long int* nslred); +SUNDIALS_EXPORT int CVodeGetActualInitStep(void* cvode_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int CVodeGetLastStep(void* cvode_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int CVodeGetCurrentStep(void* cvode_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int CVodeGetCurrentState(void* cvode_mem, N_Vector* y); +SUNDIALS_EXPORT int CVodeGetCurrentStateSens(void* cvode_mem, N_Vector** yS); +SUNDIALS_EXPORT int CVodeGetCurrentSensSolveIndex(void* cvode_mem, int* index); +SUNDIALS_EXPORT int CVodeGetCurrentTime(void* cvode_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void* cvode_mem, sunrealtype* tolsfac); +SUNDIALS_EXPORT int CVodeGetErrWeights(void* cvode_mem, N_Vector eweight); +SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void* cvode_mem, N_Vector ele); +SUNDIALS_EXPORT int CVodeGetNumGEvals(void* cvode_mem, long int* ngevals); +SUNDIALS_EXPORT int CVodeGetRootInfo(void* cvode_mem, int* rootsfound); +SUNDIALS_EXPORT int CVodeGetIntegratorStats( + void* cvode_mem, long int* nsteps, long int* nfevals, long int* nlinsetups, + long int* netfails, int* qlast, int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetNonlinearSystemData(void* cvode_mem, + sunrealtype* tcur, + N_Vector* ypred, N_Vector* yn, + N_Vector* fn, sunrealtype* gamma, + sunrealtype* rl1, N_Vector* zn1, + void** user_data); +SUNDIALS_EXPORT int CVodeGetNonlinearSystemDataSens( + void* cvode_mem, sunrealtype* tcur, N_Vector** ySpred, N_Vector** ySn, + sunrealtype* gamma, sunrealtype* rl1, N_Vector** zn1, void** user_data); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void* cvode_mem, + long int* nniters); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void* cvode_mem, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void* cvode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNumStepSolveFails(void* cvode_mem, + long int* nncfails); +SUNDIALS_EXPORT int CVodeGetUserData(void* cvode_mem, void** user_data); +SUNDIALS_EXPORT int CVodePrintAllStats(void* cvode_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* CVodeGetReturnFlagName(long int flag); + +/* Free function */ +SUNDIALS_EXPORT void CVodeFree(void** cvode_mem); + +/* CVLS interface function that depends on CVRhsFn */ +SUNDIALS_EXPORT int CVodeSetJacTimesRhsFn(void* cvode_mem, CVRhsFn jtimesRhsFn); + +/* --------------------------------- + * Exported Functions -- Quadrature + * --------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT int CVodeQuadInit(void* cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0); +SUNDIALS_EXPORT int CVodeQuadReInit(void* cvode_mem, N_Vector yQ0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int CVodeQuadSStolerances(void* cvode_mem, sunrealtype reltolQ, + sunrealtype abstolQ); +SUNDIALS_EXPORT int CVodeQuadSVtolerances(void* cvode_mem, sunrealtype reltolQ, + N_Vector abstolQ); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int CVodeSetQuadErrCon(void* cvode_mem, sunbooleantype errconQ); + +/* Extraction and Dense Output Functions for Forward Problems */ +SUNDIALS_EXPORT int CVodeGetQuad(void* cvode_mem, sunrealtype* tret, + N_Vector yQout); +SUNDIALS_EXPORT int CVodeGetQuadDky(void* cvode_mem, sunrealtype t, int k, + N_Vector dky); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int CVodeGetQuadNumRhsEvals(void* cvode_mem, long int* nfQevals); +SUNDIALS_EXPORT int CVodeGetQuadNumErrTestFails(void* cvode_mem, + long int* nQetfails); +SUNDIALS_EXPORT int CVodeGetQuadErrWeights(void* cvode_mem, N_Vector eQweight); +SUNDIALS_EXPORT int CVodeGetQuadStats(void* cvode_mem, long int* nfQevals, + long int* nQetfails); + +/* Free function */ +SUNDIALS_EXPORT void CVodeQuadFree(void* cvode_mem); + +/* ------------------------------------ + * Exported Functions -- Sensitivities + * ------------------------------------ */ + +/* Initialization functions */ +SUNDIALS_EXPORT int CVodeSensInit(void* cvode_mem, int Ns, int ism, + CVSensRhsFn fS, N_Vector* yS0); +SUNDIALS_EXPORT int CVodeSensInit1(void* cvode_mem, int Ns, int ism, + CVSensRhs1Fn fS1, N_Vector* yS0); +SUNDIALS_EXPORT int CVodeSensReInit(void* cvode_mem, int ism, N_Vector* yS0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int CVodeSensSStolerances(void* cvode_mem, sunrealtype reltolS, + sunrealtype* abstolS); +SUNDIALS_EXPORT int CVodeSensSVtolerances(void* cvode_mem, sunrealtype reltolS, + N_Vector* abstolS); +SUNDIALS_EXPORT int CVodeSensEEtolerances(void* cvode_mem); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int CVodeSetSensDQMethod(void* cvode_mem, int DQtype, + sunrealtype DQrhomax); +SUNDIALS_EXPORT int CVodeSetSensErrCon(void* cvode_mem, sunbooleantype errconS); +SUNDIALS_EXPORT int CVodeSetSensMaxNonlinIters(void* cvode_mem, int maxcorS); +SUNDIALS_EXPORT int CVodeSetSensParams(void* cvode_mem, sunrealtype* p, + sunrealtype* pbar, int* plist); + +/* Integrator nonlinear solver specification functions */ +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensSim(void* cvode_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg(void* cvode_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg1(void* cvode_mem, + SUNNonlinearSolver NLS); + +/* Enable/disable sensitivities */ +SUNDIALS_EXPORT int CVodeSensToggleOff(void* cvode_mem); + +/* Extraction and dense output functions */ +SUNDIALS_EXPORT int CVodeGetSens(void* cvode_mem, sunrealtype* tret, + N_Vector* ySout); +SUNDIALS_EXPORT int CVodeGetSens1(void* cvode_mem, sunrealtype* tret, int is, + N_Vector ySout); + +SUNDIALS_EXPORT int CVodeGetSensDky(void* cvode_mem, sunrealtype t, int k, + N_Vector* dkyA); +SUNDIALS_EXPORT int CVodeGetSensDky1(void* cvode_mem, sunrealtype t, int k, + int is, N_Vector dky); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int CVodeGetSensNumRhsEvals(void* cvode_mem, long int* nfSevals); +SUNDIALS_EXPORT int CVodeGetNumRhsEvalsSens(void* cvode_mem, long int* nfevalsS); +SUNDIALS_EXPORT int CVodeGetSensNumErrTestFails(void* cvode_mem, + long int* nSetfails); +SUNDIALS_EXPORT int CVodeGetSensNumLinSolvSetups(void* cvode_mem, + long int* nlinsetupsS); +SUNDIALS_EXPORT int CVodeGetSensErrWeights(void* cvode_mem, N_Vector* eSweight); +SUNDIALS_EXPORT int CVodeGetSensStats(void* cvode_mem, long int* nfSevals, + long int* nfevalsS, long int* nSetfails, + long int* nlinsetupsS); +SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvIters(void* cvode_mem, + long int* nSniters); +SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvConvFails(void* cvode_mem, + long int* nSnfails); +SUNDIALS_EXPORT int CVodeGetSensNonlinSolvStats(void* cvode_mem, + long int* nSniters, + long int* nSnfails); +SUNDIALS_EXPORT int CVodeGetNumStepSensSolveFails(void* cvode_mem, + long int* nSncfails); +SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvIters(void* cvode_mem, + long int* nSTGR1niters); +SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvConvFails(void* cvode_mem, + long int* nSTGR1nfails); +SUNDIALS_EXPORT int CVodeGetStgrSensNonlinSolvStats(void* cvode_mem, + long int* nSTGR1niters, + long int* nSTGR1nfails); +SUNDIALS_EXPORT int CVodeGetNumStepStgrSensSolveFails(void* cvode_mem, + long int* nSTGR1ncfails); + +/* Free function */ +SUNDIALS_EXPORT void CVodeSensFree(void* cvode_mem); + +/* ------------------------------------------------------- + * Exported Functions -- Sensitivity dependent quadrature + * ------------------------------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT int CVodeQuadSensInit(void* cvode_mem, CVQuadSensRhsFn fQS, + N_Vector* yQS0); +SUNDIALS_EXPORT int CVodeQuadSensReInit(void* cvode_mem, N_Vector* yQS0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int CVodeQuadSensSStolerances(void* cvode_mem, + sunrealtype reltolQS, + sunrealtype* abstolQS); +SUNDIALS_EXPORT int CVodeQuadSensSVtolerances(void* cvode_mem, + sunrealtype reltolQS, + N_Vector* abstolQS); +SUNDIALS_EXPORT int CVodeQuadSensEEtolerances(void* cvode_mem); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int CVodeSetQuadSensErrCon(void* cvode_mem, + sunbooleantype errconQS); + +/* Extraction and dense output functions */ +SUNDIALS_EXPORT int CVodeGetQuadSens(void* cvode_mem, sunrealtype* tret, + N_Vector* yQSout); +SUNDIALS_EXPORT int CVodeGetQuadSens1(void* cvode_mem, sunrealtype* tret, + int is, N_Vector yQSout); + +SUNDIALS_EXPORT int CVodeGetQuadSensDky(void* cvode_mem, sunrealtype t, int k, + N_Vector* dkyQS_all); +SUNDIALS_EXPORT int CVodeGetQuadSensDky1(void* cvode_mem, sunrealtype t, int k, + int is, N_Vector dkyQS); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int CVodeGetQuadSensNumRhsEvals(void* cvode_mem, + long int* nfQSevals); +SUNDIALS_EXPORT int CVodeGetQuadSensNumErrTestFails(void* cvode_mem, + long int* nQSetfails); +SUNDIALS_EXPORT int CVodeGetQuadSensErrWeights(void* cvode_mem, + N_Vector* eQSweight); +SUNDIALS_EXPORT int CVodeGetQuadSensStats(void* cvode_mem, long int* nfQSevals, + long int* nQSetfails); + +/* Free function */ +SUNDIALS_EXPORT void CVodeQuadSensFree(void* cvode_mem); + +/* ---------------------------------------- + * Exported Functions -- Backward Problems + * ---------------------------------------- */ + +/* Initialization functions */ + +SUNDIALS_EXPORT int CVodeAdjInit(void* cvode_mem, long int steps, int interp); + +SUNDIALS_EXPORT int CVodeAdjReInit(void* cvode_mem); + +SUNDIALS_EXPORT void CVodeAdjFree(void* cvode_mem); + +/* Backward Problem Setup Functions */ + +SUNDIALS_EXPORT int CVodeCreateB(void* cvode_mem, int lmmB, int* which); + +SUNDIALS_EXPORT int CVodeInitB(void* cvode_mem, int which, CVRhsFnB fB, + sunrealtype tB0, N_Vector yB0); +SUNDIALS_EXPORT int CVodeInitBS(void* cvode_mem, int which, CVRhsFnBS fBs, + sunrealtype tB0, N_Vector yB0); +SUNDIALS_EXPORT int CVodeReInitB(void* cvode_mem, int which, sunrealtype tB0, + N_Vector yB0); + +SUNDIALS_EXPORT int CVodeSStolerancesB(void* cvode_mem, int which, + sunrealtype reltolB, sunrealtype abstolB); +SUNDIALS_EXPORT int CVodeSVtolerancesB(void* cvode_mem, int which, + sunrealtype reltolB, N_Vector abstolB); + +SUNDIALS_EXPORT int CVodeQuadInitB(void* cvode_mem, int which, CVQuadRhsFnB fQB, + N_Vector yQB0); +SUNDIALS_EXPORT int CVodeQuadInitBS(void* cvode_mem, int which, + CVQuadRhsFnBS fQBs, N_Vector yQB0); +SUNDIALS_EXPORT int CVodeQuadReInitB(void* cvode_mem, int which, N_Vector yQB0); + +SUNDIALS_EXPORT int CVodeQuadSStolerancesB(void* cvode_mem, int which, + sunrealtype reltolQB, + sunrealtype abstolQB); +SUNDIALS_EXPORT int CVodeQuadSVtolerancesB(void* cvode_mem, int which, + sunrealtype reltolQB, + N_Vector abstolQB); + +/* Solver Function For Forward Problems */ + +SUNDIALS_EXPORT int CVodeF(void* cvode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask, int* ncheckPtr); + +/* Solver Function For Backward Problems */ + +SUNDIALS_EXPORT int CVodeB(void* cvode_mem, sunrealtype tBout, int itaskB); + +/* Optional Input Functions For Adjoint Problems */ + +SUNDIALS_EXPORT int CVodeSetAdjNoSensi(void* cvode_mem); + +SUNDIALS_EXPORT int CVodeSetUserDataB(void* cvode_mem, int which, + void* user_dataB); +SUNDIALS_EXPORT int CVodeSetMaxOrdB(void* cvode_mem, int which, int maxordB); +SUNDIALS_EXPORT int CVodeSetMaxNumStepsB(void* cvode_mem, int which, + long int mxstepsB); +SUNDIALS_EXPORT int CVodeSetStabLimDetB(void* cvode_mem, int which, + sunbooleantype stldetB); +SUNDIALS_EXPORT int CVodeSetInitStepB(void* cvode_mem, int which, + sunrealtype hinB); +SUNDIALS_EXPORT int CVodeSetMinStepB(void* cvode_mem, int which, + sunrealtype hminB); +SUNDIALS_EXPORT int CVodeSetMaxStepB(void* cvode_mem, int which, + sunrealtype hmaxB); +SUNDIALS_EXPORT int CVodeSetConstraintsB(void* cvode_mem, int which, + N_Vector constraintsB); +SUNDIALS_EXPORT int CVodeSetQuadErrConB(void* cvode_mem, int which, + sunbooleantype errconQB); + +SUNDIALS_EXPORT int CVodeSetNonlinearSolverB(void* cvode_mem, int which, + SUNNonlinearSolver NLS); + +/* Extraction And Dense Output Functions For Backward Problems */ + +SUNDIALS_EXPORT int CVodeGetB(void* cvode_mem, int which, sunrealtype* tBret, + N_Vector yB); +SUNDIALS_EXPORT int CVodeGetQuadB(void* cvode_mem, int which, + sunrealtype* tBret, N_Vector qB); + +/* Optional Output Functions For Backward Problems */ + +SUNDIALS_EXPORT void* CVodeGetAdjCVodeBmem(void* cvode_mem, int which); + +SUNDIALS_EXPORT int CVodeGetAdjY(void* cvode_mem, sunrealtype t, N_Vector y); + +typedef struct +{ + void* my_addr; + void* next_addr; + sunrealtype t0; + sunrealtype t1; + long int nstep; + int order; + sunrealtype step; +} CVadjCheckPointRec; + +SUNDIALS_EXPORT int CVodeGetAdjCheckPointsInfo(void* cvode_mem, + CVadjCheckPointRec* ckpnt); + +/* CVLS interface function that depends on CVRhsFn */ +SUNDIALS_EXPORT int CVodeSetJacTimesRhsFnB(void* cvode_mem, int which, + CVRhsFn jtimesRhsFn); + +/* Undocumented Optional Output Functions For Backward Problems */ + +/* ----------------------------------------------------------------- + * CVodeGetAdjDataPointHermite + * ----------------------------------------------------------------- + * Returns the 2 vectors stored for cubic Hermite interpolation + * at the data point 'which'. The user must allocate space for + * y and yd. Returns CV_MEM_NULL if cvode_mem is NULL, + * CV_ILL_INPUT if the interpolation type previously specified + * is not CV_HERMITE, or CV_SUCCESS otherwise. + * ----------------------------------------------------------------- + * CVodeGetAdjDataPointPolynomial + * ----------------------------------------------------------------- + * Returns the vector stored for polynomial interpolation + * at the data point 'which'. The user must allocate space for + * y. Returns CV_MEM_NULL if cvode_mem is NULL, CV_ILL_INPUT if + * the interpolation type previously specified is not + * CV_POLYNOMIAL, or CV_SUCCESS otherwise. + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT int CVodeGetAdjDataPointHermite(void* cvode_mem, int which, + sunrealtype* t, N_Vector y, + N_Vector yd); + +SUNDIALS_EXPORT int CVodeGetAdjDataPointPolynomial(void* cvode_mem, int which, + sunrealtype* t, int* order, + N_Vector y); + +/* ----------------------------------------------------------------- + * CVodeGetAdjCurrentCheckPoint + * Returns the address of the 'active' check point. + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT int CVodeGetAdjCurrentCheckPoint(void* cvode_mem, void** addr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes_bandpre.h b/inst/include/cvodes/cvodes_bandpre.h new file mode 100644 index 0000000..fe58698 --- /dev/null +++ b/inst/include/cvodes/cvodes_bandpre.h @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVBANDPRE module, which provides + * a banded difference quotient Jacobian-based preconditioner. + * -----------------------------------------------------------------*/ + +#ifndef _CVSBANDPRE_H +#define _CVSBANDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*----------------- + FORWARD PROBLEMS + -----------------*/ + +/* BandPrec inititialization function */ + +SUNDIALS_EXPORT int CVBandPrecInit(void* cvode_mem, sunindextype N, + sunindextype mu, sunindextype ml); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVBandPrecGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVBandPrecGetNumRhsEvals(void* cvode_mem, + long int* nfevalsBP); + +/*------------------ + BACKWARD PROBLEMS + ------------------*/ + +SUNDIALS_EXPORT int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB, + sunindextype muB, sunindextype mlB); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes_bbdpre.h b/inst/include/cvodes/cvodes_bbdpre.h new file mode 100644 index 0000000..f888904 --- /dev/null +++ b/inst/include/cvodes/cvodes_bbdpre.h @@ -0,0 +1,88 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVBBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _CVSBBDPRE_H +#define _CVSBBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*----------------- + FORWARD PROBLEMS + -----------------*/ + +/* User-supplied function Types */ + +typedef int (*CVLocalFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + N_Vector g, void* user_data); + +typedef int (*CVCommFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dqrely, CVLocalFn gloc, + CVCommFn cfn); + +SUNDIALS_EXPORT int CVBBDPrecReInit(void* cvode_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dqrely); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVBBDPrecGetWorkSpace(void* cvode_mem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int CVBBDPrecGetNumGfnEvals(void* cvode_mem, + long int* ngevalsBBDP); + +/*------------------ + BACKWARD PROBLEMS + ------------------*/ + +/* User-Supplied Function Types */ + +typedef int (*CVLocalFnB)(sunindextype NlocalB, sunrealtype t, N_Vector y, + N_Vector yB, N_Vector gB, void* user_dataB); + +typedef int (*CVCommFnB)(sunindextype NlocalB, sunrealtype t, N_Vector y, + N_Vector yB, void* user_dataB); + +/* Exported Functions */ + +SUNDIALS_EXPORT int CVBBDPrecInitB(void* cvode_mem, int which, + sunindextype NlocalB, sunindextype mudqB, + sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dqrelyB, + CVLocalFnB glocB, CVCommFnB cfnB); + +SUNDIALS_EXPORT int CVBBDPrecReInitB(void* cvode_mem, int which, + sunindextype mudqB, sunindextype mldqB, + sunrealtype dqrelyB); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes_diag.h b/inst/include/cvodes/cvodes_diag.h new file mode 100644 index 0000000..2a795af --- /dev/null +++ b/inst/include/cvodes/cvodes_diag.h @@ -0,0 +1,72 @@ +/* --------------------------------------------------------------------- + * Programmer(s): Radu Serban @ LLNL + * --------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the CVODE diagonal linear solver, CVDIAG. + * ---------------------------------------------------------------------*/ + +#ifndef _CVSDIAG_H +#define _CVSDIAG_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* --------------------- + * CVDIAG return values + * --------------------- */ + +#define CVDIAG_SUCCESS 0 +#define CVDIAG_MEM_NULL -1 +#define CVDIAG_LMEM_NULL -2 +#define CVDIAG_ILL_INPUT -3 +#define CVDIAG_MEM_FAIL -4 + +/* Additional last_flag values */ + +#define CVDIAG_INV_FAIL -5 +#define CVDIAG_RHSFUNC_UNRECVR -6 +#define CVDIAG_RHSFUNC_RECVR -7 + +/* Return values for adjoint module */ + +#define CVDIAG_NO_ADJ -101 + +/* ----------------- + * Forward Problems + * ----------------- */ + +/* CVDiag initialization function */ + +SUNDIALS_EXPORT int CVDiag(void* cvode_mem); + +/* Optional output functions */ + +SUNDIALS_EXPORT int CVDiagGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVDiagGetNumRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVDiagGetLastFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVDiagGetReturnFlagName(long int flag); + +/* ------------------------------------- + * Backward Problems - Function CVDiagB + * ------------------------------------- */ + +SUNDIALS_EXPORT int CVDiagB(void* cvode_mem, int which); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes_ls.h b/inst/include/cvodes/cvodes_ls.h new file mode 100644 index 0000000..a4294e0 --- /dev/null +++ b/inst/include/cvodes/cvodes_ls.h @@ -0,0 +1,245 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Radu Serban @ LLNL + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for CVODES' linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _CVSLS_H +#define _CVSLS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================= + CVLS Constants + =================================================================*/ + +#define CVLS_SUCCESS 0 +#define CVLS_MEM_NULL -1 +#define CVLS_LMEM_NULL -2 +#define CVLS_ILL_INPUT -3 +#define CVLS_MEM_FAIL -4 +#define CVLS_PMEM_NULL -5 +#define CVLS_JACFUNC_UNRECVR -6 +#define CVLS_JACFUNC_RECVR -7 +#define CVLS_SUNMAT_FAIL -8 +#define CVLS_SUNLS_FAIL -9 + +/* Return values for the adjoint module */ + +#define CVLS_NO_ADJ -101 +#define CVLS_LMEMB_NULL -102 + +/*================================================================= + Forward problems + =================================================================*/ + +/*================================================================= + CVLS user-supplied function prototypes + =================================================================*/ + +typedef int (*CVLsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + void* user_data, N_Vector tmp1, N_Vector tmp2, + N_Vector tmp3); + +typedef int (*CVLsPrecSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* user_data); + +typedef int (*CVLsPrecSolveFn)(sunrealtype t, N_Vector y, N_Vector fy, + N_Vector r, N_Vector z, sunrealtype gamma, + sunrealtype delta, int lr, void* user_data); + +typedef int (*CVLsJacTimesSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + void* user_data); + +typedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, sunrealtype t, + N_Vector y, N_Vector fy, void* user_data, + N_Vector tmp); + +typedef int (*CVLsLinSysFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix A, + sunbooleantype jok, sunbooleantype* jcur, + sunrealtype gamma, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); + +/*================================================================= + CVLS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, + SUNMatrix A); + +/*----------------------------------------------------------------- + Optional inputs to the CVLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int CVodeSetJacFn(void* cvode_mem, CVLsJacFn jac); +SUNDIALS_EXPORT int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj); +SUNDIALS_EXPORT int CVodeSetLinearSolutionScaling(void* cvode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, + sunrealtype dgmax_jbad); +SUNDIALS_EXPORT int CVodeSetEpsLin(void* cvode_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int CVodeSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn pset, + CVLsPrecSolveFn psolve); +SUNDIALS_EXPORT int CVodeSetJacTimes(void* cvode_mem, CVLsJacTimesSetupFn jtsetup, + CVLsJacTimesVecFn jtimes); +SUNDIALS_EXPORT int CVodeSetLinSysFn(void* cvode_mem, CVLsLinSysFn linsys); + +/*----------------------------------------------------------------- + Optional outputs from the CVLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int CVodeGetJac(void* cvode_mem, SUNMatrix* J); +SUNDIALS_EXPORT int CVodeGetJacTime(void* cvode_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int CVodeGetJacNumSteps(void* cvode_mem, long int* nst_J); +SUNDIALS_EXPORT int CVodeGetLinWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVodeGetNumJacEvals(void* cvode_mem, long int* njevals); +SUNDIALS_EXPORT int CVodeGetNumPrecEvals(void* cvode_mem, long int* npevals); +SUNDIALS_EXPORT int CVodeGetNumPrecSolves(void* cvode_mem, long int* npsolves); +SUNDIALS_EXPORT int CVodeGetNumLinIters(void* cvode_mem, long int* nliters); +SUNDIALS_EXPORT int CVodeGetNumLinConvFails(void* cvode_mem, long int* nlcfails); +SUNDIALS_EXPORT int CVodeGetNumJTSetupEvals(void* cvode_mem, long int* njtsetups); +SUNDIALS_EXPORT int CVodeGetNumJtimesEvals(void* cvode_mem, long int* njvevals); +SUNDIALS_EXPORT int CVodeGetNumLinRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVodeGetLinSolveStats(void* cvode_mem, long int* njevals, + long int* nfevalsLS, + long int* nliters, long int* nlcfails, + long int* npevals, long int* npsolves, + long int* njtsetups, long int* njtimes); +SUNDIALS_EXPORT int CVodeGetLastLinFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVodeGetLinReturnFlagName(long int flag); + +/*================================================================= + Backward problems + =================================================================*/ + +/*================================================================= + CVLS user-supplied function prototypes + =================================================================*/ + +typedef int (*CVLsJacFnB)(sunrealtype t, N_Vector y, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*CVLsJacFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector fyB, SUNMatrix JB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*CVLsPrecSetupFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, sunbooleantype jokB, + sunbooleantype* jcurPtrB, sunrealtype gammaB, + void* user_dataB); + +typedef int (*CVLsPrecSetupFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, sunbooleantype jokB, + sunbooleantype* jcurPtrB, sunrealtype gammaB, + void* user_dataB); + +typedef int (*CVLsPrecSolveFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, N_Vector rB, N_Vector zB, + sunrealtype gammaB, sunrealtype deltaB, int lrB, + void* user_dataB); + +typedef int (*CVLsPrecSolveFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, N_Vector rB, + N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* user_dataB); + +typedef int (*CVLsJacTimesSetupFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, void* jac_dataB); + +typedef int (*CVLsJacTimesSetupFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, void* jac_dataB); + +typedef int (*CVLsJacTimesVecFnB)(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector y, N_Vector yB, N_Vector fyB, + void* jac_dataB, N_Vector tmpB); + +typedef int (*CVLsJacTimesVecFnBS)(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector fyB, void* jac_dataB, N_Vector tmpB); + +typedef int (*CVLsLinSysFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* user_dataB, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B); + +typedef int (*CVLsLinSysFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, SUNMatrix AB, + sunbooleantype jokB, sunbooleantype* jcurB, + sunrealtype gammaB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); + +/*================================================================= + CVLS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int CVodeSetLinearSolverB(void* cvode_mem, int which, + SUNLinearSolver LS, SUNMatrix A); + +/*----------------------------------------------------------------- + Each CVodeSet***B or CVodeSet***BS function below links the + main CVODES integrator with the corresponding CVSLS + optional input function for the backward integration. + The 'which' argument is the int returned by CVodeCreateB. + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int CVodeSetJacFnB(void* cvode_mem, int which, CVLsJacFnB jacB); +SUNDIALS_EXPORT int CVodeSetJacFnBS(void* cvode_mem, int which, + CVLsJacFnBS jacBS); + +SUNDIALS_EXPORT int CVodeSetEpsLinB(void* cvode_mem, int which, + sunrealtype eplifacB); + +SUNDIALS_EXPORT int CVodeSetLSNormFactorB(void* arkode_mem, int which, + sunrealtype nrmfacB); + +SUNDIALS_EXPORT int CVodeSetLinearSolutionScalingB(void* cvode_mem, int which, + sunbooleantype onoffB); + +SUNDIALS_EXPORT int CVodeSetPreconditionerB(void* cvode_mem, int which, + CVLsPrecSetupFnB psetB, + CVLsPrecSolveFnB psolveB); +SUNDIALS_EXPORT int CVodeSetPreconditionerBS(void* cvode_mem, int which, + CVLsPrecSetupFnBS psetBS, + CVLsPrecSolveFnBS psolveBS); + +SUNDIALS_EXPORT int CVodeSetJacTimesB(void* cvode_mem, int which, + CVLsJacTimesSetupFnB jtsetupB, + CVLsJacTimesVecFnB jtimesB); +SUNDIALS_EXPORT int CVodeSetJacTimesBS(void* cvode_mem, int which, + CVLsJacTimesSetupFnBS jtsetupBS, + CVLsJacTimesVecFnBS jtimesBS); + +SUNDIALS_EXPORT int CVodeSetLinSysFnB(void* cvode_mem, int which, + CVLsLinSysFnB linsys); +SUNDIALS_EXPORT int CVodeSetLinSysFnBS(void* cvode_mem, int which, + CVLsLinSysFnBS linsys); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/cvodes/cvodes_proj.h b/inst/include/cvodes/cvodes_proj.h new file mode 100644 index 0000000..8ff792e --- /dev/null +++ b/inst/include/cvodes/cvodes_proj.h @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------------------- + * Based on CPODES by Radu Serban @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for CVODE's projection interface. + * ---------------------------------------------------------------------------*/ + +#ifndef _CVPROJ_H +#define _CVPROJ_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * CVProj user-supplied function prototypes + * ---------------------------------------------------------------------------*/ + +typedef int (*CVProjFn)(sunrealtype t, N_Vector ycur, N_Vector corr, + sunrealtype epsProj, N_Vector err, void* user_data); + +/* ----------------------------------------------------------------------------- + * CVProj Exported functions + * ---------------------------------------------------------------------------*/ + +/* Projection initialization functions */ +SUNDIALS_EXPORT int CVodeSetProjFn(void* cvode_mem, CVProjFn pfun); + +/* Optional input functions */ +SUNDIALS_EXPORT int CVodeSetProjErrEst(void* cvode_mem, sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetProjFrequency(void* cvode_mem, long int proj_freq); +SUNDIALS_EXPORT int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails); +SUNDIALS_EXPORT int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps); +SUNDIALS_EXPORT int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta); + +/* Optional output functions */ +SUNDIALS_EXPORT int CVodeGetNumProjEvals(void* cvode_mem, long int* nproj); +SUNDIALS_EXPORT int CVodeGetNumProjFails(void* cvode_mem, long int* nprf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/ida/ida.h b/inst/include/ida/ida.h new file mode 100644 index 0000000..13575b0 --- /dev/null +++ b/inst/include/ida/ida.h @@ -0,0 +1,237 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Allan G. Taylor, Alan C. Hindmarsh, Radu Serban, + * and Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main IDA solver. + * -----------------------------------------------------------------*/ + +#ifndef _IDA_H +#define _IDA_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * IDA Constants + * ----------------- */ + +/* itask */ +#define IDA_NORMAL 1 +#define IDA_ONE_STEP 2 + +/* icopt */ +#define IDA_YA_YDP_INIT 1 +#define IDA_Y_INIT 2 + +/* return values */ + +#define IDA_SUCCESS 0 +#define IDA_TSTOP_RETURN 1 +#define IDA_ROOT_RETURN 2 + +#define IDA_WARNING 99 + +#define IDA_TOO_MUCH_WORK -1 +#define IDA_TOO_MUCH_ACC -2 +#define IDA_ERR_FAIL -3 +#define IDA_CONV_FAIL -4 + +#define IDA_LINIT_FAIL -5 +#define IDA_LSETUP_FAIL -6 +#define IDA_LSOLVE_FAIL -7 +#define IDA_RES_FAIL -8 +#define IDA_REP_RES_ERR -9 +#define IDA_RTFUNC_FAIL -10 +#define IDA_CONSTR_FAIL -11 + +#define IDA_FIRST_RES_FAIL -12 +#define IDA_LINESEARCH_FAIL -13 +#define IDA_NO_RECOVERY -14 +#define IDA_NLS_INIT_FAIL -15 +#define IDA_NLS_SETUP_FAIL -16 +#define IDA_NLS_FAIL -17 + +#define IDA_MEM_NULL -20 +#define IDA_MEM_FAIL -21 +#define IDA_ILL_INPUT -22 +#define IDA_NO_MALLOC -23 +#define IDA_BAD_EWT -24 +#define IDA_BAD_K -25 +#define IDA_BAD_T -26 +#define IDA_BAD_DKY -27 +#define IDA_VECTOROP_ERR -28 + +#define IDA_CONTEXT_ERR -29 + +#define IDA_UNRECOGNIZED_ERROR -99 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*IDAResFn)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, + void* user_data); + +typedef int (*IDARootFn)(sunrealtype t, N_Vector y, N_Vector yp, + sunrealtype* gout, void* user_data); + +typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void* user_data); + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT void* IDACreate(SUNContext sunctx); + +SUNDIALS_EXPORT int IDAInit(void* ida_mem, IDAResFn res, sunrealtype t0, + N_Vector yy0, N_Vector yp0); +SUNDIALS_EXPORT int IDAReInit(void* ida_mem, sunrealtype t0, N_Vector yy0, + N_Vector yp0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int IDASStolerances(void* ida_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int IDASVtolerances(void* ida_mem, sunrealtype reltol, + N_Vector abstol); +SUNDIALS_EXPORT int IDAWFtolerances(void* ida_mem, IDAEwtFn efun); + +/* Initial condition calculation function */ +SUNDIALS_EXPORT int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1); + +/* Initial condition calculation optional input functions */ +SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon); +SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void* ida_mem, int maxnh); +SUNDIALS_EXPORT int IDASetMaxNumJacsIC(void* ida_mem, int maxnj); +SUNDIALS_EXPORT int IDASetMaxNumItersIC(void* ida_mem, int maxnit); +SUNDIALS_EXPORT int IDASetLineSearchOffIC(void* ida_mem, sunbooleantype lsoff); +SUNDIALS_EXPORT int IDASetStepToleranceIC(void* ida_mem, sunrealtype steptol); +SUNDIALS_EXPORT int IDASetMaxBacksIC(void* ida_mem, int maxbacks); + +/* Optional input functions */ +SUNDIALS_EXPORT int IDASetDeltaCjLSetup(void* ida_max, sunrealtype dcj); +SUNDIALS_EXPORT int IDASetUserData(void* ida_mem, void* user_data); +SUNDIALS_EXPORT int IDASetMaxOrd(void* ida_mem, int maxord); +SUNDIALS_EXPORT int IDASetMaxNumSteps(void* ida_mem, long int mxsteps); +SUNDIALS_EXPORT int IDASetInitStep(void* ida_mem, sunrealtype hin); +SUNDIALS_EXPORT int IDASetMaxStep(void* ida_mem, sunrealtype hmax); +SUNDIALS_EXPORT int IDASetMinStep(void* ida_mem, sunrealtype hmin); +SUNDIALS_EXPORT int IDASetStopTime(void* ida_mem, sunrealtype tstop); +SUNDIALS_EXPORT int IDAClearStopTime(void* ida_mem); +SUNDIALS_EXPORT int IDASetMaxErrTestFails(void* ida_mem, int maxnef); +SUNDIALS_EXPORT int IDASetSuppressAlg(void* ida_mem, sunbooleantype suppressalg); +SUNDIALS_EXPORT int IDASetId(void* ida_mem, N_Vector id); +SUNDIALS_EXPORT int IDASetConstraints(void* ida_mem, N_Vector constraints); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int IDASetEtaFixedStepBounds(void* ida_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int IDASetEtaMin(void* ida_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int IDASetEtaMax(void* ida_mem, sunrealtype eta_max); +SUNDIALS_EXPORT +int IDASetEtaLow(void* ida_mem, sunrealtype eta_low); +SUNDIALS_EXPORT +int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf); + +/* Nonlinear solve input functions */ +SUNDIALS_EXPORT int IDASetMaxConvFails(void* ida_mem, int maxncf); +SUNDIALS_EXPORT int IDASetMaxNonlinIters(void* ida_mem, int maxcor); +SUNDIALS_EXPORT int IDASetNlsResFn(void* IDA_mem, IDAResFn res); +SUNDIALS_EXPORT int IDASetNonlinConvCoef(void* ida_mem, sunrealtype epcon); +SUNDIALS_EXPORT int IDASetNonlinearSolver(void* ida_mem, SUNNonlinearSolver NLS); + +/* Rootfinding initialization function */ +SUNDIALS_EXPORT int IDARootInit(void* ida_mem, int nrtfn, IDARootFn g); + +/* Rootfinding optional input functions */ +SUNDIALS_EXPORT int IDASetRootDirection(void* ida_mem, int* rootdir); +SUNDIALS_EXPORT int IDASetNoInactiveRootWarn(void* ida_mem); + +/* Solver function */ +SUNDIALS_EXPORT int IDASolve(void* ida_mem, sunrealtype tout, sunrealtype* tret, + N_Vector yret, N_Vector ypret, int itask); + +/* Utility functions to update/compute y and yp based on ycor */ +SUNDIALS_EXPORT int IDAComputeY(void* ida_mem, N_Vector ycor, N_Vector y); +SUNDIALS_EXPORT int IDAComputeYp(void* ida_mem, N_Vector ycor, N_Vector yp); + +/* Dense output function */ +SUNDIALS_EXPORT int IDAGetDky(void* ida_mem, sunrealtype t, int k, N_Vector dky); + +/* Optional output functions */ +SUNDIALS_EXPORT int IDAGetWorkSpace(void* ida_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int IDAGetNumSteps(void* ida_mem, long int* nsteps); +SUNDIALS_EXPORT int IDAGetNumResEvals(void* ida_mem, long int* nrevals); +SUNDIALS_EXPORT int IDAGetNumLinSolvSetups(void* ida_mem, long int* nlinsetups); +SUNDIALS_EXPORT int IDAGetNumErrTestFails(void* ida_mem, long int* netfails); +SUNDIALS_EXPORT int IDAGetNumBacktrackOps(void* ida_mem, long int* nbacktr); +SUNDIALS_EXPORT int IDAGetConsistentIC(void* ida_mem, N_Vector yy0_mod, + N_Vector yp0_mod); +SUNDIALS_EXPORT int IDAGetLastOrder(void* ida_mem, int* klast); +SUNDIALS_EXPORT int IDAGetCurrentOrder(void* ida_mem, int* kcur); +SUNDIALS_EXPORT int IDAGetCurrentCj(void* ida_mem, sunrealtype* cj); +SUNDIALS_EXPORT int IDAGetCurrentY(void* ida_mem, N_Vector* ycur); +SUNDIALS_EXPORT int IDAGetCurrentYp(void* ida_mem, N_Vector* ypcur); +SUNDIALS_EXPORT int IDAGetActualInitStep(void* ida_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int IDAGetLastStep(void* ida_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int IDAGetCurrentStep(void* ida_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int IDAGetCurrentTime(void* ida_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetTolScaleFactor(void* ida_mem, sunrealtype* tolsfact); +SUNDIALS_EXPORT int IDAGetErrWeights(void* ida_mem, N_Vector eweight); +SUNDIALS_EXPORT int IDAGetEstLocalErrors(void* ida_mem, N_Vector ele); +SUNDIALS_EXPORT int IDAGetNumGEvals(void* ida_mem, long int* ngevals); +SUNDIALS_EXPORT int IDAGetRootInfo(void* ida_mem, int* rootsfound); +SUNDIALS_EXPORT int IDAGetIntegratorStats(void* ida_mem, long int* nsteps, + long int* nrevals, long int* nlinsetups, + long int* netfails, int* qlast, + int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, + sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetNonlinearSystemData(void* ida_mem, sunrealtype* tcur, + N_Vector* yypred, + N_Vector* yppred, N_Vector* yyn, + N_Vector* ypn, N_Vector* res, + sunrealtype* cj, void** user_data); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvIters(void* ida_mem, long int* nniters); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvConvFails(void* ida_mem, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNonlinSolvStats(void* ida_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNumStepSolveFails(void* ida_mem, long int* nncfails); +SUNDIALS_EXPORT int IDAGetUserData(void* ida_mem, void** user_data); +SUNDIALS_EXPORT int IDAPrintAllStats(void* ida_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* IDAGetReturnFlagName(long int flag); + +/* Free function */ +SUNDIALS_EXPORT void IDAFree(void** ida_mem); + +/* IDALS interface function that depends on IDAResFn */ +SUNDIALS_EXPORT int IDASetJacTimesResFn(void* ida_mem, IDAResFn jtimesResFn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/ida/ida_bbdpre.h b/inst/include/ida/ida_bbdpre.h new file mode 100644 index 0000000..fc5e4d9 --- /dev/null +++ b/inst/include/ida/ida_bbdpre.h @@ -0,0 +1,60 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU, + * Alan C. Hindmarsh, Radu Serban and Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the IDABBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _IDABBDPRE_H +#define _IDABBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* User-supplied function Types */ + +typedef int (*IDABBDLocalFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector gval, void* user_data); + +typedef int (*IDABBDCommFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dq_rel_yy, IDABBDLocalFn Gres, + IDABBDCommFn Gcomm); + +SUNDIALS_EXPORT int IDABBDPrecReInit(void* ida_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dq_rel_yy); + +/* Optional output functions */ + +SUNDIALS_EXPORT int IDABBDPrecGetWorkSpace(void* ida_mem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int IDABBDPrecGetNumGfnEvals(void* ida_mem, + long int* ngevalsBBDP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/ida/ida_ls.h b/inst/include/ida/ida_ls.h new file mode 100644 index 0000000..415e472 --- /dev/null +++ b/inst/include/ida/ida_ls.h @@ -0,0 +1,119 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Alan Hindmarsh, Radu Serban and + * Aaron Collier @ LLNL + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for IDA's linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _IDALS_H +#define _IDALS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================= + IDALS Constants + =================================================================*/ + +#define IDALS_SUCCESS 0 +#define IDALS_MEM_NULL -1 +#define IDALS_LMEM_NULL -2 +#define IDALS_ILL_INPUT -3 +#define IDALS_MEM_FAIL -4 +#define IDALS_PMEM_NULL -5 +#define IDALS_JACFUNC_UNRECVR -6 +#define IDALS_JACFUNC_RECVR -7 +#define IDALS_SUNMAT_FAIL -8 +#define IDALS_SUNLS_FAIL -9 + +/*================================================================= + IDALS user-supplied function prototypes + =================================================================*/ + +typedef int (*IDALsJacFn)(sunrealtype t, sunrealtype c_j, N_Vector y, + N_Vector yp, N_Vector r, SUNMatrix Jac, void* user_data, + N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); + +typedef int (*IDALsPrecSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, void* user_data); + +typedef int (*IDALsPrecSolveFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector rvec, N_Vector zvec, + sunrealtype c_j, sunrealtype delta, + void* user_data); + +typedef int (*IDALsJacTimesSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, + void* user_data); + +typedef int (*IDALsJacTimesVecFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector v, N_Vector Jv, + sunrealtype c_j, void* user_data, + N_Vector tmp1, N_Vector tmp2); + +/*================================================================= + IDALS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, + SUNMatrix A); + +/*----------------------------------------------------------------- + Optional inputs to the IDALS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int IDASetJacFn(void* ida_mem, IDALsJacFn jac); +SUNDIALS_EXPORT int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn pset, + IDALsPrecSolveFn psolve); +SUNDIALS_EXPORT int IDASetJacTimes(void* ida_mem, IDALsJacTimesSetupFn jtsetup, + IDALsJacTimesVecFn jtimes); +SUNDIALS_EXPORT int IDASetEpsLin(void* ida_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int IDASetLSNormFactor(void* ida_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int IDASetLinearSolutionScaling(void* ida_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int IDASetIncrementFactor(void* ida_mem, sunrealtype dqincfac); + +/*----------------------------------------------------------------- + Optional outputs from the IDALS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int IDAGetJac(void* ida_mem, SUNMatrix* J); +SUNDIALS_EXPORT int IDAGetJacCj(void* ida_mem, sunrealtype* cj_J); +SUNDIALS_EXPORT int IDAGetJacTime(void* ida_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int IDAGetJacNumSteps(void* ida_mem, long int* nst_J); +SUNDIALS_EXPORT int IDAGetLinWorkSpace(void* ida_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int IDAGetNumJacEvals(void* ida_mem, long int* njevals); +SUNDIALS_EXPORT int IDAGetNumPrecEvals(void* ida_mem, long int* npevals); +SUNDIALS_EXPORT int IDAGetNumPrecSolves(void* ida_mem, long int* npsolves); +SUNDIALS_EXPORT int IDAGetNumLinIters(void* ida_mem, long int* nliters); +SUNDIALS_EXPORT int IDAGetNumLinConvFails(void* ida_mem, long int* nlcfails); +SUNDIALS_EXPORT int IDAGetNumJTSetupEvals(void* ida_mem, long int* njtsetups); +SUNDIALS_EXPORT int IDAGetNumJtimesEvals(void* ida_mem, long int* njvevals); +SUNDIALS_EXPORT int IDAGetNumLinResEvals(void* ida_mem, long int* nrevalsLS); +SUNDIALS_EXPORT int IDAGetLastLinFlag(void* ida_mem, long int* flag); +SUNDIALS_EXPORT char* IDAGetLinReturnFlagName(long int flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/idas/idas.h b/inst/include/idas/idas.h new file mode 100644 index 0000000..3f82d6f --- /dev/null +++ b/inst/include/idas/idas.h @@ -0,0 +1,606 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main IDAS solver. + * -----------------------------------------------------------------*/ + +#ifndef _IDAS_H +#define _IDAS_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * IDAS Constants + * ----------------- */ + +/* itask */ +#define IDA_NORMAL 1 +#define IDA_ONE_STEP 2 + +/* icopt */ +#define IDA_YA_YDP_INIT 1 +#define IDA_Y_INIT 2 + +/* ism */ +#define IDA_SIMULTANEOUS 1 +#define IDA_STAGGERED 2 + +/* DQtype */ +#define IDA_CENTERED 1 +#define IDA_FORWARD 2 + +/* interp */ +#define IDA_HERMITE 1 +#define IDA_POLYNOMIAL 2 + +/* return values */ + +#define IDA_SUCCESS 0 +#define IDA_TSTOP_RETURN 1 +#define IDA_ROOT_RETURN 2 + +#define IDA_WARNING 99 + +#define IDA_TOO_MUCH_WORK -1 +#define IDA_TOO_MUCH_ACC -2 +#define IDA_ERR_FAIL -3 +#define IDA_CONV_FAIL -4 + +#define IDA_LINIT_FAIL -5 +#define IDA_LSETUP_FAIL -6 +#define IDA_LSOLVE_FAIL -7 +#define IDA_RES_FAIL -8 +#define IDA_REP_RES_ERR -9 +#define IDA_RTFUNC_FAIL -10 +#define IDA_CONSTR_FAIL -11 + +#define IDA_FIRST_RES_FAIL -12 +#define IDA_LINESEARCH_FAIL -13 +#define IDA_NO_RECOVERY -14 +#define IDA_NLS_INIT_FAIL -15 +#define IDA_NLS_SETUP_FAIL -16 +#define IDA_NLS_FAIL -17 + +#define IDA_MEM_NULL -20 +#define IDA_MEM_FAIL -21 +#define IDA_ILL_INPUT -22 +#define IDA_NO_MALLOC -23 +#define IDA_BAD_EWT -24 +#define IDA_BAD_K -25 +#define IDA_BAD_T -26 +#define IDA_BAD_DKY -27 +#define IDA_VECTOROP_ERR -28 + +#define IDA_CONTEXT_ERR -29 + +#define IDA_NO_QUAD -30 +#define IDA_QRHS_FAIL -31 +#define IDA_FIRST_QRHS_ERR -32 +#define IDA_REP_QRHS_ERR -33 + +#define IDA_NO_SENS -40 +#define IDA_SRES_FAIL -41 +#define IDA_REP_SRES_ERR -42 +#define IDA_BAD_IS -43 + +#define IDA_NO_QUADSENS -50 +#define IDA_QSRHS_FAIL -51 +#define IDA_FIRST_QSRHS_ERR -52 +#define IDA_REP_QSRHS_ERR -53 + +#define IDA_UNRECOGNIZED_ERROR -99 + +/* adjoint return values */ + +#define IDA_NO_ADJ -101 +#define IDA_NO_FWD -102 +#define IDA_NO_BCK -103 +#define IDA_BAD_TB0 -104 +#define IDA_REIFWD_FAIL -105 +#define IDA_FWD_FAIL -106 +#define IDA_GETY_BADT -107 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*IDAResFn)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, + void* user_data); + +typedef int (*IDARootFn)(sunrealtype t, N_Vector y, N_Vector yp, + sunrealtype* gout, void* user_data); + +typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void* user_data); + +typedef int (*IDAQuadRhsFn)(sunrealtype tres, N_Vector yy, N_Vector yp, + N_Vector rrQ, void* user_data); + +typedef int (*IDASensResFn)(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector resval, N_Vector* yyS, N_Vector* ypS, + N_Vector* resvalS, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); + +typedef int (*IDAQuadSensRhsFn)(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector rrQ, + N_Vector* rhsvalQS, void* user_data, + N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS); + +typedef int (*IDAResFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector yyB, + N_Vector ypB, N_Vector rrB, void* user_dataB); + +typedef int (*IDAResFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrBS, void* user_dataB); + +typedef int (*IDAQuadRhsFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rhsvalBQ, + void* user_dataB); + +typedef int (*IDAQuadRhsFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rhsvalBQS, void* user_dataB); + +/* --------------------------------------- + * Exported Functions -- Forward Problems + * --------------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT void* IDACreate(SUNContext sunctx); + +SUNDIALS_EXPORT int IDAInit(void* ida_mem, IDAResFn res, sunrealtype t0, + N_Vector yy0, N_Vector yp0); +SUNDIALS_EXPORT int IDAReInit(void* ida_mem, sunrealtype t0, N_Vector yy0, + N_Vector yp0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int IDASStolerances(void* ida_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int IDASVtolerances(void* ida_mem, sunrealtype reltol, + N_Vector abstol); +SUNDIALS_EXPORT int IDAWFtolerances(void* ida_mem, IDAEwtFn efun); + +/* Initial condition calculation function */ +SUNDIALS_EXPORT int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1); + +/* Initial condition calculation optional input functions */ +SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon); +SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void* ida_mem, int maxnh); +SUNDIALS_EXPORT int IDASetMaxNumJacsIC(void* ida_mem, int maxnj); +SUNDIALS_EXPORT int IDASetMaxNumItersIC(void* ida_mem, int maxnit); +SUNDIALS_EXPORT int IDASetLineSearchOffIC(void* ida_mem, sunbooleantype lsoff); +SUNDIALS_EXPORT int IDASetStepToleranceIC(void* ida_mem, sunrealtype steptol); +SUNDIALS_EXPORT int IDASetMaxBacksIC(void* ida_mem, int maxbacks); + +/* Optional input functions */ +SUNDIALS_EXPORT int IDASetDeltaCjLSetup(void* ida_max, sunrealtype dcj); +SUNDIALS_EXPORT int IDASetUserData(void* ida_mem, void* user_data); +SUNDIALS_EXPORT int IDASetMaxOrd(void* ida_mem, int maxord); +SUNDIALS_EXPORT int IDASetMaxNumSteps(void* ida_mem, long int mxsteps); +SUNDIALS_EXPORT int IDASetInitStep(void* ida_mem, sunrealtype hin); +SUNDIALS_EXPORT int IDASetMaxStep(void* ida_mem, sunrealtype hmax); +SUNDIALS_EXPORT int IDASetMinStep(void* ida_mem, sunrealtype hmin); +SUNDIALS_EXPORT int IDASetStopTime(void* ida_mem, sunrealtype tstop); +SUNDIALS_EXPORT int IDAClearStopTime(void* ida_mem); +SUNDIALS_EXPORT int IDASetMaxErrTestFails(void* ida_mem, int maxnef); +SUNDIALS_EXPORT int IDASetSuppressAlg(void* ida_mem, sunbooleantype suppressalg); +SUNDIALS_EXPORT int IDASetId(void* ida_mem, N_Vector id); +SUNDIALS_EXPORT int IDASetConstraints(void* ida_mem, N_Vector constraints); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int IDASetEtaFixedStepBounds(void* ida_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int IDASetEtaMin(void* ida_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int IDASetEtaMax(void* ida_mem, sunrealtype eta_max); +SUNDIALS_EXPORT +int IDASetEtaLow(void* ida_mem, sunrealtype eta_low); +SUNDIALS_EXPORT +int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf); + +/* Nonlinear solve input functions */ +SUNDIALS_EXPORT int IDASetMaxConvFails(void* ida_mem, int maxncf); +SUNDIALS_EXPORT int IDASetMaxNonlinIters(void* ida_mem, int maxcor); +SUNDIALS_EXPORT int IDASetNlsResFn(void* IDA_mem, IDAResFn res); +SUNDIALS_EXPORT int IDASetNonlinConvCoef(void* ida_mem, sunrealtype epcon); +SUNDIALS_EXPORT int IDASetNonlinearSolver(void* ida_mem, SUNNonlinearSolver NLS); + +/* Rootfinding initialization function */ +SUNDIALS_EXPORT int IDARootInit(void* ida_mem, int nrtfn, IDARootFn g); + +/* Rootfinding optional input functions */ +SUNDIALS_EXPORT int IDASetRootDirection(void* ida_mem, int* rootdir); +SUNDIALS_EXPORT int IDASetNoInactiveRootWarn(void* ida_mem); + +/* Solver function */ +SUNDIALS_EXPORT int IDASolve(void* ida_mem, sunrealtype tout, sunrealtype* tret, + N_Vector yret, N_Vector ypret, int itask); + +/* Utility functions to update/compute y and yp based on ycor */ +SUNDIALS_EXPORT int IDAComputeY(void* ida_mem, N_Vector ycor, N_Vector y); +SUNDIALS_EXPORT int IDAComputeYp(void* ida_mem, N_Vector ycor, N_Vector yp); +SUNDIALS_EXPORT int IDAComputeYSens(void* ida_mem, N_Vector* ycor, N_Vector* yyS); +SUNDIALS_EXPORT int IDAComputeYpSens(void* ida_mem, N_Vector* ycor, + N_Vector* ypS); + +/* Dense output function */ +SUNDIALS_EXPORT int IDAGetDky(void* ida_mem, sunrealtype t, int k, N_Vector dky); + +/* Optional output functions */ +SUNDIALS_EXPORT int IDAGetWorkSpace(void* ida_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int IDAGetNumSteps(void* ida_mem, long int* nsteps); +SUNDIALS_EXPORT int IDAGetNumResEvals(void* ida_mem, long int* nrevals); +SUNDIALS_EXPORT int IDAGetNumLinSolvSetups(void* ida_mem, long int* nlinsetups); +SUNDIALS_EXPORT int IDAGetNumErrTestFails(void* ida_mem, long int* netfails); +SUNDIALS_EXPORT int IDAGetNumBacktrackOps(void* ida_mem, long int* nbacktr); +SUNDIALS_EXPORT int IDAGetConsistentIC(void* ida_mem, N_Vector yy0_mod, + N_Vector yp0_mod); +SUNDIALS_EXPORT int IDAGetLastOrder(void* ida_mem, int* klast); +SUNDIALS_EXPORT int IDAGetCurrentOrder(void* ida_mem, int* kcur); +SUNDIALS_EXPORT int IDAGetCurrentCj(void* ida_mem, sunrealtype* cj); +SUNDIALS_EXPORT int IDAGetCurrentY(void* ida_mem, N_Vector* ycur); +SUNDIALS_EXPORT int IDAGetCurrentYSens(void* ida_mem, N_Vector** yS); +SUNDIALS_EXPORT int IDAGetCurrentYp(void* ida_mem, N_Vector* ypcur); +SUNDIALS_EXPORT int IDAGetCurrentYpSens(void* ida_mem, N_Vector** ypS); +SUNDIALS_EXPORT int IDAGetActualInitStep(void* ida_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int IDAGetLastStep(void* ida_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int IDAGetCurrentStep(void* ida_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int IDAGetCurrentTime(void* ida_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetTolScaleFactor(void* ida_mem, sunrealtype* tolsfact); +SUNDIALS_EXPORT int IDAGetErrWeights(void* ida_mem, N_Vector eweight); +SUNDIALS_EXPORT int IDAGetEstLocalErrors(void* ida_mem, N_Vector ele); +SUNDIALS_EXPORT int IDAGetNumGEvals(void* ida_mem, long int* ngevals); +SUNDIALS_EXPORT int IDAGetRootInfo(void* ida_mem, int* rootsfound); +SUNDIALS_EXPORT int IDAGetIntegratorStats(void* ida_mem, long int* nsteps, + long int* nrevals, long int* nlinsetups, + long int* netfails, int* qlast, + int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, + sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetNonlinearSystemData(void* ida_mem, sunrealtype* tcur, + N_Vector* yypred, + N_Vector* yppred, N_Vector* yyn, + N_Vector* ypn, N_Vector* res, + sunrealtype* cj, void** user_data); +SUNDIALS_EXPORT int IDAGetNonlinearSystemDataSens( + void* ida_mem, sunrealtype* tcur, N_Vector** yySpred, N_Vector** ypSpred, + N_Vector** yySn, N_Vector** ypSn, sunrealtype* cj, void** user_data); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvIters(void* ida_mem, long int* nniters); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvConvFails(void* ida_mem, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNonlinSolvStats(void* ida_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNumStepSolveFails(void* ida_mem, long int* nncfails); +SUNDIALS_EXPORT int IDAGetUserData(void* ida_mem, void** user_data); +SUNDIALS_EXPORT int IDAPrintAllStats(void* ida_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* IDAGetReturnFlagName(long int flag); + +/* Free function */ +SUNDIALS_EXPORT void IDAFree(void** ida_mem); + +/* IDALS interface function that depends on IDAResFn */ +SUNDIALS_EXPORT int IDASetJacTimesResFn(void* ida_mem, IDAResFn jtimesResFn); + +/* --------------------------------- + * Exported Functions -- Quadrature + * --------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT int IDAQuadInit(void* ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0); +SUNDIALS_EXPORT int IDAQuadReInit(void* ida_mem, N_Vector yQ0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int IDAQuadSStolerances(void* ida_mem, sunrealtype reltolQ, + sunrealtype abstolQ); +SUNDIALS_EXPORT int IDAQuadSVtolerances(void* ida_mem, sunrealtype reltolQ, + N_Vector abstolQ); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int IDASetQuadErrCon(void* ida_mem, sunbooleantype errconQ); + +/* Extraction and dense output functions */ +SUNDIALS_EXPORT int IDAGetQuad(void* ida_mem, sunrealtype* t, N_Vector yQout); +SUNDIALS_EXPORT int IDAGetQuadDky(void* ida_mem, sunrealtype t, int k, + N_Vector dky); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int IDAGetQuadNumRhsEvals(void* ida_mem, long int* nrhsQevals); +SUNDIALS_EXPORT int IDAGetQuadNumErrTestFails(void* ida_mem, long int* nQetfails); +SUNDIALS_EXPORT int IDAGetQuadErrWeights(void* ida_mem, N_Vector eQweight); +SUNDIALS_EXPORT int IDAGetQuadStats(void* ida_mem, long int* nrhsQevals, + long int* nQetfails); + +/* Free function */ +SUNDIALS_EXPORT void IDAQuadFree(void* ida_mem); + +/* ------------------------------------ + * Exported Functions -- Sensitivities + * ------------------------------------ */ + +/* Initialization functions */ +SUNDIALS_EXPORT int IDASensInit(void* ida_mem, int Ns, int ism, + IDASensResFn resS, N_Vector* yS0, N_Vector* ypS0); +SUNDIALS_EXPORT int IDASensReInit(void* ida_mem, int ism, N_Vector* yS0, + N_Vector* ypS0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int IDASensSStolerances(void* ida_mem, sunrealtype reltolS, + sunrealtype* abstolS); +SUNDIALS_EXPORT int IDASensSVtolerances(void* ida_mem, sunrealtype reltolS, + N_Vector* abstolS); +SUNDIALS_EXPORT int IDASensEEtolerances(void* ida_mem); + +/* Initial condition calculation function */ +SUNDIALS_EXPORT int IDAGetSensConsistentIC(void* ida_mem, N_Vector* yyS0, + N_Vector* ypS0); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int IDASetSensDQMethod(void* ida_mem, int DQtype, + sunrealtype DQrhomax); +SUNDIALS_EXPORT int IDASetSensErrCon(void* ida_mem, sunbooleantype errconS); +SUNDIALS_EXPORT int IDASetSensMaxNonlinIters(void* ida_mem, int maxcorS); +SUNDIALS_EXPORT int IDASetSensParams(void* ida_mem, sunrealtype* p, + sunrealtype* pbar, int* plist); + +/* Integrator nonlinear solver specification functions */ +SUNDIALS_EXPORT int IDASetNonlinearSolverSensSim(void* ida_mem, + SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int IDASetNonlinearSolverSensStg(void* ida_mem, + SUNNonlinearSolver NLS); + +/* Enable/disable sensitivities */ +SUNDIALS_EXPORT int IDASensToggleOff(void* ida_mem); + +/* Extraction and dense output functions */ +SUNDIALS_EXPORT int IDAGetSens(void* ida_mem, sunrealtype* tret, + N_Vector* yySout); +SUNDIALS_EXPORT int IDAGetSens1(void* ida_mem, sunrealtype* tret, int is, + N_Vector yySret); + +SUNDIALS_EXPORT int IDAGetSensDky(void* ida_mem, sunrealtype t, int k, + N_Vector* dkyS); +SUNDIALS_EXPORT int IDAGetSensDky1(void* ida_mem, sunrealtype t, int k, int is, + N_Vector dkyS); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int IDAGetSensNumResEvals(void* ida_mem, long int* nresSevals); +SUNDIALS_EXPORT int IDAGetNumResEvalsSens(void* ida_mem, long int* nresevalsS); +SUNDIALS_EXPORT int IDAGetSensNumErrTestFails(void* ida_mem, long int* nSetfails); +SUNDIALS_EXPORT int IDAGetSensNumLinSolvSetups(void* ida_mem, + long int* nlinsetupsS); +SUNDIALS_EXPORT int IDAGetSensErrWeights(void* ida_mem, N_Vector_S eSweight); +SUNDIALS_EXPORT int IDAGetSensStats(void* ida_mem, long int* nresSevals, + long int* nresevalsS, long int* nSetfails, + long int* nlinsetupsS); +SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvIters(void* ida_mem, + long int* nSniters); +SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvConvFails(void* ida_mem, + long int* nSnfails); +SUNDIALS_EXPORT int IDAGetSensNonlinSolvStats(void* ida_mem, long int* nSniters, + long int* nSnfails); +SUNDIALS_EXPORT int IDAGetNumStepSensSolveFails(void* ida_mem, + long int* nSncfails); + +/* Free function */ +SUNDIALS_EXPORT void IDASensFree(void* ida_mem); + +/* ------------------------------------------------------- + * Exported Functions -- Sensitivity dependent quadrature + * ------------------------------------------------------- */ + +/* Initialization functions */ +SUNDIALS_EXPORT int IDAQuadSensInit(void* ida_mem, IDAQuadSensRhsFn resQS, + N_Vector* yQS0); +SUNDIALS_EXPORT int IDAQuadSensReInit(void* ida_mem, N_Vector* yQS0); + +/* Tolerance input functions */ +SUNDIALS_EXPORT int IDAQuadSensSStolerances(void* ida_mem, sunrealtype reltolQS, + sunrealtype* abstolQS); +SUNDIALS_EXPORT int IDAQuadSensSVtolerances(void* ida_mem, sunrealtype reltolQS, + N_Vector* abstolQS); +SUNDIALS_EXPORT int IDAQuadSensEEtolerances(void* ida_mem); + +/* Optional input specification functions */ +SUNDIALS_EXPORT int IDASetQuadSensErrCon(void* ida_mem, sunbooleantype errconQS); + +/* Extraction and dense output functions */ +SUNDIALS_EXPORT int IDAGetQuadSens(void* ida_mem, sunrealtype* tret, + N_Vector* yyQSout); +SUNDIALS_EXPORT int IDAGetQuadSens1(void* ida_mem, sunrealtype* tret, int is, + N_Vector yyQSret); +SUNDIALS_EXPORT int IDAGetQuadSensDky(void* ida_mem, sunrealtype t, int k, + N_Vector* dkyQS); +SUNDIALS_EXPORT int IDAGetQuadSensDky1(void* ida_mem, sunrealtype t, int k, + int is, N_Vector dkyQS); + +/* Optional output specification functions */ +SUNDIALS_EXPORT int IDAGetQuadSensNumRhsEvals(void* ida_mem, + long int* nrhsQSevals); +SUNDIALS_EXPORT int IDAGetQuadSensNumErrTestFails(void* ida_mem, + long int* nQSetfails); +SUNDIALS_EXPORT int IDAGetQuadSensErrWeights(void* ida_mem, N_Vector* eQSweight); +SUNDIALS_EXPORT int IDAGetQuadSensStats(void* ida_mem, long int* nrhsQSevals, + long int* nQSetfails); + +/* Free function */ +SUNDIALS_EXPORT void IDAQuadSensFree(void* ida_mem); + +/* ---------------------------------------- + * Exported Functions -- Backward Problems + * ---------------------------------------- */ + +/* Initialization functions */ + +SUNDIALS_EXPORT int IDAAdjInit(void* ida_mem, long int steps, int interp); + +SUNDIALS_EXPORT int IDAAdjReInit(void* ida_mem); + +SUNDIALS_EXPORT void IDAAdjFree(void* ida_mem); + +/* Backward Problem Setup Functions */ + +SUNDIALS_EXPORT int IDACreateB(void* ida_mem, int* which); + +SUNDIALS_EXPORT int IDAInitB(void* ida_mem, int which, IDAResFnB resB, + sunrealtype tB0, N_Vector yyB0, N_Vector ypB0); + +SUNDIALS_EXPORT int IDAInitBS(void* ida_mem, int which, IDAResFnBS resS, + sunrealtype tB0, N_Vector yyB0, N_Vector ypB0); + +SUNDIALS_EXPORT int IDAReInitB(void* ida_mem, int which, sunrealtype tB0, + N_Vector yyB0, N_Vector ypB0); + +SUNDIALS_EXPORT int IDASStolerancesB(void* ida_mem, int which, + sunrealtype relTolB, sunrealtype absTolB); +SUNDIALS_EXPORT int IDASVtolerancesB(void* ida_mem, int which, + sunrealtype relTolB, N_Vector absTolB); + +SUNDIALS_EXPORT int IDAQuadInitB(void* ida_mem, int which, IDAQuadRhsFnB rhsQB, + N_Vector yQB0); + +SUNDIALS_EXPORT int IDAQuadInitBS(void* ida_mem, int which, + IDAQuadRhsFnBS rhsQS, N_Vector yQB0); + +SUNDIALS_EXPORT int IDAQuadReInitB(void* ida_mem, int which, N_Vector yQB0); + +SUNDIALS_EXPORT int IDAQuadSStolerancesB(void* ida_mem, int which, + sunrealtype reltolQB, + sunrealtype abstolQB); +SUNDIALS_EXPORT int IDAQuadSVtolerancesB(void* ida_mem, int which, + sunrealtype reltolQB, N_Vector abstolQB); + +/* Consistent IC calculation functions */ + +SUNDIALS_EXPORT int IDACalcICB(void* ida_mem, int which, sunrealtype tout1, + N_Vector yy0, N_Vector yp0); + +SUNDIALS_EXPORT int IDACalcICBS(void* ida_mem, int which, sunrealtype tout1, + N_Vector yy0, N_Vector yp0, N_Vector* yyS0, + N_Vector* ypS0); + +/* Solver Function For Forward Problems */ + +SUNDIALS_EXPORT int IDASolveF(void* ida_mem, sunrealtype tout, + sunrealtype* tret, N_Vector yret, N_Vector ypret, + int itask, int* ncheckPtr); + +/* Solver Function For Backward Problems */ + +SUNDIALS_EXPORT int IDASolveB(void* ida_mem, sunrealtype tBout, int itaskB); + +/* Optional Input Functions For Adjoint Problems */ + +SUNDIALS_EXPORT int IDAAdjSetNoSensi(void* ida_mem); + +SUNDIALS_EXPORT int IDASetUserDataB(void* ida_mem, int which, void* user_dataB); +SUNDIALS_EXPORT int IDASetMaxOrdB(void* ida_mem, int which, int maxordB); +SUNDIALS_EXPORT int IDASetMaxNumStepsB(void* ida_mem, int which, + long int mxstepsB); +SUNDIALS_EXPORT int IDASetInitStepB(void* ida_mem, int which, sunrealtype hinB); +SUNDIALS_EXPORT int IDASetMaxStepB(void* ida_mem, int which, sunrealtype hmaxB); +SUNDIALS_EXPORT int IDASetSuppressAlgB(void* ida_mem, int which, + sunbooleantype suppressalgB); +SUNDIALS_EXPORT int IDASetIdB(void* ida_mem, int which, N_Vector idB); +SUNDIALS_EXPORT int IDASetConstraintsB(void* ida_mem, int which, + N_Vector constraintsB); +SUNDIALS_EXPORT int IDASetQuadErrConB(void* ida_mem, int which, int errconQB); + +SUNDIALS_EXPORT int IDASetNonlinearSolverB(void* ida_mem, int which, + SUNNonlinearSolver NLS); + +/* Extraction And Dense Output Functions For Backward Problems */ + +SUNDIALS_EXPORT int IDAGetB(void* ida_mem, int which, sunrealtype* tret, + N_Vector yy, N_Vector yp); +SUNDIALS_EXPORT int IDAGetQuadB(void* ida_mem, int which, sunrealtype* tret, + N_Vector qB); + +/* Optional Output Functions For Backward Problems */ + +SUNDIALS_EXPORT void* IDAGetAdjIDABmem(void* ida_mem, int which); + +SUNDIALS_EXPORT int IDAGetConsistentICB(void* ida_mem, int which, N_Vector yyB0, + N_Vector ypB0); + +SUNDIALS_EXPORT int IDAGetAdjY(void* ida_mem, sunrealtype t, N_Vector yy, + N_Vector yp); + +typedef struct +{ + void* my_addr; + void* next_addr; + sunrealtype t0; + sunrealtype t1; + long int nstep; + int order; + sunrealtype step; +} IDAadjCheckPointRec; + +SUNDIALS_EXPORT int IDAGetAdjCheckPointsInfo(void* ida_mem, + IDAadjCheckPointRec* ckpnt); + +/* IDALS interface function that depends on IDAResFn */ +SUNDIALS_EXPORT int IDASetJacTimesResFnB(void* ida_mem, int which, + IDAResFn jtimesResFn); + +/* Undocumented Optional Output Functions For Backward Problems */ + +/* ----------------------------------------------------------------- + * IDAGetAdjDataPointHermite + * ----------------------------------------------------------------- + * Returns the 2 vectors stored for cubic Hermite interpolation + * at the data point 'which'. The user must allocate space for + * yy and yd. Returns IDA_MEM_NULL if ida_mem is NULL, + * IDA_ILL_INPUT if the interpolation type previously specified + * is not IDA_HERMITE, or IDA_SUCCESS otherwise. + * ----------------------------------------------------------------- + * IDAGetAdjDataPointPolynomial + * ----------------------------------------------------------------- + * Returns the vector stored for polynomial interpolation + * at the data point 'which'. The user must allocate space for + * y. Returns IDA_MEM_NULL if ida_mem is NULL, IDA_ILL_INPUT if + * the interpolation type previously specified is not + * IDA_POLYNOMIAL, or IDA_SUCCESS otherwise. + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT int IDAGetAdjDataPointHermite(void* ida_mem, int which, + sunrealtype* t, N_Vector yy, + N_Vector yd); + +SUNDIALS_EXPORT int IDAGetAdjDataPointPolynomial(void* ida_mem, int which, + sunrealtype* t, int* order, + N_Vector y); + +/* ----------------------------------------------------------------- + * IDAGetAdjCurrentCheckPoint + * Returns the address of the 'active' check point. + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT int IDAGetAdjCurrentCheckPoint(void* ida_mem, void** addr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/idas/idas_bbdpre.h b/inst/include/idas/idas_bbdpre.h new file mode 100644 index 0000000..47d5a8c --- /dev/null +++ b/inst/include/idas/idas_bbdpre.h @@ -0,0 +1,90 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU, + * Alan C. Hindmarsh, Radu Serban and Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the IDABBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _IDASBBDPRE_H +#define _IDASBBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*----------------- + FORWARD PROBLEMS + -----------------*/ + +/* User-supplied function Types */ + +typedef int (*IDABBDLocalFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector gval, void* user_data); + +typedef int (*IDABBDCommFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dq_rel_yy, IDABBDLocalFn Gres, + IDABBDCommFn Gcomm); + +SUNDIALS_EXPORT int IDABBDPrecReInit(void* ida_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dq_rel_yy); + +/* Optional output functions */ + +SUNDIALS_EXPORT int IDABBDPrecGetWorkSpace(void* ida_mem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int IDABBDPrecGetNumGfnEvals(void* ida_mem, + long int* ngevalsBBDP); + +/*------------------ + BACKWARD PROBLEMS + ------------------*/ + +/* User-Supplied Function Types */ + +typedef int (*IDABBDLocalFnB)(sunindextype NlocalB, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector yyB, N_Vector ypB, + N_Vector gvalB, void* user_dataB); + +typedef int (*IDABBDCommFnB)(sunindextype NlocalB, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector yyB, N_Vector ypB, + void* user_dataB); + +/* Exported Functions */ + +SUNDIALS_EXPORT int IDABBDPrecInitB(void* ida_mem, int which, + sunindextype NlocalB, sunindextype mudqB, + sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dq_rel_yyB, + IDABBDLocalFnB GresB, IDABBDCommFnB GcommB); + +SUNDIALS_EXPORT int IDABBDPrecReInitB(void* ida_mem, int which, + sunindextype mudqB, sunindextype mldqB, + sunrealtype dq_rel_yyB); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/idas/idas_ls.h b/inst/include/idas/idas_ls.h new file mode 100644 index 0000000..bfd9003 --- /dev/null +++ b/inst/include/idas/idas_ls.h @@ -0,0 +1,224 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Radu Serban @ LLNL + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for IDAS' linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _IDASLS_H +#define _IDASLS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================= + IDALS Constants + =================================================================*/ + +#define IDALS_SUCCESS 0 +#define IDALS_MEM_NULL -1 +#define IDALS_LMEM_NULL -2 +#define IDALS_ILL_INPUT -3 +#define IDALS_MEM_FAIL -4 +#define IDALS_PMEM_NULL -5 +#define IDALS_JACFUNC_UNRECVR -6 +#define IDALS_JACFUNC_RECVR -7 +#define IDALS_SUNMAT_FAIL -8 +#define IDALS_SUNLS_FAIL -9 + +/* Return values for the adjoint module */ +#define IDALS_NO_ADJ -101 +#define IDALS_LMEMB_NULL -102 + +/*================================================================= + Forward problems + =================================================================*/ + +/*================================================================= + IDALS user-supplied function prototypes + =================================================================*/ + +typedef int (*IDALsJacFn)(sunrealtype t, sunrealtype c_j, N_Vector y, + N_Vector yp, N_Vector r, SUNMatrix Jac, void* user_data, + N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); + +typedef int (*IDALsPrecSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, void* user_data); + +typedef int (*IDALsPrecSolveFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector rvec, N_Vector zvec, + sunrealtype c_j, sunrealtype delta, + void* user_data); + +typedef int (*IDALsJacTimesSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, + void* user_data); + +typedef int (*IDALsJacTimesVecFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector v, N_Vector Jv, + sunrealtype c_j, void* user_data, + N_Vector tmp1, N_Vector tmp2); + +/*================================================================= + IDALS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, + SUNMatrix A); + +/*----------------------------------------------------------------- + Optional inputs to the IDALS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int IDASetJacFn(void* ida_mem, IDALsJacFn jac); +SUNDIALS_EXPORT int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn pset, + IDALsPrecSolveFn psolve); +SUNDIALS_EXPORT int IDASetJacTimes(void* ida_mem, IDALsJacTimesSetupFn jtsetup, + IDALsJacTimesVecFn jtimes); +SUNDIALS_EXPORT int IDASetEpsLin(void* ida_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int IDASetLSNormFactor(void* ida_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int IDASetLinearSolutionScaling(void* ida_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int IDASetIncrementFactor(void* ida_mem, sunrealtype dqincfac); + +/*----------------------------------------------------------------- + Optional outputs from the IDALS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int IDAGetJac(void* ida_mem, SUNMatrix* J); +SUNDIALS_EXPORT int IDAGetJacCj(void* ida_mem, sunrealtype* cj_J); +SUNDIALS_EXPORT int IDAGetJacTime(void* ida_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int IDAGetJacNumSteps(void* ida_mem, long int* nst_J); +SUNDIALS_EXPORT int IDAGetLinWorkSpace(void* ida_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int IDAGetNumJacEvals(void* ida_mem, long int* njevals); +SUNDIALS_EXPORT int IDAGetNumPrecEvals(void* ida_mem, long int* npevals); +SUNDIALS_EXPORT int IDAGetNumPrecSolves(void* ida_mem, long int* npsolves); +SUNDIALS_EXPORT int IDAGetNumLinIters(void* ida_mem, long int* nliters); +SUNDIALS_EXPORT int IDAGetNumLinConvFails(void* ida_mem, long int* nlcfails); +SUNDIALS_EXPORT int IDAGetNumJTSetupEvals(void* ida_mem, long int* njtsetups); +SUNDIALS_EXPORT int IDAGetNumJtimesEvals(void* ida_mem, long int* njvevals); +SUNDIALS_EXPORT int IDAGetNumLinResEvals(void* ida_mem, long int* nrevalsLS); +SUNDIALS_EXPORT int IDAGetLastLinFlag(void* ida_mem, long int* flag); +SUNDIALS_EXPORT char* IDAGetLinReturnFlagName(long int flag); + +/*================================================================= + Backward problems + =================================================================*/ + +/*================================================================= + IDALS user-supplied function prototypes + =================================================================*/ + +typedef int (*IDALsJacFnB)(sunrealtype tt, sunrealtype c_jB, N_Vector yy, + N_Vector yp, N_Vector yyB, N_Vector ypB, + N_Vector rrB, SUNMatrix JacB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*IDALsJacFnBS)(sunrealtype tt, sunrealtype c_jB, N_Vector yy, + N_Vector yp, N_Vector* yS, N_Vector* ypS, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + SUNMatrix JacB, void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*IDALsPrecSetupFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsPrecSetupFnBS)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, sunrealtype c_jB, + void* user_dataB); + +typedef int (*IDALsPrecSolveFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + N_Vector rvecB, N_Vector zvecB, sunrealtype c_jB, + sunrealtype deltaB, void* user_dataB); + +typedef int (*IDALsPrecSolveFnBS)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, N_Vector rvecB, + N_Vector zvecB, sunrealtype c_jB, + sunrealtype deltaB, void* user_dataB); + +typedef int (*IDALsJacTimesSetupFnB)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsJacTimesSetupFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsJacTimesVecFnB)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + N_Vector vB, N_Vector JvB, sunrealtype c_jB, + void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B); + +typedef int (*IDALsJacTimesVecFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, N_Vector vB, + N_Vector JvB, sunrealtype c_jB, + void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B); + +/*================================================================= + IDALS Exported functions + =================================================================*/ + +SUNDIALS_EXPORT int IDASetLinearSolverB(void* ida_mem, int which, + SUNLinearSolver LS, SUNMatrix A); + +/*----------------------------------------------------------------- + Each IDASet***B or IDASet***BS function below links the + main IDAS integrator with the corresponding IDALS + optional input function for the backward integration. + The 'which' argument is the int returned by IDACreateB. + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int IDASetJacFnB(void* ida_mem, int which, IDALsJacFnB jacB); +SUNDIALS_EXPORT int IDASetJacFnBS(void* ida_mem, int which, IDALsJacFnBS jacBS); + +SUNDIALS_EXPORT int IDASetEpsLinB(void* ida_mem, int which, sunrealtype eplifacB); +SUNDIALS_EXPORT int IDASetLSNormFactorB(void* ida_mem, int which, + sunrealtype nrmfacB); +SUNDIALS_EXPORT int IDASetLinearSolutionScalingB(void* ida_mem, int which, + sunbooleantype onoffB); +SUNDIALS_EXPORT int IDASetIncrementFactorB(void* ida_mem, int which, + sunrealtype dqincfacB); +SUNDIALS_EXPORT int IDASetPreconditionerB(void* ida_mem, int which, + IDALsPrecSetupFnB psetB, + IDALsPrecSolveFnB psolveB); +SUNDIALS_EXPORT int IDASetPreconditionerBS(void* ida_mem, int which, + IDALsPrecSetupFnBS psetBS, + IDALsPrecSolveFnBS psolveBS); +SUNDIALS_EXPORT int IDASetJacTimesB(void* ida_mem, int which, + IDALsJacTimesSetupFnB jtsetupB, + IDALsJacTimesVecFnB jtimesB); +SUNDIALS_EXPORT int IDASetJacTimesBS(void* ida_mem, int which, + IDALsJacTimesSetupFnBS jtsetupBS, + IDALsJacTimesVecFnBS jtimesBS); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/kinsol/kinsol.h b/inst/include/kinsol/kinsol.h new file mode 100644 index 0000000..98d62f2 --- /dev/null +++ b/inst/include/kinsol/kinsol.h @@ -0,0 +1,155 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Allan Taylor, Alan Hindmarsh, Radu Serban, and + * Aaron Collier, Shelby Lockhart @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the main KINSOL solver. + * -----------------------------------------------------------------*/ + +#ifndef _KINSOL_H +#define _KINSOL_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------- + * KINSOL Constants + * ----------------- */ + +/* return values */ + +#define KIN_SUCCESS 0 +#define KIN_INITIAL_GUESS_OK 1 +#define KIN_STEP_LT_STPTOL 2 + +#define KIN_WARNING 99 + +#define KIN_MEM_NULL -1 +#define KIN_ILL_INPUT -2 +#define KIN_NO_MALLOC -3 +#define KIN_MEM_FAIL -4 +#define KIN_LINESEARCH_NONCONV -5 +#define KIN_MAXITER_REACHED -6 +#define KIN_MXNEWT_5X_EXCEEDED -7 +#define KIN_LINESEARCH_BCFAIL -8 +#define KIN_LINSOLV_NO_RECOVERY -9 +#define KIN_LINIT_FAIL -10 +#define KIN_LSETUP_FAIL -11 +#define KIN_LSOLVE_FAIL -12 + +#define KIN_SYSFUNC_FAIL -13 +#define KIN_FIRST_SYSFUNC_ERR -14 +#define KIN_REPTD_SYSFUNC_ERR -15 + +#define KIN_VECTOROP_ERR -16 + +#define KIN_CONTEXT_ERR -17 + +/* Anderson Acceleration Orthogonalization Choice */ +#define KIN_ORTH_MGS 0 +#define KIN_ORTH_ICWY 1 +#define KIN_ORTH_CGS2 2 +#define KIN_ORTH_DCGS2 3 + +/* Enumeration for eta choice */ +#define KIN_ETACHOICE1 1 +#define KIN_ETACHOICE2 2 +#define KIN_ETACONSTANT 3 + +/* Enumeration for global strategy */ +#define KIN_NONE 0 +#define KIN_LINESEARCH 1 +#define KIN_PICARD 2 +#define KIN_FP 3 + +/* ------------------------------ + * User-Supplied Function Types + * ------------------------------ */ + +typedef int (*KINSysFn)(N_Vector uu, N_Vector fval, void* user_data); + +typedef void (*KINInfoHandlerFn)(const char* module, const char* function, + char* msg, void* user_data); + +/* ------------------- + * Exported Functions + * ------------------- */ + +/* Creation function */ +SUNDIALS_EXPORT void* KINCreate(SUNContext sunctx); + +/* Initialization function */ +SUNDIALS_EXPORT int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl); + +/* Solver function */ +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 KINSetUserData(void* kinmem, void* user_data); +SUNDIALS_EXPORT int KINSetDamping(void* kinmem, sunrealtype beta); +SUNDIALS_EXPORT int KINSetMAA(void* kinmem, long int maa); +SUNDIALS_EXPORT int KINSetOrthAA(void* kinmem, int orthaa); +SUNDIALS_EXPORT int KINSetDelayAA(void* kinmem, long int delay); +SUNDIALS_EXPORT int KINSetDampingAA(void* kinmem, sunrealtype beta); +SUNDIALS_EXPORT int KINSetReturnNewest(void* kinmem, sunbooleantype ret_newest); +SUNDIALS_EXPORT int KINSetNumMaxIters(void* kinmem, long int mxiter); +SUNDIALS_EXPORT int KINSetNoInitSetup(void* kinmem, sunbooleantype noInitSetup); +SUNDIALS_EXPORT int KINSetNoResMon(void* kinmem, sunbooleantype noNNIResMon); +SUNDIALS_EXPORT int KINSetMaxSetupCalls(void* kinmem, long int msbset); +SUNDIALS_EXPORT int KINSetMaxSubSetupCalls(void* kinmem, long int msbsetsub); +SUNDIALS_EXPORT int KINSetEtaForm(void* kinmem, int etachoice); +SUNDIALS_EXPORT int KINSetEtaConstValue(void* kinmem, sunrealtype eta); +SUNDIALS_EXPORT int KINSetEtaParams(void* kinmem, sunrealtype egamma, + sunrealtype ealpha); +SUNDIALS_EXPORT int KINSetResMonParams(void* kinmem, sunrealtype omegamin, + sunrealtype omegamax); +SUNDIALS_EXPORT int KINSetResMonConstValue(void* kinmem, sunrealtype omegaconst); +SUNDIALS_EXPORT int KINSetNoMinEps(void* kinmem, sunbooleantype noMinEps); +SUNDIALS_EXPORT int KINSetMaxNewtonStep(void* kinmem, sunrealtype mxnewtstep); +SUNDIALS_EXPORT int KINSetMaxBetaFails(void* kinmem, long int mxnbcf); +SUNDIALS_EXPORT int KINSetRelErrFunc(void* kinmem, sunrealtype relfunc); +SUNDIALS_EXPORT int KINSetFuncNormTol(void* kinmem, sunrealtype fnormtol); +SUNDIALS_EXPORT int KINSetScaledStepTol(void* kinmem, sunrealtype scsteptol); +SUNDIALS_EXPORT int KINSetConstraints(void* kinmem, N_Vector constraints); +SUNDIALS_EXPORT int KINSetSysFunc(void* kinmem, KINSysFn func); + +/* Optional output functions */ +SUNDIALS_EXPORT int KINGetWorkSpace(void* kinmem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int KINGetNumNonlinSolvIters(void* kinmem, long int* nniters); +SUNDIALS_EXPORT int KINGetNumFuncEvals(void* kinmem, long int* nfevals); +SUNDIALS_EXPORT int KINGetNumBetaCondFails(void* kinmem, long int* nbcfails); +SUNDIALS_EXPORT int KINGetNumBacktrackOps(void* kinmem, long int* nbacktr); +SUNDIALS_EXPORT int KINGetFuncNorm(void* kinmem, sunrealtype* fnorm); +SUNDIALS_EXPORT int KINGetStepLength(void* kinmem, sunrealtype* steplength); +SUNDIALS_EXPORT int KINGetUserData(void* kinmem, void** user_data); +SUNDIALS_EXPORT int KINPrintAllStats(void* kinmem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* KINGetReturnFlagName(long int flag); + +/* Free function */ +SUNDIALS_EXPORT void KINFree(void** kinmem); + +/* KINLS interface function that depends on KINSysFn */ +SUNDIALS_EXPORT int KINSetJacTimesVecSysFn(void* kinmem, KINSysFn jtimesSysFn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/kinsol/kinsol_bbdpre.h b/inst/include/kinsol/kinsol_bbdpre.h new file mode 100644 index 0000000..1b99889 --- /dev/null +++ b/inst/include/kinsol/kinsol_bbdpre.h @@ -0,0 +1,62 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Alan Hindmarsh, Radu Serban, and + * Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the KINBBDPRE module, for a + * band-block-diagonal preconditioner, i.e. a block-diagonal + * matrix with banded blocks. + * -----------------------------------------------------------------*/ + +#ifndef _KINBBDPRE_H +#define _KINBBDPRE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* KINBBDPRE return values */ + +#define KINBBDPRE_SUCCESS 0 +#define KINBBDPRE_PDATA_NULL -11 +#define KINBBDPRE_FUNC_UNRECVR -12 + +/* User-supplied function Types */ + +typedef int (*KINBBDCommFn)(sunindextype Nlocal, N_Vector u, void* user_data); + +typedef int (*KINBBDLocalFn)(sunindextype Nlocal, N_Vector uu, N_Vector gval, + void* user_data); + +/* Exported Functions */ + +SUNDIALS_EXPORT int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, + sunindextype mudq, sunindextype mldq, + sunindextype mukeep, sunindextype mlkeep, + sunrealtype dq_rel_uu, KINBBDLocalFn gloc, + KINBBDCommFn gcomm); + +/* Optional output functions */ + +SUNDIALS_EXPORT int KINBBDPrecGetWorkSpace(void* kinmem, long int* lenrwBBDP, + long int* leniwBBDP); + +SUNDIALS_EXPORT int KINBBDPrecGetNumGfnEvals(void* kinmem, long int* ngevalsBBDP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/kinsol/kinsol_ls.h b/inst/include/kinsol/kinsol_ls.h new file mode 100644 index 0000000..fae042c --- /dev/null +++ b/inst/include/kinsol/kinsol_ls.h @@ -0,0 +1,101 @@ +/* ---------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * Scott Cohen, Alan Hindmarsh, Radu Serban, and + * Aaron Collier @ LLNL + * ---------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for KINSOL's linear solver interface. + * ----------------------------------------------------------------*/ + +#ifndef _KINLS_H +#define _KINLS_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*================================================================== + KINLS Constants + ==================================================================*/ + +#define KINLS_SUCCESS 0 + +#define KINLS_MEM_NULL -1 +#define KINLS_LMEM_NULL -2 +#define KINLS_ILL_INPUT -3 +#define KINLS_MEM_FAIL -4 +#define KINLS_PMEM_NULL -5 +#define KINLS_JACFUNC_ERR -6 +#define KINLS_SUNMAT_FAIL -7 +#define KINLS_SUNLS_FAIL -8 + +/*=============================================================== + KINLS user-supplied function prototypes + ===============================================================*/ + +typedef int (*KINLsJacFn)(N_Vector u, N_Vector fu, SUNMatrix J, void* user_data, + N_Vector tmp1, N_Vector tmp2); + +typedef int (*KINLsPrecSetupFn)(N_Vector uu, N_Vector uscale, N_Vector fval, + N_Vector fscale, void* user_data); + +typedef int (*KINLsPrecSolveFn)(N_Vector uu, N_Vector uscale, N_Vector fval, + N_Vector fscale, N_Vector vv, void* user_data); + +typedef int (*KINLsJacTimesVecFn)(N_Vector v, N_Vector Jv, N_Vector uu, + sunbooleantype* new_uu, void* J_data); + +/*================================================================== + KINLS Exported functions + ==================================================================*/ + +SUNDIALS_EXPORT int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, + SUNMatrix A); + +/*----------------------------------------------------------------- + Optional inputs to the KINLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int KINSetJacFn(void* kinmem, KINLsJacFn jac); +SUNDIALS_EXPORT int KINSetPreconditioner(void* kinmem, KINLsPrecSetupFn psetup, + KINLsPrecSolveFn psolve); +SUNDIALS_EXPORT int KINSetJacTimesVecFn(void* kinmem, KINLsJacTimesVecFn jtv); + +/*----------------------------------------------------------------- + Optional outputs from the KINLS linear solver interface + -----------------------------------------------------------------*/ + +SUNDIALS_EXPORT int KINGetJac(void* kinmem, SUNMatrix* J); +SUNDIALS_EXPORT int KINGetJacNumIters(void* kinmem, long int* nni_J); +SUNDIALS_EXPORT int KINGetLinWorkSpace(void* kinmem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int KINGetNumJacEvals(void* kinmem, long int* njevals); +SUNDIALS_EXPORT int KINGetNumLinFuncEvals(void* kinmem, long int* nfevals); +SUNDIALS_EXPORT int KINGetNumPrecEvals(void* kinmem, long int* npevals); +SUNDIALS_EXPORT int KINGetNumPrecSolves(void* kinmem, long int* npsolves); +SUNDIALS_EXPORT int KINGetNumLinIters(void* kinmem, long int* nliters); +SUNDIALS_EXPORT int KINGetNumLinConvFails(void* kinmem, long int* nlcfails); +SUNDIALS_EXPORT int KINGetNumJtimesEvals(void* kinmem, long int* njvevals); +SUNDIALS_EXPORT int KINGetLastLinFlag(void* kinmem, long int* flag); +SUNDIALS_EXPORT char* KINGetLinReturnFlagName(long int flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/nvector/nvector_manyvector.h b/inst/include/nvector/nvector_manyvector.h new file mode 100644 index 0000000..ae0eac1 --- /dev/null +++ b/inst/include/nvector/nvector_manyvector.h @@ -0,0 +1,272 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the main header file for the "ManyVector" implementation + * of the NVECTOR module. + * + * Notes: + * + * - The definition of the generic N_Vector structure can be found + * in the header file sundials_nvector.h. + * + * - The definitions of the types 'sunrealtype' and 'sunindextype' can + * be found in the header file sundials_types.h, and it may be + * changed (at the configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype'. + * + * - N_Vector arguments to arithmetic vector operations need not + * be distinct. For example, the following call: + * + * N_VLinearSum_ManyVector(a,x,b,y,y); + * + * (which stores the result of the operation a*x+b*y in y) + * is legal. + * -----------------------------------------------------------------*/ + +#ifndef _NVECTOR_MANY_VECTOR_H +#define _NVECTOR_MANY_VECTOR_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + ManyVector implementation of N_Vector + ----------------------------------------------------------------- */ + +struct _N_VectorContent_ManyVector +{ + sunindextype num_subvectors; /* number of vectors attached */ + sunindextype global_length; /* overall global manyvector length */ + N_Vector* subvec_array; /* pointer to N_Vector array */ + sunbooleantype own_data; /* flag indicating data ownership */ +}; + +typedef struct _N_VectorContent_ManyVector* N_VectorContent_ManyVector; + +/* ----------------------------------------------------------------- + functions exported by ManyVector + ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT +N_Vector N_VNew_ManyVector(sunindextype num_subvectors, N_Vector* vec_array, + SUNContext sunctx); + +SUNDIALS_EXPORT +N_Vector N_VGetSubvector_ManyVector(N_Vector v, sunindextype vec_num); + +SUNDIALS_EXPORT +sunrealtype* N_VGetSubvectorArrayPointer_ManyVector(N_Vector v, + sunindextype vec_num); + +SUNDIALS_EXPORT +SUNErrCode N_VSetSubvectorArrayPointer_ManyVector(sunrealtype* v_data, N_Vector v, + sunindextype vec_num); + +SUNDIALS_EXPORT +sunindextype N_VGetNumSubvectors_ManyVector(N_Vector v); + +/* standard vector operations */ + +SUNDIALS_EXPORT +N_Vector_ID N_VGetVectorID_ManyVector(N_Vector v); + +SUNDIALS_EXPORT +void N_VPrint_ManyVector(N_Vector v); + +SUNDIALS_EXPORT +void N_VPrintFile_ManyVector(N_Vector v, FILE* outfile); + +SUNDIALS_EXPORT +N_Vector N_VCloneEmpty_ManyVector(N_Vector w); + +SUNDIALS_EXPORT +N_Vector N_VClone_ManyVector(N_Vector w); + +SUNDIALS_EXPORT +void N_VDestroy_ManyVector(N_Vector v); + +SUNDIALS_EXPORT +void N_VSpace_ManyVector(N_Vector v, sunindextype* lrw, sunindextype* liw); + +SUNDIALS_EXPORT +sunindextype N_VGetLength_ManyVector(N_Vector v); + +SUNDIALS_EXPORT +sunindextype N_VGetSubvectorLocalLength_ManyVector(N_Vector v, + sunindextype vec_num); + +SUNDIALS_EXPORT +void N_VLinearSum_ManyVector(sunrealtype a, N_Vector x, sunrealtype b, + N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VConst_ManyVector(sunrealtype c, N_Vector z); + +SUNDIALS_EXPORT +void N_VProd_ManyVector(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VDiv_ManyVector(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VScale_ManyVector(sunrealtype c, N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAbs_ManyVector(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VInv_ManyVector(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAddConst_ManyVector(N_Vector x, sunrealtype b, N_Vector z); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNorm_ManyVector(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNormMask_ManyVector(N_Vector x, N_Vector w, N_Vector id); + +SUNDIALS_EXPORT +sunrealtype N_VWL2Norm_ManyVector(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +void N_VCompare_ManyVector(sunrealtype c, N_Vector x, N_Vector z); + +/* fused vector operations */ + +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombination_ManyVector(int nvec, sunrealtype* c, + N_Vector* V, N_Vector z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMulti_ManyVector(int nvec, sunrealtype* a, N_Vector x, + N_Vector* Y, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMulti_ManyVector(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); + +/* vector array operations */ + +SUNDIALS_EXPORT +SUNErrCode N_VLinearSumVectorArray_ManyVector(int nvec, sunrealtype a, + N_Vector* X, sunrealtype b, + N_Vector* Y, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleVectorArray_ManyVector(int nvec, sunrealtype* c, N_Vector* X, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VConstVectorArray_ManyVector(int nvecs, sunrealtype c, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormVectorArray_ManyVector(int nvecs, N_Vector* X, + N_Vector* W, sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormMaskVectorArray_ManyVector(int nvec, N_Vector* X, + N_Vector* W, N_Vector id, + sunrealtype* nrm); + +/* OPTIONAL local reduction kernels (no parallel communication) */ + +SUNDIALS_EXPORT +sunrealtype N_VDotProdLocal_ManyVector(N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +sunrealtype N_VMaxNormLocal_ManyVector(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VMinLocal_ManyVector(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VL1NormLocal_ManyVector(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumLocal_ManyVector(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumMaskLocal_ManyVector(N_Vector x, N_Vector w, N_Vector id); + +SUNDIALS_EXPORT +sunbooleantype N_VInvTestLocal_ManyVector(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +sunbooleantype N_VConstrMaskLocal_ManyVector(N_Vector c, N_Vector x, N_Vector m); + +SUNDIALS_EXPORT +sunrealtype N_VMinQuotientLocal_ManyVector(N_Vector num, N_Vector denom); + +/* OPTIONAL single buffer reduction operations */ + +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMultiLocal_ManyVector(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); + +/* OPTIONAL XBraid interface operations */ + +SUNDIALS_EXPORT +SUNErrCode N_VBufSize_ManyVector(N_Vector x, sunindextype* size); + +SUNDIALS_EXPORT +SUNErrCode N_VBufPack_ManyVector(N_Vector x, void* buf); + +SUNDIALS_EXPORT +SUNErrCode N_VBufUnpack_ManyVector(N_Vector x, void* buf); + +/* ----------------------------------------------------------------- + Enable / disable fused vector operations + ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT +SUNErrCode N_VEnableFusedOps_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearCombination_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleAddMulti_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableDotProdMulti_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearSumVectorArray_ManyVector(N_Vector v, + sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleVectorArray_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableConstVectorArray_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormVectorArray_ManyVector(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormMaskVectorArray_ManyVector(N_Vector v, + sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableDotProdMultiLocal_ManyVector(N_Vector v, sunbooleantype tf); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/inst/include/nvector/nvector_serial.h b/inst/include/nvector/nvector_serial.h new file mode 100644 index 0000000..988e090 --- /dev/null +++ b/inst/include/nvector/nvector_serial.h @@ -0,0 +1,288 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, + * and Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the serial implementation of the + * NVECTOR module. + * + * Notes: + * + * - The definition of the generic N_Vector structure can be found + * in the header file sundials_nvector.h. + * + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype'. + * + * - N_Vector arguments to arithmetic vector operations need not + * be distinct. For example, the following call: + * + * N_VLinearSum_Serial(a,x,b,y,y); + * + * (which stores the result of the operation a*x+b*y in y) + * is legal. + * -----------------------------------------------------------------*/ + +#ifndef _NVECTOR_SERIAL_H +#define _NVECTOR_SERIAL_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ----------------------------------------------------------------- + * SERIAL implementation of N_Vector + * ----------------------------------------------------------------- + */ + +struct _N_VectorContent_Serial +{ + sunindextype length; /* vector length */ + sunbooleantype own_data; /* data ownership flag */ + sunrealtype* data; /* data array */ +}; + +typedef struct _N_VectorContent_Serial* N_VectorContent_Serial; + +/* + * ----------------------------------------------------------------- + * Macros NV_CONTENT_S, NV_DATA_S, NV_OWN_DATA_S, + * NV_LENGTH_S, and NV_Ith_S + * ----------------------------------------------------------------- + */ + +#define NV_CONTENT_S(v) ((N_VectorContent_Serial)(v->content)) + +#define NV_LENGTH_S(v) (NV_CONTENT_S(v)->length) + +#define NV_OWN_DATA_S(v) (NV_CONTENT_S(v)->own_data) + +#define NV_DATA_S(v) (NV_CONTENT_S(v)->data) + +#define NV_Ith_S(v, i) (NV_DATA_S(v)[i]) + +/* + * ----------------------------------------------------------------- + * Functions exported by nvector_serial + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +N_Vector N_VNewEmpty_Serial(sunindextype vec_length, SUNContext sunctx); + +SUNDIALS_EXPORT +N_Vector N_VNew_Serial(sunindextype vec_length, SUNContext sunctx); + +SUNDIALS_EXPORT +N_Vector N_VMake_Serial(sunindextype vec_length, sunrealtype* v_data, + SUNContext sunctx); + +SUNDIALS_EXPORT +sunindextype N_VGetLength_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VPrint_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VPrintFile_Serial(N_Vector v, FILE* outfile); + +SUNDIALS_EXPORT +N_Vector_ID N_VGetVectorID_Serial(N_Vector v); + +SUNDIALS_EXPORT +N_Vector N_VCloneEmpty_Serial(N_Vector w); + +SUNDIALS_EXPORT +N_Vector N_VClone_Serial(N_Vector w); + +SUNDIALS_EXPORT +void N_VDestroy_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VSpace_Serial(N_Vector v, sunindextype* lrw, sunindextype* liw); + +SUNDIALS_EXPORT +sunrealtype* N_VGetArrayPointer_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VSetArrayPointer_Serial(sunrealtype* v_data, N_Vector v); + +/* standard vector operations */ +SUNDIALS_EXPORT +void N_VLinearSum_Serial(sunrealtype a, N_Vector x, sunrealtype b, N_Vector y, + N_Vector z); +SUNDIALS_EXPORT +void N_VConst_Serial(sunrealtype c, N_Vector z); + +SUNDIALS_EXPORT +void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VScale_Serial(sunrealtype c, N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAbs_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VInv_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAddConst_Serial(N_Vector x, sunrealtype b, N_Vector z); + +SUNDIALS_EXPORT +sunrealtype N_VDotProd_Serial(N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +sunrealtype N_VMaxNorm_Serial(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id); + +SUNDIALS_EXPORT +sunrealtype N_VMin_Serial(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VL1Norm_Serial(N_Vector x); + +SUNDIALS_EXPORT +void N_VCompare_Serial(sunrealtype c, N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +sunbooleantype N_VInvTest_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +sunbooleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); + +SUNDIALS_EXPORT +sunrealtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); + +/* fused vector operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombination_Serial(int nvec, sunrealtype* c, N_Vector* V, + N_Vector z); +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMulti_Serial(int nvec, sunrealtype* a, N_Vector x, + N_Vector* Y, N_Vector* Z); +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMulti_Serial(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); + +/* vector array operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearSumVectorArray_Serial(int nvec, sunrealtype a, N_Vector* X, + sunrealtype b, N_Vector* Y, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleVectorArray_Serial(int nvec, sunrealtype* c, N_Vector* X, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VConstVectorArray_Serial(int nvecs, sunrealtype c, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormVectorArray_Serial(int nvecs, N_Vector* X, N_Vector* W, + sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormMaskVectorArray_Serial(int nvecs, N_Vector* X, N_Vector* W, + N_Vector id, sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMultiVectorArray_Serial(int nvec, int nsum, + sunrealtype* a, N_Vector* X, + N_Vector** Y, N_Vector** Z); + +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombinationVectorArray_Serial(int nvec, int nsum, + sunrealtype* c, N_Vector** X, + N_Vector* Z); + +/* OPTIONAL local reduction kernels (no parallel communication) */ +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumMaskLocal_Serial(N_Vector x, N_Vector w, N_Vector id); + +/* OPTIONAL XBraid interface operations */ +SUNDIALS_EXPORT +SUNErrCode N_VBufSize_Serial(N_Vector x, sunindextype* size); + +SUNDIALS_EXPORT +SUNErrCode N_VBufPack_Serial(N_Vector x, void* buf); + +SUNDIALS_EXPORT +SUNErrCode N_VBufUnpack_Serial(N_Vector x, void* buf); + +/* + * ----------------------------------------------------------------- + * Enable / disable fused vector operations + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode N_VEnableFusedOps_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearCombination_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleAddMulti_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableDotProdMulti_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearSumVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableConstVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, + sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, + sunbooleantype tf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunadaptcontroller/sunadaptcontroller_imexgus.h b/inst/include/sunadaptcontroller/sunadaptcontroller_imexgus.h new file mode 100644 index 0000000..7235bec --- /dev/null +++ b/inst/include/sunadaptcontroller/sunadaptcontroller_imexgus.h @@ -0,0 +1,88 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SUNAdaptController_ImExGus module. + * -----------------------------------------------------------------*/ + +#ifndef _SUNADAPTCONTROLLER_IMEXGUS_H +#define _SUNADAPTCONTROLLER_IMEXGUS_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------- + * ImEx Gustafsson implementation of SUNAdaptController + * ---------------------------------------------------- */ + +struct _SUNAdaptControllerContent_ImExGus +{ + sunrealtype k1i; /* internal controller parameters */ + sunrealtype k2i; + sunrealtype k1e; + sunrealtype k2e; + sunrealtype bias; /* error bias factor */ + sunrealtype ep; /* error from previous step */ + sunrealtype hp; /* previous step size */ + sunbooleantype firststep; /* flag indicating first step */ +}; + +typedef struct _SUNAdaptControllerContent_ImExGus* SUNAdaptControllerContent_ImExGus; + +/* ------------------ + * Exported Functions + * ------------------ */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx); + +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); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, + sunrealtype bias); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space_ImExGus(SUNAdaptController C, + long int* lenrw, long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNADAPTCONTROLLER_IMEXGUS_H */ diff --git a/inst/include/sunadaptcontroller/sunadaptcontroller_soderlind.h b/inst/include/sunadaptcontroller/sunadaptcontroller_soderlind.h new file mode 100644 index 0000000..898e8be --- /dev/null +++ b/inst/include/sunadaptcontroller/sunadaptcontroller_soderlind.h @@ -0,0 +1,132 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SUNAdaptController_Soderlind + * module. + * -----------------------------------------------------------------*/ + +#ifndef _SUNADAPTCONTROLLER_SODERLIND_H +#define _SUNADAPTCONTROLLER_SODERLIND_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------- + * Soderlind implementation of SUNAdaptController + * ---------------------------------------------------- */ + +struct _SUNAdaptControllerContent_Soderlind +{ + sunrealtype k1; /* internal controller parameters */ + sunrealtype k2; + sunrealtype k3; + sunrealtype k4; + sunrealtype k5; + sunrealtype bias; /* error bias factor */ + sunrealtype ep; /* error from previous step */ + sunrealtype epp; /* error from 2 steps ago */ + sunrealtype hp; /* previous step size */ + sunrealtype hpp; /* step size from 2 steps ago */ + int firststeps; /* flag to handle first few steps */ +}; + +typedef struct _SUNAdaptControllerContent_Soderlind* SUNAdaptControllerContent_Soderlind; + +/* ------------------ + * Exported Functions + * ------------------ */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, + sunrealtype k1, sunrealtype k2, + sunrealtype k3, sunrealtype k4, + sunrealtype k5); + +SUNDIALS_EXPORT +SUNAdaptController_Type SUNAdaptController_GetType_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, + sunrealtype bias); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space_Soderlind(SUNAdaptController C, + long int* lenrw, long int* leniw); + +/* Convenience routines to construct subsidiary controllers */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_PID(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, + sunrealtype k2, sunrealtype k3); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_PI(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, + sunrealtype k2); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_I(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNADAPTCONTROLLER_SODERLIND_H */ diff --git a/inst/include/sundials/LICENSE b/inst/include/sundials/LICENSE new file mode 100644 index 0000000..2b12386 --- /dev/null +++ b/inst/include/sundials/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2002-2024, Lawrence Livermore National Security and Southern Methodist University. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/inst/include/sundials/NOTICE b/inst/include/sundials/NOTICE new file mode 100644 index 0000000..329b142 --- /dev/null +++ b/inst/include/sundials/NOTICE @@ -0,0 +1,21 @@ +This work was produced under the auspices of the U.S. Department of +Energy by Lawrence Livermore National Laboratory under Contract +DE-AC52-07NA27344. + +This work was prepared as an account of work sponsored by an agency of +the United States Government. Neither the United States Government nor +Lawrence Livermore National Security, LLC, nor any of their employees +makes any warranty, expressed or implied, or assumes any legal liability +or responsibility for the accuracy, completeness, or usefulness of any +information, apparatus, product, or process disclosed, or represents that +its use would not infringe privately owned rights. + +Reference herein to any specific commercial product, process, or service +by trade name, trademark, manufacturer, or otherwise does not necessarily +constitute or imply its endorsement, recommendation, or favoring by the +United States Government or Lawrence Livermore National Security, LLC. + +The views and opinions of authors expressed herein do not necessarily +state or reflect those of the United States Government or Lawrence +Livermore National Security, LLC, and shall not be used for advertising +or product endorsement purposes. \ No newline at end of file diff --git a/inst/include/sundials/priv/sundials_context_impl.h b/inst/include/sundials/priv/sundials_context_impl.h new file mode 100644 index 0000000..1281333 --- /dev/null +++ b/inst/include/sundials/priv/sundials_context_impl.h @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------- + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This is a 'private' header file and should not be used in user + * code. It is subject to change without warning. + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ----------------------------------------------------------------- + * SUNDIALS context class implementation. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_IMPL_H +#define _SUNDIALS_CONTEXT_IMPL_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +struct SUNContext_ +{ + SUNProfiler profiler; + sunbooleantype own_profiler; + SUNLogger logger; + sunbooleantype own_logger; + SUNErrCode last_err; + SUNErrHandler err_handler; + SUNComm comm; +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/inst/include/sundials/priv/sundials_errors_impl.h b/inst/include/sundials/priv/sundials_errors_impl.h new file mode 100644 index 0000000..115b5ee --- /dev/null +++ b/inst/include/sundials/priv/sundials_errors_impl.h @@ -0,0 +1,557 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------- + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This is a 'private' header file and should not be used in user + * code. It is subject to change without warning. + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ----------------------------------------------------------------- + * Contains all error checking macros and private error handling API. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ERRORS_IMPL_H +#define _SUNDIALS_ERRORS_IMPL_H + +#include + +#include "sundials/sundials_config.h" +#include "sundials/sundials_context.h" +#include "sundials/sundials_export.h" +#include "sundials/sundials_logger.h" +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------------------------------- + * Macros used in error handling + * ---------------------------------------------------------------------------*/ + +/* ------------------------------------------------------------------ + * SUNDIALS __builtin_expect related macros. + * These macros provide hints to the compiler that the condition + * is typically false (or true) which may allow the compiler to + * optimize. + * -----------------------------------------------------------------*/ + +/* Hint to the compiler that the branch is unlikely to be taken */ +#ifdef SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNHintFalse(cond) __builtin_expect((cond), 0) +#else +#define SUNHintFalse(cond) (cond) +#endif + +/* Hint to the compiler that the branch is likely to be taken */ +#ifdef SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNHintTrue(cond) __builtin_expect((cond), 1) +#else +#define SUNHintTrue(cond) (cond) +#endif + +/* ------------------------------------------------------------------ + * SUNAssume + * + * This macro tells the compiler that the condition should be assumed + * to be true. The consequence is that what happens if the assumption + * is violated is undefined. If there is not compiler support for + * assumptions, then we dont do anything as there is no reliable + * way to avoid the condition being executed in all cases (such as + * the condition being an opaque function call, which we have a lot of). + * -----------------------------------------------------------------*/ + +#if __cplusplus >= 202302L +#define SUNAssume(...) [[assume(__VA_ARGS__)]] +#elif defined(SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME) +#define SUNAssume(...) __attribute__((assume(__VA_ARGS__))) +#elif defined(SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME) +#define SUNAssume(...) __builtin_assume(__VA_ARGS__) +#elif defined(SUNDIALS_C_COMPILER_HAS_ASSUME) +#define SUNAssume(...) __assume(__VA_ARGS__) +#else +#define SUNAssume(...) +#endif + +/* ---------------------------------------------------------------------------- + * SUNErrHandler_ definition. + * ---------------------------------------------------------------------------*/ + +struct SUNErrHandler_ +{ + SUNErrHandler previous; /* next error handler to call (singly linked-list) */ + SUNErrHandlerFn call; + void* data; +}; + +/* + This function creates a new SUNErrHandler object which is a node in a + singly linked-lis of error handlers. + + :param eh_fn: An error handler callback function + :param eh_data: A pointer that will be passed back to the error handler + callback function + :param eh_out: The new SUNErrHandler object + + :return: A SUNErrCode indicating success or failure +*/ +SUNDIALS_EXPORT +SUNErrCode SUNErrHandler_Create(SUNErrHandlerFn eh_fn, void* eh_data, + SUNErrHandler* eh_out); + +/* + This function destroys and frees the memory for the given SUNErrHandler + object. + + :param eh: A pointer to a SUNErrHandler object + + :return: void +*/ +SUNDIALS_EXPORT +void SUNErrHandler_Destroy(SUNErrHandler* eh); + +/* + This function will print an error out to stderr. It is used as a fallback + when the SUNContext is NULL or corrupt. It should not be used otherwise. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msg: a message associated with the error + :param args: the arguments to be provided to the format message + + :return: void +*/ +SUNDIALS_EXPORT +void SUNGlobalFallbackErrHandler(int line, const char* func, const char* file, + const char* msgfmt, SUNErrCode code, ...); + +/* + This function calls the error handlers registered with the SUNContext + with the provided message. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msgfmt: a message associated with the error with formatting + :param code: the SUNErrCode for the error + :param sunctx: a valid SUNContext object + + :return: void +*/ +static inline void SUNHandleErrWithMsg(int line, const char* func, + const char* file, const char* msg, + SUNErrCode code, SUNContext sunctx) +{ + if (!sunctx) { SUNGlobalFallbackErrHandler(line, func, file, msg, code); } + + sunctx->last_err = code; + SUNErrHandler eh = sunctx->err_handler; + while (eh != NULL) + { + eh->call(line, func, file, msg, code, eh->data, sunctx); + eh = eh->previous; + } +} + +/* + This function calls the error handlers registered with the SUNContext + with the provided format message. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msgfmt: a message associated with the error with formatting + :param code: the SUNErrCode for the error + :param sunctx: a valid SUNContext object + :param args: the arguments to be provided to the format message + + :return: void +*/ +static inline void SUNHandleErrWithFmtMsg(int line, const char* func, + const char* file, const char* msgfmt, + SUNErrCode code, SUNContext sunctx, ...) +{ + size_t msglen; + char* msg; + va_list values; + va_start(values, sunctx); + msglen = (size_t)vsnprintf(NULL, (size_t)0, msgfmt, values); /* determine size + of buffer + needed */ + msg = (char*)malloc(msglen + 1); + vsnprintf(msg, msglen + 1, msgfmt, values); + SUNHandleErrWithMsg(line, func, file, msg, code, sunctx); + va_end(values); + free(msg); +} + +/* + The SUNCTX_ macro expands to the name of the local SUNContext object + defined by SUNFunctionBegin. SUNCTX_ should be used to reference the + SUNContext inside of SUNDIALS functions. + */ +#define SUNCTX_ sunctx_local_scope_ + +/* + The SUNFunctionBegin macro is used to declare the local SUNContext object to + be used a function. It should be used at the start of every SUNDIALS + functions. + + :param sunctx: the SUNContext to set the local SUNContext variable to + */ +#define SUNFunctionBegin(sunctx) \ + SUNContext SUNCTX_ = sunctx; \ + (void)SUNCTX_ + +/* ---------------------------------------------------------------------------- + * SUNCheck* family of error checking macros + * + * We define several different versions of SUNCheck* macros to cover various + * programming scenarios. + * + * SUNCheckCall* macros are used to check SUNDIALS function calls that + * return a SUNErrCode. + * + * SUNCheckLastErr* macros are used to check SUNDIALS function calls that + * do not return a SUNErrCode. + * ---------------------------------------------------------------------------*/ + +/* + SUNCheck evaluates the given expression and calls the error handler if it is + false. It should be used to check expressions that do not imply stringent + assumptions. If the expression should be strictly assumed as true, then use + SUNAssert instead. + + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheck(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return code; \ + } \ + } \ + while (0) +#else +#define SUNCheck(expr, code) +#endif + +/* + SUNCheckNoRet is the same as SUNCheck but *does not return from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckNoRet(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + } \ + } \ + while (0) +#else +#define SUNCheckNoRet(expr, code) +#endif + +/* + SUNCheckNull is the same as SUNCheck but *returns NULL from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckNull(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return NULL; \ + } \ + } \ + while (0) +#else +#define SUNCheckNull(expr, code) +#endif + +/* + SUNCheckNull is the same as SUNCheck but *returns void from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckVoid(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return; \ + } \ + } \ + while (0) +#else +#define SUNCheckVoid(expr, code) +#endif + +/* + SUNCheckCallMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then return the error code**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return sun_chk_call_err_code_; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNoRetMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, and call the error handler. **It does not return**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallNoRetMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + } \ + } \ + while (0) +#else +#define SUNCheckCallNoRetMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns NULL**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallNullMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return NULL; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallNullMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns void**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallVoidMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallVoidMsg(call, msg) (void)call +#endif + +/* These versions of SUNCheckCall do not take a custom message so a + default message associated with the error code will be used. */ +#define SUNCheckCall(call) SUNCheckCallMsg(call, NULL) +#define SUNCheckCallNoRet(call) SUNCheckCallNoRetMsg(call, NULL) +#define SUNCheckCallNull(call) SUNCheckCallNullMsg(call, NULL) +#define SUNCheckCallVoid(call) SUNCheckCallVoidMsg(call, NULL) + +/* SUNCheckLastErrMsg checks the last_err value in the SUNContext. + If an error occured, then it will log the error, set the last_err + value, and call the error handler, **and then returns the code**. */ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckLastErrMsg(msg) \ + do { \ + SUNCheckCallMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrNoRetMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler. **It does not return.** + + :param msg: an error message +*/ +#define SUNCheckLastErrNoRetMsg(msg) \ + do { \ + SUNCheckCallNoRetMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns NULL**. + + :param msg: an error message +*/ +#define SUNCheckLastErrNullMsg(msg) \ + do { \ + SUNCheckCallNullMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrVoidMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns void**. + + :param msg: an error message +*/ +#define SUNCheckLastErrVoidMsg(msg) \ + do { \ + SUNCheckCallVoidMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) +#else +#define SUNCheckLastErrNoRetMsg(msg) +#define SUNCheckLastErrMsg(msg) +#define SUNCheckLastErrVoidMsg(msg) +#define SUNCheckLastErrNullMsg(msg) +#endif + +/* These versions of SUNCheckLastErr do not take a custom message so the + default message associated with the error code will be used. */ +#define SUNCheckLastErr() SUNCheckLastErrMsg(NULL) +#define SUNCheckLastErrNoRet() SUNCheckLastErrNoRetMsg(NULL) +#define SUNCheckLastErrVoid() SUNCheckLastErrVoidMsg(NULL) +#define SUNCheckLastErrNull() SUNCheckLastErrNullMsg(NULL) + +/* + SUNAssert checks if an expression is true. It expands to SUNCheck in debug + builds othewrise we try to expand it to an assumption, if the compiler + supports assumptions, so that the compiler can make optimizations based on the + assumption. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssert(expr, code) SUNCheck(expr, code) +#else +#define SUNAssert(expr, code) +#endif + +/* + SUNAssertNoRet is the same as SUNAssert but it does not return from the + caller. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertNoRet(expr, code) SUNCheckNoRet(expr, code) +#else +#define SUNAssertNoRet(expr, code) +#endif + +/* + SUNAssertNull is the same as SUNAssert but it *returns NULL from the caller*. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertNull(expr, code) SUNCheckNull(expr, code) +#else +#define SUNAssertNull(expr, code) +#endif + +/* + SUNAssertVoid is the same as SUNAssert but it *returns void from the caller*. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertVoid(expr, code) SUNCheckVoid(expr, code) +#else +#define SUNAssertVoid(expr, code) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_ERRORS_IMPL_H */ diff --git a/inst/include/sundials/sundials_adaptcontroller.h b/inst/include/sundials/sundials_adaptcontroller.h new file mode 100644 index 0000000..b27d7c7 --- /dev/null +++ b/inst/include/sundials/sundials_adaptcontroller.h @@ -0,0 +1,157 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 accuracy-based adaptivity controller class. These + * objects estimate step sizes for time integration methods such + * that the next step solution should satisfy a desired temporal + * accuracy. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ADAPTCONTROLLER_H +#define _SUNDIALS_ADAPTCONTROLLER_H + +#include +#include +#include + +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + * SUNAdaptController types (currently, only "H" is implemented; + * others are planned): + * NONE - empty controller (does nothing) + * H - controls a single-rate step size + * ----------------------------------------------------------------- */ + +typedef enum +{ + SUN_ADAPTCONTROLLER_NONE, + SUN_ADAPTCONTROLLER_H +} SUNAdaptController_Type; + +/* ----------------------------------------------------------------- + * Generic definition of SUNAdaptController + * ----------------------------------------------------------------- */ + +/* Forward reference for pointer to SUNAdaptController_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNAdaptController_Ops* SUNAdaptController_Ops; + +/* Forward reference for pointer to SUNAdaptController object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNAdaptController* SUNAdaptController; + +/* Structure containing function pointers to controller operations */ +struct _generic_SUNAdaptController_Ops +{ + /* REQUIRED of all controller implementations. */ + SUNAdaptController_Type (*gettype)(SUNAdaptController C); + + /* REQUIRED for controllers of SUN_ADAPTCONTROLLER_H type. */ + SUNErrCode (*estimatestep)(SUNAdaptController C, sunrealtype h, int p, + sunrealtype dsm, sunrealtype* hnew); + + /* OPTIONAL for all SUNAdaptController implementations. */ + SUNErrCode (*destroy)(SUNAdaptController C); + SUNErrCode (*reset)(SUNAdaptController C); + SUNErrCode (*setdefaults)(SUNAdaptController C); + SUNErrCode (*write)(SUNAdaptController C, FILE* fptr); + SUNErrCode (*seterrorbias)(SUNAdaptController C, sunrealtype bias); + SUNErrCode (*updateh)(SUNAdaptController C, sunrealtype h, sunrealtype dsm); + SUNErrCode (*space)(SUNAdaptController C, long int* lenrw, long int* leniw); +}; + +/* A SUNAdaptController is a structure with an implementation-dependent + 'content' field, and a pointer to a structure of + operations corresponding to that implementation. */ +struct _generic_SUNAdaptController +{ + void* content; + SUNAdaptController_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------- + * Functions exported by SUNAdaptController module + * ----------------------------------------------------------------- */ + +/* Function to create an empty SUNAdaptController data structure. */ +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_NewEmpty(SUNContext sunctx); + +/* Function to free a generic SUNAdaptController (assumes content is already empty) */ +SUNDIALS_EXPORT +void SUNAdaptController_DestroyEmpty(SUNAdaptController C); + +/* Function to report the type of a SUNAdaptController object. */ +SUNDIALS_EXPORT +SUNAdaptController_Type SUNAdaptController_GetType(SUNAdaptController C); + +/* Function to deallocate a SUNAdaptController object. + + Any return value other than SUN_SUCCESS will be treated as + an unrecoverable failure. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C); + +/* Main step size controller function. This is called following + a time step with size 'h' and local error factor 'dsm', and the + controller should estimate 'hnew' so that the ensuing step + will have 'dsm' value JUST BELOW 1. + + Any return value other than SUN_SUCCESS will be treated as + an unrecoverable failure. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, + int p, sunrealtype dsm, + sunrealtype* hnew); + +/* Function to reset the controller to its initial state, e.g., if + it stores a small number of previous dsm or step size values. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset(SUNAdaptController C); + +/* Function to set the controller parameters to their default values. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C); + +/* Function to write all controller parameters to the indicated file + pointer. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write(SUNAdaptController C, FILE* fptr); + +/* Function to set an error bias factor to use for scaling the local error + 'dsm' factors above. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, + sunrealtype bias); + +/* Function to notify a controller of type SUN_ADAPTCONTROLLER_H that + a successful time step was taken with stepsize h and local error factor + dsm, indicating that these can be saved for subsequent controller functions. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, + sunrealtype dsm); + +/* Function to return the memory requirements of the controller object. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space(SUNAdaptController C, long int* lenrw, + long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_ADAPTCONTROLLER_H */ diff --git a/inst/include/sundials/sundials_band.h b/inst/include/sundials/sundials_band.h new file mode 100644 index 0000000..9860acf --- /dev/null +++ b/inst/include/sundials/sundials_band.h @@ -0,0 +1,194 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic BAND linear solver + * package, based on the SUNDlsMat type defined in sundials_direct.h. + * + * There are two sets of band solver routines listed in + * this file: one set uses type SUNDlsMat defined below and the + * other set uses the type sunrealtype ** for band matrix arguments. + * Routines that work with the type SUNDlsMat begin with "Band". + * Routines that work with sunrealtype ** begin with "band". + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_BAND_H +#define _SUNDIALS_BAND_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_BandGBTRF + * ----------------------------------------------------------------- + * Usage : ier = SUNDlsMat_BandGBTRF(A, p); + * if (ier != 0) ... A is singular + * ----------------------------------------------------------------- + * SUNDlsMat_BandGBTRF performs the LU factorization of the N by N band + * matrix A. This is done using standard Gaussian elimination + * with partial pivoting. + * + * A successful LU factorization leaves the "matrix" A and the + * pivot array p with the following information: + * + * (1) p[k] contains the row number of the pivot element chosen + * at the beginning of elimination step k, k = 0, 1, ..., N-1. + * + * (2) If the unique LU factorization of A is given by PA = LU, + * where P is a permutation matrix, L is a lower triangular + * matrix with all 1's on the diagonal, and U is an upper + * triangular matrix, then the upper triangular part of A + * (including its diagonal) contains U and the strictly lower + * triangular part of A contains the multipliers, I-L. + * + * SUNDlsMat_BandGBTRF returns 0 if successful. Otherwise it encountered + * a zero diagonal element during the factorization. In this case + * it returns the column index (numbered from one) at which + * it encountered the zero. + * + * Important Note: A must be allocated to accommodate the increase + * in upper bandwidth that occurs during factorization. If + * mathematically, A is a band matrix with upper bandwidth mu and + * lower bandwidth ml, then the upper triangular factor U can + * have upper bandwidth as big as smu = MIN(n-1,mu+ml). The lower + * triangular factor L has lower bandwidth ml. Allocate A with + * call A = BandAllocMat(N,mu,ml,smu), where mu, ml, and smu are + * as defined above. The user does not have to zero the "extra" + * storage allocated for the purpose of factorization. This will + * handled by the SUNDlsMat_BandGBTRF routine. + * + * SUNDlsMat_BandGBTRF is only a wrapper around SUNDlsMat_bandGBTRF. + * All work is done in SUNDlsMat_bandGBTRF, which works directly on the + * data in the SUNDlsMat A (i.e. in the field A->cols). + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_BandGBTRF(SUNDlsMat A, sunindextype* p); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_bandGBTRF(sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, + sunindextype smu, sunindextype* p); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_BandGBTRS + * ----------------------------------------------------------------- + * Usage: SUNDlsMat_BandGBTRS(A, p, b); + * ----------------------------------------------------------------- + * SUNDlsMat_BandGBTRS solves the N-dimensional system A x = b using + * the LU factorization in A and the pivot information in p computed + * in SUNDlsMat_BandGBTRF. The solution x is returned in b. This + * routine cannot fail if the corresponding call to + * SUNDlsMat_BandGBTRF did not fail. + * + * SUNDlsMat_BandGBTRS is only a wrapper around SUNDlsMat_bandGBTRS + * which does all the work directly on the data in the DlsMat A (i.e. + * in A->cols). + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_BandGBTRS(SUNDlsMat A, sunindextype* p, sunrealtype* b); + +SUNDIALS_EXPORT +void SUNDlsMat_bandGBTRS(sunrealtype** a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype* p, sunrealtype* b); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_BandCopy + * ----------------------------------------------------------------- + * Usage: SUNDlsMat_BandCopy(A, B, copymu, copyml); + * ----------------------------------------------------------------- + * SUNDlsMat_BandCopy copies the submatrix with upper and lower + * bandwidths copymu, copyml of the N by N band matrix A into the N by + * N band matrix B. + * + * SUNDlsMat_BandCopy is a wrapper around SUNDlsMat_bandCopy which + * accesses the data in the DlsMat A and DlsMat B (i.e. the fields + * cols). + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, + sunindextype copyml); +SUNDIALS_EXPORT +void SUNDlsMat_bandCopy(sunrealtype** a, sunrealtype** b, sunindextype n, + sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_BandScale + * ----------------------------------------------------------------- + * Usage: SUNDlsMat_BandScale(c, A); + * ----------------------------------------------------------------- + * A(i,j) <- c*A(i,j), j-(A->mu) < = i < = j+(A->ml). + * + * SUNDlsMat_BandScale is a wrapper around SUNDlsMat_bandScale which + * performs the actual scaling by accessing the data in the + * SUNDlsMat A (i.e. the field A->cols). + * ----------------------------------------------------------------- + */ + +void SUNDlsMat_BandScale(sunrealtype c, SUNDlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_bandScale(sunrealtype c, sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_bandAddIdentity + * ----------------------------------------------------------------- + * SUNDlsMat_bandAddIdentity adds the identity matrix to the n-by-n + * matrix stored in the sunrealtype** arrays. + * ----------------------------------------------------------------- + */ + +void SUNDlsMat_bandAddIdentity(sunrealtype** a, sunindextype n, sunindextype smu); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_BandMatvec + * ----------------------------------------------------------------- + * SUNDlsMat_BandMatvec computes the matrix-vector product y = A*x, + * where A is an M-by-N band matrix, x is a vector of length N, and y + * is a vector of length M. No error checking is performed on the + * length of the arrays x and y. Only y is modified in this routine. + * + * SUNDlsMat_BandMatvec is a wrapper around SUNDlsMat_bandMatvec which + * performs the actual product by accessing the data in the SUNDlsMat + * A. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_BandMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y); + +SUNDIALS_EXPORT +void SUNDlsMat_bandMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, + sunindextype n, sunindextype mu, sunindextype ml, + sunindextype smu); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_base.hpp b/inst/include/sundials/sundials_base.hpp new file mode 100644 index 0000000..9a43da9 --- /dev/null +++ b/inst/include/sundials/sundials_base.hpp @@ -0,0 +1,151 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * Base classes for C++ implementations of SUNDIALS objects and wrappers (views) + * of SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_BASE_HPP +#define _SUNDIALS_BASE_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { + +// +// Common base class for C++ implementations of SUNDIALS data structures. +// +template +class BaseObject +{ +public: + BaseObject() = default; + + BaseObject(SUNContext sunctx) + : sunctx_(sunctx), + object_(std::make_unique()), + object_ops_(std::make_unique()) + { + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + } + + // Move constructor + BaseObject(BaseObject&& other) noexcept + : sunctx_(std::move(other.sunctx_)), + object_(std::move(other.object_)), + object_ops_(std::move(other.object_ops_)) + { + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + } + + // Copy constructor + BaseObject(const BaseObject& other) + : sunctx_(other.sunctx_), + object_(std::make_unique()), + object_ops_(std::make_unique(*other.object_ops_)) + { + object_->content = this; + object_->sunctx = other.sunctx_; + object_->ops = object_ops_.get(); + } + + // Move assignment + BaseObject& operator=(BaseObject&& rhs) noexcept + { + sunctx_ = std::move(rhs.sunctx_); + object_ops_ = std::move(rhs.object_ops_); + object_ = std::move(rhs.object_); + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + return *this; + } + + // Copy assignment + BaseObject& operator=(const BaseObject& rhs) + { + sunctx_ = rhs.sunctx_; + object_ops_ = std::make_unique(*rhs.object_ops_); + object_ = std::make_unique(); + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + return *this; + } + + // We have a pure virtual destructor to make this an asbtract class + virtual ~BaseObject() = 0; + + // Getters + SUNContext sunctx() const { return this->object_->sunctx; } + +protected: + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + SUNContext sunctx_{}; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + std::unique_ptr object_; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + std::unique_ptr object_ops_; +}; + +// Pure virtual destructor requires implementation +template +BaseObject::~BaseObject() = default; + +} // namespace impl + +namespace experimental { + +template +class ClassView : public sundials::ConvertibleTo +{ +public: + ClassView() : object_(nullptr) {} + + ClassView(T&& object) : object_(std::make_unique(object)) {} + + ClassView(const ClassView&) = delete; + ClassView(ClassView&& other) = default; + + ClassView& operator=(const ClassView&) = delete; + ClassView& operator=(ClassView&& rhs) = default; + + ~ClassView() + { + if (object_) { Deleter{}(this->Convert()); } + }; + + // Override ConvertibleTo functions + T Convert() override { return *object_.get(); } + + T Convert() const override { return *object_.get(); } + + operator T() override { return *object_.get(); } + + operator T() const override { return *object_.get(); } + +private: + std::unique_ptr object_; +}; + +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_config.h b/inst/include/sundials/sundials_config.h new file mode 100644 index 0000000..05d55d9 --- /dev/null +++ b/inst/include/sundials/sundials_config.h @@ -0,0 +1,295 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 configuration header file. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONFIG_H +#define _SUNDIALS_CONFIG_H + +#include "sundials/sundials_export.h" + +/* Indicates that the function will not report an error via last_err, + a return code. In C++, it is just defined as noexcept. */ +#if defined(__cplusplus) +#define SUNDIALS_NOEXCEPT noexcept +#else +#define SUNDIALS_NOEXCEPT +#endif + +#ifndef SUNDIALS_DEPRECATED_MSG +# define SUNDIALS_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT_MSG +# define SUNDIALS_DEPRECATED_EXPORT_MSG(msg) SUNDIALS_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT_MSG +# define SUNDIALS_DEPRECATED_NO_EXPORT_MSG(msg) SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +/* ------------------------------------------------------------------ + * Define SUNDIALS version numbers + * -----------------------------------------------------------------*/ + + +#define SUNDIALS_VERSION "7.1.1" +#define SUNDIALS_VERSION_MAJOR 7 +#define SUNDIALS_VERSION_MINOR 1 +#define SUNDIALS_VERSION_PATCH 1 +#define SUNDIALS_VERSION_LABEL "" +#define SUNDIALS_GIT_VERSION "" + + +/* ------------------------------------------------------------------ + * SUNDIALS build information + * -----------------------------------------------------------------*/ + +#define SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME +/* #undef SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME */ +/* #undef SUNDIALS_C_COMPILER_HAS_ASSUME */ +#define SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED + +/* Define precision of SUNDIALS data type 'sunrealtype' + * Depending on the precision level, one of the following + * three macros will be defined: + * #define SUNDIALS_SINGLE_PRECISION 1 + * #define SUNDIALS_DOUBLE_PRECISION 1 + * #define SUNDIALS_EXTENDED_PRECISION 1 + */ +#define SUNDIALS_DOUBLE_PRECISION 1 + +/* Define type of vector indices in SUNDIALS 'sunindextype'. + * Depending on user choice of index type, one of the following + * two macros will be defined: + * #define SUNDIALS_INT64_T 1 + * #define SUNDIALS_INT32_T 1 + */ +#define SUNDIALS_INT64_T 1 + +/* Define the type of vector indices in SUNDIALS 'sunindextype'. + * The macro will be defined with a type of the appropriate size. + */ +#define SUNDIALS_INDEX_TYPE int64_t + +/* Use POSIX timers if available. + * #define SUNDIALS_HAVE_POSIX_TIMERS + */ +#define SUNDIALS_HAVE_POSIX_TIMERS + +/* BUILD CVODE with fused kernel functionality */ +/* #undef SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS */ + +/* BUILD SUNDIALS with monitoring functionalities */ +/* #undef SUNDIALS_BUILD_WITH_MONITORING */ + +/* BUILD SUNDIALS with profiling functionalities */ +/* #undef SUNDIALS_BUILD_WITH_PROFILING */ + +/* Enable error checking within SUNDIALS */ +/* #undef SUNDIALS_ENABLE_ERROR_CHECKS */ + +/* BUILD SUNDIALS with logging functionalities */ +#define SUNDIALS_LOGGING_LEVEL 2 + +/* Build metadata */ +#define SUN_C_COMPILER "GNU" +#define SUN_C_COMPILER_VERSION "13.3.0" +#define SUN_C_COMPILER_FLAGS "-O2 -Wall -mfpmath=sse -msse2 -mstackrealign" + +#define SUN_CXX_COMPILER "" +#define SUN_CXX_COMPILER_VERSION "" +#define SUN_CXX_COMPILER_FLAGS "" + +#define SUN_FORTRAN_COMPILER "" +#define SUN_FORTRAN_COMPILER_VERSION "" +#define SUN_FORTRAN_COMPILER_FLAGS "" + +#define SUN_BUILD_TYPE "Release" + +#define SUN_JOB_ID "20241213081704" +#define SUN_JOB_START_TIME "20241213081704" + +#define SUN_TPL_LIST "" +#define SUN_TPL_LIST_SIZE "" + +#define SUNDIALS_SPACK_VERSION "" + +/* ------------------------------------------------------------------ + * SUNDIALS TPL macros + * -----------------------------------------------------------------*/ + +/* Caliper */ +/* #undef SUNDIALS_CALIPER_ENABLED */ + +/* Adiak */ +/* #undef SUNDIALS_ADIAK_ENABLED */ + +/* Ginkgo */ +/* #undef SUNDIALS_GINKGO_ENABLED */ +#define SUN_GINKGO_VERSION "" + +/* HYPRE */ +/* #undef SUNDIALS_HYPRE_ENABLED */ +#define SUN_HYPRE_VERSION "" + +/* KLU */ +/* #undef SUNDIALS_KLU_ENABLED */ +#define SUN_KLU_VERSION "" + +/* KOKKOS */ +/* #undef SUNDIALS_KOKKOS_ENABLED */ +#define SUN_KOKKOS_VERSION "" + +/* KOKKOS_KERNELS */ +/* #undef SUNDIALS_KOKKOS_KERNELS_ENABLED */ +#define SUN_KOKKOS_KERNELS_VERSION "" + +/* LAPACK */ +/* #undef SUNDIALS_BLAS_LAPACK_ENABLED */ +#define SUN_LAPACK_VERSION "" + +/* MAGMA */ +/* #undef SUNDIALS_MAGMA_ENABLED */ +#define SUN_MAGMA_VERSION "" + +/* MPI */ +#define SUN_MPI_C_COMPILER "" +#define SUN_MPI_C_VERSION "" + +#define SUN_MPI_CXX_COMPILER "" +#define SUN_MPI_CXX_VERSION "" + +#define SUN_MPI_FORTRAN_COMPILER "" +#define SUN_MPI_FORTRAN_VERSION "" + +/* ONEMKL */ +/* #undef SUNDIALS_ONEMKL_ENABLED */ +#define SUN_ONEMKL_VERSION "" + +/* OpenMP */ +/* #undef SUNDIALS_OPENMP_ENABLED */ +#define SUN_OPENMP_VERSION "" + +/* PETSC */ +/* #undef SUNDIALS_PETSC_ENABLED */ +#define SUN_PETSC_VERSION "" + +/* PTHREADS */ +/* #undef SUNDIALS_PTHREADS_ENABLED */ +#define SUN_PTHREADS_VERSION "" + +/* RAJA */ +/* #undef SUNDIALS_RAJA_ENABLED */ +#define SUN_RAJA_VERSION "" + +/* SUPERLUDIST */ +/* #undef SUNDIALS_SUPERLUDIST_ENABLED */ +#define SUN_SUPERLUDIST_VERSION "" + +/* SUPERLUMT */ +/* #undef SUNDIALS_SUPERLUMT_ENABLED */ +#define SUN_SUPERLUMT_VERSION "" + +/* TRILLINOS */ +/* #undef SUNDIALS_TRILLINOS_ENABLED */ +#define SUN_TRILLINOS_VERSION "" + +/* XBRAID */ +/* #undef SUNDIALS_XBRAID_ENABLED */ +#define SUN_XBRAID_VERSION "" + +/* RAJA backends */ +/* #undef SUNDIALS_RAJA_BACKENDS_CUDA */ +/* #undef SUNDIALS_RAJA_BACKENDS_HIP */ +/* #undef SUNDIALS_RAJA_BACKENDS_SYCL */ + +/* Ginkgo backends */ +/* #undef SUNDIALS_GINKGO_BACKENDS_CUDA */ +/* #undef SUNDIALS_GINKGO_BACKENDS_HIP */ +/* #undef SUNDIALS_GINKGO_BACKENDS_OMP */ +/* #undef SUNDIALS_GINKGO_BACKENDS_REF */ +/* #undef SUNDIALS_GINKGO_BACKENDS_SYCL */ + +/* MAGMA backends */ +/* #undef SUNDIALS_MAGMA_BACKENDS_CUDA */ +/* #undef SUNDIALS_MAGMA_BACKENDS_HIP */ + +/* Set if SUNDIALS is built with MPI support, then + * #define SUNDIALS_MPI_ENABLED 1 + * otherwise + * #define SUNDIALS_MPI_ENABLED 0 + */ +#define SUNDIALS_MPI_ENABLED 0 + +/* oneMKL interface options */ +/* #undef SUNDIALS_ONEMKL_USE_GETRF_LOOP */ +/* #undef SUNDIALS_ONEMKL_USE_GETRS_LOOP */ + +/* SUPERLUMT threading type */ +#define SUNDIALS_SUPERLUMT_THREAD_TYPE "" + +/* Trilinos with MPI is available, then + * #define SUNDIALS_TRILINOS_HAVE_MPI + */ +/* #undef SUNDIALS_TRILINOS_HAVE_MPI */ + + +/* ------------------------------------------------------------------ + * SUNDIALS language macros + * -----------------------------------------------------------------*/ + +/* CUDA */ +/* #undef SUNDIALS_CUDA_ENABLED */ +#define SUN_CUDA_VERSION "" +#define SUN_CUDA_COMPILER "" +#define SUN_CUDA_ARCHITECTURES "" + +/* HIP */ +/* #undef SUNDIALS_HIP_ENABLED */ +#define SUN_HIP_VERSION "" +#define SUN_AMDGPU_TARGETS "" + +/* SYCL options */ +/* #undef SUNDIALS_SYCL_2020_UNSUPPORTED */ + + +/* ------------------------------------------------------------------ + * SUNDIALS modules enabled + * -----------------------------------------------------------------*/ + +#define SUNDIALS_ARKODE 1 +#define SUNDIALS_CVODE 1 +#define SUNDIALS_CVODES 1 +#define SUNDIALS_IDA 1 +#define SUNDIALS_IDAS 1 +#define SUNDIALS_KINSOL 1 +#define SUNDIALS_NVECTOR_SERIAL 1 +#define SUNDIALS_NVECTOR_MANYVECTOR 1 +#define SUNDIALS_SUNMATRIX_BAND 1 +#define SUNDIALS_SUNMATRIX_DENSE 1 +#define SUNDIALS_SUNMATRIX_SPARSE 1 +#define SUNDIALS_SUNLINSOL_BAND 1 +#define SUNDIALS_SUNLINSOL_DENSE 1 +#define SUNDIALS_SUNLINSOL_PCG 1 +#define SUNDIALS_SUNLINSOL_SPBCGS 1 +#define SUNDIALS_SUNLINSOL_SPFGMR 1 +#define SUNDIALS_SUNLINSOL_SPGMR 1 +#define SUNDIALS_SUNLINSOL_SPTFQMR 1 +#define SUNDIALS_SUNNONLINSOL_NEWTON 1 +#define SUNDIALS_SUNNONLINSOL_FIXEDPOINT 1 + + +#endif /* _SUNDIALS_CONFIG_H */ diff --git a/inst/include/sundials/sundials_context.h b/inst/include/sundials/sundials_context.h new file mode 100644 index 0000000..49e2bda --- /dev/null +++ b/inst/include/sundials/sundials_context.h @@ -0,0 +1,66 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 context class. A context object holds data that all + * SUNDIALS objects in a simulation share. It is thread-safe provided + * that each thread has its own context object. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_H +#define _SUNDIALS_CONTEXT_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +SUNErrCode SUNContext_Create(SUNComm comm, SUNContext* sunctx_out); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetLastError(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PeekLastError(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PushErrHandler(SUNContext sunctx, SUNErrHandlerFn err_fn, + void* err_user_data); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PopErrHandler(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_ClearErrHandlers(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetProfiler(SUNContext sunctx, SUNProfiler* profiler); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_SetProfiler(SUNContext sunctx, SUNProfiler profiler); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetLogger(SUNContext sunctx, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_SetLogger(SUNContext sunctx, SUNLogger logger); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_Free(SUNContext* ctx); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/inst/include/sundials/sundials_context.hpp b/inst/include/sundials/sundials_context.hpp new file mode 100644 index 0000000..c28fb80 --- /dev/null +++ b/inst/include/sundials/sundials_context.hpp @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ interface to the SUNDIALS context object + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_HPP +#define _SUNDIALS_CONTEXT_HPP + +#include +#include +#include + +#include "sundials/sundials_types.h" + +namespace sundials { + +class Context : public sundials::ConvertibleTo +{ +public: + explicit Context(SUNComm comm = SUN_COMM_NULL) + { + sunctx_ = std::make_unique(); + SUNContext_Create(comm, sunctx_.get()); + } + + /* disallow copy, but allow move construction */ + Context(const Context&) = delete; + Context(Context&&) = default; + + /* disallow copy, but allow move operators */ + Context& operator=(const Context&) = delete; + Context& operator=(Context&&) = default; + + SUNContext Convert() override { return *sunctx_.get(); } + + SUNContext Convert() const override { return *sunctx_.get(); } + + operator SUNContext() override { return *sunctx_.get(); } + + operator SUNContext() const override { return *sunctx_.get(); } + + ~Context() + { + if (sunctx_) { SUNContext_Free(sunctx_.get()); } + } + +private: + std::unique_ptr sunctx_; +}; + +} // namespace sundials + +#endif // _SUNDIALS_CONTEXT_HPP diff --git a/inst/include/sundials/sundials_convertibleto.hpp b/inst/include/sundials/sundials_convertibleto.hpp new file mode 100644 index 0000000..7443ed4 --- /dev/null +++ b/inst/include/sundials/sundials_convertibleto.hpp @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * Base class for converting C++ wappers (views) to SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONVERTIBLETO_HPP +#define _SUNDIALS_CONVERTIBLETO_HPP + +namespace sundials { + +template +class ConvertibleTo +{ +public: + // Explicit conversion to the underlying type + virtual T Convert() = 0; + virtual T Convert() const = 0; + + // Implicit conversion to the underlying type + virtual operator T() = 0; + virtual operator T() const = 0; + + virtual ~ConvertibleTo() = default; +}; + +} // namespace sundials + +#endif // _SUNDIALS_CONVERTIBLETO_HPP diff --git a/inst/include/sundials/sundials_core.h b/inst/include/sundials/sundials_core.h new file mode 100644 index 0000000..592d1d7 --- /dev/null +++ b/inst/include/sundials/sundials_core.h @@ -0,0 +1,38 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------- + * Header file that includes the SUNDIALS core. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CORE_H +#define _SUNDIALS_CORE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if SUNDIALS_MPI_ENABLED +#include +#endif + +#endif /* _SUNDIALS_CORE_H */ diff --git a/inst/include/sundials/sundials_core.hpp b/inst/include/sundials/sundials_core.hpp new file mode 100644 index 0000000..51372a3 --- /dev/null +++ b/inst/include/sundials/sundials_core.hpp @@ -0,0 +1,25 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CORE_HPP +#define _SUNDIALS_CORE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* _SUNDIALS_CORE_HPP */ diff --git a/inst/include/sundials/sundials_dense.h b/inst/include/sundials/sundials_dense.h new file mode 100644 index 0000000..8ee1964 --- /dev/null +++ b/inst/include/sundials/sundials_dense.h @@ -0,0 +1,234 @@ +/* ----------------------------------------------------------------- + * Programmer: Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic package of DENSE matrix + * operations, based on the DlsMat type defined in sundials_direct.h. + * + * There are two sets of dense solver routines listed in + * this file: one set uses type DlsMat defined below and the + * other set uses the type sunrealtype ** for dense matrix arguments. + * Routines that work with the type DlsMat begin with "Dense". + * Routines that work with sunrealtype** begin with "dense". + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_DENSE_H +#define _SUNDIALS_DENSE_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ---------------------------------------------------------------------------- + * Functions: SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF performs the LU factorization of the M by N dense matrix A. + * This is done using standard Gaussian elimination with partial (row) pivoting. + * Note that this applies only to matrices with M >= N and full column rank. + * + * A successful LU factorization leaves the matrix A and the pivot array p with + * the following information: + * + * (1) p[k] contains the row number of the pivot element chosen at the beginning + * of elimination step k, k=0, 1, ..., N-1. + * + * (2) If the unique LU factorization of A is given by PA = LU, where P is a + * permutation matrix, L is a lower trapezoidal matrix with all 1's on the + * diagonal, and U is an upper triangular matrix, then the upper triangular + * part of A (including its diagonal) contains U and the strictly lower + * trapezoidal part of A contains the multipliers, I-L. + * + * For square matrices (M = N), L is unit lower triangular. + * + * SUNDlsMat_DenseGETRF returns 0 if successful. Otherwise it encountered a zero + * diagonal element during the factorization. In this case it returns the column + * index (numbered from one) at which it encountered the zero. + * + * SUNDlsMat_DenseGETRS solves the N-dimensional system A x = b using the LU + * factorization in A and the pivot information in p computed in + * SUNDlsMat_DenseGETRF. The solution x is returned in b. This routine cannot fail + * if the corresponding call to SUNDlsMat_DenseGETRF did not fail. + * SUNDlsMat_DenseGETRS does NOT check for a square matrix! + * + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS are simply wrappers around + * SUNDlsMat_denseGETRF and SUNDlsMat_denseGETRS, respectively, which perform all the + * work by directly accessing the data in the SUNDlsMat A (i.e. in A->cols). + * ---------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DenseGETRF(SUNDlsMat A, sunindextype* p); + +SUNDIALS_EXPORT +void SUNDlsMat_DenseGETRS(SUNDlsMat A, sunindextype* p, sunrealtype* b); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_denseGETRF(sunrealtype** a, sunindextype m, + sunindextype n, sunindextype* p); + +SUNDIALS_EXPORT +void SUNDlsMat_denseGETRS(sunrealtype** a, sunindextype n, sunindextype* p, + sunrealtype* b); + +/* + * ---------------------------------------------------------------------------- + * Functions : SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF computes the Cholesky factorization of a real symmetric + * positive definite matrix A. + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRS solves a system of linear equations A*X = B with a + * symmetric positive definite matrix A using the Cholesky factorization A = + * L*L**T computed by SUNDlsMat_DensePOTRF. + * + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS are simply wrappers around + * SUNDlsMat_densePOTRF and SUNDlsMat_densePOTRS, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ---------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DensePOTRF(SUNDlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_DensePOTRS(SUNDlsMat A, sunrealtype* b); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_densePOTRF(sunrealtype** a, sunindextype m); + +SUNDIALS_EXPORT +void SUNDlsMat_densePOTRS(sunrealtype** a, sunindextype m, sunrealtype* b); + +/* + * ----------------------------------------------------------------------------- + * Functions : SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF computes a QR factorization of a real M-by-N matrix A: A = + * Q * R (with M>= N). + * + * SUNDlsMat_DenseGEQRF requires a temporary work vector wrk of length M. + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseORMQR computes the product w = Q * v where Q is a real orthogonal + * matrix defined as the product of k elementary reflectors + * + * Q = H(1) H(2) . . . H(k) + * + * as returned by SUNDlsMat_DenseGEQRF. Q is an M-by-N matrix, v is a vector of + * length N and w is a vector of length M (with M >= N). + * + * SUNDlsMat_DenseORMQR requires a temporary work vector wrk of length M. + * + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR are simply wrappers around + * SUNDlsMat_denseGEQRF and SUNDlsMat_denseORMQR, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ----------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNDlsMat_DenseGEQRF(SUNDlsMat A, sunrealtype* beta, sunrealtype* wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_DenseORMQR(SUNDlsMat A, sunrealtype* beta, sunrealtype* vn, + sunrealtype* vm, sunrealtype* wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_denseGEQRF(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_denseORMQR(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* v, sunrealtype* w, + sunrealtype* wrk); + +/* + * ---------------------------------------------------------------------------- + * Function : SUNDlsMat_DenseCopy + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseCopy copies the contents of the M-by-N matrix A into the + * M-by-N matrix B. + * + * SUNDlsMat_DenseCopy is a wrapper around SUNDlsMat_denseCopy which accesses + * the data in the SUNDlsMat A and SUNDlsMat B (i.e. the fields cols) + * ----------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_DenseCopy(SUNDlsMat A, SUNDlsMat B); + +SUNDIALS_EXPORT +void SUNDlsMat_denseCopy(sunrealtype** a, sunrealtype** b, sunindextype m, + sunindextype n); + +/* + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseScale + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseScale scales the elements of the M-by-N matrix A by the + * constant c and stores the result back in A. + * + * SUNDlsMat_DenseScale is a wrapper around SUNDlsMat_denseScale which performs + * the actual scaling by accessing the data in the SUNDlsMat A (i.e. in + * A->cols). + * ----------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_DenseScale(sunrealtype c, SUNDlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_denseScale(sunrealtype c, sunrealtype** a, sunindextype m, + sunindextype n); + +/* + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_denseAddIdentity + * ----------------------------------------------------------------------------- + * SUNDlsMat_denseAddIdentity adds the identity matrix to the n-by-n matrix + * stored in a sunrealtype** array. + * ----------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_denseAddIdentity(sunrealtype** a, sunindextype n); + +/* + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseMatvec + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseMatvec computes the matrix-vector product y = A*x, where A is + * an M-by-N matrix, x is a vector of length N, and y is a vector of length M. + * No error checking is performed on the length of the arrays x and y. Only y + * is modified in this routine. + * + * SUNDlsMat_DenseMatvec is a wrapper around SUNDlsMat_denseMatvec which + * performs the actual product by accessing the data in the SUNDlsMat A. + * ----------------------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_DenseMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y); + +SUNDIALS_EXPORT +void SUNDlsMat_denseMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, + sunindextype m, sunindextype n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_direct.h b/inst/include/sundials/sundials_direct.h new file mode 100644 index 0000000..7b8b315 --- /dev/null +++ b/inst/include/sundials/sundials_direct.h @@ -0,0 +1,366 @@ +/* ----------------------------------------------------------------- + * Programmer: Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file contains definitions and declarations for use by + * generic direct linear solvers for Ax = b. It defines types for + * dense and banded matrices and corresponding accessor macros. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_DIRECT_H +#define _SUNDIALS_DIRECT_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ================================================================= + * C O N S T A N T S + * ================================================================= + */ + +/* + * SUNDIALS_DENSE: dense matrix + * SUNDIALS_BAND: banded matrix + */ + +#define SUNDIALS_DENSE 1 +#define SUNDIALS_BAND 2 + +/* + * ================================================================== + * Type definitions + * ================================================================== + */ + +/* + * ----------------------------------------------------------------- + * Type : SUNDlsMat + * ----------------------------------------------------------------- + * The type SUNDlsMat is defined to be a pointer to a structure + * with various sizes, a data field, and an array of pointers to + * the columns which defines a dense or band matrix for use in + * direct linear solvers. The M and N fields indicates the number + * of rows and columns, respectively. The data field is a one + * dimensional array used for component storage. The cols field + * stores the pointers in data for the beginning of each column. + * ----------------------------------------------------------------- + * For DENSE matrices, the relevant fields in SUNDlsMat are: + * type = SUNDIALS_DENSE + * M - number of rows + * N - number of columns + * ldim - leading dimension (ldim >= M) + * data - pointer to a contiguous block of sunrealtype variables + * ldata - length of the data array =ldim*N + * cols - array of pointers. cols[j] points to the first element + * of the j-th column of the matrix in the array data. + * + * The elements of a dense matrix are stored columnwise (i.e. columns + * are stored one on top of the other in memory). + * If A is of type SUNDlsMat, then the (i,j)th element of A (with + * 0 <= i < M and 0 <= j < N) is given by (A->data)[j*n+i]. + * + * The SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM macros below allow a + * user to access efficiently individual matrix elements without + * writing out explicit data structure references and without knowing + * too much about the underlying element storage. The only storage + * assumption needed is that elements are stored columnwise and that a + * pointer to the jth column of elements can be obtained via the + * SUNDLS_DENSE_COL macro. + * ----------------------------------------------------------------- + * For BAND matrices, the relevant fields in SUNDlsMat are: + * type = SUNDIALS_BAND + * M - number of rows + * N - number of columns + * mu - upper bandwidth, 0 <= mu <= min(M,N) + * ml - lower bandwidth, 0 <= ml <= min(M,N) + * s_mu - storage upper bandwidth, mu <= s_mu <= N-1. + * The dgbtrf routine writes the LU factors into the storage + * for A. The upper triangular factor U, however, may have + * an upper bandwidth as big as MIN(N-1,mu+ml) because of + * partial pivoting. The s_mu field holds the upper + * bandwidth allocated for A. + * ldim - leading dimension (ldim >= s_mu) + * data - pointer to a contiguous block of sunrealtype variables + * ldata - length of the data array =ldim*(s_mu+ml+1) + * cols - array of pointers. cols[j] points to the first element + * of the j-th column of the matrix in the array data. + * + * The SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM + * macros below allow a user to access individual matrix elements + * without writing out explicit data structure references and without + * knowing too much about the underlying element storage. The only + * storage assumption needed is that elements are stored columnwise + * and that a pointer into the jth column of elements can be obtained + * via the SUNDLS_BAND_COL macro. The SUNDLS_BAND_COL_ELEM macro + * selects an element from a column which has already been isolated + * via SUNDLS_BAND_COL. The macro SUNDLS_BAND_COL_ELEM allows the user + * to avoid the translation from the matrix location (i,j) to the + * index in the array returned by SUNDLS_BAND_COL at which the (i,j)th + * element is stored. + * ----------------------------------------------------------------- + */ + +typedef struct _DlsMat +{ + int type; + sunindextype M; + sunindextype N; + sunindextype ldim; + sunindextype mu; + sunindextype ml; + sunindextype s_mu; + sunrealtype* data; + sunindextype ldata; + sunrealtype** cols; +}* SUNDlsMat; + +/* + * ================================================================== + * Data accessor macros + * ================================================================== + */ + +/* + * ----------------------------------------------------------------- + * SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM + * ----------------------------------------------------------------- + * + * SUNDLS_DENSE_COL(A,j) references the jth column of the M-by-N dense + * matrix A, 0 <= j < N. The type of the expression SUNDLS_DENSE_COL(A,j) + * is (sunrealtype *). After the assignment col_j = SUNDLS_DENSE_COL(A,j), + * col_j may be treated as an array indexed from 0 to M-1. The (i,j)-th + * element of A is thus referenced by * col_j[i]. + * + * SUNDLS_DENSE_ELEM(A,i,j) references the (i,j)th element of the dense + * M-by-N matrix A, 0 <= i < M ; 0 <= j < N. + * + * ----------------------------------------------------------------- + */ + +#define SUNDLS_DENSE_COL(A, j) ((A->cols)[j]) +#define SUNDLS_DENSE_ELEM(A, i, j) ((A->cols)[j][i]) + +/* + * ----------------------------------------------------------------- + * SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM + * ----------------------------------------------------------------- + * + * SUNDLS_BAND_COL(A,j) references the diagonal element of the jth + * column of the N by N band matrix A, 0 <= j <= N-1. The type of the + * expression SUNDLS_BAND_COL(A,j) is sunrealtype *. The pointer returned + * by the call SUNDLS_BAND_COL(A,j) can be treated as an array which + * is indexed from -(A->mu) to (A->ml). + * + * SUNDLS_BAND_COL_ELEM references the (i,j)th entry of the band + * matrix A when used in conjunction with SUNDLS_BAND_COL. The index + * (i,j) should satisfy j-(A->mu) <= i <= j+(A->ml). + * + * SUNDLS_BAND_ELEM(A,i,j) references the (i,j)th element of the + * M-by-N band matrix A, where 0 <= i,j <= N-1. The location (i,j) + * should further satisfy j-(A->mu) <= i <= j+(A->ml). + * + * ----------------------------------------------------------------- + */ + +#define SUNDLS_BAND_COL(A, j) (((A->cols)[j]) + (A->s_mu)) +#define SUNDLS_BAND_COL_ELEM(col_j, i, j) (col_j[(i) - (j)]) +#define SUNDLS_BAND_ELEM(A, i, j) ((A->cols)[j][(i) - (j) + (A->s_mu)]) +/* + * ================================================================== + * Exported function prototypes (functions working on SUNDlsMat) + * ================================================================== + */ + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_NewDenseMat + * ----------------------------------------------------------------- + * SUNDlsMat_NewDenseMat allocates memory for an M-by-N dense matrix + * and returns the storage allocated (type SUNDlsMat). + * SUNDlsMat_NewDenseMat returns NULL if the request for matrix + * storage cannot be satisfied. See the above documentation for the + * type SUNDlsMat for matrix storage details. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewDenseMat(sunindextype M, sunindextype N); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_NewBandMat + * ----------------------------------------------------------------- + * SUNDlsMat_NewBandMat allocates memory for an M-by-N band matrix + * with upper bandwidth mu, lower bandwidth ml, and storage upper + * bandwidth smu. Pass smu as follows depending on whether A will be + * LU factored: + * + * (1) Pass smu = mu if A will not be factored. + * + * (2) Pass smu = MIN(N-1,mu+ml) if A will be factored. + * + * SUNDlsMat_NewBandMat returns the storage allocated (type SUNDlsMat) + * or NULL if the request for matrix storage cannot be satisfied. See + * the documentation for the type SUNDlsMat for matrix storage + * details. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, + sunindextype smu); + +/* + * ----------------------------------------------------------------- + * Functions: SUNDlsMat_DestroyMat + * ----------------------------------------------------------------- + * SUNDlsMat_DestroyMat frees the memory allocated by + * SUNDlsMat_NewDenseMat or SUNDlsMat_NewBandMat + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_DestroyMat(SUNDlsMat A); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_NewIntArray + * ----------------------------------------------------------------- + * SUNDlsMat_NewIntArray allocates memory an array of N int's and + * returns the pointer to the memory it allocates. If the request for + * memory storage cannot be satisfied, it returns NULL. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int* SUNDlsMat_NewIntArray(int N); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_NewIndexArray + * ----------------------------------------------------------------- + * SUNDlsMat_NewIndexArray allocates memory an array of N + * sunindextype's and returns the pointer to the memory it + * allocates. If the request for memory storage cannot be satisfied, + * it returns NULL. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_NewIndexArray(sunindextype N); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_NewRealArray + * ----------------------------------------------------------------- + * SUNDlsMat_NewRealArray allocates memory an array of N sunrealtype and + * returns the pointer to the memory it allocates. If the request for + * memory storage cannot be satisfied, it returns NULL. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +sunrealtype* SUNDlsMat_NewRealArray(sunindextype N); + +/* + * ----------------------------------------------------------------- + * Function: SUNDlsMat_DestroyArray + * ----------------------------------------------------------------- + * SUNDlsMat_DestroyArray frees memory allocated by + * SUNDlsMat_NewIntArray, SUNDlsMat_NewIndexArray, or + * SUNDlsMat_NewRealArray. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_DestroyArray(void* p); + +/* + * ----------------------------------------------------------------- + * Function : SUNDlsMat_AddIdentity + * ----------------------------------------------------------------- + * SUNDlsMat_AddIdentity adds 1.0 to the main diagonal (A_ii, + * i=0,1,...,N-1) of the M-by-N matrix A (M>= N) and stores the result + * back in A. SUNDlsMat_AddIdentity is typically used with square + * matrices. SUNDlsMat_AddIdentity does not check for M >= N and + * therefore a segmentation fault will occur if M < N! + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_AddIdentity(SUNDlsMat A); + +/* + * ----------------------------------------------------------------- + * Function : SUNDlsMat_SetToZero + * ----------------------------------------------------------------- + * SUNDlsMat_SetToZero sets all the elements of the M-by-N matrix A + * to 0.0. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_SetToZero(SUNDlsMat A); + +/* + * ----------------------------------------------------------------- + * Functions: SUNDlsMat_PrintMat + * ----------------------------------------------------------------- + * This function prints the M-by-N (dense or band) matrix A to + * outfile as it would normally appear on paper. + * It is intended as debugging tools with small values of M and N. + * The elements are printed using the %g/%lg/%Lg option. + * A blank line is printed before and after the matrix. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +void SUNDlsMat_PrintMat(SUNDlsMat A, FILE* outfile); + +/* + * ================================================================== + * Exported function prototypes (functions working on sunrealtype**) + * ================================================================== + */ + +SUNDIALS_EXPORT +sunrealtype** SUNDlsMat_newDenseMat(sunindextype m, sunindextype n); + +SUNDIALS_EXPORT +sunrealtype** SUNDlsMat_newBandMat(sunindextype n, sunindextype smu, + sunindextype ml); + +SUNDIALS_EXPORT +void SUNDlsMat_destroyMat(sunrealtype** a); + +SUNDIALS_EXPORT +int* SUNDlsMat_newIntArray(int n); + +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_newIndexArray(sunindextype n); + +SUNDIALS_EXPORT +sunrealtype* SUNDlsMat_newRealArray(sunindextype m); + +SUNDIALS_EXPORT +void SUNDlsMat_destroyArray(void* v); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_errors.h b/inst/include/sundials/sundials_errors.h new file mode 100644 index 0000000..b132b0f --- /dev/null +++ b/inst/include/sundials/sundials_errors.h @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------- + * Contains all error handling interfaces for SUNDIALS that do + * not depend on MPI. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ERRORS_H +#define _SUNDIALS_ERRORS_H + +#include +#include +#include +#include +#include +#include + +/* ---------------------------------------------------------------------------- + * Error code definitions + * ---------------------------------------------------------------------------*/ + +/* SUN_ERR_CODE_LIST is an X macro that can be expanded in various ways */ +#define SUN_ERR_CODE_LIST(ENTRY) \ + ENTRY(SUN_ERR_ARG_CORRUPT, "argument provided is NULL or corrupted") \ + ENTRY(SUN_ERR_ARG_INCOMPATIBLE, "argument provided is not compatible") \ + ENTRY(SUN_ERR_ARG_OUTOFRANGE, "argument is out of the valid range") \ + ENTRY(SUN_ERR_ARG_WRONGTYPE, "argument provided is not the right type") \ + ENTRY(SUN_ERR_ARG_DIMSMISMATCH, "argument dimensions do not agree") \ + \ + ENTRY(SUN_ERR_GENERIC, "an error occurred") \ + ENTRY(SUN_ERR_CORRUPT, "value is NULL or corrupt") \ + ENTRY(SUN_ERR_OUTOFRANGE, "Value is out of the expected range") \ + ENTRY(SUN_ERR_FILE_OPEN, "Unable to open file") \ + ENTRY(SUN_ERR_OP_FAIL, "an operation failed") \ + ENTRY(SUN_ERR_MEM_FAIL, "a memory operation failed") \ + ENTRY(SUN_ERR_MALLOC_FAIL, "malloc returned NULL") \ + ENTRY(SUN_ERR_EXT_FAIL, "a failure occurred in an external library") \ + ENTRY(SUN_ERR_DESTROY_FAIL, "a destroy function returned an error") \ + ENTRY(SUN_ERR_NOT_IMPLEMENTED, \ + "operation is not implemented: function pointer is NULL") \ + ENTRY(SUN_ERR_USER_FCN_FAIL, "the user provided callback function failed") \ + \ + ENTRY(SUN_ERR_PROFILER_MAPFULL, \ + "the number of profiler entries exceeded SUNPROFILER_MAX_ENTRIES") \ + ENTRY(SUN_ERR_PROFILER_MAPGET, "unknown error getting SUNProfiler timer") \ + ENTRY(SUN_ERR_PROFILER_MAPINSERT, \ + "unknown error inserting SUNProfiler timer") \ + ENTRY(SUN_ERR_PROFILER_MAPKEYNOTFOUND, "timer was not found in SUNProfiler") \ + ENTRY(SUN_ERR_PROFILER_MAPSORT, "error sorting SUNProfiler map") \ + \ + ENTRY(SUN_ERR_SUNCTX_CORRUPT, "SUNContext is NULL or corrupt") \ + \ + ENTRY(SUN_ERR_MPI_FAIL, \ + "an MPI call returned something other than MPI_SUCCESS") \ + \ + ENTRY(SUN_ERR_UNREACHABLE, \ + "Reached code that should be unreachable: open an issue at: " \ + "https://github.com/LLNL/sundials") \ + ENTRY(SUN_ERR_UNKNOWN, "Unknown error occured: open an issue at " \ + "https://github.com/LLNL/sundials") + +/* Expand SUN_ERR_CODE_LIST to enum */ +#define SUN_EXPAND_TO_ENUM(name, description) name, + +/* SUNErrorCode range is [-10000, -1000] to avoid conflicts with package error + codes, and old/deprecated codes for matrix and (non)linear solvers. */ + +/* clang-format off */ +enum +{ + SUN_ERR_MINIMUM = -10000, + SUN_ERR_CODE_LIST(SUN_EXPAND_TO_ENUM) + SUN_ERR_MAXIMUM = -1000, + SUN_SUCCESS = 0 +}; + +/* clang-format on */ + +/* ---------------------------------------------------------------------------- + * Error handler definitions + * ---------------------------------------------------------------------------*/ + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +void SUNLogErrHandlerFn(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNAbortErrHandlerFn(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +/* ---------------------------------------------------------------------------- + * Error functions + * ---------------------------------------------------------------------------*/ + +/* Turn error code into error message */ +SUNDIALS_EXPORT +const char* SUNGetErrMsg(SUNErrCode code); + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +} /* extern "C" */ +#endif +#endif /* _SUNDIALS_ERRORS_H */ diff --git a/inst/include/sundials/sundials_export.h b/inst/include/sundials/sundials_export.h new file mode 100644 index 0000000..82463d6 --- /dev/null +++ b/inst/include/sundials/sundials_export.h @@ -0,0 +1,43 @@ + +#ifndef SUNDIALS_EXPORT_H +#define SUNDIALS_EXPORT_H + +#ifdef SUNDIALS_STATIC_DEFINE +# define SUNDIALS_EXPORT +# define SUNDIALS_NO_EXPORT +#else +# ifndef SUNDIALS_EXPORT +# ifdef sundials_core_EXPORTS + /* We are building this library */ +# define SUNDIALS_EXPORT +# else + /* We are using this library */ +# define SUNDIALS_EXPORT +# endif +# endif + +# ifndef SUNDIALS_NO_EXPORT +# define SUNDIALS_NO_EXPORT +# endif +#endif + +#ifndef SUNDIALS_DEPRECATED +# define SUNDIALS_DEPRECATED __declspec(deprecated) +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT +# define SUNDIALS_DEPRECATED_EXPORT SUNDIALS_EXPORT SUNDIALS_DEPRECATED +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT +# define SUNDIALS_DEPRECATED_NO_EXPORT SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED +#endif + +/* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */ +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef SUNDIALS_NO_DEPRECATED +# define SUNDIALS_NO_DEPRECATED +# endif +#endif + +#endif /* SUNDIALS_EXPORT_H */ diff --git a/inst/include/sundials/sundials_futils.h b/inst/include/sundials/sundials_futils.h new file mode 100644 index 0000000..257e685 --- /dev/null +++ b/inst/include/sundials/sundials_futils.h @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 Fortran 2003 interface utility definitions. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_FUTILS_H +#define _SUNDIALS_FUTILS_H + +#include +#include + +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Create a file pointer with the given file name and mode. */ +SUNDIALS_EXPORT SUNErrCode SUNDIALSFileOpen(const char* filename, + const char* modes, FILE** fp); + +/* Close a file pointer with the given file name. */ +SUNDIALS_EXPORT SUNErrCode SUNDIALSFileClose(FILE** fp); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_iterative.h b/inst/include/sundials/sundials_iterative.h new file mode 100644 index 0000000..6192bf7 --- /dev/null +++ b/inst/include/sundials/sundials_iterative.h @@ -0,0 +1,474 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Scott D. Cohen and Alan C. Hindmarsh @ LLNL + * Shelby Lockhart @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file contains declarations intended for use by + * generic iterative solvers of Ax = b. The enumeration gives + * symbolic names for the type of preconditioning to be used. + * The function type declarations give the prototypes for the + * functions to be called within an iterative linear solver, that + * are responsible for + * multiplying A by a given vector v (SUNATimesFn), + * setting up a preconditioner P (SUNPSetupFn), and + * solving the preconditioner equation Pz = r (SUNPSolveFn). + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ITERATIVE_H +#define _SUNDIALS_ITERATIVE_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ----------------------------------------------------------------- + * enum : types of preconditioning + * ----------------------------------------------------------------- + * SUN_PREC_NONE : The iterative linear solver should not use + * preconditioning. + * + * SUN_PREC_LEFT : The iterative linear solver uses preconditioning + * on the left only. + * + * SUN_PREC_RIGHT : The iterative linear solver uses preconditioning + * on the right only. + * + * SUN_PREC_BOTH : The iterative linear solver uses preconditioning + * on both the left and the right. + * ----------------------------------------------------------------- + */ + +enum +{ + SUN_PREC_NONE, + SUN_PREC_LEFT, + SUN_PREC_RIGHT, + SUN_PREC_BOTH +}; + +/* + * ----------------------------------------------------------------- + * enum : types of Gram-Schmidt routines + * ----------------------------------------------------------------- + * SUN_MODIFIED_GS : The iterative solver uses the modified + * Gram-Schmidt routine SUNModifiedGS listed in + * this file. + * + * SUN_CLASSICAL_GS : The iterative solver uses the classical + * Gram-Schmidt routine SUNClassicalGS listed in + * this file. + * ----------------------------------------------------------------- + */ + +enum +{ + SUN_MODIFIED_GS = 1, + SUN_CLASSICAL_GS = 2 +}; + +/* + * ----------------------------------------------------------------- + * Type: SUNATimesFn + * ----------------------------------------------------------------- + * An SUNATimesFn multiplies Av and stores the result in z. The + * caller is responsible for allocating memory for the z vector. + * The parameter A_data is a pointer to any information about A + * which the function needs in order to do its job. The vector v + * is unchanged. An SUNATimesFn returns 0 if successful and a + * non-zero value if unsuccessful. + * ----------------------------------------------------------------- + */ + +typedef int (*SUNATimesFn)(void* A_data, N_Vector v, N_Vector z); + +/* + * ----------------------------------------------------------------- + * Type: SUNPSetupFn + * ----------------------------------------------------------------- + * A SUNPSetupFn is an integrator-supplied routine that accesses data + * stored in the integrator memory structure (P_data), and calls the + * user-supplied, integrator-specific preconditioner setup routine. + * ----------------------------------------------------------------- + */ + +typedef int (*SUNPSetupFn)(void* P_data); + +/* + * ----------------------------------------------------------------- + * Type: SUNPSolveFn + * ----------------------------------------------------------------- + * A SUNPSolveFn solves the preconditioner equation Pz = r for the + * vector z. The caller is responsible for allocating memory for + * the z vector. The parameter P_data is a pointer to any + * information about P which the function needs in order to do + * its job. The parameter lr is input, and indicates whether P + * is to be taken as the left preconditioner or the right + * preconditioner: lr = 1 for left and lr = 2 for right. + * If preconditioning is on one side only, lr can be ignored. + * If the preconditioner is iterative, then it should strive to + * solve the preconditioner equation so that + * || Pz - r ||_wrms < tol + * where the weight vector for the WRMS norm may be accessed from + * the main integrator memory structure. + * The vector r should not be modified by the SUNPSolveFn. + * A SUNPSolveFn returns 0 if successful and a non-zero value if + * unsuccessful. On a failure, a negative return value indicates + * an unrecoverable condition, while a positive value indicates + * a recoverable one, in which the calling routine may reattempt + * the solution after updating preconditioner data. + * ----------------------------------------------------------------- + */ + +typedef int (*SUNPSolveFn)(void* P_data, N_Vector r, N_Vector z, + sunrealtype tol, int lr); + +/* + * ----------------------------------------------------------------- + * Type: SUNQRAddFn + * ----------------------------------------------------------------- + * A QRAddFn updates a given QR factorization defined by the input + * parameters: + * Q : N_Vector * + * R : sunrealtype * + * with the input vector + * f : N_Vector + * + * Additional input parameters include: + * + * m : (int) the number of vectors already in the QR factorization + * + * mMax : (int) the maximum number of vectors to be in the QR + * factorization (the number of N_Vectors allocated to be in Q) + * + * SUNQR_data : (void *) a structure containing any additional inputs + * required for the execution of QRAddFn + * + * ----------------------------------------------------------------- + */ + +typedef int (*SUNQRAddFn)(N_Vector* Q, sunrealtype* R, N_Vector f, int m, + int mMax, void* QR_data); + +/* + * ----------------------------------------------------------------- + * Function: SUNModifiedGS + * ----------------------------------------------------------------- + * SUNModifiedGS performs a modified Gram-Schmidt orthogonalization + * of the N_Vector v[k] against the p unit N_Vectors at + * v[k-1], v[k-2], ..., v[k-p]. + * + * v is an array of (k+1) N_Vectors v[i], i=0, 1, ..., k. + * v[k-1], v[k-2], ..., v[k-p] are assumed to have L2-norm + * equal to 1. + * + * h is the output k by k Hessenberg matrix of inner products. + * This matrix must be allocated row-wise so that the (i,j)th + * entry is h[i][j]. The inner products (v[i],v[k]), + * i=i0, i0+1, ..., k-1, are stored at h[i][k-1]. Here + * i0=SUNMAX(0,k-p). + * + * k is the index of the vector in the v array that needs to be + * orthogonalized against previous vectors in the v array. + * + * p is the number of previous vectors in the v array against + * which v[k] is to be orthogonalized. + * + * new_vk_norm is a pointer to memory allocated by the caller to + * hold the Euclidean norm of the orthogonalized vector v[k]. + * + * If (k-p) < 0, then SUNModifiedGS uses p=k. The orthogonalized + * v[k] is NOT normalized and is stored over the old v[k]. Once + * the orthogonalization has been performed, the Euclidean norm + * of v[k] is stored in (*new_vk_norm). + * + * SUNModifiedGS returns 0 to indicate success. It cannot fail. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNModifiedGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm); + +/* + * ----------------------------------------------------------------- + * Function: SUNClassicalGS + * ----------------------------------------------------------------- + * SUNClassicalGS performs a classical Gram-Schmidt + * orthogonalization of the N_Vector v[k] against the p unit + * N_Vectors at v[k-1], v[k-2], ..., v[k-p]. The parameters v, h, + * k, p, and new_vk_norm are as described in the documentation + * for SUNModifiedGS. + * + * stemp is a length k+1 array of sunrealtype which can be used as + * workspace by the SUNClassicalGS routine. + * + * vtemp is an N_Vector array of k+1 vectors which can be used as + * workspace by the SUNClassicalGS routine. + * + * SUNClassicalGS returns 0 to indicate success. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNClassicalGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm, sunrealtype* stemp, + N_Vector* vtemp); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRfact + * ----------------------------------------------------------------- + * SUNQRfact performs a QR factorization of the Hessenberg matrix H. + * + * n is the problem size; the matrix H is (n+1) by n. + * + * h is the (n+1) by n Hessenberg matrix H to be factored. It is + * stored row-wise. + * + * q is an array of length 2*n containing the Givens rotations + * computed by this function. A Givens rotation has the form: + * | c -s | + * | s c |. + * The components of the Givens rotations are stored in q as + * (c, s, c, s, ..., c, s). + * + * job is a control flag. If job==0, then a new QR factorization + * is performed. If job!=0, then it is assumed that the first + * n-1 columns of h have already been factored and only the last + * column needs to be updated. + * + * SUNQRfact returns 0 if successful. If a zero is encountered on + * the diagonal of the triangular factor R, then SUNQRfact returns + * the equation number of the zero entry, where the equations are + * numbered from 1, not 0. If SUNQRsol is subsequently called in + * this situation, it will return an error because it could not + * divide by the zero diagonal entry. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRfact(int n, sunrealtype** h, sunrealtype* q, int job); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRsol + * ----------------------------------------------------------------- + * SUNQRsol solves the linear least squares problem + * + * min (b - H*x, b - H*x), x in R^n, + * + * where H is a Hessenberg matrix, and b is in R^(n+1). + * It uses the QR factors of H computed by SUNQRfact. + * + * n is the problem size; the matrix H is (n+1) by n. + * + * h is a matrix (computed by SUNQRfact) containing the upper + * triangular factor R of the original Hessenberg matrix H. + * + * q is an array of length 2*n (computed by SUNQRfact) containing + * the Givens rotations used to factor H. + * + * b is the (n+1)-vector appearing in the least squares problem + * above. + * + * On return, b contains the solution x of the least squares + * problem, if SUNQRsol was successful. + * + * SUNQRsol returns a 0 if successful. Otherwise, a zero was + * encountered on the diagonal of the triangular factor R. + * In this case, SUNQRsol returns the equation number (numbered + * from 1, not 0) of the zero entry. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRsol(int n, sunrealtype** h, sunrealtype* q, sunrealtype* b); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_MGS + * ----------------------------------------------------------------- + * SUNQRAdd_MGS uses Modified Gram Schmidt to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_MGS was successful. + * + * SUNQRAdd_MGS returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_MGS(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY + * ----------------------------------------------------------------- + * SUNQRAdd_ICWY uses the Inverse Compact WY Modified Gram Schmidt + * method to update the QR factorization stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * - sunrealtype *T (held within (void *) QRdata) + * to include the orthonormalized vector input by + * - N_Vector df. + * where the factorization to be updated is of the form + * Q * T * R + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, sunrealtype *temp_array (this will be used for T) + * + * On return, Q, R, and T contain the updated Q T R factors, if + * SUNQRAdd_ICWY was successful. + * + * SUNQRAdd_ICWY returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_ICWY(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_ICWY but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_ICWY_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_CGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_CGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation to update the QR factorization stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, sunrealtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_CGS2 was successful. + * + * SUNQRAdd_CGS2 returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_CGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_DCGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation that delays reorthogonlization (for the purpose of + * reducing number of inner products) to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, sunrealtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_DCGS2 was successful. + * + * SUNQRAdd_DCGS2 returns a 0 if successful. Otherwise,.... + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_DCGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_DCGS2 but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_DCGS2_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_linearsolver.h b/inst/include/sundials/sundials_linearsolver.h new file mode 100644 index 0000000..6aa6c06 --- /dev/null +++ b/inst/include/sundials/sundials_linearsolver.h @@ -0,0 +1,244 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * David Gardner, Carol Woodward, + * Slaven Peles, Cody Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic linear solver package. + * It defines the SUNLinearSolver structure (_generic_SUNLinearSolver) + * which contains the following fields: + * - an implementation-dependent 'content' field which contains + * any internal data required by the solver + * - an 'ops' filed which contains a structure listing operations + * acting on/by such solvers + * + * We consider both direct linear solvers and iterative linear solvers + * as available implementations of this package. Furthermore, iterative + * linear solvers can either use a matrix or be matrix-free. As a + * result of these different solver characteristics, some of the + * routines are applicable only to some types of linear solver. + * ----------------------------------------------------------------- + * This header file contains: + * - enumeration constants for all SUNDIALS-defined linear solver + * types, as well as a generic type for user-supplied linear + * solver types, + * - type declarations for the _generic_SUNLinearSolver and + * _generic_SUNLinearSolver_Ops structures, as well as references + * to pointers to such structures (SUNLinearSolver), + * - prototypes for the linear solver functions which operate + * on/by SUNLinearSolver objects, and + * - return codes for SUNLinearSolver objects. + * ----------------------------------------------------------------- + * At a minimum, a particular implementation of a SUNLinearSolver must + * do the following: + * - specify the 'content' field of SUNLinearSolver, + * - implement the operations on/by those SUNLinearSolver objects, + * - provide a constructor routine for new SUNLinearSolver objects + * + * Additionally, a SUNLinearSolver implementation may provide the + * following: + * - "Set" routines to control solver-specific parameters/options + * - "Get" routines to access solver-specific performance metrics + * -----------------------------------------------------------------*/ + +#ifndef _SUNLINEARSOLVER_H +#define _SUNLINEARSOLVER_H + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + * Implemented SUNLinearSolver types and IDs: + * ----------------------------------------------------------------- */ + +typedef enum +{ + SUNLINEARSOLVER_DIRECT, + SUNLINEARSOLVER_ITERATIVE, + SUNLINEARSOLVER_MATRIX_ITERATIVE, + SUNLINEARSOLVER_MATRIX_EMBEDDED +} SUNLinearSolver_Type; + +typedef enum +{ + SUNLINEARSOLVER_BAND, + SUNLINEARSOLVER_DENSE, + SUNLINEARSOLVER_KLU, + SUNLINEARSOLVER_LAPACKBAND, + SUNLINEARSOLVER_LAPACKDENSE, + SUNLINEARSOLVER_PCG, + SUNLINEARSOLVER_SPBCGS, + SUNLINEARSOLVER_SPFGMR, + SUNLINEARSOLVER_SPGMR, + SUNLINEARSOLVER_SPTFQMR, + SUNLINEARSOLVER_SUPERLUDIST, + SUNLINEARSOLVER_SUPERLUMT, + SUNLINEARSOLVER_CUSOLVERSP_BATCHQR, + SUNLINEARSOLVER_MAGMADENSE, + SUNLINEARSOLVER_ONEMKLDENSE, + SUNLINEARSOLVER_GINKGO, + SUNLINEARSOLVER_KOKKOSDENSE, + SUNLINEARSOLVER_CUSTOM +} SUNLinearSolver_ID; + +/* ----------------------------------------------------------------- + * Generic definition of SUNLinearSolver + * ----------------------------------------------------------------- */ + +/* Forward reference for pointer to SUNLinearSolver_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver_Ops* SUNLinearSolver_Ops; + +/* Forward reference for pointer to SUNLinearSolver object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver* SUNLinearSolver; + +/* Structure containing function pointers to linear solver operations */ +struct _generic_SUNLinearSolver_Ops +{ + SUNLinearSolver_Type (*gettype)(SUNLinearSolver); + SUNLinearSolver_ID (*getid)(SUNLinearSolver); + SUNErrCode (*setatimes)(SUNLinearSolver, void*, SUNATimesFn); + SUNErrCode (*setpreconditioner)(SUNLinearSolver, void*, SUNPSetupFn, + SUNPSolveFn); + SUNErrCode (*setscalingvectors)(SUNLinearSolver, N_Vector, N_Vector); + SUNErrCode (*setzeroguess)(SUNLinearSolver, sunbooleantype); + SUNErrCode (*initialize)(SUNLinearSolver); + int (*setup)(SUNLinearSolver, SUNMatrix); + int (*solve)(SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, sunrealtype); + int (*numiters)(SUNLinearSolver); + sunrealtype (*resnorm)(SUNLinearSolver); + sunindextype (*lastflag)(SUNLinearSolver); + SUNErrCode (*space)(SUNLinearSolver, long int*, long int*); + N_Vector (*resid)(SUNLinearSolver); + SUNErrCode (*free)(SUNLinearSolver); +}; + +/* A linear solver is a structure with an implementation-dependent + 'content' field, and a pointer to a structure of linear solver + operations corresponding to that implementation. */ +struct _generic_SUNLinearSolver +{ + void* content; + SUNLinearSolver_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------- + * Functions exported by SUNLinearSolver module + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNLinSolFreeEmpty(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, + N_Vector s2); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetZeroGuess(SUNLinearSolver S, sunbooleantype onoff); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +/* TODO(CJB): We should consider changing the return type to long int since + batched solvers could in theory return a very large number here. */ +SUNDIALS_EXPORT +int SUNLinSolNumIters(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunrealtype SUNLinSolResNorm(SUNLinearSolver S); + +SUNDIALS_EXPORT +N_Vector SUNLinSolResid(SUNLinearSolver S); + +/* TODO(CJB): sunindextype being the return type here could cause a problem if + sunindextype happened to be smaller than an int. */ +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree(SUNLinearSolver S); + +/* ----------------------------------------------------------------- + * SUNLinearSolver return values + * ----------------------------------------------------------------- */ + +#define SUNLS_ATIMES_NULL -804 /* atimes function is NULL */ +#define SUNLS_ATIMES_FAIL_UNREC -805 /* atimes unrecoverable failure */ +#define SUNLS_PSET_FAIL_UNREC -806 /* pset unrecoverable failure */ +#define SUNLS_PSOLVE_NULL -807 /* psolve function is NULL */ +#define SUNLS_PSOLVE_FAIL_UNREC -808 /* psolve unrecoverable failure */ +#define SUNLS_GS_FAIL -810 /* Gram-Schmidt failure */ +#define SUNLS_QRSOL_FAIL -811 /* QRsol found singular R */ + +#define SUNLS_RECOV_FAILURE 800 /* generic recoverable failure */ +#define SUNLS_RES_REDUCED 801 /* nonconv. solve, resid reduced */ +#define SUNLS_CONV_FAIL 802 /* nonconvergent solve */ +#define SUNLS_ATIMES_FAIL_REC 803 /* atimes failed recoverably */ +#define SUNLS_PSET_FAIL_REC 804 /* pset failed recoverably */ +#define SUNLS_PSOLVE_FAIL_REC 805 /* psolve failed recoverably */ +#define SUNLS_PACKAGE_FAIL_REC 806 /* external package recov. fail */ +#define SUNLS_QRFACT_FAIL 807 /* QRfact found singular matrix */ +#define SUNLS_LUFACT_FAIL 808 /* LUfact found singular matrix */ + +/* ----------------------------------------------------------------------------- + * SUNLinearSolver messages + * ---------------------------------------------------------------------------*/ + +#if defined(SUNDIALS_EXTENDED_PRECISION) +#define SUNLS_MSG_RESIDUAL "\t\tlin. iteration %ld, lin. residual: %Lg\n" +#elif defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNLS_MSG_RESIDUAL "\t\tlin. iteration %ld, lin. residual: %g\n" +#else +#define SUNLS_MSG_RESIDUAL "\t\tlin. iteration %ld, lin. residual: %g\n" +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/inst/include/sundials/sundials_linearsolver.hpp b/inst/include/sundials/sundials_linearsolver.hpp new file mode 100644 index 0000000..5426611 --- /dev/null +++ b/inst/include/sundials/sundials_linearsolver.hpp @@ -0,0 +1,43 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNLinaerSolver + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_LINEARSOLVER_HPP +#define _SUNDIALS_LINEARSOLVER_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseLinearSolver = + BaseObject<_generic_SUNLinearSolver, _generic_SUNLinearSolver_Ops>; +} // namespace impl + +namespace experimental { +struct SUNLinearSolverDeleter +{ + void operator()(SUNLinearSolver LS) + { + if (LS) { SUNLinSolFree(LS); } + } +}; + +using SUNLinearSolverView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_logger.h b/inst/include/sundials/sundials_logger.h new file mode 100644 index 0000000..7525404 --- /dev/null +++ b/inst/include/sundials/sundials_logger.h @@ -0,0 +1,74 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_LOGGER_H +#define _SUNDIALS_LOGGER_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + SUN_LOGLEVEL_ALL = -1, + SUN_LOGLEVEL_NONE = 0, + SUN_LOGLEVEL_ERROR = 1, + SUN_LOGLEVEL_WARNING = 2, + SUN_LOGLEVEL_INFO = 3, + SUN_LOGLEVEL_DEBUG = 4 +} SUNLogLevel; + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Create(SUNComm comm, int output_rank, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_CreateFromEnv(SUNComm comm, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetErrorFilename(SUNLogger logger, + const char* error_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetWarningFilename(SUNLogger logger, + const char* warning_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetDebugFilename(SUNLogger logger, + const char* debug_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetInfoFilename(SUNLogger logger, const char* info_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl, + const char* scope, const char* label, + const char* msg_txt, ...); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Flush(SUNLogger logger, SUNLogLevel lvl); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_GetOutputRank(SUNLogger logger, int* output_rank); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Destroy(SUNLogger* logger); + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +} +#endif +#endif /* SUNDIALS_LOGGER_H_ */ diff --git a/inst/include/sundials/sundials_math.h b/inst/include/sundials/sundials_math.h new file mode 100644 index 0000000..4585c7c --- /dev/null +++ b/inst/include/sundials/sundials_math.h @@ -0,0 +1,245 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and + * Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a simple C-language math library. The + * routines listed here work with the type sunrealtype as defined in + * the header file sundials_types.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNDIALSMATH_H +#define _SUNDIALSMATH_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + * ----------------------------------------------------------------- + * Macros + * ----------------------------------------------------------------- + * SUNMIN(A,B) returns the minimum of A and B + * + * SUNMAX(A,B) returns the maximum of A and B + * + * SUNSQR(A) returns A^2 + * + * SUNRsqrt calls the appropriate version of sqrt + * + * SUNRabs calls the appropriate version of abs + * + * SUNRexp calls the appropriate version of exp + * + * SUNRceil calls the appropriate version of ceil + * ----------------------------------------------------------------- + */ + +#ifndef SUNMIN +#define SUNMIN(A, B) ((A) < (B) ? (A) : (B)) +#endif + +#ifndef SUNMAX +#define SUNMAX(A, B) ((A) > (B) ? (A) : (B)) +#endif + +#ifndef SUNSQR +#define SUNSQR(A) ((A) * (A)) +#endif + +/* + * ----------------------------------------------------------------- + * Function : SUNRsqrt + * ----------------------------------------------------------------- + * Usage : sunrealtype sqrt_x; + * sqrt_x = SUNRsqrt(x); + * ----------------------------------------------------------------- + * SUNRsqrt(x) returns the square root of x. If x < ZERO, then + * SUNRsqrt returns ZERO. + * ----------------------------------------------------------------- + */ + +#ifndef SUNRsqrt +#if defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrt((x)))) +#elif defined(SUNDIALS_SINGLE_PRECISION) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrtf((x)))) +#elif defined(SUNDIALS_EXTENDED_PRECISION) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrtl((x)))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" +#endif +#endif + +/* + * ----------------------------------------------------------------- + * Function : SUNRabs + * ----------------------------------------------------------------- + * Usage : sunrealtype abs_x; + * abs_x = SUNRabs(x); + * ----------------------------------------------------------------- + * SUNRabs(x) returns the absolute value of x. + * ----------------------------------------------------------------- + */ + +#ifndef SUNRabs +#if defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNRabs(x) (fabs((x))) +#elif defined(SUNDIALS_SINGLE_PRECISION) +#define SUNRabs(x) (fabsf((x))) +#elif defined(SUNDIALS_EXTENDED_PRECISION) +#define SUNRabs(x) (fabsl((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" +#endif +#endif + +/* + * ----------------------------------------------------------------- + * Function : SUNRexp + * ----------------------------------------------------------------- + * Usage : sunrealtype exp_x; + * exp_x = SUNRexp(x); + * ----------------------------------------------------------------- + * SUNRexp(x) returns e^x (base-e exponential function). + * ----------------------------------------------------------------- + */ + +#ifndef SUNRexp +#if defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNRexp(x) (exp((x))) +#elif defined(SUNDIALS_SINGLE_PRECISION) +#define SUNRexp(x) (expf((x))) +#elif defined(SUNDIALS_EXTENDED_PRECISION) +#define SUNRexp(x) (expl((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" +#endif +#endif + +/* + * ----------------------------------------------------------------- + * Function : SUNRceil + * ----------------------------------------------------------------- + * Usage : sunrealtype ceil_x; + * ceil_x = SUNRceil(x); + * ----------------------------------------------------------------- + * SUNRceil(x) returns the smallest integer value not less than x. + * ----------------------------------------------------------------- + */ + +#ifndef SUNRceil +#if defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNRceil(x) (ceil((x))) +#elif defined(SUNDIALS_SINGLE_PRECISION) +#define SUNRceil(x) (ceilf((x))) +#elif defined(SUNDIALS_EXTENDED_PRECISION) +#define SUNRceil(x) (ceill((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" +#endif +#endif + +/* + * ----------------------------------------------------------------- + * Function : SUNRpowerI + * ----------------------------------------------------------------- + * Usage : int exponent; + * sunrealtype base, ans; + * ans = SUNRpowerI(base,exponent); + * ----------------------------------------------------------------- + * SUNRpowerI returns the value of base^exponent, where base is of type + * sunrealtype and exponent is of type int. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT sunrealtype SUNRpowerI(sunrealtype base, int exponent); + +/* + * ----------------------------------------------------------------- + * Function : SUNRpowerR + * ----------------------------------------------------------------- + * Usage : sunrealtype base, exponent, ans; + * ans = SUNRpowerR(base,exponent); + * ----------------------------------------------------------------- + * SUNRpowerR returns the value of base^exponent, where both base and + * exponent are of type sunrealtype. If base < ZERO, then SUNRpowerR + * returns ZERO. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT sunrealtype SUNRpowerR(sunrealtype base, sunrealtype exponent); + +/* + * ----------------------------------------------------------------- + * Function : SUNRCompare + * ----------------------------------------------------------------- + * Usage : int isNotEqual; + * sunrealtype a, b; + * isNotEqual = SUNRCompare(a, b); + * ----------------------------------------------------------------- + * SUNRCompareTol returns 0 if the relative difference of a and b is + * less than or equal to 10*machine epsilon. If the relative + * difference is greater than 10*machine epsilon, it returns 1. The + * function handles the case where a or b are near zero as well as + * the case where a or b are inf/nan. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT sunbooleantype SUNRCompare(sunrealtype a, sunrealtype b); + +/* + * ----------------------------------------------------------------- + * Function : SUNRCompareTol + * ----------------------------------------------------------------- + * Usage : int isNotEqual; + * sunrealtype a, b, tol; + * isNotEqual = SUNRCompareTol(a, b, tol); + * ----------------------------------------------------------------- + * SUNRCompareTol returns 0 if the relative difference of a and b is + * less than or equal to the provided tolerance. If the relative + * difference is greater than the tolerance, it returns 1. The + * function handles the case where a or b are near zero as well as + * the case where a or b are inf/nan. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT sunbooleantype SUNRCompareTol(sunrealtype a, sunrealtype b, + sunrealtype tol); + +/* + * ----------------------------------------------------------------- + * Function : SUNStrToReal + * ----------------------------------------------------------------- + * Usage : sunrealtype a = SUNStrToReal(const char* str) + * ----------------------------------------------------------------- + * SUNStrToReal parses str into the sunrealtype variable. Uses standard + * strtod variants when they are available. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT sunrealtype SUNStrToReal(const char* str); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_matrix.h b/inst/include/sundials/sundials_matrix.h new file mode 100644 index 0000000..40dfdc2 --- /dev/null +++ b/inst/include/sundials/sundials_matrix.h @@ -0,0 +1,156 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * David Gardner, Carol Woodward, Slaven Peles, + * Cody Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic matrix package. + * It defines the SUNMatrix structure (_generic_SUNMatrix) which + * contains the following fields: + * - an implementation-dependent 'content' field which contains + * the description and actual data of the matrix + * - an 'ops' filed which contains a structure listing operations + * acting on such matrices + * ----------------------------------------------------------------- + * This header file contains: + * - enumeration constants for all SUNDIALS-defined matrix types, + * as well as a generic type for user-supplied matrix types, + * - type declarations for the _generic_SUNMatrix and + * _generic_SUNMatrix_Ops structures, as well as references to + * pointers to such structures (SUNMatrix), and + * - prototypes for the matrix functions which operate on + * SUNMatrix objects. + * ----------------------------------------------------------------- + * At a minimum, a particular implementation of a SUNMatrix must + * do the following: + * - specify the 'content' field of SUNMatrix, + * - implement the operations on those SUNMatrix objects, + * - provide a constructor routine for new SUNMatrix objects + * + * Additionally, a SUNMatrix implementation may provide the following: + * - macros to access the underlying SUNMatrix data + * - a routine to print the content of a SUNMatrix + * -----------------------------------------------------------------*/ + +#ifndef _SUNMATRIX_H +#define _SUNMATRIX_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + * Implemented SUNMatrix types + * ----------------------------------------------------------------- */ + +typedef enum +{ + SUNMATRIX_DENSE, + SUNMATRIX_MAGMADENSE, + SUNMATRIX_ONEMKLDENSE, + SUNMATRIX_BAND, + SUNMATRIX_SPARSE, + SUNMATRIX_SLUNRLOC, + SUNMATRIX_CUSPARSE, + SUNMATRIX_GINKGO, + SUNMATRIX_KOKKOSDENSE, + SUNMATRIX_CUSTOM +} SUNMatrix_ID; + +/* ----------------------------------------------------------------- + * Generic definition of SUNMatrix + * ----------------------------------------------------------------- */ + +/* Forward reference for pointer to SUNMatrix_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix_Ops* SUNMatrix_Ops; + +/* Forward reference for pointer to SUNMatrix object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix* SUNMatrix; + +/* Structure containing function pointers to matrix operations */ +struct _generic_SUNMatrix_Ops +{ + SUNMatrix_ID (*getid)(SUNMatrix); + SUNMatrix (*clone)(SUNMatrix); + void (*destroy)(SUNMatrix); + SUNErrCode (*zero)(SUNMatrix); + SUNErrCode (*copy)(SUNMatrix, SUNMatrix); + SUNErrCode (*scaleadd)(sunrealtype, SUNMatrix, SUNMatrix); + SUNErrCode (*scaleaddi)(sunrealtype, SUNMatrix); + SUNErrCode (*matvecsetup)(SUNMatrix); + SUNErrCode (*matvec)(SUNMatrix, N_Vector, N_Vector); + SUNErrCode (*space)(SUNMatrix, long int*, long int*); +}; + +/* A matrix is a structure with an implementation-dependent + 'content' field, and a pointer to a structure of matrix + operations corresponding to that implementation. */ +struct _generic_SUNMatrix +{ + void* content; + SUNMatrix_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------- + * Functions exported by SUNMatrix module + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT +SUNMatrix SUNMatNewEmpty(SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNMatFreeEmpty(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatCopyOps(SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNMatrix_ID SUNMatGetID(SUNMatrix A); + +SUNDIALS_EXPORT +SUNMatrix SUNMatClone(SUNMatrix A); + +SUNDIALS_EXPORT +void SUNMatDestroy(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatZero(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatCopy(SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAdd(sunrealtype c, SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAddI(sunrealtype c, SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvecSetup(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvec(SUNMatrix A, N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +SUNErrCode SUNMatSpace(SUNMatrix A, long int* lenrw, long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNMATRIX_H */ diff --git a/inst/include/sundials/sundials_matrix.hpp b/inst/include/sundials/sundials_matrix.hpp new file mode 100644 index 0000000..b6b8a79 --- /dev/null +++ b/inst/include/sundials/sundials_matrix.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNMatrix + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MATRIX_HPP +#define _SUNDIALS_MATRIX_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseMatrix = BaseObject<_generic_SUNMatrix, _generic_SUNMatrix_Ops>; +} // namespace impl + +namespace experimental { +struct SUNMatrixDeleter +{ + void operator()(SUNMatrix A) + { + if (A) { SUNMatDestroy(A); } + } +}; + +using SUNMatrixView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_memory.h b/inst/include/sundials/sundials_memory.h new file mode 100644 index 0000000..b2ac7c6 --- /dev/null +++ b/inst/include/sundials/sundials_memory.h @@ -0,0 +1,168 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 memory helpers and types. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MEMORY_H +#define _SUNDIALS_MEMORY_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + SUNMEMTYPE_HOST, /* pageable memory accessible on the host */ + SUNMEMTYPE_PINNED, /* page-locked memory accesible on the host */ + SUNMEMTYPE_DEVICE, /* memory accessible from the device */ + SUNMEMTYPE_UVM /* memory accessible from the host or device */ +} SUNMemoryType; + +/* + * SUNMemory is a simple abstraction of a pointer to some + * contiguos memory, so that we can keep track of its type + * and its ownership. + */ + +typedef struct SUNMemory_* SUNMemory; + +struct SUNMemory_ +{ + void* ptr; + SUNMemoryType type; + sunbooleantype own; + size_t bytes; +}; + +/* Creates a new SUNMemory object with a NULL ptr */ +SUNDIALS_EXPORT SUNMemory SUNMemoryNewEmpty(SUNContext sunctx); + +/* + * SUNMemoryHelper holds ops which can allocate, deallocate, + * and copy SUNMemory. + */ + +typedef struct SUNMemoryHelper_Ops_* SUNMemoryHelper_Ops; +typedef struct SUNMemoryHelper_* SUNMemoryHelper; + +struct SUNMemoryHelper_ +{ + void* content; + SUNMemoryHelper_Ops ops; + SUNContext sunctx; +}; + +struct SUNMemoryHelper_Ops_ +{ + /* operations that implementations are required to provide */ + SUNErrCode (*alloc)(SUNMemoryHelper, SUNMemory* memptr, size_t mem_size, + SUNMemoryType mem_type, void* queue); + SUNErrCode (*dealloc)(SUNMemoryHelper, SUNMemory mem, void* queue); + SUNErrCode (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); + + /* operations that provide default implementations */ + SUNErrCode (*copyasync)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); + SUNErrCode (*getallocstats)(SUNMemoryHelper, SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); + SUNMemoryHelper (*clone)(SUNMemoryHelper); + SUNErrCode (*destroy)(SUNMemoryHelper); +}; + +/* + * Generic SUNMemoryHelper functions that work without a SUNMemoryHelper object. + */ + +/* Creates a new SUNMemory object which points to the same data as another + * SUNMemory object. + * The SUNMemory returned will not own the ptr, therefore, it will not free + * the ptr in Dealloc. */ +SUNDIALS_EXPORT +SUNMemory SUNMemoryHelper_Alias(SUNMemoryHelper, SUNMemory mem); + +/* Creates a new SUNMemory object with ptr set to the user provided pointer + * The SUNMemory returned will not own the ptr, therefore, it will not free + * the ptr in Dealloc. */ +SUNDIALS_EXPORT +SUNMemory SUNMemoryHelper_Wrap(SUNMemoryHelper, void* ptr, + SUNMemoryType mem_type); + +/* + * Required SUNMemoryHelper operations. + */ + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Alloc(SUNMemoryHelper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Dealloc(SUNMemoryHelper, SUNMemory mem, void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Copy(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); + +/* + * Optional SUNMemoryHelper operations. + */ + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_CopyAsync(SUNMemoryHelper, SUNMemory dst, + SUNMemory src, size_t mem_size, void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_GetAllocStats(SUNMemoryHelper, SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); + +/* Clones the SUNMemoryHelper */ +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Clone(SUNMemoryHelper); + +/* Frees the SUNMemoryHelper */ +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Destroy(SUNMemoryHelper); + +/* + * Utility SUNMemoryHelper functions. + */ + +/* Creates an empty SUNMemoryHelper object */ +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_NewEmpty(SUNContext sunctx); + +/* Copyies the SUNMemoryHelper ops structure from src->ops to dst->ops. */ +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_CopyOps(SUNMemoryHelper src, SUNMemoryHelper dst); + +/* Checks that all required SUNMemoryHelper ops are provided */ +SUNDIALS_EXPORT +sunbooleantype SUNMemoryHelper_ImplementsRequiredOps(SUNMemoryHelper); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_memory.hpp b/inst/include/sundials/sundials_memory.hpp new file mode 100644 index 0000000..cb64279 --- /dev/null +++ b/inst/include/sundials/sundials_memory.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNMemoryHelper + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MEMORY_HPP +#define _SUNDIALS_MEMORY_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseMemoryHelper = BaseObject; +} // namespace impl + +namespace experimental { +struct SUNMemoryHelperDeleter +{ + void operator()(SUNMemoryHelper helper) + { + if (helper) { SUNMemoryHelper_Destroy(helper); } + } +}; + +using SUNMemoryHelperView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_mpi_types.h b/inst/include/sundials/sundials_mpi_types.h new file mode 100644 index 0000000..697327e --- /dev/null +++ b/inst/include/sundials/sundials_mpi_types.h @@ -0,0 +1,38 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file contains definitions of MPI data types, which + * are used by MPI parallel vector implementations. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MPI_TYPES_H +#define _SUNDIALS_MPI_TYPES_H + +#include +#include + +/* define MPI data types */ + +#if defined(SUNDIALS_SINGLE_PRECISION) +#define MPI_SUNREALTYPE MPI_FLOAT +#elif defined(SUNDIALS_DOUBLE_PRECISION) +#define MPI_SUNREALTYPE MPI_DOUBLE +#elif defined(SUNDIALS_EXTENDED_PRECISION) +#define MPI_SUNREALTYPE MPI_LONG_DOUBLE +#endif + +#if defined(SUNDIALS_INT64_T) +#define MPI_SUNINDEXTYPE MPI_INT64_T +#elif defined(SUNDIALS_INT32_T) +#define MPI_SUNINDEXTYPE MPI_INT32_T +#endif + +#endif /* _SUNDIALS_MPI_TYPES_H */ diff --git a/inst/include/sundials/sundials_nonlinearsolver.h b/inst/include/sundials/sundials_nonlinearsolver.h new file mode 100644 index 0000000..a4b2e15 --- /dev/null +++ b/inst/include/sundials/sundials_nonlinearsolver.h @@ -0,0 +1,211 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner, and Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic nonlinear solver package. It defines + * the SUNNonlinearSolver structure (_generic_SUNNonlinearSolver) which contains + * the following fields: + * - an implementation-dependent 'content' field which contains any internal + * data required by the solver + * - an 'ops' filed which contains a structure listing operations acting on/by + * such solvers + * + * We consider iterative nonlinear solvers for systems in both root finding + * (F(y) = 0) or fixed-point (G(y) = y) form. As a result, some of the routines + * are applicable only to one type of nonlinear solver. + * ----------------------------------------------------------------------------- + * This header file contains: + * - function types supplied to a SUNNonlinearSolver, + * - enumeration constants for SUNDIALS-defined nonlinear solver types, + * - type declarations for the _generic_SUNNonlinearSolver and + * _generic_SUNNonlinearSolver_Ops structures, as well as references to + * pointers to such structures (SUNNonlinearSolver), + * - prototypes for the nonlinear solver functions which operate + * on/by SUNNonlinearSolver objects, and + * - return codes for SUNNonLinearSolver objects. + * ----------------------------------------------------------------------------- + * At a minimum, a particular implementation of a SUNNonlinearSolver must do the + * following: + * - specify the 'content' field of a SUNNonlinearSolver, + * - implement the operations on/by the SUNNonlinearSovler objects, + * - provide a constructor routine for new SUNNonlinearSolver objects + * + * Additionally, a SUNNonlinearSolver implementation may provide the following: + * - "Set" routines to control solver-specific parameters/options + * - "Get" routines to access solver-specific performance metrics + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNNONLINEARSOLVER_H +#define _SUNNONLINEARSOLVER_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * Forward references for SUNNonlinearSolver types defined below + * ---------------------------------------------------------------------------*/ + +/* Forward reference for pointer to SUNNonlinearSolver_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver_Ops* SUNNonlinearSolver_Ops; + +/* Forward reference for pointer to SUNNonlinearSolver object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver* SUNNonlinearSolver; + +/* ----------------------------------------------------------------------------- + * Integrator supplied function types + * ---------------------------------------------------------------------------*/ + +typedef int (*SUNNonlinSolSysFn)(N_Vector y, N_Vector F, void* mem); + +typedef int (*SUNNonlinSolLSetupFn)(sunbooleantype jbad, sunbooleantype* jcur, + void* mem); + +typedef int (*SUNNonlinSolLSolveFn)(N_Vector b, void* mem); + +typedef int (*SUNNonlinSolConvTestFn)(SUNNonlinearSolver NLS, N_Vector y, + N_Vector del, sunrealtype tol, + N_Vector ewt, void* mem); + +/* ----------------------------------------------------------------------------- + * SUNNonlinearSolver types + * ---------------------------------------------------------------------------*/ + +typedef enum +{ + SUNNONLINEARSOLVER_ROOTFIND, + SUNNONLINEARSOLVER_FIXEDPOINT +} SUNNonlinearSolver_Type; + +/* ----------------------------------------------------------------------------- + * Generic definition of SUNNonlinearSolver + * ---------------------------------------------------------------------------*/ + +/* Structure containing function pointers to nonlinear solver operations */ +struct _generic_SUNNonlinearSolver_Ops +{ + SUNNonlinearSolver_Type (*gettype)(SUNNonlinearSolver); + SUNErrCode (*initialize)(SUNNonlinearSolver); + int (*setup)(SUNNonlinearSolver, N_Vector, void*); + int (*solve)(SUNNonlinearSolver, N_Vector, N_Vector, N_Vector, sunrealtype, + sunbooleantype, void*); + SUNErrCode (*free)(SUNNonlinearSolver); + SUNErrCode (*setsysfn)(SUNNonlinearSolver, SUNNonlinSolSysFn); + SUNErrCode (*setlsetupfn)(SUNNonlinearSolver, SUNNonlinSolLSetupFn); + SUNErrCode (*setlsolvefn)(SUNNonlinearSolver, SUNNonlinSolLSolveFn); + SUNErrCode (*setctestfn)(SUNNonlinearSolver, SUNNonlinSolConvTestFn, void*); + SUNErrCode (*setmaxiters)(SUNNonlinearSolver, int); + SUNErrCode (*getnumiters)(SUNNonlinearSolver, long int*); + SUNErrCode (*getcuriter)(SUNNonlinearSolver, int*); + SUNErrCode (*getnumconvfails)(SUNNonlinearSolver, long int*); +}; + +/* A nonlinear solver is a structure with an implementation-dependent 'content' + field, and a pointer to a structure of solver nonlinear solver operations + corresponding to that implementation. */ +struct _generic_SUNNonlinearSolver +{ + void* content; + SUNNonlinearSolver_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------------------- + * Functions exported by SUNNonlinearSolver module + * ---------------------------------------------------------------------------*/ + +/* empty constructor/destructor */ +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSolNewEmpty(SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNNonlinSolFreeEmpty(SUNNonlinearSolver NLS); + +/* core functions */ +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +int SUNNonlinSolSetup(SUNNonlinearSolver NLS, N_Vector y, void* mem); + +SUNDIALS_EXPORT +int SUNNonlinSolSolve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, N_Vector w, + sunrealtype tol, sunbooleantype callLSetup, void* mem); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree(SUNNonlinearSolver NLS); + +/* set functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSetupFn(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn SetupFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSolveFn(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn SolveFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters(SUNNonlinearSolver NLS, int maxiters); + +/* get functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters(SUNNonlinearSolver NLS, long int* niters); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter(SUNNonlinearSolver NLS, int* iter); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails(SUNNonlinearSolver NLS, + long int* nconvfails); + +/* ----------------------------------------------------------------------------- + * SUNNonlinearSolver return values + * ---------------------------------------------------------------------------*/ + +/* Recoverable */ +#define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ +#define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ + +/* ----------------------------------------------------------------------------- + * SUNNonlinearSolver messages + * ---------------------------------------------------------------------------*/ + +#if defined(SUNDIALS_EXTENDED_PRECISION) +#define SUN_NLS_MSG_RESIDUAL "\tnonlin. iteration %ld, nonlin. residual: %Lg\n" +#elif defined(SUNDIALS_DOUBLE_PRECISION) +#define SUN_NLS_MSG_RESIDUAL "\tnonlin. iteration %ld, nonlin. residual: %g\n" +#else +#define SUN_NLS_MSG_RESIDUAL "\tnonlin. iteration %ld, nonlin. residual: %g\n" +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_nonlinearsolver.hpp b/inst/include/sundials/sundials_nonlinearsolver.hpp new file mode 100644 index 0000000..d4a5cae --- /dev/null +++ b/inst/include/sundials/sundials_nonlinearsolver.hpp @@ -0,0 +1,44 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNNonlinearSolver + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_NONLINEARSOLVER_HPP +#define _SUNDIALS_NONLINEARSOLVER_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseNonlinearSolver = + BaseObject<_generic_SUNNonlinearSolver, _generic_SUNNonlinearSolver_Ops>; +} // namespace impl + +namespace experimental { +struct SUNNonlinearSolverDeleter +{ + void operator()(SUNNonlinearSolver NLS) + { + if (NLS) { SUNNonlinSolFree(NLS); } + } +}; + +using SUNNonlinearSolverView = + ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_nvector.h b/inst/include/sundials/sundials_nvector.h new file mode 100644 index 0000000..68ea934 --- /dev/null +++ b/inst/include/sundials/sundials_nvector.h @@ -0,0 +1,348 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Radu Serban and Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for a generic NVECTOR package. + * It defines the N_Vector structure (_generic_N_Vector) which + * contains the following fields: + * - an implementation-dependent 'content' field which contains + * the description and actual data of the vector + * - an 'ops' filed which contains a structure listing operations + * acting on such vectors + * ----------------------------------------------------------------- + * This header file contains: + * - enumeration constants for all SUNDIALS-defined vector types, + * as well as a generic type for user-supplied vector types, + * - type declarations for the _generic_N_Vector and + * _generic_N_Vector_Ops structures, as well as references to + * pointers to such structures (N_Vector), and + * - prototypes for the vector functions which operate on + * N_Vector objects. + * ----------------------------------------------------------------- + * At a minimum, a particular implementation of an NVECTOR must + * do the following: + * - specify the 'content' field of N_Vector, + * - implement the operations on those N_Vector objects, + * - provide a constructor routine for new N_Vector objects + * + * Additionally, an NVECTOR implementation may provide the following: + * - macros to access the underlying N_Vector data + * - a constructor for an array of N_Vectors + * - a constructor for an empty N_Vector (i.e., a new N_Vector with + * a NULL data pointer). + * - a routine to print the content of an N_Vector + * -----------------------------------------------------------------*/ + +#ifndef _NVECTOR_H +#define _NVECTOR_H + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + * Implemented N_Vector types + * ----------------------------------------------------------------- */ + +typedef enum +{ + SUNDIALS_NVEC_SERIAL, + SUNDIALS_NVEC_PARALLEL, + SUNDIALS_NVEC_OPENMP, + SUNDIALS_NVEC_PTHREADS, + SUNDIALS_NVEC_PARHYP, + SUNDIALS_NVEC_PETSC, + SUNDIALS_NVEC_CUDA, + SUNDIALS_NVEC_HIP, + SUNDIALS_NVEC_SYCL, + SUNDIALS_NVEC_RAJA, + SUNDIALS_NVEC_KOKKOS, + SUNDIALS_NVEC_OPENMPDEV, + SUNDIALS_NVEC_TRILINOS, + SUNDIALS_NVEC_MANYVECTOR, + SUNDIALS_NVEC_MPIMANYVECTOR, + SUNDIALS_NVEC_MPIPLUSX, + SUNDIALS_NVEC_CUSTOM +} N_Vector_ID; + +/* ----------------------------------------------------------------- + * Generic definition of N_Vector + * ----------------------------------------------------------------- */ + +/* Forward reference for pointer to N_Vector_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_N_Vector_Ops* N_Vector_Ops; + +/* Forward reference for pointer to N_Vector object */ +typedef _SUNDIALS_STRUCT_ _generic_N_Vector* N_Vector; + +/* Define array of N_Vectors */ +typedef N_Vector* N_Vector_S; + +/* Structure containing function pointers to vector operations */ +struct _generic_N_Vector_Ops +{ + /* + * REQUIRED operations. + * + * These must be implemented by derivations of the generic N_Vector. + */ + + /* constructors, destructors, and utility operations */ + N_Vector_ID (*nvgetvectorid)(N_Vector); + N_Vector (*nvclone)(N_Vector); + N_Vector (*nvcloneempty)(N_Vector); + void (*nvdestroy)(N_Vector); + void (*nvspace)(N_Vector, sunindextype*, sunindextype*); + sunrealtype* (*nvgetarraypointer)(N_Vector); + sunrealtype* (*nvgetdevicearraypointer)(N_Vector); + void (*nvsetarraypointer)(sunrealtype*, N_Vector); + SUNComm (*nvgetcommunicator)(N_Vector); + sunindextype (*nvgetlength)(N_Vector); + sunindextype (*nvgetlocallength)(N_Vector); + + /* standard vector operations */ + void (*nvlinearsum)(sunrealtype, N_Vector, sunrealtype, N_Vector, N_Vector); + void (*nvconst)(sunrealtype, N_Vector); + void (*nvprod)(N_Vector, N_Vector, N_Vector); + void (*nvdiv)(N_Vector, N_Vector, N_Vector); + void (*nvscale)(sunrealtype, N_Vector, N_Vector); + void (*nvabs)(N_Vector, N_Vector); + void (*nvinv)(N_Vector, N_Vector); + void (*nvaddconst)(N_Vector, sunrealtype, N_Vector); + sunrealtype (*nvdotprod)(N_Vector, N_Vector); + sunrealtype (*nvmaxnorm)(N_Vector); + sunrealtype (*nvwrmsnorm)(N_Vector, N_Vector); + sunrealtype (*nvwrmsnormmask)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvmin)(N_Vector); + sunrealtype (*nvwl2norm)(N_Vector, N_Vector); + sunrealtype (*nvl1norm)(N_Vector); + void (*nvcompare)(sunrealtype, N_Vector, N_Vector); + sunbooleantype (*nvinvtest)(N_Vector, N_Vector); + sunbooleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvminquotient)(N_Vector, N_Vector); + + /* + * OPTIONAL operations. + * + * These operations provide default implementations that may be overriden. + */ + + /* OPTIONAL fused vector operations */ + SUNErrCode (*nvlinearcombination)(int, sunrealtype*, N_Vector*, N_Vector); + SUNErrCode (*nvscaleaddmulti)(int, sunrealtype*, N_Vector, N_Vector*, + N_Vector*); + SUNErrCode (*nvdotprodmulti)(int, N_Vector, N_Vector*, sunrealtype*); + + /* OPTIONAL vector array operations */ + SUNErrCode (*nvlinearsumvectorarray)(int, sunrealtype, N_Vector*, sunrealtype, + N_Vector*, N_Vector*); + SUNErrCode (*nvscalevectorarray)(int, sunrealtype*, N_Vector*, N_Vector*); + SUNErrCode (*nvconstvectorarray)(int, sunrealtype, N_Vector*); + SUNErrCode (*nvwrmsnormvectorarray)(int, N_Vector*, N_Vector*, sunrealtype*); + SUNErrCode (*nvwrmsnormmaskvectorarray)(int, N_Vector*, N_Vector*, N_Vector, + sunrealtype*); + SUNErrCode (*nvscaleaddmultivectorarray)(int, int, sunrealtype*, N_Vector*, + N_Vector**, N_Vector**); + SUNErrCode (*nvlinearcombinationvectorarray)(int, int, sunrealtype*, + N_Vector**, N_Vector*); + + /* + * OPTIONAL operations with no default implementation. + */ + + /* Local reduction kernels (no parallel communication) */ + sunrealtype (*nvdotprodlocal)(N_Vector, N_Vector); + sunrealtype (*nvmaxnormlocal)(N_Vector); + sunrealtype (*nvminlocal)(N_Vector); + sunrealtype (*nvl1normlocal)(N_Vector); + sunbooleantype (*nvinvtestlocal)(N_Vector, N_Vector); + sunbooleantype (*nvconstrmasklocal)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvminquotientlocal)(N_Vector, N_Vector); + sunrealtype (*nvwsqrsumlocal)(N_Vector, N_Vector); + sunrealtype (*nvwsqrsummasklocal)(N_Vector, N_Vector, N_Vector); + + /* Single buffer reduction operations */ + SUNErrCode (*nvdotprodmultilocal)(int, N_Vector, N_Vector*, sunrealtype*); + SUNErrCode (*nvdotprodmultiallreduce)(int, N_Vector, sunrealtype*); + + /* XBraid interface operations */ + SUNErrCode (*nvbufsize)(N_Vector, sunindextype*); + SUNErrCode (*nvbufpack)(N_Vector, void*); + SUNErrCode (*nvbufunpack)(N_Vector, void*); + + /* Debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined). */ + void (*nvprint)(N_Vector); + void (*nvprintfile)(N_Vector, FILE*); +}; + +/* A vector is a structure with an implementation-dependent + 'content' field, and a pointer to a structure of vector + operations corresponding to that implementation. */ +struct _generic_N_Vector +{ + void* content; + N_Vector_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------- + * Functions exported by NVECTOR module + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT N_Vector N_VNewEmpty(SUNContext sunctx); +SUNDIALS_EXPORT void N_VFreeEmpty(N_Vector v); +SUNDIALS_EXPORT SUNErrCode N_VCopyOps(N_Vector w, N_Vector v); + +/* + * Required operations. + */ + +SUNDIALS_EXPORT N_Vector_ID N_VGetVectorID(N_Vector w); +SUNDIALS_EXPORT N_Vector N_VClone(N_Vector w); +SUNDIALS_EXPORT N_Vector N_VCloneEmpty(N_Vector w); +SUNDIALS_EXPORT void N_VDestroy(N_Vector v); +SUNDIALS_EXPORT void N_VSpace(N_Vector v, sunindextype* lrw, sunindextype* liw); +SUNDIALS_EXPORT sunrealtype* N_VGetArrayPointer(N_Vector v); +SUNDIALS_EXPORT sunrealtype* N_VGetDeviceArrayPointer(N_Vector v); +SUNDIALS_EXPORT void N_VSetArrayPointer(sunrealtype* v_data, N_Vector v); +SUNDIALS_EXPORT SUNComm N_VGetCommunicator(N_Vector v); +SUNDIALS_EXPORT sunindextype N_VGetLength(N_Vector v); +SUNDIALS_EXPORT sunindextype N_VGetLocalLength(N_Vector v); + +/* standard vector operations */ +SUNDIALS_EXPORT void N_VLinearSum(sunrealtype a, N_Vector x, sunrealtype b, + N_Vector y, N_Vector z); +SUNDIALS_EXPORT void N_VConst(sunrealtype c, N_Vector z); +SUNDIALS_EXPORT void N_VProd(N_Vector x, N_Vector y, N_Vector z); +SUNDIALS_EXPORT void N_VDiv(N_Vector x, N_Vector y, N_Vector z); +SUNDIALS_EXPORT void N_VScale(sunrealtype c, N_Vector x, N_Vector z); +SUNDIALS_EXPORT void N_VAbs(N_Vector x, N_Vector z); +SUNDIALS_EXPORT void N_VInv(N_Vector x, N_Vector z); +SUNDIALS_EXPORT void N_VAddConst(N_Vector x, sunrealtype b, N_Vector z); +SUNDIALS_EXPORT sunrealtype N_VDotProd(N_Vector x, N_Vector y); +SUNDIALS_EXPORT sunrealtype N_VMaxNorm(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWrmsNorm(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VWrmsNormMask(N_Vector x, N_Vector w, N_Vector id); +SUNDIALS_EXPORT sunrealtype N_VMin(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWL2Norm(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VL1Norm(N_Vector x); +SUNDIALS_EXPORT void N_VCompare(sunrealtype c, N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VInvTest(N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); +SUNDIALS_EXPORT sunrealtype N_VMinQuotient(N_Vector num, N_Vector denom); + +/* + * OPTIONAL operations with default implementations. + */ + +/* fused vector operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombination(int nvec, sunrealtype* c, N_Vector* X, + N_Vector z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMulti(int nvec, sunrealtype* a, N_Vector x, N_Vector* Y, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); + +/* vector array operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearSumVectorArray(int nvec, sunrealtype a, N_Vector* X, + sunrealtype b, N_Vector* Y, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleVectorArray(int nvec, sunrealtype* c, N_Vector* X, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VConstVectorArray(int nvec, sunrealtype c, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormVectorArray(int nvec, N_Vector* X, N_Vector* W, + sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormMaskVectorArray(int nvec, N_Vector* X, N_Vector* W, + N_Vector id, sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMultiVectorArray(int nvec, int nsum, sunrealtype* a, + N_Vector* X, N_Vector** Y, N_Vector** Z); + +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombinationVectorArray(int nvec, int nsum, sunrealtype* c, + N_Vector** X, N_Vector* Z); + +/* + * OPTIONAL operations with no default implementation. + */ + +/* local reduction kernels (no parallel communication) */ +SUNDIALS_EXPORT sunrealtype N_VDotProdLocal(N_Vector x, N_Vector y); +SUNDIALS_EXPORT sunrealtype N_VMaxNormLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VMinLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VL1NormLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWSqrSumLocal(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VWSqrSumMaskLocal(N_Vector x, N_Vector w, + N_Vector id); +SUNDIALS_EXPORT sunbooleantype N_VInvTestLocal(N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VConstrMaskLocal(N_Vector c, N_Vector x, + N_Vector m); +SUNDIALS_EXPORT sunrealtype N_VMinQuotientLocal(N_Vector num, N_Vector denom); + +/* single buffer reduction operations */ +SUNDIALS_EXPORT SUNErrCode N_VDotProdMultiLocal(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); +SUNDIALS_EXPORT SUNErrCode N_VDotProdMultiAllReduce(int nvec_total, N_Vector x, + sunrealtype* sum); + +/* XBraid interface operations */ +SUNDIALS_EXPORT SUNErrCode N_VBufSize(N_Vector x, sunindextype* size); +SUNDIALS_EXPORT SUNErrCode N_VBufPack(N_Vector x, void* buf); +SUNDIALS_EXPORT SUNErrCode N_VBufUnpack(N_Vector x, void* buf); + +/* ----------------------------------------------------------------- + * Additional functions exported by NVECTOR module + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT N_Vector* N_VNewVectorArray(int count, SUNContext sunctx); +SUNDIALS_EXPORT N_Vector* N_VCloneEmptyVectorArray(int count, N_Vector w); +SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray(int count, N_Vector w); +SUNDIALS_EXPORT void N_VDestroyVectorArray(N_Vector* vs, int count); + +/* These function are really only for users of the Fortran interface */ +SUNDIALS_EXPORT N_Vector N_VGetVecAtIndexVectorArray(N_Vector* vs, int index); +SUNDIALS_EXPORT void N_VSetVecAtIndexVectorArray(N_Vector* vs, int index, + N_Vector w); + +/* ----------------------------------------------------------------- + * Debugging functions + * ----------------------------------------------------------------- */ + +SUNDIALS_EXPORT void N_VPrint(N_Vector v); +SUNDIALS_EXPORT void N_VPrintFile(N_Vector v, FILE* outfile); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sundials/sundials_nvector.hpp b/inst/include/sundials/sundials_nvector.hpp new file mode 100644 index 0000000..e8151fa --- /dev/null +++ b/inst/include/sundials/sundials_nvector.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS NVector + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_NVECTOR_HPP +#define _SUNDIALS_NVECTOR_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseNVector = BaseObject<_generic_N_Vector, _generic_N_Vector_Ops>; +} // namespace impl + +namespace experimental { +struct NVectorDeleter +{ + void operator()(N_Vector v) + { + if (v) { N_VDestroy(v); } + } +}; + +using NVectorView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/inst/include/sundials/sundials_profiler.h b/inst/include/sundials/sundials_profiler.h new file mode 100644 index 0000000..98da9e4 --- /dev/null +++ b/inst/include/sundials/sundials_profiler.h @@ -0,0 +1,101 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_PROFILER_H +#define _SUNDIALS_PROFILER_H + +#include +#include +#include + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) +#include "caliper/cali.h" +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Create(SUNComm comm, const char* title, SUNProfiler* p); +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Free(SUNProfiler* p); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Begin(SUNProfiler p, const char* name); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_End(SUNProfiler p, const char* name); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_GetTimerResolution(SUNProfiler p, double* resolution); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_GetElapsedTime(SUNProfiler p, const char* name, + double* time); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Print(SUNProfiler p, FILE* fp); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Reset(SUNProfiler p); + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) CALI_MARK_FUNCTION_BEGIN + +#define SUNDIALS_MARK_FUNCTION_END(profobj) CALI_MARK_FUNCTION_END + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \ + CALI_WRAP_STATEMENT(name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) CALI_MARK_BEGIN(name) + +#define SUNDIALS_MARK_END(profobj, name) CALI_MARK_END(name) + +#elif defined(SUNDIALS_BUILD_WITH_PROFILING) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) \ + SUNProfiler_Begin(profobj, __func__) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) SUNProfiler_End(profobj, __func__) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \ + SUNProfiler_Begin(profobj, (name)); \ + stmt; \ + SUNProfiler_End(profobj, (name)); + +#define SUNDIALS_MARK_BEGIN(profobj, name) SUNProfiler_Begin(profobj, (name)) + +#define SUNDIALS_MARK_END(profobj, name) SUNProfiler_End(profobj, (name)) + +#else + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) + +#define SUNDIALS_MARK_END(profobj, name) + +#endif + +#ifdef __cplusplus +} + +#endif +#endif /* SUNDIALS_PROFILER_H */ diff --git a/inst/include/sundials/sundials_profiler.hpp b/inst/include/sundials/sundials_profiler.hpp new file mode 100644 index 0000000..df589fa --- /dev/null +++ b/inst/include/sundials/sundials_profiler.hpp @@ -0,0 +1,52 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_PROFILER_HPP +#define _SUNDIALS_PROFILER_HPP + +#include +#include +#include + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) +#define SUNDIALS_CXX_MARK_FUNCTION(projobj) CALI_CXX_MARK_FUNCTION +#elif defined(SUNDIALS_BUILD_WITH_PROFILING) +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) \ + sundials::ProfilerMarkScope ProfilerMarkScope__(profobj, __func__) +#else +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) +#endif + +namespace sundials { +/* Convenience class for C++ codes. + Allows for simpler profiler statements using C++ scoping rules. */ +class ProfilerMarkScope +{ +public: + ProfilerMarkScope(SUNProfiler prof, const char* name) + { + prof_ = prof; + name_ = name; + SUNProfiler_Begin(prof_, name_); + } + + ~ProfilerMarkScope() { SUNProfiler_End(prof_, name_); } + +private: + SUNProfiler prof_; + const char* name_; +}; +} // namespace sundials + +#endif /* SUNDIALS_PROFILER_HPP */ diff --git a/inst/include/sundials/sundials_types.h b/inst/include/sundials/sundials_types.h new file mode 100644 index 0000000..c959b6f --- /dev/null +++ b/inst/include/sundials/sundials_types.h @@ -0,0 +1,233 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Scott Cohen, Alan Hindmarsh, Radu Serban, + * Aaron Collier, and Slaven Peles @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file exports three types: sunrealtype, sunindextype, + * and sunbooleantype, as well as the constants SUNTRUE and SUNFALSE. + * + * Users should include the header file sundials_types.h in every + * program file and use the exported name sunrealtype instead of + * float, double or long double. + * + * The constants SUNDIALS_SINGLE_PRECISION, SUNDIALS_DOUBLE_PRECISION + * and SUNDIALS_LONG_DOUBLE_PRECISION indicate the underlying data + * type of sunrealtype. + * + * The legal types for sunrealtype are float, double and long double. + * + * The constants SUNDIALS_INT64_T and SUNDIALS_INT32_T indicate + * the underlying data type of sunindextype -- the integer data type + * used for vector and matrix indices. + * + * Data types are set at the configuration stage. + * + * The macro SUN_RCONST gives the user a convenient way to define + * real-valued literal constants. To use the constant 1.0, for example, + * the user should write the following: + * + * #define ONE SUN_RCONST(1.0) + * + * If sunrealtype is defined as a double, then SUN_RCONST(1.0) expands + * to 1.0. If sunrealtype is defined as a float, then SUN_RCONST(1.0) + * expands to 1.0F. If sunrealtype is defined as a long double, + * then SUN_RCONST(1.0) expands to 1.0L. There is never a need to + * explicitly cast 1.0 to (sunrealtype). The macro can be used for + * literal constants only. It cannot be used for expressions. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_TYPES_H +#define _SUNDIALS_TYPES_H + +#include +#include +#include +#include + +#if SUNDIALS_MPI_ENABLED +#include +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + *------------------------------------------------------------------ + * Macro _SUNDIALS_STRUCT_ + * The _SUNDIALS_STRUCT_ macro is defined as a `struct` unless + * generating the SWIG interfaces - in that case it is defined as + * nothing. This is needed to work around a bug in SWIG which prevents + * it from properly parsing our generic module structures. + *------------------------------------------------------------------ + */ +#ifdef SWIG +#define _SUNDIALS_STRUCT_ +#else +#define _SUNDIALS_STRUCT_ struct +#endif + +/* + *------------------------------------------------------------------ + * Type sunrealtype + * Macro SUN_RCONST + * Constants SUN_SMALL_REAL, SUN_BIG_REAL, and SUN_UNIT_ROUNDOFF + *------------------------------------------------------------------ + */ + +#if defined(SUNDIALS_SINGLE_PRECISION) + +typedef float sunrealtype; +#define SUN_RCONST(x) x##F +#define SUN_BIG_REAL FLT_MAX +#define SUN_SMALL_REAL FLT_MIN +#define SUN_UNIT_ROUNDOFF FLT_EPSILON + +#elif defined(SUNDIALS_DOUBLE_PRECISION) + +typedef double sunrealtype; +#define SUN_RCONST(x) x +#define SUN_BIG_REAL DBL_MAX +#define SUN_SMALL_REAL DBL_MIN +#define SUN_UNIT_ROUNDOFF DBL_EPSILON + +#elif defined(SUNDIALS_EXTENDED_PRECISION) + +typedef long double sunrealtype; +#define SUN_RCONST(x) x##L +#define SUN_BIG_REAL LDBL_MAX +#define SUN_SMALL_REAL LDBL_MIN +#define SUN_UNIT_ROUNDOFF LDBL_EPSILON + +#endif + +/* + *------------------------------------------------------------------ + * Type : sunindextype + *------------------------------------------------------------------ + * Defines integer type to be used for vector and matrix indices. + * User can build sundials to use 32- or 64-bit signed integers. + * If compiler does not support portable data types, the SUNDIALS + * CMake build system tries to find a type of the desired size. + *------------------------------------------------------------------ + */ + +typedef SUNDIALS_INDEX_TYPE sunindextype; + +/* + *------------------------------------------------------------------ + * Type : sunbooleantype + *------------------------------------------------------------------ + * Constants : SUNFALSE and SUNTRUE + *------------------------------------------------------------------ + * ANSI C does not have a built-in boolean data type. Below is the + * definition for a new type called sunbooleantype. The advantage of + * using the name sunbooleantype (instead of int) is an increase in + * code readability. It also allows the programmer to make a + * distinction between int and boolean data. Variables of type + * sunbooleantype are intended to have only the two values SUNFALSE and + * SUNTRUE which are defined below to be equal to 0 and 1, + * respectively. + *------------------------------------------------------------------ + */ + +#ifndef sunbooleantype +#define sunbooleantype int +#endif + +#ifndef SUNFALSE +#define SUNFALSE 0 +#endif + +#ifndef SUNTRUE +#define SUNTRUE 1 +#endif + +/* + *------------------------------------------------------------------ + * Type : SUNOutputFormat + *------------------------------------------------------------------ + * Constants for different output formats + *------------------------------------------------------------------ + */ + +typedef enum +{ + SUN_OUTPUTFORMAT_TABLE, + SUN_OUTPUTFORMAT_CSV +} SUNOutputFormat; + +/* + *------------------------------------------------------------------ + * Type : SUNErrCode + *------------------------------------------------------------------ + * Error code type + *------------------------------------------------------------------ + */ + +typedef int SUNErrCode; + +/* ----------------------------------------------------------------------------- + * Forward declarations of SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +/* SUNDIALS context -- see sundials_context_impl.h */ +typedef struct SUNContext_* SUNContext; + +/* SUNDIALS error handler -- see sundials_errors.h */ +typedef struct SUNErrHandler_* SUNErrHandler; + +/* SUNDIALS profiler */ +typedef struct SUNProfiler_* SUNProfiler; + +/* SUNDIALS logger */ +typedef struct SUNLogger_* SUNLogger; + +/* ----------------------------------------------------------------------------- + * SUNDIALS function types + * ---------------------------------------------------------------------------*/ + +/* Error handler function */ +typedef void (*SUNErrHandlerFn)(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +/* + *------------------------------------------------------------------ + * Type : SUNComm + *------------------------------------------------------------------ + * SUNComm replaces MPI_Comm use in SUNDIALS code. It maps to + * MPI_Comm when MPI is enabled. + *------------------------------------------------------------------ + */ + +/* We don't define SUN_COMM_NULL when SWIG is processing the header + because we manually insert the wrapper code for SUN_COMM_NULL + (and %ignoring it in the SWIG code doesn't seem to work). */ + +#if SUNDIALS_MPI_ENABLED +#ifndef SWIG +#define SUN_COMM_NULL MPI_COMM_NULL +#endif +typedef MPI_Comm SUNComm; +#else +#ifndef SWIG +#define SUN_COMM_NULL 0 +#endif +typedef int SUNComm; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_TYPES_H */ diff --git a/inst/include/sundials/sundials_types_deprecated.h b/inst/include/sundials/sundials_types_deprecated.h new file mode 100644 index 0000000..4313639 --- /dev/null +++ b/inst/include/sundials/sundials_types_deprecated.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file exports realtype and booleantype and a few macros + * related to realtype for backwards compatibility. It is preferable + * to only use the types defined in sundials_types.h . + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_TYPES_DEPRECATED_H +#define _SUNDIALS_TYPES_DEPRECATED_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + *------------------------------------------------------------------ + * Type realtype + * Macro RCONST + * Constants SMALL_REAL, BIG_REAL, and UNIT_ROUNDOFF + *------------------------------------------------------------------ + */ + +#if defined(SUNDIALS_SINGLE_PRECISION) + +typedef float realtype; +#define RCONST(x) x##F +#define BIG_REAL FLT_MAX +#define SMALL_REAL FLT_MIN +#define UNIT_ROUNDOFF FLT_EPSILON + +#elif defined(SUNDIALS_DOUBLE_PRECISION) + +typedef double realtype; +#define RCONST(x) x +#define BIG_REAL DBL_MAX +#define SMALL_REAL DBL_MIN +#define UNIT_ROUNDOFF DBL_EPSILON + +#elif defined(SUNDIALS_EXTENDED_PRECISION) + +typedef long double realtype; +#define RCONST(x) x##L +#define BIG_REAL LDBL_MAX +#define SMALL_REAL LDBL_MIN +#define UNIT_ROUNDOFF LDBL_EPSILON + +#endif + +#ifndef booleantype +#define booleantype int +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_TYPES_DEPRECATED_H */ diff --git a/inst/include/sundials/sundials_version.h b/inst/include/sundials/sundials_version.h new file mode 100644 index 0000000..ca47c68 --- /dev/null +++ b/inst/include/sundials/sundials_version.h @@ -0,0 +1,41 @@ +/* ----------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 header file is for routines to get SUNDIALS version info + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_VERSION_H +#define _SUNDIALS_VERSION_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Fill a string with SUNDIALS version information */ +SUNDIALS_EXPORT +SUNErrCode SUNDIALSGetVersion(char* version, int len); + +/* Fills integers with the major, minor, and patch release version numbers and a + string with the release label.*/ +SUNDIALS_EXPORT +SUNErrCode SUNDIALSGetVersionNumber(int* major, int* minor, int* patch, + char* label, int len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_band.h b/inst/include/sunlinsol/sunlinsol_band.h new file mode 100644 index 0000000..280c901 --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_band.h @@ -0,0 +1,87 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the band implementation of the + * SUNLINSOL module, SUNLINSOL_BAND. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_BAND_H +#define _SUNLINSOL_BAND_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* --------------------------------------- + * Band Implementation of SUNLinearSolver + * --------------------------------------- */ + +struct _SUNLinearSolverContent_Band +{ + sunindextype N; + sunindextype* pivots; + sunindextype last_flag; +}; + +typedef struct _SUNLinearSolverContent_Band* SUNLinearSolverContent_Band; + +/* -------------------------------------- + * Exported Functions for SUNLINSOL_BAND + * -------------------------------------- */ + +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Band(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_dense.h b/inst/include/sunlinsol/sunlinsol_dense.h new file mode 100644 index 0000000..cc7d49a --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_dense.h @@ -0,0 +1,92 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the dense implementation of the + * SUNLINSOL module, SUNLINSOL_DENSE. + * + * Notes: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype' and 'indextype'. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_DENSE_H +#define _SUNLINSOL_DENSE_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------- + * Dense Implementation of SUNLinearSolver + * ---------------------------------------- */ + +struct _SUNLinearSolverContent_Dense +{ + sunindextype N; + sunindextype* pivots; + sunindextype last_flag; +}; + +typedef struct _SUNLinearSolverContent_Dense* SUNLinearSolverContent_Dense; + +/* ---------------------------------------- + * Exported Functions for SUNLINSOL_DENSE + * ---------------------------------------- */ + +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Dense(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_pcg.h b/inst/include/sunlinsol/sunlinsol_pcg.h new file mode 100644 index 0000000..ad604fe --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_pcg.h @@ -0,0 +1,135 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the PCG implementation of the + * SUNLINSOL module, SUNLINSOL_PCG. The PCG algorithm is based + * on the Preconditioned Conjugate Gradient. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_PCG_H +#define _SUNLINSOL_PCG_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Default PCG solver parameters */ +#define SUNPCG_MAXL_DEFAULT 5 + +/* -------------------------------------- + * PCG Implementation of SUNLinearSolver + * -------------------------------------- */ + +struct _SUNLinearSolverContent_PCG +{ + int maxl; + int pretype; + sunbooleantype zeroguess; + int numiters; + sunrealtype resnorm; + int last_flag; + + SUNATimesFn ATimes; + void* ATData; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; + void* PData; + + N_Vector s; + N_Vector r; + N_Vector p; + N_Vector z; + N_Vector Ap; +}; + +typedef struct _SUNLinearSolverContent_PCG* SUNLinearSolverContent_PCG; + +/* ------------------------------------- + * Exported Functions for SUNLINSOL_PCG + * ------------------------------------- */ + +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, + SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, + N_Vector nul); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, sunbooleantype onoff); + +SUNDIALS_EXPORT +int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul); + +SUNDIALS_EXPORT +int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +int SUNLinSolNumIters_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunrealtype SUNLinSolResNorm_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +N_Vector SUNLinSolResid_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_PCG(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_spbcgs.h b/inst/include/sunlinsol/sunlinsol_spbcgs.h new file mode 100644 index 0000000..2b9b8a5 --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_spbcgs.h @@ -0,0 +1,115 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * Based on code sundials_spbcgs.h by: Peter Brown and + * Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SPBCGS implementation of the + * SUNLINSOL module, SUNLINSOL_SPBCGS. The SPBCGS algorithm is based + * on the Scaled Preconditioned Bi-CG-Stabilized method. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_SPBCGS_H +#define _SUNLINSOL_SPBCGS_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Default SPBCGS solver parameters */ +#define SUNSPBCGS_MAXL_DEFAULT 5 + +/* ----------------------------------------- + * SPBCGS Implementation of SUNLinearSolver + * ---------------------------------------- */ + +struct _SUNLinearSolverContent_SPBCGS +{ + int maxl; + int pretype; + sunbooleantype zeroguess; + int numiters; + sunrealtype resnorm; + int last_flag; + + SUNATimesFn ATimes; + void* ATData; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; + void* PData; + + N_Vector s1; + N_Vector s2; + N_Vector r; + N_Vector r_star; + N_Vector p; + N_Vector q; + N_Vector u; + N_Vector Ap; + N_Vector vtemp; +}; + +typedef struct _SUNLinearSolverContent_SPBCGS* SUNLinearSolverContent_SPBCGS; + +/* --------------------------------------- + *Exported Functions for SUNLINSOL_SPBCGS + * --------------------------------------- */ + +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, + int pretype); +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 SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, + sunbooleantype onoff); +SUNDIALS_EXPORT int SUNLinSolSetup_SPBCGS(SUNLinearSolver S, SUNMatrix A); +SUNDIALS_EXPORT int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, + N_Vector x, N_Vector b, + sunrealtype tol); +SUNDIALS_EXPORT int SUNLinSolNumIters_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPBCGS(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPBCGS(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_spfgmr.h b/inst/include/sunlinsol/sunlinsol_spfgmr.h new file mode 100644 index 0000000..5f9508e --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_spfgmr.h @@ -0,0 +1,125 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * Based on code sundials_spfgmr.h by: Daniel R. Reynolds and + * Hilari C. Tiedeman @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SPFGMR implementation of the + * SUNLINSOL module, SUNLINSOL_SPFGMR. The SPFGMR algorithm is based + * on the Scaled Preconditioned FGMRES (Flexible Generalized Minimal + * Residual) method [Y. Saad, SIAM J. Sci. Comput., 1993]. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_SPFGMR_H +#define _SUNLINSOL_SPFGMR_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Default SPFGMR solver parameters */ +#define SUNSPFGMR_MAXL_DEFAULT 5 +#define SUNSPFGMR_MAXRS_DEFAULT 0 +#define SUNSPFGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS + +/* ----------------------------------------- + * SPFGMR Implementation of SUNLinearSolver + * ----------------------------------------- */ + +struct _SUNLinearSolverContent_SPFGMR +{ + int maxl; + int pretype; + int gstype; + int max_restarts; + sunbooleantype zeroguess; + int numiters; + sunrealtype resnorm; + int last_flag; + + SUNATimesFn ATimes; + void* ATData; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; + void* PData; + + N_Vector s1; + N_Vector s2; + N_Vector* V; + N_Vector* Z; + sunrealtype** Hes; + sunrealtype* givens; + N_Vector xcor; + sunrealtype* yg; + N_Vector vtemp; + + sunrealtype* cv; + N_Vector* Xv; +}; + +typedef struct _SUNLinearSolverContent_SPFGMR* SUNLinearSolverContent_SPFGMR; + +/* ---------------------------------------- + * Exported Functions for SUNLINSOL_SPFGMR + * ---------------------------------------- */ + +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, + int gstype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, + int maxrs); +SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, + sunbooleantype onoff); +SUNDIALS_EXPORT int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A); +SUNDIALS_EXPORT int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, + N_Vector x, N_Vector b, + sunrealtype tol); +SUNDIALS_EXPORT int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPFGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPFGMR(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_spgmr.h b/inst/include/sunlinsol/sunlinsol_spgmr.h new file mode 100644 index 0000000..ecf3bde --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_spgmr.h @@ -0,0 +1,124 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * Based on code sundials_spgmr.h by: Scott D. Cohen, + * Alan C. Hindmarsh and Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SPGMR implementation of the + * SUNLINSOL module, SUNLINSOL_SPGMR. The SPGMR algorithm is based + * on the Scaled Preconditioned GMRES (Generalized Minimal Residual) + * method. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_SPGMR_H +#define _SUNLINSOL_SPGMR_H + +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Default SPGMR solver parameters */ +#define SUNSPGMR_MAXL_DEFAULT 5 +#define SUNSPGMR_MAXRS_DEFAULT 0 +#define SUNSPGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS + +/* ---------------------------------------- + * SPGMR Implementation of SUNLinearSolver + * ---------------------------------------- */ + +struct _SUNLinearSolverContent_SPGMR +{ + int maxl; + int pretype; + int gstype; + int max_restarts; + sunbooleantype zeroguess; + int numiters; + sunrealtype resnorm; + int last_flag; + + SUNATimesFn ATimes; + void* ATData; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; + void* PData; + + N_Vector s1; + N_Vector s2; + N_Vector* V; + sunrealtype** Hes; + sunrealtype* givens; + N_Vector xcor; + sunrealtype* yg; + N_Vector vtemp; + + sunrealtype* cv; + N_Vector* Xv; +}; + +typedef struct _SUNLinearSolverContent_SPGMR* SUNLinearSolverContent_SPGMR; + +/* --------------------------------------- + * Exported Functions for SUNLINSOL_SPGMR + * --------------------------------------- */ + +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, + int gstype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, + int maxrs); +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 SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, + sunbooleantype onff); +SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A); +SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, + N_Vector x, N_Vector b, sunrealtype tol); +SUNDIALS_EXPORT int SUNLinSolNumIters_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPGMR(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunlinsol/sunlinsol_sptfqmr.h b/inst/include/sunlinsol/sunlinsol_sptfqmr.h new file mode 100644 index 0000000..e7dc35c --- /dev/null +++ b/inst/include/sunlinsol/sunlinsol_sptfqmr.h @@ -0,0 +1,117 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * Based on code sundials_sptfqmr.h by: Aaron Collier @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SPTFQMR implementation of the + * SUNLINSOL module, SUNLINSOL_SPTFQMR. The SPTFQMR algorithm is + * based on the Scaled Preconditioned Transpose-free Quasi-Minimum + * Residual method. + * + * Note: + * - The definition of the generic SUNLinearSolver structure can + * be found in the header file sundials_linearsolver.h. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNLINSOL_SPTFQMR_H +#define _SUNLINSOL_SPTFQMR_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Default SPTFQMR solver parameters */ +#define SUNSPTFQMR_MAXL_DEFAULT 5 + +/* ------------------------------------------ + * SPTFQMR Implementation of SUNLinearSolver + * ------------------------------------------ */ + +struct _SUNLinearSolverContent_SPTFQMR +{ + int maxl; + int pretype; + sunbooleantype zeroguess; + int numiters; + sunrealtype resnorm; + int last_flag; + + SUNATimesFn ATimes; + void* ATData; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; + void* PData; + + N_Vector s1; + N_Vector s2; + N_Vector r_star; + N_Vector q; + N_Vector d; + N_Vector v; + N_Vector p; + N_Vector* r; + N_Vector u; + N_Vector vtemp1; + N_Vector vtemp2; + N_Vector vtemp3; +}; + +typedef struct _SUNLinearSolverContent_SPTFQMR* SUNLinearSolverContent_SPTFQMR; + +/* ------------------------------------- + * Exported Functions SUNLINSOL_SPTFQMR + * -------------------------------------- */ + +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, + int pretype); +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 SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, + sunbooleantype onoff); +SUNDIALS_EXPORT int SUNLinSolSetup_SPTFQMR(SUNLinearSolver S, SUNMatrix A); +SUNDIALS_EXPORT int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, + N_Vector x, N_Vector b, + sunrealtype tol); +SUNDIALS_EXPORT int SUNLinSolNumIters_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPTFQMR(SUNLinearSolver S); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunmatrix/sunmatrix_band.h b/inst/include/sunmatrix/sunmatrix_band.h new file mode 100644 index 0000000..1936d6a --- /dev/null +++ b/inst/include/sunmatrix/sunmatrix_band.h @@ -0,0 +1,131 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * David Gardner @ LLNL + * Based on code sundials_direct.h by: Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the band implementation of the + * SUNMATRIX module, SUNMATRIX_BAND. + * + * Notes: + * - The definition of the generic SUNMatrix structure can be found + * in the header file sundials_matrix.h. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype' and 'indextype'. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNMATRIX_BAND_H +#define _SUNMATRIX_BAND_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* --------------------------------- + * Band implementation of SUNMatrix + * --------------------------------- */ + +struct _SUNMatrixContent_Band +{ + sunindextype M; + sunindextype N; + sunindextype ldim; + sunindextype mu; + sunindextype ml; + sunindextype s_mu; + sunrealtype* data; + sunindextype ldata; + sunrealtype** cols; +}; + +typedef struct _SUNMatrixContent_Band* SUNMatrixContent_Band; + +/* ------------------------------------ + * Macros for access to SUNMATRIX_BAND + * ------------------------------------ */ + +#define SM_CONTENT_B(A) ((SUNMatrixContent_Band)(A->content)) + +#define SM_ROWS_B(A) (SM_CONTENT_B(A)->M) + +#define SM_COLUMNS_B(A) (SM_CONTENT_B(A)->N) + +#define SM_LDATA_B(A) (SM_CONTENT_B(A)->ldata) + +#define SM_UBAND_B(A) (SM_CONTENT_B(A)->mu) + +#define SM_LBAND_B(A) (SM_CONTENT_B(A)->ml) + +#define SM_SUBAND_B(A) (SM_CONTENT_B(A)->s_mu) + +#define SM_LDIM_B(A) (SM_CONTENT_B(A)->ldim) + +#define SM_DATA_B(A) (SM_CONTENT_B(A)->data) + +#define SM_COLS_B(A) (SM_CONTENT_B(A)->cols) + +#define SM_COLUMN_B(A, j) (((SM_CONTENT_B(A)->cols)[j]) + SM_SUBAND_B(A)) + +#define SM_COLUMN_ELEMENT_B(col_j, i, j) (col_j[(i) - (j)]) + +#define SM_ELEMENT_B(A, i, j) \ + ((SM_CONTENT_B(A)->cols)[j][(i) - (j) + SM_SUBAND_B(A)]) + +/* ---------------------------------------- + * Exported Functions for SUNMATRIX_BAND + * ---------------------------------------- */ + +SUNDIALS_EXPORT SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, + sunindextype ml, SUNContext sunctx); + +SUNDIALS_EXPORT SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, + sunindextype ml, sunindextype smu, + SUNContext sunctx); + +SUNDIALS_EXPORT void SUNBandMatrix_Print(SUNMatrix A, FILE* outfile); + +SUNDIALS_EXPORT sunindextype SUNBandMatrix_Rows(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_Columns(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_LowerBandwidth(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_UpperBandwidth(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_StoredUpperBandwidth(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_LDim(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_LData(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNBandMatrix_Data(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype** SUNBandMatrix_Cols(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNBandMatrix_Column(SUNMatrix A, sunindextype j); + +SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Band(SUNMatrix A); +SUNDIALS_EXPORT SUNMatrix SUNMatClone_Band(SUNMatrix A); +SUNDIALS_EXPORT void SUNMatDestroy_Band(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatZero_Band(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatCopy_Band(SUNMatrix A, SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAdd_Band(sunrealtype c, SUNMatrix A, + SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAddI_Band(sunrealtype c, SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvec_Band(SUNMatrix A, N_Vector x, N_Vector y); +SUNDIALS_EXPORT SUNErrCode SUNMatSpace_Band(SUNMatrix A, long int* lenrw, + long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunmatrix/sunmatrix_dense.h b/inst/include/sunmatrix/sunmatrix_dense.h new file mode 100644 index 0000000..2a49da3 --- /dev/null +++ b/inst/include/sunmatrix/sunmatrix_dense.h @@ -0,0 +1,109 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * David Gardner @ LLNL + * Based on code sundials_direct.h by: Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the dense implementation of the + * SUNMATRIX module, SUNMATRIX_DENSE. + * + * Notes: + * - The definition of the generic SUNMatrix structure can be found + * in the header file sundials_matrix.h. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype' and 'indextype'. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNMATRIX_DENSE_H +#define _SUNMATRIX_DENSE_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------- + * Dense implementation of SUNMatrix + * ---------------------------------- */ + +struct _SUNMatrixContent_Dense +{ + sunindextype M; + sunindextype N; + sunrealtype* data; + sunindextype ldata; + sunrealtype** cols; +}; + +typedef struct _SUNMatrixContent_Dense* SUNMatrixContent_Dense; + +/* ------------------------------------ + * Macros for access to SUNMATRIX_DENSE + * ------------------------------------ */ + +#define SM_CONTENT_D(A) ((SUNMatrixContent_Dense)(A->content)) + +#define SM_ROWS_D(A) (SM_CONTENT_D(A)->M) + +#define SM_COLUMNS_D(A) (SM_CONTENT_D(A)->N) + +#define SM_LDATA_D(A) (SM_CONTENT_D(A)->ldata) + +#define SM_DATA_D(A) (SM_CONTENT_D(A)->data) + +#define SM_COLS_D(A) (SM_CONTENT_D(A)->cols) + +#define SM_COLUMN_D(A, j) ((SM_CONTENT_D(A)->cols)[j]) + +#define SM_ELEMENT_D(A, i, j) ((SM_CONTENT_D(A)->cols)[j][i]) + +/* --------------------------------------- + * Exported Functions for SUNMATRIX_DENSE + * --------------------------------------- */ + +SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N, + SUNContext sunctx); + +SUNDIALS_EXPORT void SUNDenseMatrix_Print(SUNMatrix A, FILE* outfile); + +SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Rows(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Columns(SUNMatrix A); +SUNDIALS_EXPORT sunindextype SUNDenseMatrix_LData(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNDenseMatrix_Data(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype** SUNDenseMatrix_Cols(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNDenseMatrix_Column(SUNMatrix A, sunindextype j); + +SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Dense(SUNMatrix A); +SUNDIALS_EXPORT SUNMatrix SUNMatClone_Dense(SUNMatrix A); +SUNDIALS_EXPORT void SUNMatDestroy_Dense(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatZero_Dense(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatCopy_Dense(SUNMatrix A, SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAdd_Dense(sunrealtype c, SUNMatrix A, + SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAddI_Dense(sunrealtype c, SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvec_Dense(SUNMatrix A, N_Vector x, + N_Vector y); +SUNDIALS_EXPORT SUNErrCode SUNMatSpace_Dense(SUNMatrix A, long int* lenrw, + long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunmatrix/sunmatrix_sparse.h b/inst/include/sunmatrix/sunmatrix_sparse.h new file mode 100644 index 0000000..edb929c --- /dev/null +++ b/inst/include/sunmatrix/sunmatrix_sparse.h @@ -0,0 +1,185 @@ +/* + * ----------------------------------------------------------------- + * Programmer(s): Daniel Reynolds @ SMU + * David Gardner @ LLNL + * Based on code sundials_sparse.h by: Carol Woodward and + * Slaven Peles @ LLNL, and Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the sparse implementation of the + * SUNMATRIX module, SUNMATRIX_SPARSE. + * + * Notes: + * - The definition of the generic SUNMatrix structure can be found + * in the header file sundials_matrix.h. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. + * The sundials_types.h file also contains the definition + * for the type 'sunbooleantype' and 'indextype'. + * ----------------------------------------------------------------- + */ + +#ifndef _SUNMATRIX_SPARSE_H +#define _SUNMATRIX_SPARSE_H + +#include +#include +#include +#include + +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ------------------------ + * Matrix Type Definitions + * ------------------------ */ + +#define CSC_MAT 0 +#define CSR_MAT 1 + +/* ------------------------------------------ + * Sparse Implementation of SUNMATRIX_SPARSE + * ------------------------------------------ */ + +struct _SUNMatrixContent_Sparse +{ + sunindextype M; + sunindextype N; + sunindextype NNZ; + sunindextype NP; + sunrealtype* data; + int sparsetype; + sunindextype* indexvals; + sunindextype* indexptrs; + /* CSC indices */ + sunindextype** rowvals; + sunindextype** colptrs; + /* CSR indices */ + sunindextype** colvals; + sunindextype** rowptrs; +}; + +typedef struct _SUNMatrixContent_Sparse* SUNMatrixContent_Sparse; + +/* --------------------------------------- + * Macros for access to SUNMATRIX_SPARSE + * --------------------------------------- */ + +#define SM_CONTENT_S(A) ((SUNMatrixContent_Sparse)(A->content)) + +#define SM_ROWS_S(A) (SM_CONTENT_S(A)->M) + +#define SM_COLUMNS_S(A) (SM_CONTENT_S(A)->N) + +#define SM_NNZ_S(A) (SM_CONTENT_S(A)->NNZ) + +#define SM_NP_S(A) (SM_CONTENT_S(A)->NP) + +#define SM_SPARSETYPE_S(A) (SM_CONTENT_S(A)->sparsetype) + +#define SM_DATA_S(A) (SM_CONTENT_S(A)->data) + +#define SM_INDEXVALS_S(A) (SM_CONTENT_S(A)->indexvals) + +#define SM_INDEXPTRS_S(A) (SM_CONTENT_S(A)->indexptrs) + +/* ---------------------------------------- + * Exported Functions for SUNMATRIX_SPARSE + * ---------------------------------------- */ + +SUNDIALS_EXPORT +SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, sunindextype NNZ, + int sparsetype, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNMatrix SUNSparseFromDenseMatrix(SUNMatrix A, sunrealtype droptol, + int sparsetype); + +SUNDIALS_EXPORT +SUNMatrix SUNSparseFromBandMatrix(SUNMatrix A, sunrealtype droptol, + int sparsetype); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_ToCSR(const SUNMatrix A, SUNMatrix* Bout); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_ToCSC(const SUNMatrix A, SUNMatrix* Bout); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_Realloc(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_Reallocate(SUNMatrix A, sunindextype NNZ); + +SUNDIALS_EXPORT +void SUNSparseMatrix_Print(SUNMatrix A, FILE* outfile); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_Rows(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_Columns(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_NNZ(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_NP(SUNMatrix A); + +SUNDIALS_EXPORT +int SUNSparseMatrix_SparseType(SUNMatrix A); + +SUNDIALS_EXPORT +sunrealtype* SUNSparseMatrix_Data(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype* SUNSparseMatrix_IndexValues(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype* SUNSparseMatrix_IndexPointers(SUNMatrix A); + +SUNDIALS_EXPORT +SUNMatrix_ID SUNMatGetID_Sparse(SUNMatrix A); + +SUNDIALS_EXPORT +SUNMatrix SUNMatClone_Sparse(SUNMatrix A); + +SUNDIALS_EXPORT +void SUNMatDestroy_Sparse(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatZero_Sparse(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatCopy_Sparse(SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAdd_Sparse(sunrealtype c, SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAddI_Sparse(sunrealtype c, SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvec_Sparse(SUNMatrix A, N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +SUNErrCode SUNMatSpace_Sparse(SUNMatrix A, long int* lenrw, long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunmemory/sunmemory_system.h b/inst/include/sunmemory/sunmemory_system.h new file mode 100644 index 0000000..2e45ca2 --- /dev/null +++ b/inst/include/sunmemory/sunmemory_system.h @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 system memory helper header file. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_SYSMEMORY_H +#define _SUNDIALS_SYSMEMORY_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Implementation specific functions */ + +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx); + +/* SUNMemoryHelper functions */ + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); + +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Clone_Sys(SUNMemoryHelper helper); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h b/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h new file mode 100644 index 0000000..779538a --- /dev/null +++ b/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h @@ -0,0 +1,134 @@ +/* --------------------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * --------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SUNNonlinearSolver module implementation of + * the Anderson-accelerated fixed-point method. + * + * Part I defines the solver-specific content structure. + * + * Part II contains prototypes for the solver constructor and operations. + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNNONLINSOL_FIXEDPOINT_H +#define _SUNNONLINSOL_FIXEDPOINT_H + +#include + +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/*----------------------------------------------------------------------------- + I. Content structure + ---------------------------------------------------------------------------*/ + +struct _SUNNonlinearSolverContent_FixedPoint +{ + /* functions provided by the integrator */ + SUNNonlinSolSysFn Sys; /* fixed-point iteration function */ + SUNNonlinSolConvTestFn CTest; /* convergence test function */ + + /* nonlinear solver variables */ + int m; /* number of acceleration vectors to use */ + int* imap; /* array of length m */ + sunbooleantype damping; /* flag to apply dampling in acceleration */ + sunrealtype beta; /* damping paramter */ + sunrealtype* R; /* array of length m*m */ + sunrealtype* gamma; /* array of length m */ + sunrealtype* cvals; /* array of length m+1 for fused vector op */ + N_Vector* df; /* vector array of length m */ + N_Vector* dg; /* vector array of length m */ + N_Vector* q; /* vector array of length m */ + N_Vector* Xvecs; /* array of length m+1 for fused vector op */ + N_Vector yprev; /* temporary vectors for performing solve */ + N_Vector gy; + N_Vector fold; + N_Vector gold; + N_Vector delta; /* correction vector (change between 2 iterates) */ + int curiter; /* current iteration number in a solve attempt */ + int maxiters; /* maximum number of iterations per solve attempt */ + long int niters; /* total number of iterations across all solves */ + long int nconvfails; /* total number of convergence failures */ + void* ctest_data; /* data to pass to convergence test function */ +}; + +typedef struct _SUNNonlinearSolverContent_FixedPoint* SUNNonlinearSolverContent_FixedPoint; + +/* ----------------------------------------------------------------------------- + II: Exported functions + ---------------------------------------------------------------------------*/ + +/* Constructor to create solver and allocates memory */ +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, + SUNContext sunctx); + +/* core functions */ +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, + N_Vector y, N_Vector w, sunrealtype tol, + sunbooleantype callSetup, void* mem); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS); + +/* set functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, + int maxiters); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, + sunrealtype beta); + +/* get functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, + long int* niters); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, int* iter); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, + long int* nconvfails); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inst/include/sunnonlinsol/sunnonlinsol_newton.h b/inst/include/sunnonlinsol/sunnonlinsol_newton.h new file mode 100644 index 0000000..ef7774e --- /dev/null +++ b/inst/include/sunnonlinsol/sunnonlinsol_newton.h @@ -0,0 +1,126 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, 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 is the header file for the SUNNonlinearSolver module implementation of + * Newton's method. + * + * Part I defines the solver-specific content structure. + * + * Part II contains prototypes for the solver constructor and operations. + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNNONLINSOL_NEWTON_H +#define _SUNNONLINSOL_NEWTON_H + +#include "sundials/sundials_nonlinearsolver.h" +#include "sundials/sundials_nvector.h" +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * I. Content structure + * ---------------------------------------------------------------------------*/ + +struct _SUNNonlinearSolverContent_Newton +{ + /* functions provided by the integrator */ + SUNNonlinSolSysFn Sys; /* nonlinear system residual function */ + SUNNonlinSolLSetupFn LSetup; /* linear solver setup function */ + SUNNonlinSolLSolveFn LSolve; /* linear solver solve function */ + SUNNonlinSolConvTestFn CTest; /* nonlinear solver convergence test function */ + + /* nonlinear solver variables */ + N_Vector delta; /* Newton update vector */ + sunbooleantype jcur; /* Jacobian status, current = SUNTRUE / stale = SUNFALSE */ + int curiter; /* current number of iterations in a solve attempt */ + int maxiters; /* maximum number of iterations in a solve attempt */ + long int niters; /* total number of nonlinear iterations across all solves */ + long int nconvfails; /* total number of convergence failures across all solves + */ + void* ctest_data; /* data to pass to convergence test function */ +}; + +typedef struct _SUNNonlinearSolverContent_Newton* SUNNonlinearSolverContent_Newton; + +/* ----------------------------------------------------------------------------- + * II: Exported functions + * ---------------------------------------------------------------------------*/ + +/* Constructor to create solver and allocates memory */ +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, + SUNContext sunctx); + +/* core functions */ +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS); + +SUNDIALS_EXPORT +int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, + N_Vector w, sunrealtype tol, + sunbooleantype callLSetup, void* mem); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS); + +/* set functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn LSetupFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn LSolveFn); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, int maxiters); + +/* get functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, + long int* niters); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, int* iter); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, + long int* nconvfails); + +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/Makevars.ucrt b/src/Makevars.ucrt deleted file mode 100644 index 5c18bde..0000000 --- a/src/Makevars.ucrt +++ /dev/null @@ -1,9 +0,0 @@ -PKG_CPPFLAGS = -I../inst/include/ -I/ucrt64/include/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 - -###PKG_LDFLAGS = -L/ucrt64/lib/ ###-L/mingw64/lib/ -L/mingw32/lib/ -L/clang64/lib/ -LIBS=-L/ -L/clang64/lib/ -L/mingw64/lib/ -L/mingw32/lib/ -L/ucrt64/lib/ - -PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/ucrt64/lib/ -lsundials_idas -lsundials_cvodes -lsundials_nvecserial -lsundials_sunlinsoldense -lsundials_sunmatrixdense -lsundials_core -lm - -### -L/mingw64/lib/ -L/mingw32/lib/ -L/clang64/lib/ -###-I../inst/include/ -I../inst/ -I/mingw32/include/ -I/clang64/include/ -I/ming64/include/ -I/ucrt64/include/ diff --git a/src/Makevars.win b/src/Makevars.win deleted file mode 100644 index 170d2bb..0000000 --- a/src/Makevars.win +++ /dev/null @@ -1,22 +0,0 @@ -#CXX=clang++ -#CXX_STD = CXX11 -###PKG_CPPFLAGS= -I../inst/include/ -I./inst/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 -I./sundials/sundials -### PKG_CPPFLAGS= -I../inst/include/ -I../inst/ -I/mingw32/include/ #-I/clang64/include/ -I/ming64/include/ -I/ucrt64/include/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 -##PKG_LDFLAGS = -L/clang64/lib/ -L/mingw64/lib/ -L/mingw32/lib/ -L/ucrt64/lib/ -##LIBS=-L/ -L/clang64/lib/ -L/mingw64/lib/ -L/mingw32/lib/ -L/ucrt64/lib/ -###PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/ucrt64/lib/ -L/mingw64/lib/ -L/mingw32/lib/ -L/clang64/lib/ -lsundials_idas -lsundials_cvodes -lsundials_nvecserial -lsundials_sunlinsoldense -lsundials_sunmatrixdense -lsundials_core -lm - -##PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/clang64/lib/libsundials_core.a -L/clang64/lib/libsundials_nvecserial.a -L/clang64/lib/libsundials_cvodes.a -L/clang64/lib/libsundials_idas.a -L/clang64/lib/libsundials_sunlinsoldense.a -L/clang64/lib/libsundials_sunmatrixdense.a -lm - -##PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/mingw64/lib/libsundials_core.a -L/mingw64/lib/libsundials_nvecserial.a -L/mingw64/lib/libsundials_cvodes.a -L/mingw64/lib/libsundials_idas.a -L/mingw64/lib/libsundials_sunlinsoldense.a -L/mingw64/lib/libsundials_sunmatrixdense.a -lm - -##PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/mingw32/lib/libsundials_core.a -L/mingw32/lib/libsundials_nvecserial.a -L/mingw32/lib/libsundials_cvodes.a -L/mingw32/lib/libsundials_idas.a -L/mingw32/lib/libsundials_sunlinsoldense.a -L/mingw32/lib/libsundials_sunmatrixdense.a -lm - -###PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/ucrt/lib/libsundials_core.a -L/ucrt/lib/libsundials_nvecserial.a -L/ucrt/lib/libsundials_cvodes.a -L/ucrt/lib/libsundials_idas.a -L/ucrt/lib/libsundials_sunlinsoldense.a -L/ucrt/lib/libsundials_sunmatrixdense.a -lm - -PKG_CPPFLAGS = -I../inst/include/ -I/mingw64/include/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 -###PKG_LDFLAGS = -L/ucrt64/lib/ ###-L/mingw64/lib/ -L/mingw32/lib/ -L/clang64/lib/ -LIBS=-L/ -L/clang64/lib/ -L/mingw64/lib/ -L/mingw32/lib/ -L/ucrt64/lib/ -PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L/mingw64/lib/ -lsundials_idas -lsundials_cvodes -lsundials_nvecserial -lsundials_sunlinsoldense -lsundials_sunmatrixdense -lsundials_core -lm -### -L/mingw64/lib/ -L/mingw32/lib/ -L/clang64/lib/ -###-I../inst/include/ -I../inst/ -I/mingw32/include/ -I/clang64/include/ -I/ming64/include/ -I/ucrt64/include/