diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 5b20405a..20f0564e 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -46,6 +46,7 @@ jobs: sudo apt-get install pkgconf sudo apt-get install python sudo apt-get install qt5-default + sudo apt-get install rapidjson-dev - name: Build working-directory: ./src diff --git a/.hooks/pre-commit b/.hooks/pre-commit index ccaa151b..cd34bb69 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -7,13 +7,13 @@ def get_files(): '--name-only', 'HEAD']).split() def apply_code_style(): - files = filter(lambda x: x.find('tests/system/gt_data') == -1, get_files()) + files = filter(lambda x: x.find(b'tests/system/gt_data') == -1, get_files()) - files = filter(lambda x: x.endswith('.c') or - x.endswith('.h') or - x.endswith('.cpp'), files) + files = filter(lambda x: x.endswith(b'.c') or + x.endswith(b'.h') or + x.endswith(b'.cpp'), files) for f in files: - print("Apply code style to: " + f) + print("Apply code style to: " + str(f)) subprocess.check_output(['clang-format-7', '-i', f]) subprocess.check_output(['git', 'add', f]) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c6818a16 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "sonarlint.pathToCompileCommands": "${workspaceFolder}/src/engine/compile_commands.json" +} \ No newline at end of file diff --git a/src/engine/classic/classic_cvode_integrator.c b/src/engine/classic/classic_cvode_integrator.c index 09687554..dc66286d 100644 --- a/src/engine/classic/classic_cvode_integrator.c +++ b/src/engine/classic/classic_cvode_integrator.c @@ -233,6 +233,13 @@ void CVODE_integrate(SIM_simulator simulate) if (check_flag(&flag, "CVDense", 1, simulator)) return; } + if (simulator->data->params->CVODE_max_order != 0) { + flag = CVodeSetMaxOrd(cvode_mem, simulator->data->params->CVODE_max_order); + if (check_flag(&flag, "CVodeSetMaxOrd", 1, simulator)) { + return; + } + } + getTime(simulator->stats->sTime); if (is_sampled) { CLC_save_step(simOutput, solution, solution_time, t, totalOutputSteps, NV_DATA_S(y), clcData->d, clcData->alg); diff --git a/src/engine/classic/classic_data.c b/src/engine/classic/classic_data.c index e589c802..1a3dc511 100644 --- a/src/engine/classic/classic_data.c +++ b/src/engine/classic/classic_data.c @@ -42,7 +42,6 @@ CLC_data CLC_Data(int states, int discretes, int events, int inputs, int algebra strcat(fileName, ".ini"); SET_settings settings = SET_Settings(fileName); CLC_data p = checkedMalloc(sizeof(*p)); - int i; p->states = states; p->discretes = discretes; p->events = events; @@ -78,14 +77,15 @@ CLC_data CLC_Data(int states, int discretes, int events, int inputs, int algebra cleanVector(p->nDS, 0, states); double sameDQMin = (settings->nDQMin == 1) ? settings->dqmin[0] : 0; double sameDQRel = (settings->nDQRel == 1) ? settings->dqrel[0] : 0; - for (i = 0; i < states; i++) { + for (int i = 0; i < states; i++) { p->nSD[i] = 0; p->dQMin[i] = (sameDQMin > 0) ? sameDQMin : settings->dqmin[i]; p->dQRel[i] = (sameDQRel > 0) ? sameDQRel : settings->dqrel[i]; } p->event = SD_EventData(events); p->params = SD_Parameters(settings->derdelta, settings->zchyst, settings->minstep, settings->symdiff, settings->lps, settings->nodesize, - settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian); + settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian, + settings->CVODE_max_order); p->scalarEvaluations = 0; p->zeroCrossings = 0; p->funEvaluations = 0; diff --git a/src/engine/common/data.c b/src/engine/common/data.c index 47cd2211..aa04fdaf 100644 --- a/src/engine/common/data.c +++ b/src/engine/common/data.c @@ -171,7 +171,7 @@ void SD_cleanEventData(SD_eventData events, int size) } SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int symDiff, int lps, int nodeSize, SD_PartitionMethod pm, - double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian) + double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order) { SD_parameters p = checkedMalloc(sizeof(*p)); p->derDelta = derDelta; @@ -185,6 +185,7 @@ SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int p->dtSynch = synch; p->partitionerOptions = partitionerOptions; p->jacobian = jacobian; + p->CVODE_max_order = CVODE_max_order; return p; } diff --git a/src/engine/common/data.h b/src/engine/common/data.h index a4aee0d1..bd7569c3 100644 --- a/src/engine/common/data.h +++ b/src/engine/common/data.h @@ -169,13 +169,14 @@ struct SD_parameters_ { int lps; //!< Number of LPs defined for parallel simulations. int nodeSize; //!< Node size used in the memory list for output simulation values. int jacobian; + int CVODE_max_order; SD_PartitionMethod pm; //!< Partition method used to obtain a model partition for parallel simulations. SD_DtSynch dtSynch; //!< \f $ \delta t $ \f synchronization policy. SD_partitionerOptions partitionerOptions; }; SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int symDiff, int lps, int nodeSize, SD_PartitionMethod pm, - double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian); + double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order); SD_parameters SD_copyParameters(SD_parameters parameters); diff --git a/src/engine/common/settings.c b/src/engine/common/settings.c index e43b0451..ed015516 100644 --- a/src/engine/common/settings.c +++ b/src/engine/common/settings.c @@ -119,9 +119,13 @@ int _getOrder(SD_Solver sol) SET_settings SET_Settings(char *fname) { - config_t cfg, *cf; + config_t cfg; + config_t *cf; const config_setting_t *lists; - int count, n, ires, option; + int count; + int n; + int ires; + int option; double dres; const char *sol; const char *bdf; @@ -153,6 +157,7 @@ SET_settings SET_Settings(char *fname) p->dtSynch = SD_DT_Adaptive; p->BDFPart = 0; p->BDFPartitionDepth = 1; + p->CVODE_max_order = 0; p->BDFMaxStep = 0; if (config_lookup_float(cf, "minstep", &dres)) { if (dres == 0) { @@ -201,6 +206,9 @@ SET_settings SET_Settings(char *fname) if (config_lookup_int(cf, "jacobian", &ires)) { p->jacobian = ires; } + if (config_lookup_int(cf, "CVODEMaxOrder", &ires)) { + p->CVODE_max_order = ires; + } if (config_lookup_int(cf, "nodesize", &ires)) { if (ires == 0) { p->nodesize = NODE_SIZE; diff --git a/src/engine/common/settings.h b/src/engine/common/settings.h index e6e04358..674cc69d 100644 --- a/src/engine/common/settings.h +++ b/src/engine/common/settings.h @@ -43,6 +43,7 @@ struct SET_settings_ { int nDQRel; int jacobian; int BDFPartitionDepth; + int CVODE_max_order; SD_PartitionMethod pm; SD_DtSynch dtSynch; SD_partitionerOptions partitionerOptions; diff --git a/src/engine/qss/qss_data.c b/src/engine/qss/qss_data.c index aac9e2e7..af91c39e 100644 --- a/src/engine/qss/qss_data.c +++ b/src/engine/qss/qss_data.c @@ -308,7 +308,7 @@ QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, i exit(-1); } QSS_data p = checkedMalloc(sizeof(*p)); - int i, order = settings->order; + int order = settings->order; int xOrder = order + 1; p->states = states; p->discretes = discretes; @@ -421,7 +421,7 @@ QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, i } } - for (i = 0; i < states; i++) { + for (int i = 0; i < states; i++) { p->dQMin[i] = (same_DQMin) ? settings->dqmin[0] : settings->dqmin[i]; p->dQRel[i] = (same_DQRel) ? settings->dqrel[0] : settings->dqrel[i]; } @@ -439,7 +439,8 @@ QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, i p->event = NULL; } p->params = SD_Parameters(settings->derdelta, settings->zchyst, settings->minstep, settings->symdiff, settings->lps, settings->nodesize, - settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian); + settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian, + settings->CVODE_max_order); p->lp = NULL; if (settings->lps > 0) { QSS_setReinitBuffer(TRUE);