Skip to content

Commit

Permalink
Document DASSL and IDA numeric Jacobian routines (#9974)
Browse files Browse the repository at this point in the history
* Update .gitignore for CMake
* Documenting Numeric Jacobian in DASSL
* Cleanup and more documentation for ida_solver
  - Improve readability of ida_solver functions.
  - Documenting most of the previously undocumented functions.
* Unify setJacElementFunc for IDA und KLU
* Reformulate scaling option in IDA
* Doc/error handling for _omc_SUNMatScaleIAdd_Sparse
* Move _omc_SUNMatScaleIAdd_Sparse to sundials_util
  • Loading branch information
AnHeuermann committed Feb 23, 2023
1 parent a083b0e commit 78141e0
Show file tree
Hide file tree
Showing 18 changed files with 974 additions and 585 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -5,12 +5,15 @@
/.vscode/
/autom4te.cache/
/build/
/build_cmake/
/config.guess
/config.log
/config.status
/config.sub
/configure
/install-sh
/install_cmake/
/install/
/issues/
/Makefile
/OMCompiler/SimulationRuntime/ModelicaExternalC/build/
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/SimulationRuntime/c/Makefile.common
Expand Up @@ -107,6 +107,7 @@ RUNTIMESIMSOLVER_HEADERS = ./simulation/solver/cvode_solver.h \
./simulation/solver/spatialDistribution.h \
./simulation/solver/stateset.h \
./simulation/solver/sundials_error.h \
./simulation/solver/sundials_util.h \
./simulation/solver/synchronous.h

RUNTIMEMETA_HEADERS = ./meta/meta_modelica_builtin_boxptr.h \
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/SimulationRuntime/c/Makefile.objs
Expand Up @@ -178,6 +178,7 @@ ifeq ($(OMC_MINIMAL_RUNTIME),)
nonlinearSolverNewton$(OBJ_EXT) \
radau$(OBJ_EXT) \
sundials_error$(OBJ_EXT) \
sundials_util$(OBJ_EXT) \
sym_solver_ssc$(OBJ_EXT)
else
SOLVER_OBJS=$(SOLVER_OBJS_MINIMAL)
Expand All @@ -202,6 +203,7 @@ SOLVER_HFILES = cvode_solver.h \
spatialDistribution.h \
stateset.h \
sundials_error.h \
sundials_util.h \
sym_solver_ssc.h

INITIALIZATION_OBJS = initialization$(OBJ_EXT)
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/SimulationRuntime/c/RuntimeSources.mo.tpl
Expand Up @@ -24,7 +24,7 @@ encapsulated package RuntimeSources
"sundials/sundials/sundials_nvector.h"};

constant list<String> simrt_c_sundials_sources={"simulation/solver/cvode_solver.c",
"simulation/solver/sundials_error.c"};
"simulation/solver/sundials_error.c"};

constant list<String> dgesv_headers={"./external_solvers/blaswrap.h", "./external_solvers/clapack.h", "./external_solvers/f2c.h"};
constant list<String> dgesv_sources={DGESV_FILES};
Expand Down
Expand Up @@ -115,6 +115,7 @@ set(SOURCE_FMU_COMMON_HEADERS \"./omc_inline.h\",
\"./simulation/solver/spatialDistribution.h\",
\"./simulation/solver/stateset.h\",
\"./simulation/solver/sundials_error.h\",
\"./simulation/solver/sundials_util.h\",
\"./simulation/solver/synchronous.h\",
\"./simulation/solver/initialization/initialization.h\",
\"./meta/meta_modelica_builtin_boxptr.h\",
Expand Down
20 changes: 10 additions & 10 deletions OMCompiler/SimulationRuntime/c/simulation/solver/cvode_solver.c
Expand Up @@ -222,14 +222,14 @@ static int jacColoredNumericalDense(double currentTime, N_Vector y, N_Vector fy,
* Not usable at the moment!
*
* @param t Independent variable (time).
* @param y Dependent varaible vector.
* @param y Dependent variable vector.
* @param fy Current value of f(t,y).
* @param Jac Output Jacobian.
* @param user_data User supplied data.
* @param tmp1 Pointer to allocated memory to be used as temp storage or work space.
* @param tmp2 "
* @param tmp3 "
* @return int Returns 0 on succes, positiv value for recoverable error, negative value for error.
* @return int Returns 0 on success, positive value for recoverable error, negative value for error.
*/
static int callDenseJacobian(double t, N_Vector y, N_Vector fy,
SUNMatrix Jac, void *user_data,
Expand Down Expand Up @@ -517,7 +517,7 @@ void cvodeGetConfig(CVODE_CONFIG *config, threadData_t *threadData, booleantype
* @param data Runtime data struct
* @param threadData Thread data for error handling
* @param solverInfo Information about main solver. Unused at the moment.
* @param cvodeData CVODE solver data struckt.
* @param cvodeData CVODE solver data struct.
* @return int Return 0 on success.
*/
int cvode_solver_initial(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo, CVODE_SOLVER *cvodeData, int isFMI)
Expand Down Expand Up @@ -619,13 +619,13 @@ int cvode_solver_initial(DATA *data, threadData_t *threadData, SOLVER_INFO *solv
infoStreamPrint(LOG_SOLVER, 0, "CVODE Use internal dense numeric jacobian method.");
break;
case COLOREDNUMJAC:
throwStreamPrint(threadData, "##CVODE## Linear solver method %s not implemented yet!", JACOBIAN_METHOD[cvodeData->config.jacobianMethod]);
flag = CVodeSetJacFn(cvodeData->cvode_mem, callDenseJacobian);
checkReturnFlag_SUNDIALS(flag, SUNDIALS_CVLS_FLAG, "CVodeSetJacFn");
infoStreamPrint(LOG_SOLVER, 0, "CVODE Use colored dense numeric jacobian method.");
throwStreamPrint(threadData, "##CVODE## LJacobian method %s not yet implemented.", JACOBIAN_METHOD[cvodeData->config.jacobianMethod]);
//flag = CVodeSetJacFn(cvodeData->cvode_mem, callDenseJacobian);
//checkReturnFlag_SUNDIALS(flag, SUNDIALS_CVLS_FLAG, "CVodeSetJacFn");
//infoStreamPrint(LOG_SOLVER, 0, "CVODE Use colored dense numeric jacobian method.");
break;
default:
throwStreamPrint(threadData, "##CVODE## Unknown linear solver method %s.", JACOBIAN_METHOD[cvodeData->config.jacobianMethod]);
throwStreamPrint(threadData, "##CVODE## Jacobian method %s not yet implemented.", JACOBIAN_METHOD[cvodeData->config.jacobianMethod]);
}

/* Set optional non-linear solver module */
Expand Down Expand Up @@ -849,11 +849,11 @@ void cvode_save_statistics(void *cvode_mem, SOLVERSTATS *solverStats, threadData
/**
* @brief Main CVODE function to make a step.
*
* Integrates on current time intervall.
* Integrates on current time interval.
*
* @param data Runtime data struct
* @param threadData Thread data for error handling
* @param cvodeData CVODE solver data struckt.
* @param cvodeData CVODE solver data struct.
* @return int Returns 0 on success and return flag from CVode else.
*/
int cvode_solver_step(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo)
Expand Down

0 comments on commit 78141e0

Please sign in to comment.