From 8fefb8cd5233493e408251ec301ee24eb405a8fc Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Thu, 1 Jun 2023 11:06:03 -0300 Subject: [PATCH] Added new system tests GT files for mmoc. --- .../gt_data/BouncingBall/BouncingBall.c | 710 ++++++++++++++ .../gt_data/BouncingBall/BouncingBall.h | 226 +++++ .../gt_data/BouncingBall/BouncingBall.ini | 15 + .../gt_data/BouncingBall/BouncingBall.mo | 69 ++ src/mmoc/tests/system/gt_data/TYSON/TYSON.c | 916 ++++++++++++++++++ src/mmoc/tests/system/gt_data/TYSON/TYSON.h | 231 +++++ src/mmoc/tests/system/gt_data/TYSON/TYSON.ini | 15 + src/mmoc/tests/system/gt_data/TYSON/TYSON.mo | 64 ++ src/mmoc/tests/system/gt_data/VIRplanoS/rnd.c | 10 + .../tests/system/gt_data/VIRplanoS/srnd.c | 9 + .../gt_data/advectionFlux/advectionFlux.c | 400 ++++++++ .../gt_data/advectionFlux/advectionFlux.h | 129 +++ .../gt_data/advectionFlux/advectionFlux.ini | 15 + .../gt_data/advectionFlux/advectionFlux.mo | 37 + .../tests/system/gt_data/burgers/burgers.c | 553 +++++++++++ .../tests/system/gt_data/burgers/burgers.h | 125 +++ .../tests/system/gt_data/burgers/burgers.ini | 15 + .../tests/system/gt_data/burgers/burgers.mo | 57 ++ .../tests/system/gt_data/testFor/testFor.c | 307 ++++++ .../tests/system/gt_data/testFor/testFor.h | 95 ++ .../tests/system/gt_data/testFor/testFor.ini | 15 + .../tests/system/gt_data/testFor/testFor.mo | 33 + 22 files changed, 4046 insertions(+) create mode 100644 src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.c create mode 100644 src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.h create mode 100644 src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.ini create mode 100644 src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.mo create mode 100644 src/mmoc/tests/system/gt_data/TYSON/TYSON.c create mode 100644 src/mmoc/tests/system/gt_data/TYSON/TYSON.h create mode 100644 src/mmoc/tests/system/gt_data/TYSON/TYSON.ini create mode 100644 src/mmoc/tests/system/gt_data/TYSON/TYSON.mo create mode 100644 src/mmoc/tests/system/gt_data/VIRplanoS/rnd.c create mode 100644 src/mmoc/tests/system/gt_data/VIRplanoS/srnd.c create mode 100644 src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.c create mode 100644 src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.h create mode 100644 src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.ini create mode 100644 src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.mo create mode 100644 src/mmoc/tests/system/gt_data/burgers/burgers.c create mode 100644 src/mmoc/tests/system/gt_data/burgers/burgers.h create mode 100644 src/mmoc/tests/system/gt_data/burgers/burgers.ini create mode 100644 src/mmoc/tests/system/gt_data/burgers/burgers.mo create mode 100644 src/mmoc/tests/system/gt_data/testFor/testFor.c create mode 100644 src/mmoc/tests/system/gt_data/testFor/testFor.h create mode 100644 src/mmoc/tests/system/gt_data/testFor/testFor.ini create mode 100644 src/mmoc/tests/system/gt_data/testFor/testFor.mo diff --git a/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.c b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.c new file mode 100644 index 00000000..10a99c21 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.c @@ -0,0 +1,710 @@ +#include +#include +#include +#include + +#include "BouncingBall.h" +#include +#include +#include +#include +#include + +void MOD_settings(SD_simulationSettings settings) +{ + settings->debug = 0; + settings->parallel = FALSE; + settings->hybrid = TRUE; + settings->method = 7; +} + +void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) +{ + switch(idx) { + case _eval_ball1_y(0): { + _der_ball1_y(0) = _ball1_v(0); + _der_ball1_y(1) = (0)/2; + _der_ball1_y(2) = (0)/6; + + return; + } + case _eval_ball1_v(0): { + _fixed1_flange1_v(0) = 0; + _fixed1_flange1_v(1) = 0; + _fixed1_flange1_v(2) = 0; + _ball1_flange1_v(0) = _ball1_v(0); + _ball1_flange1_v(1) = 0; + _ball1_flange1_v(2) = 0; + _spring1_flange2_v(0) = _fixed1_flange1_v(0); + _spring1_flange2_v(1) = 0; + _spring1_flange2_v(2) = 0; + _spring1_flange1_v(0) = _ball1_flange1_v(0); + _spring1_flange1_v(1) = 0; + _spring1_flange1_v(2) = 0; + _fixed1_flange1_s(0) = _fixed1_s0; + _fixed1_flange1_s(1) = 0; + _fixed1_flange1_s(2) = 0; + _ball1_flange1_s(0) = _ball1_y(0); + _ball1_flange1_s(1) = 0; + _ball1_flange1_s(2) = 0; + _spring1_flange2_s(0) = _fixed1_flange1_s(0); + _spring1_flange2_s(1) = 0; + _spring1_flange2_s(2) = 0; + _spring1_flange1_s(0) = _ball1_flange1_s(0); + _spring1_flange1_s(1) = 0; + _spring1_flange1_s(2) = 0; + _spring1_dv(0) = _spring1_flange1_v(0)-_spring1_flange2_v(0); + _spring1_dv(1) = 0; + _spring1_dv(2) = 0; + _spring1_dy(0) = _spring1_flange1_s(0)-_spring1_flange2_s(0); + _spring1_dy(1) = 0; + _spring1_dy(2) = 0; + _spring1_flange1_f(0) = _d0*(_spring1_b*_spring1_dv(0)+_spring1_k*_spring1_dy(0))+(1-_d0)*(0); + _spring1_flange1_f(1) = 0; + _spring1_flange1_f(2) = 0; + _ball1_flange1_f(0) = (-_spring1_flange1_f(0)); + _ball1_flange1_f(1) = 0; + _ball1_flange1_f(2) = 0; + _der_ball1_v(0) = (_ball1_flange1_f(0)-_ball1_m*_ball1_g)*(1/(_ball1_m)); + _der_ball1_v(1) = (0)/2; + _der_ball1_v(2) = (0)/6; + + return; + } + } +} + +void MOD_zeroCrossing(int idx, double *x, double *d, double *a, double t, double *zc) +{ + switch(idx) { + case _eval_event_1: { + _fixed1_flange1_s(0) = _fixed1_s0; + _fixed1_flange1_s(1) = 0; + _fixed1_flange1_s(2) = 0; + _ball1_flange1_s(0) = _ball1_y(0); + _ball1_flange1_s(1) = 0; + _ball1_flange1_s(2) = 0; + _spring1_flange2_s(0) = _fixed1_flange1_s(0); + _spring1_flange2_s(1) = 0; + _spring1_flange2_s(2) = 0; + _spring1_flange1_s(0) = _ball1_flange1_s(0); + _spring1_flange1_s(1) = 0; + _spring1_flange1_s(2) = 0; + _spring1_dy(0) = _spring1_flange1_s(0)-_spring1_flange2_s(0); + _spring1_dy(1) = 0; + _spring1_dy(2) = 0; + _zc(0) = _spring1_dy(0)-(0); + _zc(1) = (0)/1; + _zc(2) = (0)/2; + + return; + } + case _eval_event_2: { + _zc(0) = _d0-(0); + _zc(1) = (0)/1; + _zc(2) = (0)/2; + + return; + } + case _eval_event_3: { + _zc(0) = _d0-(1); + _zc(1) = (0)/1; + _zc(2) = (0)/2; + + return; + } + } +} + +void MOD_handlerPos(int idx, double *x, double* q, double *d, double *a, double t) +{ + switch(idx) { + case _eval_event_1: { + _d0 = 0; + return; + } + case _eval_event_2: { + _d1 = 1; + return; + } + } +} + +void MOD_handlerNeg(int idx, double *x, double* q, double *d, double *a, double t) +{ + switch(idx) { + case _eval_event_1: { + _d0 = 1; + return; + } + case _eval_event_3: { + _d1 = 0; + return; + } + } +} + +void MOD_output(int idx, double *x, double *d, double *a, double t, double *out) +{ + switch(idx) { + case _eval_out_exp_1: { + _out = _ball1_y(0); + return; + } + } +} + +void MOD_jacobian(double *x, double *d, double *a, double t, SD_jacMatrices dvdx, double *jac) +{ + int row, row_t, eq_var, c_row, c_row_g; + int col, col_g, col_t; + int x_ind; + double aux; + SD_cleanJacMatrices(dvdx); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[2]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_v(0); + col = pos(dvdx->dg_dx[7]->index[c_row], dvdx->dg_dx[7]->size[c_row], x_ind); + c_row_g = _idx_ball1_flange1_v(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->dg_dx[7]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_v(0); + col = pos(dvdx->dg_dx[8]->index[c_row], dvdx->dg_dx[8]->size[c_row], x_ind); + c_row_g = _idx_spring1_flange1_v(0) - 7; + col_g = pos(dvdx->dg_dx[7]->index[c_row_g], dvdx->dg_dx[7]->size[c_row_g], x_ind); + dvdx->dg_dx[8]->value[c_row][col] += aux * dvdx->dg_dx[7]->value[c_row_g][col_g]; + aux = 0; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_y(0); + col = pos(dvdx->dg_dx[3]->index[c_row], dvdx->dg_dx[3]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[3]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_y(0); + col = pos(dvdx->dg_dx[6]->index[c_row], dvdx->dg_dx[6]->size[c_row], x_ind); + c_row_g = _idx_ball1_flange1_s(0) - 3; + col_g = pos(dvdx->dg_dx[3]->index[c_row_g], dvdx->dg_dx[3]->size[c_row_g], x_ind); + dvdx->dg_dx[6]->value[c_row][col] += aux * dvdx->dg_dx[3]->value[c_row_g][col_g]; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_y(0); + col = pos(dvdx->dg_dx[9]->index[c_row], dvdx->dg_dx[9]->size[c_row], x_ind); + c_row_g = _idx_spring1_flange1_s(0) - 6; + col_g = pos(dvdx->dg_dx[6]->index[c_row_g], dvdx->dg_dx[6]->size[c_row_g], x_ind); + dvdx->dg_dx[9]->value[c_row][col] += aux * dvdx->dg_dx[6]->value[c_row_g][col_g]; + aux = 0; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_v(0); + col = pos(dvdx->dg_dx[10]->index[c_row], dvdx->dg_dx[10]->size[c_row], x_ind); + c_row_g = _idx_spring1_dv(0) - 8; + col_g = pos(dvdx->dg_dx[8]->index[c_row_g], dvdx->dg_dx[8]->size[c_row_g], x_ind); + dvdx->dg_dx[10]->value[c_row][col] += aux * dvdx->dg_dx[8]->value[c_row_g][col_g]; + aux = 0; + x_ind = _idx_ball1_y(0); + col = pos(dvdx->dg_dx[10]->index[c_row], dvdx->dg_dx[10]->size[c_row], x_ind); + c_row_g = _idx_spring1_dy(0) - 9; + col_g = pos(dvdx->dg_dx[9]->index[c_row_g], dvdx->dg_dx[9]->size[c_row_g], x_ind); + dvdx->dg_dx[10]->value[c_row][col] += aux * dvdx->dg_dx[9]->value[c_row_g][col_g]; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_v(0); + col = pos(dvdx->dg_dx[12]->index[c_row], dvdx->dg_dx[12]->size[c_row], x_ind); + c_row_g = _idx_spring1_flange1_f(0) - 10; + col_g = pos(dvdx->dg_dx[10]->index[c_row_g], dvdx->dg_dx[10]->size[c_row_g], x_ind); + dvdx->dg_dx[12]->value[c_row][col] += aux * dvdx->dg_dx[10]->value[c_row_g][col_g]; + x_ind = _idx_ball1_y(0); + col = pos(dvdx->dg_dx[12]->index[c_row], dvdx->dg_dx[12]->size[c_row], x_ind); + c_row_g = _idx_spring1_flange1_f(0) - 10; + col_g = pos(dvdx->dg_dx[10]->index[c_row_g], dvdx->dg_dx[10]->size[c_row_g], x_ind); + dvdx->dg_dx[12]->value[c_row][col] += aux * dvdx->dg_dx[10]->value[c_row_g][col_g]; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_ball1_v(0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + c_row_g = _idx_ball1_flange1_f(0) - 12; + col_g = pos(dvdx->dg_dx[12]->index[c_row_g], dvdx->dg_dx[12]->size[c_row_g], x_ind); + dvdx->df_dx[1]->value[c_row][col] += aux * dvdx->dg_dx[12]->value[c_row_g][col_g]; + x_ind = _idx_ball1_y(0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + c_row_g = _idx_ball1_flange1_f(0) - 12; + col_g = pos(dvdx->dg_dx[12]->index[c_row_g], dvdx->dg_dx[12]->size[c_row_g], x_ind); + dvdx->df_dx[1]->value[c_row][col] += aux * dvdx->dg_dx[12]->value[c_row_g][col_g]; + } + // Assign Jacobian Matrix values for equation: 0 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[0]->size[row]; col++) { + row_t = dvdx->df_dx[0]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[0]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 1 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[1]->size[row]; col++) { + row_t = dvdx->df_dx[1]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[1]->value[row][col]); + } + } +} + +void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) +{ + switch(idx) { + case _eval_ball1_v(0): { + _fixed1_flange1_v(0) = 0; + _fixed1_flange1_v(1) = 0; + _fixed1_flange1_v(2) = 0; + _ball1_flange1_v(0) = _ball1_v(0); + _ball1_flange1_v(1) = 0; + _ball1_flange1_v(2) = 0; + _spring1_flange2_v(0) = _fixed1_flange1_v(0); + _spring1_flange2_v(1) = 0; + _spring1_flange2_v(2) = 0; + _spring1_flange1_v(0) = _ball1_flange1_v(0); + _spring1_flange1_v(1) = 0; + _spring1_flange1_v(2) = 0; + _fixed1_flange1_s(0) = _fixed1_s0; + _fixed1_flange1_s(1) = 0; + _fixed1_flange1_s(2) = 0; + _ball1_flange1_s(0) = _ball1_y(0); + _ball1_flange1_s(1) = 0; + _ball1_flange1_s(2) = 0; + _spring1_flange2_s(0) = _fixed1_flange1_s(0); + _spring1_flange2_s(1) = 0; + _spring1_flange2_s(2) = 0; + _spring1_flange1_s(0) = _ball1_flange1_s(0); + _spring1_flange1_s(1) = 0; + _spring1_flange1_s(2) = 0; + _spring1_dv(0) = _spring1_flange1_v(0)-_spring1_flange2_v(0); + _spring1_dv(1) = 0; + _spring1_dv(2) = 0; + _spring1_dy(0) = _spring1_flange1_s(0)-_spring1_flange2_s(0); + _spring1_dy(1) = 0; + _spring1_dy(2) = 0; + _spring1_flange1_f(0) = _d0*(_spring1_b*_spring1_dv(0)+_spring1_k*_spring1_dy(0))+(1-_d0)*(0); + _spring1_flange1_f(1) = 0; + _spring1_flange1_f(2) = 0; + _ball1_flange1_f(0) = (-_spring1_flange1_f(0)); + _ball1_flange1_f(1) = 0; + _ball1_flange1_f(2) = 0; + _eval_dep_ball1_y(1) = _ball1_v(0); + _eval_dep_ball1_y(2) = (0)/2; + _eval_dep_ball1_y(3) = (0)/6; + _eval_dep_ball1_v(1) = (_ball1_flange1_f(0)-_ball1_m*_ball1_g)*(1/(_ball1_m)); + _eval_dep_ball1_v(2) = (0)/2; + _eval_dep_ball1_v(3) = (0)/6; + break; + } + case _eval_ball1_y(0): { + _fixed1_flange1_v(0) = 0; + _fixed1_flange1_v(1) = 0; + _fixed1_flange1_v(2) = 0; + _ball1_flange1_v(0) = _ball1_v(0); + _ball1_flange1_v(1) = 0; + _ball1_flange1_v(2) = 0; + _spring1_flange2_v(0) = _fixed1_flange1_v(0); + _spring1_flange2_v(1) = 0; + _spring1_flange2_v(2) = 0; + _spring1_flange1_v(0) = _ball1_flange1_v(0); + _spring1_flange1_v(1) = 0; + _spring1_flange1_v(2) = 0; + _fixed1_flange1_s(0) = _fixed1_s0; + _fixed1_flange1_s(1) = 0; + _fixed1_flange1_s(2) = 0; + _ball1_flange1_s(0) = _ball1_y(0); + _ball1_flange1_s(1) = 0; + _ball1_flange1_s(2) = 0; + _spring1_flange2_s(0) = _fixed1_flange1_s(0); + _spring1_flange2_s(1) = 0; + _spring1_flange2_s(2) = 0; + _spring1_flange1_s(0) = _ball1_flange1_s(0); + _spring1_flange1_s(1) = 0; + _spring1_flange1_s(2) = 0; + _spring1_dv(0) = _spring1_flange1_v(0)-_spring1_flange2_v(0); + _spring1_dv(1) = 0; + _spring1_dv(2) = 0; + _spring1_dy(0) = _spring1_flange1_s(0)-_spring1_flange2_s(0); + _spring1_dy(1) = 0; + _spring1_dy(2) = 0; + _spring1_flange1_f(0) = _d0*(_spring1_b*_spring1_dv(0)+_spring1_k*_spring1_dy(0))+(1-_d0)*(0); + _spring1_flange1_f(1) = 0; + _spring1_flange1_f(2) = 0; + _ball1_flange1_f(0) = (-_spring1_flange1_f(0)); + _ball1_flange1_f(1) = 0; + _ball1_flange1_f(2) = 0; + _eval_dep_ball1_v(1) = (_ball1_flange1_f(0)-_ball1_m*_ball1_g)*(1/(_ball1_m)); + _eval_dep_ball1_v(2) = (0)/2; + _eval_dep_ball1_v(3) = (0)/6; + break; + } + } +} + +void MOD_BDF_definition(double *x, double *d, double *a, double t, double *dx, int *BDFMap, int nBDF) +{ + int idx; + int __bdf_it; + for(__bdf_it = 0; __bdf_it < nBDF; __bdf_it++) { + idx = BDFMap[__bdf_it]; + switch(idx) { + case _eval_ball1_y(0): { + _eval_dep_ball1_y(1) = _ball1_v(0); + + + continue; + } + case _eval_ball1_v(0): { + _fixed1_flange1_v(0) = 0; + + _ball1_flange1_v(0) = _ball1_v(0); + + _spring1_flange2_v(0) = _fixed1_flange1_v(0); + + _spring1_flange1_v(0) = _ball1_flange1_v(0); + + _fixed1_flange1_s(0) = _fixed1_s0; + + _ball1_flange1_s(0) = _ball1_y(0); + + _spring1_flange2_s(0) = _fixed1_flange1_s(0); + + _spring1_flange1_s(0) = _ball1_flange1_s(0); + + _spring1_dv(0) = _spring1_flange1_v(0)-_spring1_flange2_v(0); + + _spring1_dy(0) = _spring1_flange1_s(0)-_spring1_flange2_s(0); + + _spring1_flange1_f(0) = _d0*(_spring1_b*_spring1_dv(0)+_spring1_k*_spring1_dy(0))+(1-_d0)*(0); + + _ball1_flange1_f(0) = (-_spring1_flange1_f(0)); + + _eval_dep_ball1_v(1) = (_ball1_flange1_f(0)-_ball1_m*_ball1_g)*(1/(_ball1_m)); + + + continue; + } + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(2,2,3,0,14,2,14,"BouncingBall"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* algebraics = (int*) malloc(14*sizeof(int)); + int* states = (int*) malloc(2*sizeof(int)); + int* discretes = (int*) malloc(2*sizeof(int)); + int* events = (int*) malloc(3*sizeof(int)); + int* outputs = (int*) malloc(1*sizeof(int)); + int row, eq_var, c_row; + int x_ind; + _ball1_g = 9.800000e+00; + _ball1_m = 1; + _init_ball1_y(0) = 10; + _fixed1_s0 = 0; + _spring1_b = 10; + _spring1_k = 10000; + modelData->nSD[_idx_ball1_v(0)]++; + modelData->nSD[_idx_ball1_v(0)]++; + modelData->nSD[_idx_ball1_y(0)]++; + modelData->nDS[_idx_ball1_y(0)]++; + modelData->nDS[_idx_ball1_v(0)]++; + modelData->nDS[_idx_ball1_v(0)]++; + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[0]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[7]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[8]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[3]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[6]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[9]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[10]->size[c_row]++; + modelData->jac_matrices->dg_dx[10]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[12]->size[c_row]++; + modelData->jac_matrices->dg_dx[12]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[1]->size[c_row]++; + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + modelData->nSZ[_idx_ball1_y(0)]++; + modelData->nZS[_idx_event_1]++; + modelData->nHZ[_idx_event_1]++; + modelData->nHZ[_idx_event_1]++; + modelData->nHD[_idx_event_1]++; + modelData->event[_idx_event_1].nLHSDsc++; + modelData->event[_idx_event_2].nLHSDsc++; + modelData->event[_idx_event_3].nLHSDsc++; + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 2); + modelData->SD[_idx_ball1_v(0)][states[_idx_ball1_v(0)]++] = _idx_ball1_y(0); + modelData->SD[_idx_ball1_v(0)][states[_idx_ball1_v(0)]++] = _idx_ball1_v(0); + modelData->SD[_idx_ball1_y(0)][states[_idx_ball1_y(0)]++] = _idx_ball1_v(0); + cleanVector(states, 0, 2); + modelData->DS[_idx_ball1_y(0)][states[_idx_ball1_y(0)]++] = _idx_ball1_v(0); + modelData->DS[_idx_ball1_v(0)][states[_idx_ball1_v(0)]++] = _idx_ball1_v(0); + modelData->DS[_idx_ball1_v(0)][states[_idx_ball1_v(0)]++] = _idx_ball1_y(0); + cleanVector(states, 0, 2); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->dg_dx[7]->index[c_row],modelData->jac_matrices->dg_dx[7]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[7]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[7]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->dg_dx[8]->index[c_row],modelData->jac_matrices->dg_dx[8]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[8]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[8]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->dg_dx[3]->index[c_row],modelData->jac_matrices->dg_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[3]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->dg_dx[6]->index[c_row],modelData->jac_matrices->dg_dx[6]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[6]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[6]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->dg_dx[9]->index[c_row],modelData->jac_matrices->dg_dx[9]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[9]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[9]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->dg_dx[10]->index[c_row],modelData->jac_matrices->dg_dx[10]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[10]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[10]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->dg_dx[10]->index[c_row],modelData->jac_matrices->dg_dx[10]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[10]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[10]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 14); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->dg_dx[12]->index[c_row],modelData->jac_matrices->dg_dx[12]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[12]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[12]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->dg_dx[12]->index[c_row],modelData->jac_matrices->dg_dx[12]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[12]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[12]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 2); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_ball1_v(0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_ball1_y(0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 2); + modelData->SZ[_idx_ball1_y(0)][states[_idx_ball1_y(0)]++] = _idx_event_1; + cleanVector(events, 0, 3); + modelData->ZS[_idx_event_1][events[_idx_event_1]++] = _idx_ball1_y(0); + cleanVector(events, 0, 3); + modelData->HZ[_idx_event_1][events[_idx_event_1]++] = _idx_event_2; + modelData->HZ[_idx_event_1][events[_idx_event_1]++] = _idx_event_3; + cleanVector(events, 0, 3); + modelData->HD[_idx_event_1][events[_idx_event_1]++] = _idx_ball1_v(0); + cleanVector(events, 0, 3); + modelData->event[_idx_event_1].LHSDsc[events[_idx_event_1]++] = _idx_d0; + modelData->event[_idx_event_2].LHSDsc[events[_idx_event_2]++] = _idx_d1; + modelData->event[_idx_event_3].LHSDsc[events[_idx_event_3]++] = _idx_d1; + modelData->event[_idx_event_1].direction = 0; + modelData->event[_idx_event_1].relation = 0; + modelData->event[_idx_event_2].direction = 1; + modelData->event[_idx_event_2].relation = 2; + modelData->event[_idx_event_3].direction = -1; + modelData->event[_idx_event_3].relation = 0; + SD_setupJacMatrices(modelData->jac_matrices); + simulator->time = QSS_Time(2,3,0,0,ST_Binary, NULL); + double period[1]; + period[0] = 0.01; + simulator->output = SD_Output("BouncingBall",1,2,2,period,1,0,CI_Sampled,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + modelOutput->nOS[_idx_out_exp_1]++; + modelOutput->nSO[_idx_ball1_y(0)]++; + SD_allocOutputMatrix(modelOutput, 2, 2); + sprintf(modelOutput->variable[_idx_out_exp_1].name, "ball1_y"); + cleanVector(outputs, 0, 1); + modelOutput->OS[_idx_out_exp_1][outputs[_idx_out_exp_1]++] = _idx_ball1_y(0); + cleanVector(states, 0, 2); + modelOutput->SO[_idx_ball1_y(0)][states[_idx_ball1_y(0)]++] = _idx_out_exp_1; + simulator->model = QSS_Model(MOD_definition, MOD_dependencies, MOD_zeroCrossing, MOD_handlerPos, MOD_handlerNeg, MOD_jacobian, MOD_BDF_definition); + free(algebraics); + free(states); + free(discretes); + free(events); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.h b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.h new file mode 100644 index 00000000..dd7eef96 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.h @@ -0,0 +1,226 @@ +// Model data access macro. + +#define MODEL_DATA_ACCESS(m) \ + double* x = m->x; \ + double* d = m->d; \ + double* a = m->alg; + +// Coeff multipliers definition. + +#define COEFF_MULTIPLIER(c) COEFF_MULTIPLIER_##c +#define COEFF_MULTIPLIER_0 1 +#define COEFF_MULTIPLIER_1 1 +#define COEFF_MULTIPLIER_2 2 +#define COEFF_MULTIPLIER_3 6 + +// Model Variables Macros + +// Macros definition for variable: _event_1 +#define _idx_event_1 0 +#define _eval_event_1 0 + +// Macros definition for variable: _event_2 +#define _idx_event_2 1 +#define _eval_event_2 1 + +// Macros definition for variable: _event_3 +#define _idx_event_3 2 +#define _eval_event_3 2 + +// Macros definition for variable: _out_exp_1 +#define _idx_out_exp_1 0 +#define _eval_out_exp_1 0 + +// Macros definition for variable: ball1_flange1_f +#define _idx_ball1_flange1_f(coeff) 12 +#define _state_idx_ball1_flange1_f(coeff) 12*4 + coeff +#define _ball1_flange1_f(coeff) a[_state_idx_ball1_flange1_f(coeff)] + +// Macros definition for variable: ball1_flange1_s +#define _idx_ball1_flange1_s(coeff) 3 +#define _state_idx_ball1_flange1_s(coeff) 3*4 + coeff +#define _ball1_flange1_s(coeff) a[_state_idx_ball1_flange1_s(coeff)] + +// Macros definition for variable: ball1_flange1_v +#define _idx_ball1_flange1_v(coeff) 2 +#define _state_idx_ball1_flange1_v(coeff) 2*4 + coeff +#define _ball1_flange1_v(coeff) a[_state_idx_ball1_flange1_v(coeff)] + +// Macros definition for variable: ball1_g +#define _ball1_g __PAR__ball1_g + +// Macros definition for variable: ball1_m +#define _ball1_m __PAR__ball1_m + +// Macros definition for variable: ball1_v +#define _idx_ball1_v(coeff) 1 +#define _state_idx_ball1_v(coeff) 1*4 + coeff +#define _ball1_v(coeff) x[_state_idx_ball1_v(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_ball1_v(coeff) x[_state_idx_ball1_v(coeff)] +#define _q_ball1_v(coeff) q[_state_idx_ball1_v(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_ball1_v(coeff) 1 +#define _eval_dep_ball1_v(coeff) dx[_state_idx_ball1_v(coeff)] + +// Macros definition for variable: ball1_y +#define _idx_ball1_y(coeff) 0 +#define _state_idx_ball1_y(coeff) 0*4 + coeff +#define _ball1_y(coeff) x[_state_idx_ball1_y(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_ball1_y(coeff) x[_state_idx_ball1_y(coeff)] +#define _q_ball1_y(coeff) q[_state_idx_ball1_y(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_ball1_y(coeff) 0 +#define _eval_dep_ball1_y(coeff) dx[_state_idx_ball1_y(coeff)] + +// Macros definition for variable: d0 +#define _idx_d0 0 +#define _d0 d[_idx_d0] + +// Macros definition for variable: d1 +#define _idx_d1 1 +#define _d1 d[_idx_d1] + +// Macros definition for variable: fixed1_flange1_f +#define _idx_fixed1_flange1_f(coeff) 13 +#define _state_idx_fixed1_flange1_f(coeff) 13*4 + coeff +#define _fixed1_flange1_f(coeff) a[_state_idx_fixed1_flange1_f(coeff)] + +// Macros definition for variable: fixed1_flange1_s +#define _idx_fixed1_flange1_s(coeff) 0 +#define _state_idx_fixed1_flange1_s(coeff) 0*4 + coeff +#define _fixed1_flange1_s(coeff) a[_state_idx_fixed1_flange1_s(coeff)] + +// Macros definition for variable: fixed1_flange1_v +#define _idx_fixed1_flange1_v(coeff) 1 +#define _state_idx_fixed1_flange1_v(coeff) 1*4 + coeff +#define _fixed1_flange1_v(coeff) a[_state_idx_fixed1_flange1_v(coeff)] + +// Macros definition for variable: fixed1_s0 +#define _fixed1_s0 __PAR__fixed1_s0 + +// Macros definition for variable: spring1_b +#define _spring1_b __PAR__spring1_b + +// Macros definition for variable: spring1_dv +#define _idx_spring1_dv(coeff) 8 +#define _state_idx_spring1_dv(coeff) 8*4 + coeff +#define _spring1_dv(coeff) a[_state_idx_spring1_dv(coeff)] + +// Macros definition for variable: spring1_dy +#define _idx_spring1_dy(coeff) 9 +#define _state_idx_spring1_dy(coeff) 9*4 + coeff +#define _spring1_dy(coeff) a[_state_idx_spring1_dy(coeff)] + +// Macros definition for variable: spring1_flange1_f +#define _idx_spring1_flange1_f(coeff) 10 +#define _state_idx_spring1_flange1_f(coeff) 10*4 + coeff +#define _spring1_flange1_f(coeff) a[_state_idx_spring1_flange1_f(coeff)] + +// Macros definition for variable: spring1_flange1_s +#define _idx_spring1_flange1_s(coeff) 6 +#define _state_idx_spring1_flange1_s(coeff) 6*4 + coeff +#define _spring1_flange1_s(coeff) a[_state_idx_spring1_flange1_s(coeff)] + +// Macros definition for variable: spring1_flange1_v +#define _idx_spring1_flange1_v(coeff) 7 +#define _state_idx_spring1_flange1_v(coeff) 7*4 + coeff +#define _spring1_flange1_v(coeff) a[_state_idx_spring1_flange1_v(coeff)] + +// Macros definition for variable: spring1_flange2_f +#define _idx_spring1_flange2_f(coeff) 11 +#define _state_idx_spring1_flange2_f(coeff) 11*4 + coeff +#define _spring1_flange2_f(coeff) a[_state_idx_spring1_flange2_f(coeff)] + +// Macros definition for variable: spring1_flange2_s +#define _idx_spring1_flange2_s(coeff) 4 +#define _state_idx_spring1_flange2_s(coeff) 4*4 + coeff +#define _spring1_flange2_s(coeff) a[_state_idx_spring1_flange2_s(coeff)] + +// Macros definition for variable: spring1_flange2_v +#define _idx_spring1_flange2_v(coeff) 5 +#define _state_idx_spring1_flange2_v(coeff) 5*4 + coeff +#define _spring1_flange2_v(coeff) a[_state_idx_spring1_flange2_v(coeff)] + +// Macros definition for variable: spring1_k +#define _spring1_k __PAR__spring1_k + + +// Model Parameters Declaration + +// Macro for parameter: ball1_g +double __PAR__ball1_g; +// Macro for parameter: ball1_m +double __PAR__ball1_m; +// Macro for parameter: fixed1_s0 +double __PAR__fixed1_s0; +// Macro for parameter: spring1_b +double __PAR__spring1_b; +// Macro for parameter: spring1_k +double __PAR__spring1_k; + +// Derivative Equations Macros + +// Macros for equation: 1 + +// Macros for equation: 2 + + +// Algebraic Equations Macros + +// Macros for algebraic equation: 1 + +// Macros for algebraic equation: 2 + +// Macros for algebraic equation: 3 + +// Macros for algebraic equation: 4 + +// Macros for algebraic equation: 5 + +// Macros for algebraic equation: 6 + +// Macros for algebraic equation: 7 + +// Macros for algebraic equation: 8 + +// Macros for algebraic equation: 9 + +// Macros for algebraic equation: 10 + +// Macros for algebraic equation: 11 + +// Macros for algebraic equation: 12 + +// Macros for algebraic equation: 13 + +// Macros for algebraic equation: 14 + + +// Event Macros + +// Macros for event: 1 + +// Macros for event: 2 + +// Macros for event: 3 + +#define _zc(coeff) zc[coeff] + +// Output Equations Macros + +// Macros for output equation: 1 + +#define _out out[0] + +// Jacobian Macros definition. +#define _assign_jac(r, val) \ + col_t = dvdx->df_dx_t->size[r] + dvdx->df_dx_t->index[r][0]; \ + dvdx->df_dx_t->index[r][0]++; \ + jac[col_t] = val; +#define _c_index(i) (i-1) + +#define _time t + +// Derivative Macros definition. +// Derivative definition for variable: ball1_v +#define _der_ball1_v(coeff) dx[coeff+1] +// Derivative definition for variable: ball1_y +#define _der_ball1_y(coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.ini b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.ini new file mode 100644 index 00000000..bf135791 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.ini @@ -0,0 +1,15 @@ +minstep=1.00000e-14; +zchyst=1.00000e-12; +derdelta=1.00000e-08; +symdiff=1; +lps=0; +nodesize=10000; +jacobian=1; +it=0.00000e+00; +ft=1.00000e+01; +sol="LIQSS3"; +dqmin=(1.00000e-06); +dqrel=(1.00000e-03); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.mo b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.mo new file mode 100644 index 00000000..8e9fc9c4 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/BouncingBall/BouncingBall.mo @@ -0,0 +1,69 @@ +model BouncingBall + Real spring1_flange1_f; + Real spring1_flange1_s; + Real spring1_flange1_v; + Real spring1_flange2_f; + Real spring1_flange2_s; + Real spring1_flange2_v; + Real spring1_dy; + Real spring1_dv; + parameter Real spring1_b=10; + parameter Real spring1_k=10000; + Real fixed1_flange1_f; + Real fixed1_flange1_s; + Real fixed1_flange1_v; + parameter Real fixed1_s0=0; + Real ball1_flange1_f; + Real ball1_flange1_s; + Real ball1_flange1_v; + Real ball1_v; + parameter Real ball1_m=1; + parameter Real ball1_g=9.8; + Real ball1_y(start=10); + discrete Real d0; + discrete Real d1; +equation + fixed1_flange1_s = fixed1_s0; + fixed1_flange1_v = 0; + der(ball1_y) = ball1_v; + ball1_flange1_v = ball1_v; + ball1_flange1_s = ball1_y; + spring1_flange2_s = fixed1_flange1_s; + spring1_flange2_v = fixed1_flange1_v; + spring1_flange1_s = ball1_flange1_s; + spring1_flange1_v = ball1_flange1_v; + spring1_dv = spring1_flange1_v-spring1_flange2_v; + spring1_dy = spring1_flange1_s-spring1_flange2_s; + spring1_flange1_f = d0*(spring1_b*spring1_dv+spring1_k*spring1_dy)+(1-d0)*(0); + spring1_flange2_f = (((-spring1_flange1_f))); + ball1_flange1_f = (-spring1_flange1_f); + der(ball1_v) = (ball1_flange1_f-ball1_m*ball1_g)*(1/(ball1_m)); + fixed1_flange1_f = (-spring1_flange2_f); +algorithm + when spring1_dy<0 then + d0:=1; + elsewhen spring1_dy>=0 then + d0:=0; + end when; + when d0>0 then + d1:=1; + elsewhen d0<1 then + d1:=0; + end when; + annotation( + + experiment( + MMO_Description="", + MMO_Solver=LIQSS3, + MMO_PartitionMethod=Metis, + MMO_Output={ball1_y}, + MMO_OutputType=CI_Sampled, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime=0.0, + StopTime=10, + Tolerance={1e-3}, + AbsTolerance={1e-6} + )); +end BouncingBall; diff --git a/src/mmoc/tests/system/gt_data/TYSON/TYSON.c b/src/mmoc/tests/system/gt_data/TYSON/TYSON.c new file mode 100644 index 00000000..37541edb --- /dev/null +++ b/src/mmoc/tests/system/gt_data/TYSON/TYSON.c @@ -0,0 +1,916 @@ +#include +#include +#include +#include + +#include "TYSON.h" +#include "pkg_math.h" +#include +#include +#include +#include +#include + +void MOD_settings(SD_simulationSettings settings) +{ + settings->debug = 0; + settings->parallel = FALSE; + settings->hybrid = FALSE; + settings->method = 4; +} + +void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) +{ + switch(idx) { + case _eval_C2(0): { + _der_C2(0) = _k6*_M(0)-_k8*_C2(0)+_k9*_CP(0); + + + return; + } + case _eval_CP(0): { + _der_CP(0) = -_k3*_CP(0)*_Y(0)+_k8*_C2(0)-_k9*_CP(0); + + + return; + } + case _eval_pM(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _der_pM(0) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + + + return; + } + case _eval_M(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _der_M(0) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + + + return; + } + case _eval_Y(0): { + _der_Y(0) = _k1-_k2*_Y(0)-_k3*_CP(0)*_Y(0); + + + return; + } + case _eval_yP(0): { + _der_yP(0) = _k6*_M(0)-_k7*_yP(0); + + + return; + } + } +} + +void MOD_zeroCrossing(int idx, double *x, double *d, double *a, double t, double *zc) +{ +} + +void MOD_handlerPos(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_handlerNeg(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_output(int idx, double *x, double *d, double *a, double t, double *out) +{ + switch(idx) { + case _eval_out_exp_1: { + _out = _C2(0); + return; + } + case _eval_out_exp_2: { + _out = _CP(0); + return; + } + case _eval_out_exp_3: { + _out = _pM(0); + return; + } + case _eval_out_exp_4: { + _out = _M(0); + return; + } + case _eval_out_exp_5: { + _out = _Y(0); + return; + } + case _eval_out_exp_6: { + _out = _yP(0); + return; + } + } +} + +void MOD_jacobian(double *x, double *d, double *a, double t, SD_jacMatrices dvdx, double *jac) +{ + int row, row_t, eq_var, c_row, c_row_g; + int col, col_g, col_t; + int x_ind; + double aux; + SD_cleanJacMatrices(dvdx); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + x_ind = _idx_Y(0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + col = pos(dvdx->dg_dx[0]->index[c_row], dvdx->dg_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[0]->value[c_row][col] += aux; + x_ind = _idx_CP(0); + col = pos(dvdx->dg_dx[0]->index[c_row], dvdx->dg_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[0]->value[c_row][col] += aux; + x_ind = _idx_M(0); + col = pos(dvdx->dg_dx[0]->index[c_row], dvdx->dg_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[0]->value[c_row][col] += aux; + x_ind = _idx_pM(0); + col = pos(dvdx->dg_dx[0]->index[c_row], dvdx->dg_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[0]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_C2(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + c_row_g = _idx_CT(0) - 0; + col_g = pos(dvdx->dg_dx[0]->index[c_row_g], dvdx->dg_dx[0]->size[c_row_g], x_ind); + dvdx->dg_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[0]->value[c_row_g][col_g]; + x_ind = _idx_CP(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + c_row_g = _idx_CT(0) - 0; + col_g = pos(dvdx->dg_dx[0]->index[c_row_g], dvdx->dg_dx[0]->size[c_row_g], x_ind); + dvdx->dg_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[0]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + c_row_g = _idx_CT(0) - 0; + col_g = pos(dvdx->dg_dx[0]->index[c_row_g], dvdx->dg_dx[0]->size[c_row_g], x_ind); + dvdx->dg_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[0]->value[c_row_g][col_g]; + x_ind = _idx_pM(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + c_row_g = _idx_CT(0) - 0; + col_g = pos(dvdx->dg_dx[0]->index[c_row_g], dvdx->dg_dx[0]->size[c_row_g], x_ind); + dvdx->dg_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[0]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->dg_dx[2]->index[c_row], dvdx->dg_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->dg_dx[2]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_C2(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_pM(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[2]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + x_ind = _idx_Y(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + x_ind = _idx_pM(0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + x_ind = _idx_C2(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[3]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[3]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[3]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_pM(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[3]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + c_row_g = _idx_F(0) - 2; + col_g = pos(dvdx->dg_dx[2]->index[c_row_g], dvdx->dg_dx[2]->size[c_row_g], x_ind); + dvdx->df_dx[3]->value[c_row][col] += aux * dvdx->dg_dx[2]->value[c_row_g][col_g]; + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[3]->value[c_row][col] += aux; + x_ind = _idx_pM(0); + col = pos(dvdx->df_dx[3]->index[c_row], dvdx->df_dx[3]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[3]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_CP(0); + col = pos(dvdx->df_dx[4]->index[c_row], dvdx->df_dx[4]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[4]->value[c_row][col] += aux; + x_ind = _idx_Y(0); + col = pos(dvdx->df_dx[4]->index[c_row], dvdx->df_dx[4]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[4]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_M(0); + col = pos(dvdx->df_dx[5]->index[c_row], dvdx->df_dx[5]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[5]->value[c_row][col] += aux; + x_ind = _idx_yP(0); + col = pos(dvdx->df_dx[5]->index[c_row], dvdx->df_dx[5]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[5]->value[c_row][col] += aux; + } + // Assign Jacobian Matrix values for equation: 0 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[0]->size[row]; col++) { + row_t = dvdx->df_dx[0]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[0]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 1 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[1]->size[row]; col++) { + row_t = dvdx->df_dx[1]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[1]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 2 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[2]->size[row]; col++) { + row_t = dvdx->df_dx[2]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[2]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 3 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[3]->size[row]; col++) { + row_t = dvdx->df_dx[3]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[3]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 4 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[4]->size[row]; col++) { + row_t = dvdx->df_dx[4]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[4]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 5 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[5]->size[row]; col++) { + row_t = dvdx->df_dx[5]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[5]->value[row][col]); + } + } +} + +void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) +{ + switch(idx) { + case _eval_C2(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_C2(1) = _k6*_M(0)-_k8*_C2(0)+_k9*_CP(0); + _eval_dep_CP(1) = -_k3*_CP(0)*_Y(0)+_k8*_C2(0)-_k9*_CP(0); + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + _eval_dep_M(1) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + break; + } + case _eval_CP(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_C2(1) = _k6*_M(0)-_k8*_C2(0)+_k9*_CP(0); + _eval_dep_CP(1) = -_k3*_CP(0)*_Y(0)+_k8*_C2(0)-_k9*_CP(0); + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + _eval_dep_M(1) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + _eval_dep_Y(1) = _k1-_k2*_Y(0)-_k3*_CP(0)*_Y(0); + break; + } + case _eval_M(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_C2(1) = _k6*_M(0)-_k8*_C2(0)+_k9*_CP(0); + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + _eval_dep_M(1) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + _eval_dep_yP(1) = _k6*_M(0)-_k7*_yP(0); + break; + } + case _eval_Y(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_CP(1) = -_k3*_CP(0)*_Y(0)+_k8*_C2(0)-_k9*_CP(0); + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + _eval_dep_Y(1) = _k1-_k2*_Y(0)-_k3*_CP(0)*_Y(0); + break; + } + case _eval_pM(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + _eval_dep_M(1) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + break; + } + case _eval_yP(0): { + _eval_dep_yP(1) = _k6*_M(0)-_k7*_yP(0); + break; + } + } +} + +void MOD_BDF_definition(double *x, double *d, double *a, double t, double *dx, int *BDFMap, int nBDF) +{ + int idx; + int __bdf_it; + for(__bdf_it = 0; __bdf_it < nBDF; __bdf_it++) { + idx = BDFMap[__bdf_it]; + switch(idx) { + case _eval_C2(0): { + _eval_dep_C2(1) = _k6*_M(0)-_k8*_C2(0)+_k9*_CP(0); + + + continue; + } + case _eval_CP(0): { + _eval_dep_CP(1) = -_k3*_CP(0)*_Y(0)+_k8*_C2(0)-_k9*_CP(0); + + + continue; + } + case _eval_pM(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_pM(1) = _k3*_CP(0)*_Y(0)+-_pM(0)*_F(0)+_k5*_M(0); + + + continue; + } + case _eval_M(0): { + _CT(0) = _C2(0)+_CP(0)+_pM(0)+_M(0); + + _F(0) = _k4prim+_k4*__math__pow((_M(0)*1.000000e+00/_CT(0)), 2); + + _eval_dep_M(1) = _pM(0)*_F(0)-_k5*_M(0)-_k6*_M(0); + + + continue; + } + case _eval_Y(0): { + _eval_dep_Y(1) = _k1-_k2*_Y(0)-_k3*_CP(0)*_Y(0); + + + continue; + } + case _eval_yP(0): { + _eval_dep_yP(1) = _k6*_M(0)-_k7*_yP(0); + + + continue; + } + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(6,0,0,0,4,6,4,"TYSON"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* algebraics = (int*) malloc(4*sizeof(int)); + int* states = (int*) malloc(6*sizeof(int)); + int* outputs = (int*) malloc(6*sizeof(int)); + int row, eq_var, c_row; + int x_ind; + _init_C2(0) = 0.000000e+00; + _init_CP(0) = 7.500000e-01; + _init_M(0) = 0.000000e+00; + _init_Y(0) = 0.000000e+00; + _k1 = 1.500000e-02; + _k2 = 0.000000e+00; + _k3 = 200; + _k4 = 180; + _k4prim = 1.800000e-02; + _k5 = 0.000000e+00; + _k6 = 1.000000e+00; + _k7 = 6.000000e-01; + _k8 = 1.000000e+06; + _k9 = 1.000000e+03; + _init_pM(0) = 2.500000e-01; + _init_yP(0) = 0.000000e+00; + modelData->nSD[_idx_C2(0)]++; + modelData->nSD[_idx_C2(0)]++; + modelData->nSD[_idx_C2(0)]++; + modelData->nSD[_idx_C2(0)]++; + modelData->nSD[_idx_CP(0)]++; + modelData->nSD[_idx_CP(0)]++; + modelData->nSD[_idx_CP(0)]++; + modelData->nSD[_idx_CP(0)]++; + modelData->nSD[_idx_CP(0)]++; + modelData->nSD[_idx_M(0)]++; + modelData->nSD[_idx_M(0)]++; + modelData->nSD[_idx_M(0)]++; + modelData->nSD[_idx_M(0)]++; + modelData->nSD[_idx_Y(0)]++; + modelData->nSD[_idx_Y(0)]++; + modelData->nSD[_idx_Y(0)]++; + modelData->nSD[_idx_pM(0)]++; + modelData->nSD[_idx_pM(0)]++; + modelData->nSD[_idx_yP(0)]++; + modelData->nDS[_idx_C2(0)]++; + modelData->nDS[_idx_CP(0)]++; + modelData->nDS[_idx_pM(0)]++; + modelData->nDS[_idx_M(0)]++; + modelData->nDS[_idx_C2(0)]++; + modelData->nDS[_idx_CP(0)]++; + modelData->nDS[_idx_pM(0)]++; + modelData->nDS[_idx_M(0)]++; + modelData->nDS[_idx_Y(0)]++; + modelData->nDS[_idx_C2(0)]++; + modelData->nDS[_idx_pM(0)]++; + modelData->nDS[_idx_M(0)]++; + modelData->nDS[_idx_yP(0)]++; + modelData->nDS[_idx_CP(0)]++; + modelData->nDS[_idx_pM(0)]++; + modelData->nDS[_idx_Y(0)]++; + modelData->nDS[_idx_pM(0)]++; + modelData->nDS[_idx_M(0)]++; + modelData->nDS[_idx_yP(0)]++; + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[0]->size[c_row]++; + modelData->jac_matrices->df_dx[0]->size[c_row]++; + modelData->jac_matrices->df_dx[0]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[1]->size[c_row]++; + modelData->jac_matrices->df_dx[1]->size[c_row]++; + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[0]->size[c_row]++; + modelData->jac_matrices->dg_dx[0]->size[c_row]++; + modelData->jac_matrices->dg_dx[0]->size[c_row]++; + modelData->jac_matrices->dg_dx[0]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + modelData->jac_matrices->dg_dx[2]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + modelData->jac_matrices->df_dx[3]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[4]->size[c_row]++; + modelData->jac_matrices->df_dx[4]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[5]->size[c_row]++; + modelData->jac_matrices->df_dx[5]->size[c_row]++; + } + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 6); + modelData->SD[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_C2(0); + modelData->SD[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_CP(0); + modelData->SD[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_pM(0); + modelData->SD[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_M(0); + modelData->SD[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_C2(0); + modelData->SD[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_CP(0); + modelData->SD[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_pM(0); + modelData->SD[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_M(0); + modelData->SD[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_Y(0); + modelData->SD[_idx_M(0)][states[_idx_M(0)]++] = _idx_C2(0); + modelData->SD[_idx_M(0)][states[_idx_M(0)]++] = _idx_pM(0); + modelData->SD[_idx_M(0)][states[_idx_M(0)]++] = _idx_M(0); + modelData->SD[_idx_M(0)][states[_idx_M(0)]++] = _idx_yP(0); + modelData->SD[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_CP(0); + modelData->SD[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_pM(0); + modelData->SD[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_Y(0); + modelData->SD[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_pM(0); + modelData->SD[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_M(0); + modelData->SD[_idx_yP(0)][states[_idx_yP(0)]++] = _idx_yP(0); + cleanVector(states, 0, 6); + modelData->DS[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_C2(0); + modelData->DS[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_C2(0); + modelData->DS[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_C2(0); + modelData->DS[_idx_M(0)][states[_idx_M(0)]++] = _idx_C2(0); + modelData->DS[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_CP(0); + modelData->DS[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_CP(0); + modelData->DS[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_CP(0); + modelData->DS[_idx_M(0)][states[_idx_M(0)]++] = _idx_CP(0); + modelData->DS[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_CP(0); + modelData->DS[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_M(0); + modelData->DS[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_M(0); + modelData->DS[_idx_M(0)][states[_idx_M(0)]++] = _idx_M(0); + modelData->DS[_idx_yP(0)][states[_idx_yP(0)]++] = _idx_M(0); + modelData->DS[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_Y(0); + modelData->DS[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_Y(0); + modelData->DS[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_Y(0); + modelData->DS[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_pM(0); + modelData->DS[_idx_M(0)][states[_idx_M(0)]++] = _idx_pM(0); + modelData->DS[_idx_yP(0)][states[_idx_yP(0)]++] = _idx_yP(0); + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_Y(0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 4); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->dg_dx[0]->index[c_row],modelData->jac_matrices->dg_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[0]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->dg_dx[0]->index[c_row],modelData->jac_matrices->dg_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[0]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->dg_dx[0]->index[c_row],modelData->jac_matrices->dg_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[0]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->dg_dx[0]->index[c_row],modelData->jac_matrices->dg_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[0]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(algebraics, 0, 4); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->dg_dx[2]->index[c_row],modelData->jac_matrices->dg_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[2]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_Y(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_C2(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_pM(0); + if(in(modelData->jac_matrices->df_dx[3]->index[c_row],modelData->jac_matrices->df_dx[3]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[3]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[3]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_CP(0); + if(in(modelData->jac_matrices->df_dx[4]->index[c_row],modelData->jac_matrices->df_dx[4]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[4]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[4]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_Y(0); + if(in(modelData->jac_matrices->df_dx[4]->index[c_row],modelData->jac_matrices->df_dx[4]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[4]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[4]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 6); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_M(0); + if(in(modelData->jac_matrices->df_dx[5]->index[c_row],modelData->jac_matrices->df_dx[5]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[5]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[5]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_yP(0); + if(in(modelData->jac_matrices->df_dx[5]->index[c_row],modelData->jac_matrices->df_dx[5]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[5]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[5]->index[c_row][states[c_row]++] = x_ind; + } + } + SD_setupJacMatrices(modelData->jac_matrices); + simulator->time = QSS_Time(6,0,0,0,ST_Binary, NULL); + simulator->output = SD_Output("TYSON",6,0,6,NULL,0,0,CI_Step,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + modelOutput->nOS[_idx_out_exp_1]++; + modelOutput->nOS[_idx_out_exp_2]++; + modelOutput->nOS[_idx_out_exp_4]++; + modelOutput->nOS[_idx_out_exp_5]++; + modelOutput->nOS[_idx_out_exp_3]++; + modelOutput->nOS[_idx_out_exp_6]++; + modelOutput->nSO[_idx_C2(0)]++; + modelOutput->nSO[_idx_CP(0)]++; + modelOutput->nSO[_idx_M(0)]++; + modelOutput->nSO[_idx_Y(0)]++; + modelOutput->nSO[_idx_pM(0)]++; + modelOutput->nSO[_idx_yP(0)]++; + SD_allocOutputMatrix(modelOutput, 6, 0); + sprintf(modelOutput->variable[_idx_out_exp_1].name, "C2"); + sprintf(modelOutput->variable[_idx_out_exp_2].name, "CP"); + sprintf(modelOutput->variable[_idx_out_exp_3].name, "pM"); + sprintf(modelOutput->variable[_idx_out_exp_4].name, "M"); + sprintf(modelOutput->variable[_idx_out_exp_5].name, "Y"); + sprintf(modelOutput->variable[_idx_out_exp_6].name, "yP"); + cleanVector(outputs, 0, 6); + modelOutput->OS[_idx_out_exp_1][outputs[_idx_out_exp_1]++] = _idx_C2(0); + modelOutput->OS[_idx_out_exp_2][outputs[_idx_out_exp_2]++] = _idx_CP(0); + modelOutput->OS[_idx_out_exp_4][outputs[_idx_out_exp_4]++] = _idx_M(0); + modelOutput->OS[_idx_out_exp_5][outputs[_idx_out_exp_5]++] = _idx_Y(0); + modelOutput->OS[_idx_out_exp_3][outputs[_idx_out_exp_3]++] = _idx_pM(0); + modelOutput->OS[_idx_out_exp_6][outputs[_idx_out_exp_6]++] = _idx_yP(0); + cleanVector(states, 0, 6); + modelOutput->SO[_idx_C2(0)][states[_idx_C2(0)]++] = _idx_out_exp_1; + modelOutput->SO[_idx_CP(0)][states[_idx_CP(0)]++] = _idx_out_exp_2; + modelOutput->SO[_idx_M(0)][states[_idx_M(0)]++] = _idx_out_exp_4; + modelOutput->SO[_idx_Y(0)][states[_idx_Y(0)]++] = _idx_out_exp_5; + modelOutput->SO[_idx_pM(0)][states[_idx_pM(0)]++] = _idx_out_exp_3; + modelOutput->SO[_idx_yP(0)][states[_idx_yP(0)]++] = _idx_out_exp_6; + simulator->model = QSS_Model(MOD_definition, MOD_dependencies, MOD_zeroCrossing, MOD_handlerPos, MOD_handlerNeg, MOD_jacobian, MOD_BDF_definition); + free(algebraics); + free(states); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/TYSON/TYSON.h b/src/mmoc/tests/system/gt_data/TYSON/TYSON.h new file mode 100644 index 00000000..594727ca --- /dev/null +++ b/src/mmoc/tests/system/gt_data/TYSON/TYSON.h @@ -0,0 +1,231 @@ +// Model data access macro. + +#define MODEL_DATA_ACCESS(m) \ + double* x = m->x; \ + double* a = m->alg; + +// Coeff multipliers definition. + +#define COEFF_MULTIPLIER(c) COEFF_MULTIPLIER_##c +#define COEFF_MULTIPLIER_0 1 +#define COEFF_MULTIPLIER_1 1 +#define COEFF_MULTIPLIER_2 2 + +// Model Variables Macros + +// Macros definition for variable: C2 +#define _idx_C2(coeff) 0 +#define _state_idx_C2(coeff) 0*3 + coeff +#define _C2(coeff) x[_state_idx_C2(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_C2(coeff) x[_state_idx_C2(coeff)] +#define _q_C2(coeff) q[_state_idx_C2(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_C2(coeff) 0 +#define _eval_dep_C2(coeff) dx[_state_idx_C2(coeff)] + +// Macros definition for variable: CP +#define _idx_CP(coeff) 1 +#define _state_idx_CP(coeff) 1*3 + coeff +#define _CP(coeff) x[_state_idx_CP(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_CP(coeff) x[_state_idx_CP(coeff)] +#define _q_CP(coeff) q[_state_idx_CP(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_CP(coeff) 1 +#define _eval_dep_CP(coeff) dx[_state_idx_CP(coeff)] + +// Macros definition for variable: CT +#define _idx_CT(coeff) 0 +#define _state_idx_CT(coeff) 0*3 + coeff +#define _CT(coeff) a[_state_idx_CT(coeff)] + +// Macros definition for variable: F +#define _idx_F(coeff) 2 +#define _state_idx_F(coeff) 2*3 + coeff +#define _F(coeff) a[_state_idx_F(coeff)] + +// Macros definition for variable: M +#define _idx_M(coeff) 3 +#define _state_idx_M(coeff) 3*3 + coeff +#define _M(coeff) x[_state_idx_M(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_M(coeff) x[_state_idx_M(coeff)] +#define _q_M(coeff) q[_state_idx_M(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_M(coeff) 3 +#define _eval_dep_M(coeff) dx[_state_idx_M(coeff)] + +// Macros definition for variable: Y +#define _idx_Y(coeff) 4 +#define _state_idx_Y(coeff) 4*3 + coeff +#define _Y(coeff) x[_state_idx_Y(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_Y(coeff) x[_state_idx_Y(coeff)] +#define _q_Y(coeff) q[_state_idx_Y(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_Y(coeff) 4 +#define _eval_dep_Y(coeff) dx[_state_idx_Y(coeff)] + +// Macros definition for variable: YT +#define _idx_YT(coeff) 1 +#define _state_idx_YT(coeff) 1*3 + coeff +#define _YT(coeff) a[_state_idx_YT(coeff)] + +// Macros definition for variable: _out_exp_1 +#define _idx_out_exp_1 0 +#define _eval_out_exp_1 0 + +// Macros definition for variable: _out_exp_2 +#define _idx_out_exp_2 1 +#define _eval_out_exp_2 1 + +// Macros definition for variable: _out_exp_3 +#define _idx_out_exp_3 2 +#define _eval_out_exp_3 2 + +// Macros definition for variable: _out_exp_4 +#define _idx_out_exp_4 3 +#define _eval_out_exp_4 3 + +// Macros definition for variable: _out_exp_5 +#define _idx_out_exp_5 4 +#define _eval_out_exp_5 4 + +// Macros definition for variable: _out_exp_6 +#define _idx_out_exp_6 5 +#define _eval_out_exp_6 5 + +// Macros definition for variable: k1 +#define _k1 __PAR__k1 + +// Macros definition for variable: k2 +#define _k2 __PAR__k2 + +// Macros definition for variable: k3 +#define _k3 __PAR__k3 + +// Macros definition for variable: k4 +#define _k4 __PAR__k4 + +// Macros definition for variable: k4prim +#define _k4prim __PAR__k4prim + +// Macros definition for variable: k5 +#define _k5 __PAR__k5 + +// Macros definition for variable: k6 +#define _k6 __PAR__k6 + +// Macros definition for variable: k7 +#define _k7 __PAR__k7 + +// Macros definition for variable: k8 +#define _k8 __PAR__k8 + +// Macros definition for variable: k9 +#define _k9 __PAR__k9 + +// Macros definition for variable: pM +#define _idx_pM(coeff) 2 +#define _state_idx_pM(coeff) 2*3 + coeff +#define _pM(coeff) x[_state_idx_pM(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_pM(coeff) x[_state_idx_pM(coeff)] +#define _q_pM(coeff) q[_state_idx_pM(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_pM(coeff) 2 +#define _eval_dep_pM(coeff) dx[_state_idx_pM(coeff)] + +// Macros definition for variable: yP +#define _idx_yP(coeff) 5 +#define _state_idx_yP(coeff) 5*3 + coeff +#define _yP(coeff) x[_state_idx_yP(coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_yP(coeff) x[_state_idx_yP(coeff)] +#define _q_yP(coeff) q[_state_idx_yP(coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_yP(coeff) 5 +#define _eval_dep_yP(coeff) dx[_state_idx_yP(coeff)] + +// Macros definition for variable: yt +#define _idx_yt(coeff) 3 +#define _state_idx_yt(coeff) 3*3 + coeff +#define _yt(coeff) a[_state_idx_yt(coeff)] + + +// Model Parameters Declaration + +// Macro for parameter: k1 +double __PAR__k1; +// Macro for parameter: k2 +double __PAR__k2; +// Macro for parameter: k3 +double __PAR__k3; +// Macro for parameter: k4 +double __PAR__k4; +// Macro for parameter: k4prim +double __PAR__k4prim; +// Macro for parameter: k5 +double __PAR__k5; +// Macro for parameter: k6 +double __PAR__k6; +// Macro for parameter: k7 +double __PAR__k7; +// Macro for parameter: k8 +double __PAR__k8; +// Macro for parameter: k9 +double __PAR__k9; + +// Derivative Equations Macros + +// Macros for equation: 1 + +// Macros for equation: 2 + +// Macros for equation: 3 + +// Macros for equation: 4 + +// Macros for equation: 5 + +// Macros for equation: 6 + + +// Algebraic Equations Macros + +// Macros for algebraic equation: 1 + +// Macros for algebraic equation: 2 + +// Macros for algebraic equation: 3 + +// Macros for algebraic equation: 4 + + +// Output Equations Macros + +// Macros for output equation: 1 + +// Macros for output equation: 2 + +// Macros for output equation: 3 + +// Macros for output equation: 4 + +// Macros for output equation: 5 + +// Macros for output equation: 6 + +#define _out out[0] + +// Jacobian Macros definition. +#define _assign_jac(r, val) \ + col_t = dvdx->df_dx_t->size[r] + dvdx->df_dx_t->index[r][0]; \ + dvdx->df_dx_t->index[r][0]++; \ + jac[col_t] = val; +#define _c_index(i) (i-1) + +#define _time t + +// Derivative Macros definition. +// Derivative definition for variable: C2 +#define _der_C2(coeff) dx[coeff+1] +// Derivative definition for variable: CP +#define _der_CP(coeff) dx[coeff+1] +// Derivative definition for variable: M +#define _der_M(coeff) dx[coeff+1] +// Derivative definition for variable: Y +#define _der_Y(coeff) dx[coeff+1] +// Derivative definition for variable: pM +#define _der_pM(coeff) dx[coeff+1] +// Derivative definition for variable: yP +#define _der_yP(coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/TYSON/TYSON.ini b/src/mmoc/tests/system/gt_data/TYSON/TYSON.ini new file mode 100644 index 00000000..1a4307cd --- /dev/null +++ b/src/mmoc/tests/system/gt_data/TYSON/TYSON.ini @@ -0,0 +1,15 @@ +minstep=1.00000e-14; +zchyst=1.00000e-12; +derdelta=1.00000e-08; +symdiff=0; +lps=0; +nodesize=10000; +jacobian=1; +it=0.00000e+00; +ft=1.00000e+02; +sol="LIQSS2"; +dqmin=(1.00000e-06); +dqrel=(1.00000e-03); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/TYSON/TYSON.mo b/src/mmoc/tests/system/gt_data/TYSON/TYSON.mo new file mode 100644 index 00000000..f69ba786 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/TYSON/TYSON.mo @@ -0,0 +1,64 @@ +model TYSON + import math; + // BioRica Constant k1 + parameter Real k1 = 0.015; + // BioRica Constant k2 + parameter Real k2 = 0.0; + // BioRica Constant k3 + parameter Real k3 = 200; + // BioRica Constant k4 + parameter Real k4 = 180; + // BioRica Constant k4prim + parameter Real k4prim = 0.018; + // BioRica Constant k5 + parameter Real k5 = 0.0; + // BioRica Constant k6 + parameter Real k6 = 1.0; + // BioRica Constant k7 + parameter Real k7 = 0.6; + // BioRica Constant k8 + parameter Real k8 = 1000000.0; + // BioRica Constant k9 + parameter Real k9 = 1000.0; + Real CP(start = 0.75); + Real yt; + Real C2(start = 0.0); + Real M(start = 0.0); + Real pM(start = 0.25); + Real CT; + Real Y(start = 0.0); + Real YT; + Real F; + Real yP(start = 0.0); + equation + + // BioRica Formula CT instance: + CT = C2+CP+pM+M; + // BioRica Formula YT instance: + YT = Y+yP+pM+M; + // BioRica Formula F instance: + F = k4prim+k4*pow((M*1.0/CT),2); + yt = YT; + der(C2) = k6*M-k8*C2+k9*CP; + der(CP) = -k3*CP*Y+k8*C2-k9*CP; + der(pM) = k3*CP*Y+-pM*F+k5*M; + der(M) = pM*F-k5*M-k6*M; + der(Y) = k1-k2*Y-k3*CP*Y; + der(yP) = k6*M-k7*yP; + annotation( + + experiment( + MMO_Description="TYSON automatic model translation.", + MMO_Solver=LIQSS2, + MMO_SymDiff=false, + MMO_PartitionMethod=Metis, + MMO_Output={C2,CP,pM,M,Y,yP}, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime=0.0, + StopTime=100, + Tolerance={1e-3}, + AbsTolerance={1e-6} + )); +end TYSON; diff --git a/src/mmoc/tests/system/gt_data/VIRplanoS/rnd.c b/src/mmoc/tests/system/gt_data/VIRplanoS/rnd.c new file mode 100644 index 00000000..36d3e072 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/VIRplanoS/rnd.c @@ -0,0 +1,10 @@ +#include +#include +#include +double rnd(double y) +{ +// srand(time(0)); + double r; + r= 1.0*y*rand()/RAND_MAX; + return r; +} diff --git a/src/mmoc/tests/system/gt_data/VIRplanoS/srnd.c b/src/mmoc/tests/system/gt_data/VIRplanoS/srnd.c new file mode 100644 index 00000000..591af940 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/VIRplanoS/srnd.c @@ -0,0 +1,9 @@ +#include +#include +#include +double srnd() +{ + srand(time(0)); + double r=0; + return r; +} diff --git a/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.c b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.c new file mode 100644 index 00000000..1cc1e8cb --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.c @@ -0,0 +1,400 @@ +#include +#include +#include +#include + +#include "advectionFlux.h" +#include +#include +#include +#include +#include + +void MOD_settings(SD_simulationSettings settings) +{ + settings->debug = 0; + settings->parallel = FALSE; + settings->hybrid = FALSE; + settings->method = 4; +} + +void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) +{ + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _F(1,0) = _v*_inVal; + _F(1,1) = 0; + _F(2,0) = _v*_u(1,0); + _F(2,1) = 0; + _der_u(1,0) = -(_F(2,0)-_F(1,0))*100/_L; + _der_u(1,1) = (0)/2; + + return; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_alg_eq_2(_d1+1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + _F(j,1) = 0; + } + _apply_usage_alg_eq_2(_d1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + _F(j,1) = 0; + } + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 100)) { + _der_u(j,0) = -(_F(j+1,0)-_F(j,0))*100/_L; + _der_u(j,1) = (0)/2; + + } + return; + } +} + +void MOD_zeroCrossing(int idx, double *x, double *d, double *a, double t, double *zc) +{ +} + +void MOD_handlerPos(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_handlerNeg(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_output(int idx, double *x, double *d, double *a, double t, double *out) +{ + switch(idx) { + case _eval_out_exp_1: { + _out = _u(100,0); + return; + } + } +} + +void MOD_jacobian(double *x, double *d, double *a, double t, SD_jacMatrices dvdx, double *jac) +{ + int row, row_t, eq_var, c_row, c_row_g; + int col, col_g, col_t; + int x_ind; + double aux; + int _d1; + int _rg_d1; + int j; + SD_cleanJacMatrices(dvdx); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 100; row++) { + c_row = _c_index(row); + _get_alg_eq_2_var_idxs(row, eq_var); + _get_F_idxs(eq_var); + if((1 <= _d1-1 && _d1-1 <= 100)) { + x_ind = _idx_u(_d1-1,0); + col = pos(dvdx->dg_dx[1]->index[c_row], dvdx->dg_dx[1]->size[c_row], x_ind); + _apply_usage_alg_eq_2(_d1); + aux = 0; + dvdx->dg_dx[1]->value[c_row][col] += aux; + } + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + aux = 0; + aux = 0; + x_ind = _idx_u(1,0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + c_row_g = _idx_F(1,0) - 1; + col_g = pos(dvdx->dg_dx[1]->index[c_row_g], dvdx->dg_dx[1]->size[c_row_g], x_ind); + dvdx->df_dx[0]->value[c_row][col] += aux * dvdx->dg_dx[1]->value[c_row_g][col_g]; + } + for(row = 1; row <= 99; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + _apply_usage_eq_2(_d1); + aux = 0; + if((2 <= _d1 && _d1 <= 100) && (3 <= _d1 + 1 && _d1 + 1 <= 101)) { + x_ind = _idx_u(_d1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + c_row_g = _idx_F(_rg_d1+1,0) - 1; + col_g = pos(dvdx->dg_dx[1]->index[c_row_g], dvdx->dg_dx[1]->size[c_row_g], x_ind); + dvdx->df_dx[1]->value[c_row][col] += aux * dvdx->dg_dx[1]->value[c_row_g][col_g]; + } + _apply_usage_eq_2(_d1); + aux = 0; + if((1 <= _d1-1 && _d1-1 <= 99) && (2 <= _d1 && _d1 <= 100)) { + x_ind = _idx_u(_d1-1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + c_row_g = _idx_F(_rg_d1,0) - 1; + col_g = pos(dvdx->dg_dx[1]->index[c_row_g], dvdx->dg_dx[1]->size[c_row_g], x_ind); + dvdx->df_dx[1]->value[c_row][col] += aux * dvdx->dg_dx[1]->value[c_row_g][col_g]; + } + } + // Assign Jacobian Matrix values for equation: 0 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[0]->size[row]; col++) { + row_t = dvdx->df_dx[0]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[0]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 1 + for (row = 0; row < 99; row++) { + for (col = 0; col < dvdx->df_dx[1]->size[row]; col++) { + row_t = dvdx->df_dx[1]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[1]->value[row][col]); + } + } +} + +void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) +{ + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _F(1,0) = _v*_inVal; + _F(1,1) = 0; + _F(2,0) = _v*_u(1,0); + _F(2,1) = 0; + _eval_dep_u(1,1) = -(_F(2,0)-_F(1,0))*100/_L; + _eval_dep_u(1,2) = (0)/2; + break; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_alg_eq_2(_d1+1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + _F(j,1) = 0; + } + _apply_usage_alg_eq_2(_d1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + _F(j,1) = 0; + } + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 100)) { + _eval_dep_u(j,1) = -(_F(j+1,0)-_F(j,0))*100/_L; + _eval_dep_u(j,2) = (0)/2; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_alg_eq_2(_d1+2); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + _F(j,1) = 0; + } + _apply_usage_eq_2(_d1+1); + if ((j >= 2 && j <= 100)) { + _eval_dep_u(j,1) = -(_F(j+1,0)-_F(j,0))*100/_L; + _eval_dep_u(j,2) = (0)/2; + } + } +} + +void MOD_BDF_definition(double *x, double *d, double *a, double t, double *dx, int *BDFMap, int nBDF) +{ + int idx; + int __bdf_it; + for(__bdf_it = 0; __bdf_it < nBDF; __bdf_it++) { + idx = BDFMap[__bdf_it]; + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _F(1,0) = _v*_inVal; + + _F(2,0) = _v*_u(1,0); + + _eval_dep_u(1,1) = -(_F(2,0)-_F(1,0))*100/_L; + + + continue; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_alg_eq_2(_d1+1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + + } + _apply_usage_alg_eq_2(_d1); + if ((j >= 2 && j <= 101)) { + _F(j,0) = _v*_u(j-1,0); + + } + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 100)) { + _eval_dep_u(j,1) = -(_F(j+1,0)-_F(j,0))*100/_L; + + + } + continue; + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(100,0,0,0,101,2,2,"advectionFlux"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* algebraics = (int*) malloc(101*sizeof(int)); + int* states = (int*) malloc(100*sizeof(int)); + int* outputs = (int*) malloc(1*sizeof(int)); + int row, eq_var, c_row; + int x_ind; + int _d1; + int _rg_d1; + int i; + int j; + _L = 1.000000e+00; + _beta = 1.000000e+02; + _diff = 0.000000e+00; + _gam = 0.000000e+00; + _inVal = 0; + _outVal = 1; + _v = 1.000000e+00; + _x0 = 5.000000e-01; + for(i = 1; i<=50; i+=1) { + _x(i) = 1.000000e+00*i/(double)100; + _init_u(i,0) = 1; + } + modelData->nSD[_idx_u(1,0)]++; + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->nSD[_idx_u(_d1,0)]++; + } + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->nSD[_idx_u(_d1-1,0)]++; + } + modelData->nDS[_idx_u(1,0)]++; + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->nDS[_idx_u(_d1,0)]++; + } + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->nDS[_idx_u(_d1,0)]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + for(row = 1; row <= 100; row++) { + c_row = _c_index(row); + _get_alg_eq_2_var_idxs(row, eq_var); + _get_F_idxs(eq_var); + if((1 <= _d1-1 && _d1-1 <= 100)) { + modelData->jac_matrices->dg_dx[1]->size[c_row]++; + } + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[0]->size[c_row]++; + } + for(row = 1; row <= 99; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + if((2 <= _d1 && _d1 <= 100) && (3 <= _d1 + 1 && _d1 + 1 <= 101)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + if((1 <= _d1-1 && _d1-1 <= 99) && (2 <= _d1 && _d1 <= 100)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + } + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 100); + modelData->SD[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1,0); + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->SD[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1,0); + } + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->SD[_idx_u(_d1-1,0)][states[_idx_u(_d1-1,0)]++] = _idx_u(_d1,0); + } + cleanVector(states, 0, 100); + modelData->DS[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1,0); + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->DS[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1,0); + } + for(_d1 = 2; _d1<=100; _d1+=1) { + modelData->DS[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1-1,0); + } + cleanVector(algebraics, 0, 101); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + } + cleanVector(algebraics, 0, 101); + for(row = 1; row <= 100; row++) { + c_row = _c_index(row); + _get_alg_eq_2_var_idxs(row, eq_var); + _get_F_idxs(eq_var); + if((1 <= _d1-1 && _d1-1 <= 100)) { + x_ind = _idx_u(_d1-1,0); + if(in(modelData->jac_matrices->dg_dx[1]->index[c_row],modelData->jac_matrices->dg_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->dg_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->dg_dx[1]->index[c_row][algebraics[c_row]++] = x_ind; + } + } + } + cleanVector(states, 0, 100); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u(1,0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 100); + for(row = 1; row <= 99; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + if((2 <= _d1 && _d1 <= 100) && (3 <= _d1 + 1 && _d1 + 1 <= 101)) { + x_ind = _idx_u(_d1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + if((1 <= _d1-1 && _d1-1 <= 99) && (2 <= _d1 && _d1 <= 100)) { + x_ind = _idx_u(_d1-1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + } + SD_setupJacMatrices(modelData->jac_matrices); + simulator->time = QSS_Time(100,0,0,0,ST_Binary, NULL); + simulator->output = SD_Output("advectionFlux",1,0,100,NULL,0,0,CI_Step,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + modelOutput->nOS[_idx_out_exp_1]++; + modelOutput->nSO[_idx_u(100,0)]++; + SD_allocOutputMatrix(modelOutput, 100, 0); + sprintf(modelOutput->variable[_idx_out_exp_1].name, "u[100]"); + cleanVector(outputs, 0, 1); + modelOutput->OS[_idx_out_exp_1][outputs[_idx_out_exp_1]++] = _idx_u(100,0); + cleanVector(states, 0, 100); + modelOutput->SO[_idx_u(100,0)][states[_idx_u(100,0)]++] = _idx_out_exp_1; + simulator->model = QSS_Model(MOD_definition, MOD_dependencies, MOD_zeroCrossing, MOD_handlerPos, MOD_handlerNeg, MOD_jacobian, MOD_BDF_definition); + free(algebraics); + free(states); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.h b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.h new file mode 100644 index 00000000..bd84dde8 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.h @@ -0,0 +1,129 @@ +// Model data access macro. + +#define MODEL_DATA_ACCESS(m) \ + double* x = m->x; \ + double* a = m->alg; + +// Coeff multipliers definition. + +#define COEFF_MULTIPLIER(c) COEFF_MULTIPLIER_##c +#define COEFF_MULTIPLIER_0 1 +#define COEFF_MULTIPLIER_1 1 +#define COEFF_MULTIPLIER_2 2 + +// Model Variables Macros + +// Macros definition for variable: F +#define _idx_F(d1,coeff) ((d1-1)) +#define _state_idx_F(d1,coeff) ((d1-1))*3 + coeff +#define _F(d1,coeff) a[_state_idx_F(d1,coeff)] +#define _is_var_F(idx) idx >= 0 && idx < 101 +#define _get_F_idxs(idx)\ + _d1 = (idx)+ 1; + +// Macros definition for variable: L +#define _L __PAR__L + +// Macros definition for variable: _out_exp_1 +#define _idx_out_exp_1 0 +#define _eval_out_exp_1 0 + +// Macros definition for variable: beta +#define _beta __PAR__beta + +// Macros definition for variable: diff +#define _diff __PAR__diff + +// Macros definition for variable: gam +#define _gam __PAR__gam + +// Macros definition for variable: inVal +#define _inVal __PAR__inVal + +// Macros definition for variable: outVal +#define _outVal __PAR__outVal + +// Macros definition for variable: u +#define _idx_u(d1,coeff) ((d1-1)) +#define _state_idx_u(d1,coeff) ((d1-1))*3 + coeff +#define _u(d1,coeff) x[_state_idx_u(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_u(d1,coeff) x[_state_idx_u(d1,coeff)] +#define _q_u(d1,coeff) q[_state_idx_u(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_u(d1,coeff) ((d1-1)) +#define _is_var_u(idx) idx >= 0 && idx < 100 +#define _get_u_idxs(idx)\ + _d1 = (idx)+ 1; +#define _eval_dep_u(d1,coeff) dx[_state_idx_u(d1,coeff)] + +// Macros definition for variable: v +#define _v __PAR__v + +// Macros definition for variable: x +#define _idx_x(d1) ((d1-1)) +#define _x(d1) __PAR__x[_idx_x(d1)] + +// Macros definition for variable: x0 +#define _x0 __PAR__x0 + + +// Model Parameters Declaration + +// Macro for parameter: L +double __PAR__L; +// Macro for parameter: beta +double __PAR__beta; +// Macro for parameter: diff +double __PAR__diff; +// Macro for parameter: gam +double __PAR__gam; +// Macro for parameter: inVal +double __PAR__inVal; +// Macro for parameter: outVal +double __PAR__outVal; +// Macro for parameter: v +double __PAR__v; +// Macro for parameter: x +double __PAR__x[100]; +// Macro for parameter: x0 +double __PAR__x0; + +// Derivative Equations Macros + +// Macros for equation: 1 + +// Macros for equation: 2 +#define _apply_usage_eq_2(_d1) \ + j = _d1; +#define _get_eq_2_var_idxs(row, var)\ + _rg_d1 = 1 + (row-1)+ 1;\ + var = _idx_u(_rg_d1,0); + +// Algebraic Equations Macros + +// Macros for algebraic equation: 1 + +// Macros for algebraic equation: 2 +#define _apply_usage_alg_eq_2(_d1) \ + j = _d1; +#define _get_alg_eq_2_var_idxs(row, var)\ + _rg_d1 = 1 + (row-1)+ 1;\ + var = _idx_F(_rg_d1,0); + +// Output Equations Macros + +// Macros for output equation: 1 + +#define _out out[0] + +// Jacobian Macros definition. +#define _assign_jac(r, val) \ + col_t = dvdx->df_dx_t->size[r] + dvdx->df_dx_t->index[r][0]; \ + dvdx->df_dx_t->index[r][0]++; \ + jac[col_t] = val; +#define _c_index(i) (i-1) + +#define _time t + +// Derivative Macros definition. +// Derivative definition for variable: u +#define _der_u(d1,coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.ini b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.ini new file mode 100644 index 00000000..333f4a05 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.ini @@ -0,0 +1,15 @@ +minstep=1.00000e-14; +zchyst=1.00000e-12; +derdelta=1.00000e-08; +symdiff=1; +lps=0; +nodesize=10000; +jacobian=1; +it=0.00000e+00; +ft=1.00000e+00; +sol="LIQSS2"; +dqmin=(1.00000e-05); +dqrel=(1.00000e-05); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.mo b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.mo new file mode 100644 index 00000000..2817ee23 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advectionFlux/advectionFlux.mo @@ -0,0 +1,37 @@ +model advectionFlux + constant Integer N = 100, M = 101; + parameter Real L = 1.0, v = 1.0, beta = 100.0, x0 = 0.5, diff = 0.0000, gam = 0.0, x[N], inVal = 0, outVal = 1; + Real u[N], F[M]; +initial algorithm + for i in 1:N / 2 loop + x[i] := 1.0 * i / N; + u[i] := 1; + end for; + // u[i]:=2.718^(-beta*(x[i]-x0)^2)*cos(gam*(x[i]-x0)); //Condici�n inicial: Gaussiana con m�ximo=1 +equation + //Upwind advection + F[1] = v * inVal; + for j in 2:M loop + F[j] = v * u[j - 1]; + end for; + der(u[1]) = -(F[2] - F[1]) * N / L; + for j in 2:N loop + der(u[j]) = -(F[j + 1] - F[j]) * N / L; + // der(u[j]) = -((v*u[j])-(v*u[j-1]))*N/L; +end for; + annotation( + + experiment( + MMO_Description=" Advection Equation.", + MMO_Solver=LIQSS2, + MMO_PartitionMethod=Metis, + MMO_Output={u[N]}, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime= 0.0, + StopTime= 1, + Tolerance={1e-5}, + AbsTolerance={1e-5} + )); +end advectionFlux; diff --git a/src/mmoc/tests/system/gt_data/burgers/burgers.c b/src/mmoc/tests/system/gt_data/burgers/burgers.c new file mode 100644 index 00000000..9b6e78b1 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/burgers/burgers.c @@ -0,0 +1,553 @@ +#include +#include +#include +#include + +#include "burgers.h" +#include +#include +#include +#include +#include + +void MOD_settings(SD_simulationSettings settings) +{ + settings->debug = 0; + settings->parallel = FALSE; + settings->hybrid = TRUE; + settings->method = 4; +} + +void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) +{ + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _der_u(1,0) = _ap(1)*(_u(1,0)+_u(1000,0))/(double)2*(-_u(1,0)+_u(1000,0))*1000+(1-_ap(1))*(_u(2,0)+_u(1,0))/2*(-_u(2,0)+_u(1,0))*1000; + + + return; + } + case _eval_u(1000,0): { + _der_u(1000,0) = _ap(1000)*(_u(1000,0)+_u(999,0))/(double)2*(-_u(1000,0)+_u(999,0))*1000+(1-_ap(1000))*(_u(1,0)+_u(1000,0))*(-_u(1,0)+_u(1000,0))*1000; + + + return; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 999)) { + _der_u(j,0) = _ap(j)*(_u(j,0)+_u(j-1,0))/(double)2*(-_u(j,0)+_u(j-1,0))*1000+(1-_ap(j))*(_u(j+1,0)+_u(j,0))*(-_u(j+1,0)+_u(j,0))*1000; + + + } + return; + } +} + +void MOD_zeroCrossing(int idx, double *x, double *d, double *a, double t, double *zc) +{ + int _d1; + int i; + if (_is_var_event_1(idx)) { + _get_event_1_idxs(idx); + _apply_usage_event_1(_d1); + if ((i >= 1 && i <= 1000)) { + _zc(0) = _u(i,0)-(0); + + + } + return; + } +} + +void MOD_handlerPos(int idx, double *x, double* q, double *d, double *a, double t) +{ + int _d1; + int i; + if (_is_var_event_1(idx)) { + _get_event_1_idxs(idx); + _apply_usage_event_1(_d1); + if ((i >= 1 && i <= 1000)) { + _ap(i) = 1; + } + return; + } +} + +void MOD_handlerNeg(int idx, double *x, double* q, double *d, double *a, double t) +{ + int _d1; + int i; + if (_is_var_event_1(idx)) { + _get_event_1_idxs(idx); + _apply_usage_event_1(_d1); + if ((i >= 1 && i <= 1000)) { + _ap(i) = 0; + } + return; + } +} + +void MOD_output(int idx, double *x, double *d, double *a, double t, double *out) +{ + int _d1; + if (_is_var_out_exp_1(idx)) { + _get_out_exp_1_idxs(idx); + _apply_usage_out_exp_1(_d1); + if ((_d1 >= 1 && _d1 <= 5)) { + _out = _u(200*_d1-199,0); + } + return; + } +} + +void MOD_jacobian(double *x, double *d, double *a, double t, SD_jacMatrices dvdx, double *jac) +{ + int row, row_t, eq_var, c_row, c_row_g; + int col, col_g, col_t; + int x_ind; + double aux; + int _d1; + int _rg_d1; + int j; + SD_cleanJacMatrices(dvdx); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u(1,0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + x_ind = _idx_u(1000,0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + x_ind = _idx_u(2,0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + } + for(row = 1; row <= 998; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + if((3 <= _d1 + 1 && _d1 + 1 <= 1000)) { + x_ind = _idx_u(_d1+1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + _apply_usage_eq_2(_d1); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + if((2 <= _d1 && _d1 <= 999)) { + x_ind = _idx_u(_d1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + _apply_usage_eq_2(_d1); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + if((1 <= _d1-1 && _d1-1 <= 998)) { + x_ind = _idx_u(_d1-1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + _apply_usage_eq_2(_d1); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u(1,0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + x_ind = _idx_u(1000,0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + x_ind = _idx_u(999,0); + col = pos(dvdx->df_dx[2]->index[c_row], dvdx->df_dx[2]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[2]->value[c_row][col] += aux; + } + // Assign Jacobian Matrix values for equation: 0 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[0]->size[row]; col++) { + row_t = dvdx->df_dx[0]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[0]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 1 + for (row = 0; row < 998; row++) { + for (col = 0; col < dvdx->df_dx[1]->size[row]; col++) { + row_t = dvdx->df_dx[1]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[1]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 2 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[2]->size[row]; col++) { + row_t = dvdx->df_dx[2]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[2]->value[row][col]); + } + } +} + +void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) +{ + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _eval_dep_u(1,1) = _ap(1)*(_u(1,0)+_u(1000,0))/(double)2*(-_u(1,0)+_u(1000,0))*1000+(1-_ap(1))*(_u(2,0)+_u(1,0))/2*(-_u(2,0)+_u(1,0))*1000; + _eval_dep_u(1000,1) = _ap(1000)*(_u(1000,0)+_u(999,0))/(double)2*(-_u(1000,0)+_u(999,0))*1000+(1-_ap(1000))*(_u(1,0)+_u(1000,0))*(-_u(1,0)+_u(1000,0))*1000; + break; + } + case _eval_u(1000,0): { + _eval_dep_u(1,1) = _ap(1)*(_u(1,0)+_u(1000,0))/(double)2*(-_u(1,0)+_u(1000,0))*1000+(1-_ap(1))*(_u(2,0)+_u(1,0))/2*(-_u(2,0)+_u(1,0))*1000; + _eval_dep_u(1000,1) = _ap(1000)*(_u(1000,0)+_u(999,0))/(double)2*(-_u(1000,0)+_u(999,0))*1000+(1-_ap(1000))*(_u(1,0)+_u(1000,0))*(-_u(1,0)+_u(1000,0))*1000; + break; + } + case _eval_u(2,0): { + _eval_dep_u(1,1) = _ap(1)*(_u(1,0)+_u(1000,0))/(double)2*(-_u(1,0)+_u(1000,0))*1000+(1-_ap(1))*(_u(2,0)+_u(1,0))/2*(-_u(2,0)+_u(1,0))*1000; + break; + } + case _eval_u(999,0): { + _eval_dep_u(1000,1) = _ap(1000)*(_u(1000,0)+_u(999,0))/(double)2*(-_u(1000,0)+_u(999,0))*1000+(1-_ap(1000))*(_u(1,0)+_u(1000,0))*(-_u(1,0)+_u(1000,0))*1000; + break; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_eq_2(_d1-1); + if ((j >= 2 && j <= 999)) { + _eval_dep_u(j,1) = _ap(j)*(_u(j,0)+_u(j-1,0))/(double)2*(-_u(j,0)+_u(j-1,0))*1000+(1-_ap(j))*(_u(j+1,0)+_u(j,0))*(-_u(j+1,0)+_u(j,0))*1000; + + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 999)) { + _eval_dep_u(j,1) = _ap(j)*(_u(j,0)+_u(j-1,0))/(double)2*(-_u(j,0)+_u(j-1,0))*1000+(1-_ap(j))*(_u(j+1,0)+_u(j,0))*(-_u(j+1,0)+_u(j,0))*1000; + + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_eq_2(_d1+1); + if ((j >= 2 && j <= 999)) { + _eval_dep_u(j,1) = _ap(j)*(_u(j,0)+_u(j-1,0))/(double)2*(-_u(j,0)+_u(j-1,0))*1000+(1-_ap(j))*(_u(j+1,0)+_u(j,0))*(-_u(j+1,0)+_u(j,0))*1000; + + } + } +} + +void MOD_BDF_definition(double *x, double *d, double *a, double t, double *dx, int *BDFMap, int nBDF) +{ + int idx; + int __bdf_it; + for(__bdf_it = 0; __bdf_it < nBDF; __bdf_it++) { + idx = BDFMap[__bdf_it]; + int _d1; + int j; + switch(idx) { + case _eval_u(1,0): { + _eval_dep_u(1,1) = _ap(1)*(_u(1,0)+_u(1000,0))/(double)2*(-_u(1,0)+_u(1000,0))*1000+(1-_ap(1))*(_u(2,0)+_u(1,0))/2*(-_u(2,0)+_u(1,0))*1000; + + + continue; + } + case _eval_u(1000,0): { + _eval_dep_u(1000,1) = _ap(1000)*(_u(1000,0)+_u(999,0))/(double)2*(-_u(1000,0)+_u(999,0))*1000+(1-_ap(1000))*(_u(1,0)+_u(1000,0))*(-_u(1,0)+_u(1000,0))*1000; + + + continue; + } + } + if (_is_var_u(idx)) { + _get_u_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 999)) { + _eval_dep_u(j,1) = _ap(j)*(_u(j,0)+_u(j-1,0))/(double)2*(-_u(j,0)+_u(j-1,0))*1000+(1-_ap(j))*(_u(j+1,0)+_u(j,0))*(-_u(j+1,0)+_u(j,0))*1000; + + + } + continue; + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(1000,1000,1000,0,0,3,0,"burgers"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* states = (int*) malloc(1000*sizeof(int)); + int* discretes = (int*) malloc(1000*sizeof(int)); + int* events = (int*) malloc(1000*sizeof(int)); + int* outputs = (int*) malloc(5*sizeof(int)); + int row, eq_var, c_row; + int x_ind; + int _d1; + int _rg_d1; + int i; + int j; + _ap(_d1) = 0; + _beta = 100; + _inVal = 1; + _outVal = 1; + _pi = 3.141590e+00; + _x0 = 5.000000e-01; + for(i = 1; i<=1000; i+=1) { + _x(i) = 1.000000e+00*i/(double)1000; + _init_u(i,0) = sin(_pi*2*_x(i)); + if(_init_u(i,0)>0) { + _ap(i) = 1; + } else { + _ap(i) = 0; + } + } + modelData->nSD[_idx_u(1,0)]++; + modelData->nSD[_idx_u(1,0)]++; + modelData->nSD[_idx_u(1000,0)]++; + modelData->nSD[_idx_u(1000,0)]++; + modelData->nSD[_idx_u(2,0)]++; + modelData->nSD[_idx_u(999,0)]++; + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nSD[_idx_u(_d1+1,0)]++; + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nSD[_idx_u(_d1,0)]++; + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nSD[_idx_u(_d1-1,0)]++; + } + modelData->nDS[_idx_u(1,0)]++; + modelData->nDS[_idx_u(1000,0)]++; + modelData->nDS[_idx_u(1,0)]++; + modelData->nDS[_idx_u(1000,0)]++; + modelData->nDS[_idx_u(1,0)]++; + modelData->nDS[_idx_u(1000,0)]++; + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nDS[_idx_u(_d1,0)]++; + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nDS[_idx_u(_d1,0)]++; + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nDS[_idx_u(_d1,0)]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[0]->size[c_row]++; + modelData->jac_matrices->df_dx[0]->size[c_row]++; + modelData->jac_matrices->df_dx[0]->size[c_row]++; + } + for(row = 1; row <= 998; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + if((3 <= _d1 + 1 && _d1 + 1 <= 1000)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + if((2 <= _d1 && _d1 <= 999)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + if((1 <= _d1-1 && _d1-1 <= 998)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + modelData->jac_matrices->df_dx[2]->size[c_row]++; + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->nSZ[_idx_u(_d1,0)]++; + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->nZS[_idx_event_1(_d1)]++; + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->nHD[_idx_event_1(_d1)]++; + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->nHD[_idx_event_1(_d1)]++; + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->nHD[_idx_event_1(_d1)]++; + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->event[_idx_event_1(_d1)].nLHSDsc++; + } + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 1000); + modelData->SD[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1,0); + modelData->SD[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1000,0); + modelData->SD[_idx_u(1000,0)][states[_idx_u(1000,0)]++] = _idx_u(1,0); + modelData->SD[_idx_u(1000,0)][states[_idx_u(1000,0)]++] = _idx_u(1000,0); + modelData->SD[_idx_u(2,0)][states[_idx_u(2,0)]++] = _idx_u(1,0); + modelData->SD[_idx_u(999,0)][states[_idx_u(999,0)]++] = _idx_u(1000,0); + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->SD[_idx_u(_d1+1,0)][states[_idx_u(_d1+1,0)]++] = _idx_u(_d1,0); + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->SD[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1,0); + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->SD[_idx_u(_d1-1,0)][states[_idx_u(_d1-1,0)]++] = _idx_u(_d1,0); + } + cleanVector(states, 0, 1000); + modelData->DS[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1,0); + modelData->DS[_idx_u(1000,0)][states[_idx_u(1000,0)]++] = _idx_u(1,0); + modelData->DS[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(1000,0); + modelData->DS[_idx_u(1000,0)][states[_idx_u(1000,0)]++] = _idx_u(1000,0); + modelData->DS[_idx_u(1,0)][states[_idx_u(1,0)]++] = _idx_u(2,0); + modelData->DS[_idx_u(1000,0)][states[_idx_u(1000,0)]++] = _idx_u(999,0); + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->DS[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1+1,0); + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->DS[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1,0); + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->DS[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_u(_d1-1,0); + } + cleanVector(states, 0, 1000); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u(1,0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_u(1000,0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_u(2,0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 1000); + for(row = 1; row <= 998; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_idxs(eq_var); + if((3 <= _d1 + 1 && _d1 + 1 <= 1000)) { + x_ind = _idx_u(_d1+1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + if((2 <= _d1 && _d1 <= 999)) { + x_ind = _idx_u(_d1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + if((1 <= _d1-1 && _d1-1 <= 998)) { + x_ind = _idx_u(_d1-1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + } + cleanVector(states, 0, 1000); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u(1,0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_u(1000,0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + x_ind = _idx_u(999,0); + if(in(modelData->jac_matrices->df_dx[2]->index[c_row],modelData->jac_matrices->df_dx[2]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[2]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[2]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 1000); + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->SZ[_idx_u(_d1,0)][states[_idx_u(_d1,0)]++] = _idx_event_1(_d1); + } + cleanVector(events, 0, 1000); + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->ZS[_idx_event_1(_d1)][events[_idx_event_1(_d1)]++] = _idx_u(_d1,0); + } + cleanVector(events, 0, 1000); + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->HD[_idx_event_1(_d1)][events[_idx_event_1(_d1)]++] = _idx_u(1,0); + } + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->HD[_idx_event_1(_d1)][events[_idx_event_1(_d1)]++] = _idx_u(1000,0); + } + for(_d1 = 2; _d1<=999; _d1+=1) { + modelData->HD[_idx_event_1(_d1)][events[_idx_event_1(_d1)]++] = _idx_u(i,0); + } + cleanVector(events, 0, 1000); + for(_d1 = 1; _d1<=1000; _d1+=1) { + modelData->event[_idx_event_1(_d1)].LHSDsc[events[_idx_event_1(_d1)]++] = _idx_ap(_d1); + } + for(i = 1; i<=1000; i+=1) { + modelData->event[_idx_event_1(i)].direction = 0; + modelData->event[_idx_event_1(i)].relation = 2; + } + SD_setupJacMatrices(modelData->jac_matrices); + simulator->time = QSS_Time(1000,1000,0,0,ST_Binary, NULL); + double period[1]; + period[0] = 0.01; + simulator->output = SD_Output("burgers",5,1000,1000,period,1,0,CI_Sampled,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + for(_d1 = 1; _d1<=5; _d1+=1) { + modelOutput->nOS[_idx_out_exp_1(_d1)]++; + } + for(_d1 = 1; _d1<=5; _d1+=1) { + modelOutput->nSO[_idx_u(200*_d1-199,0)]++; + } + SD_allocOutputMatrix(modelOutput, 1000, 1000); + for(_d1 = 1; _d1<=5; _d1+=1) { + sprintf(modelOutput->variable[_idx_out_exp_1(_d1)].name, "u[%d]",200*_d1-199); + } + cleanVector(outputs, 0, 5); + for(_d1 = 1; _d1<=5; _d1+=1) { + modelOutput->OS[_idx_out_exp_1(_d1)][outputs[_idx_out_exp_1(_d1)]++] = _idx_u(200*_d1-199,0); + } + cleanVector(states, 0, 1000); + for(_d1 = 1; _d1<=5; _d1+=1) { + modelOutput->SO[_idx_u(200*_d1-199,0)][states[_idx_u(200*_d1-199,0)]++] = _idx_out_exp_1(_d1); + } + simulator->model = QSS_Model(MOD_definition, MOD_dependencies, MOD_zeroCrossing, MOD_handlerPos, MOD_handlerNeg, MOD_jacobian, MOD_BDF_definition); + free(states); + free(discretes); + free(events); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/burgers/burgers.h b/src/mmoc/tests/system/gt_data/burgers/burgers.h new file mode 100644 index 00000000..473900f1 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/burgers/burgers.h @@ -0,0 +1,125 @@ +// Model data access macro. + +#define MODEL_DATA_ACCESS(m) \ + double* x = m->x; \ + double* d = m->d; + +// Coeff multipliers definition. + +#define COEFF_MULTIPLIER(c) COEFF_MULTIPLIER_##c +#define COEFF_MULTIPLIER_0 1 +#define COEFF_MULTIPLIER_1 1 +#define COEFF_MULTIPLIER_2 2 + +// Model Variables Macros + +// Macros definition for variable: _event_1 +#define _idx_event_1(d1) ((d1-1)) +#define _eval_event_1(d1) ((d1-1)) +#define _is_var_event_1(idx) idx >= 0 && idx < 1000 +#define _get_event_1_idxs(idx)\ + _d1 = (idx)+ 1; + +// Macros definition for variable: _out_exp_1 +#define _idx_out_exp_1(d1) ((d1-1)) +#define _eval_out_exp_1(d1) ((d1-1)) +#define _is_var_out_exp_1(idx) idx >= 0 && idx < 5 +#define _get_out_exp_1_idxs(idx)\ + _d1 = (idx)+ 1; + +// Macros definition for variable: ap +#define _idx_ap(d1) ((d1-1)) +#define _ap(d1) d[_idx_ap(d1)] + +// Macros definition for variable: beta +#define _beta __PAR__beta + +// Macros definition for variable: inVal +#define _inVal __PAR__inVal + +// Macros definition for variable: outVal +#define _outVal __PAR__outVal + +// Macros definition for variable: pi +#define _pi __PAR__pi + +// Macros definition for variable: u +#define _idx_u(d1,coeff) ((d1-1)) +#define _state_idx_u(d1,coeff) ((d1-1))*3 + coeff +#define _u(d1,coeff) x[_state_idx_u(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_u(d1,coeff) x[_state_idx_u(d1,coeff)] +#define _q_u(d1,coeff) q[_state_idx_u(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_u(d1,coeff) ((d1-1)) +#define _is_var_u(idx) idx >= 0 && idx < 1000 +#define _get_u_idxs(idx)\ + _d1 = (idx)+ 1; +#define _eval_dep_u(d1,coeff) dx[_state_idx_u(d1,coeff)] + +// Macros definition for variable: x +#define _idx_x(d1) ((d1-1)) +#define _x(d1) __PAR__x[_idx_x(d1)] + +// Macros definition for variable: x0 +#define _x0 __PAR__x0 + + +// Model Parameters Declaration + +// Macro for parameter: beta +double __PAR__beta; +// Macro for parameter: inVal +double __PAR__inVal; +// Macro for parameter: outVal +double __PAR__outVal; +// Macro for parameter: pi +double __PAR__pi; +// Macro for parameter: x +double __PAR__x[1000]; +// Macro for parameter: x0 +double __PAR__x0; + +// Derivative Equations Macros + +// Macros for equation: 1 + +// Macros for equation: 2 +#define _apply_usage_eq_2(_d1) \ + j = _d1; +#define _get_eq_2_var_idxs(row, var)\ + _rg_d1 = 1 + (row-1)+ 1;\ + var = _idx_u(_rg_d1,0); +// Macros for equation: 3 + + +// Event Macros + +// Macros for event: 1 +#define _apply_usage_event_1(_d1) \ + i = _d1; +#define _get_event_1_var_idxs(row, var)\ + _rg_d1 = 0 + (row-1)+ 1;\ + var = _idx_event_1(_rg_d1); +#define _zc(coeff) zc[coeff] + +// Output Equations Macros + +// Macros for output equation: 1 +#define _apply_usage_out_exp_1(_d1) \ + _d1 = _d1; +#define _get_out_exp_1_var_idxs(row, var)\ + _rg_d1 = 0 + (row-1)+ 1;\ + var = _idx_out_exp_1(_rg_d1); +#define _out out[0] + +// Jacobian Macros definition. +#define _assign_jac(r, val) \ + col_t = dvdx->df_dx_t->size[r] + dvdx->df_dx_t->index[r][0]; \ + dvdx->df_dx_t->index[r][0]++; \ + jac[col_t] = val; +#define _c_index(i) (i-1) + +#define _time t + +// Derivative Macros definition. +// Derivative definition for variable: u +#define _der_u(d1,coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/burgers/burgers.ini b/src/mmoc/tests/system/gt_data/burgers/burgers.ini new file mode 100644 index 00000000..28fe2f45 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/burgers/burgers.ini @@ -0,0 +1,15 @@ +minstep=1.00000e-14; +zchyst=1.00000e-12; +derdelta=1.00000e-08; +symdiff=0; +lps=0; +nodesize=10000; +jacobian=1; +it=0.00000e+00; +ft=1.00000e+00; +sol="LIQSS2"; +dqmin=(1.00000e-05); +dqrel=(1.00000e-05); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/burgers/burgers.mo b/src/mmoc/tests/system/gt_data/burgers/burgers.mo new file mode 100644 index 00000000..7f4a8cc0 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/burgers/burgers.mo @@ -0,0 +1,57 @@ +model burgers + constant Integer N = 1000; + parameter Real beta=100,x0=0.5,pi=3.14159,x[N],inVal=1,outVal=1; + discrete Real ap[N](start=0); + Real u[N]; + initial algorithm + for i in 1:N loop + x[i]:=1.0*i/N; + // u[i]:=sin(pi*2*x[i])+2; //Condici�n inicial que mantiene u>0 en todo el dominio + u[i]:=sin(pi*2*x[i]); //Condici�n inicial con u<0 //Sin la suma convexa, el esquema falla. + if u[i] > 0 then + ap[i]:=1; + else + ap[i]:=0; + end if; + end for; + + equation +//Eq. Burgers inv�scida: u_t+(1/2)*(u^2)_x=0 +//T�rmino viscoso: eps*uxx (t�rmino fuente a la derecha) +//Forma cuasi-lineal: u_t+u*u_x=0 (lamb=u) +//La velocidad de propagaci�n es igual a la variable. +//Upwind: +// der(u[1])=(u[1]+u[N])/2*(-u[1]+u[N])*N; //Condici�n peri�dica para u>0 + der(u[1])=ap[1]*(u[1]+u[N])/2*(-u[1]+u[N])*N+(1-ap[1])*(u[2]+u[1])/2*(-u[2]+u[1])*N; //No puedo hacer andar esta suma convexa. + for j in 2:N-1 loop + // der(u[j])=(u[j]+u[j-1])/2*(-u[j]+u[j-1])*N; + der(u[j])=ap[j]*(u[j]+u[j-1])/2*(-u[j]+u[j-1])*N+(1-ap[j])*(u[j+1]+u[j])*(-u[j+1]+u[j])*N; //No puedo hacer andar esta suma convexa. + end for; + der(u[N])=ap[N]*(u[N]+u[N-1])/2*(-u[N]+u[N-1])*N+(1-ap[N])*(u[1]+u[N])*(-u[1]+u[N])*N; //No puedo hacer andar esta suma convexa. +algorithm + for i in 1:N loop + when u[i] > 0 then + ap[i]:=1; elsewhen u[i] < 0 then + ap[i]:=0; + end when; + end for; + +//Lax-Wendroff: esquema 2 orden: Problema para implementarlo: necesito afectar el avance temporal con elementos de la discretizaci�n espacial + annotation( + + experiment( + MMO_Description="Burgers Equation", + MMO_Solver=LIQSS2, + MMO_SymDiff=false, + MMO_PartitionMethod=Metis, + MMO_Output={u[1:N/5:N]}, + MMO_OutputType=CI_Sampled, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime=0.0, + StopTime=1.0, + Tolerance={1e-5}, + AbsTolerance={1e-5} + )); +end burgers; diff --git a/src/mmoc/tests/system/gt_data/testFor/testFor.c b/src/mmoc/tests/system/gt_data/testFor/testFor.c new file mode 100644 index 00000000..ace0cf17 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/testFor/testFor.c @@ -0,0 +1,307 @@ +#include +#include +#include +#include + +#include "testFor.h" +#include +#include +#include +#include +#include + +void MOD_settings(SD_simulationSettings settings) +{ + settings->debug = 0; + settings->parallel = FALSE; + settings->hybrid = FALSE; + settings->method = 4; +} + +void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) +{ + int _d1; + int i; + switch(idx) { + case _eval_u1(1,0): { + _der_u1(1,0) = (-_u1(1,0)*_ax/_dx)+(-_u1(1,0)*_ay/_dy); + + + return; + } + } + if (_is_var_u1(idx)) { + _get_u1_idxs(idx); + _apply_usage_eq_2(_d1); + if ((i >= 2 && i <= 2)) { + _der_u1(i,0) = (-_u1(i,0)+_u1(i-1,0))*_ax/_dx+(-_u1(i,0)*_ay/_dy); + + + } + return; + } +} + +void MOD_zeroCrossing(int idx, double *x, double *d, double *a, double t, double *zc) +{ +} + +void MOD_handlerPos(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_handlerNeg(int idx, double *x, double* q, double *d, double *a, double t) +{ +} + +void MOD_output(int idx, double *x, double *d, double *a, double t, double *out) +{ + int _d1; + if (_is_var_out_exp_1(idx)) { + _get_out_exp_1_idxs(idx); + _apply_usage_out_exp_1(_d1); + if ((_d1 >= 1 && _d1 <= 2)) { + _out = _u1(_d1,0); + } + return; + } +} + +void MOD_jacobian(double *x, double *d, double *a, double t, SD_jacMatrices dvdx, double *jac) +{ + int row, row_t, eq_var, c_row, c_row_g; + int col, col_g, col_t; + int x_ind; + double aux; + int _d1; + int _rg_d1; + int i; + SD_cleanJacMatrices(dvdx); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u1(1,0); + col = pos(dvdx->df_dx[0]->index[c_row], dvdx->df_dx[0]->size[c_row], x_ind); + aux = 0; + dvdx->df_dx[0]->value[c_row][col] += aux; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u1_idxs(eq_var); + if((2 <= _d1 && _d1 <= 2)) { + x_ind = _idx_u1(_d1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + _apply_usage_eq_2(_d1); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + if((1 <= _d1-1 && _d1-1 <= 1)) { + x_ind = _idx_u1(_d1-1,0); + col = pos(dvdx->df_dx[1]->index[c_row], dvdx->df_dx[1]->size[c_row], x_ind); + _apply_usage_eq_2(_d1); + aux = 0; + dvdx->df_dx[1]->value[c_row][col] += aux; + } + } + // Assign Jacobian Matrix values for equation: 0 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[0]->size[row]; col++) { + row_t = dvdx->df_dx[0]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[0]->value[row][col]); + } + } + // Assign Jacobian Matrix values for equation: 1 + for (row = 0; row < 1; row++) { + for (col = 0; col < dvdx->df_dx[1]->size[row]; col++) { + row_t = dvdx->df_dx[1]->index[row][col]; + _assign_jac(row_t, dvdx->df_dx[1]->value[row][col]); + } + } +} + +void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) +{ + int _d1; + int i; + switch(idx) { + case _eval_u1(1,0): { + _eval_dep_u1(1,1) = (-_u1(1,0)*_ax/_dx)+(-_u1(1,0)*_ay/_dy); + break; + } + } + if (_is_var_u1(idx)) { + _get_u1_idxs(idx); + _apply_usage_eq_2(_d1); + if ((i >= 2 && i <= 2)) { + _eval_dep_u1(i,1) = (-_u1(i,0)+_u1(i-1,0))*_ax/_dx+(-_u1(i,0)*_ay/_dy); + + } + } + if (_is_var_u1(idx)) { + _get_u1_idxs(idx); + _apply_usage_eq_2(_d1+1); + if ((i >= 2 && i <= 2)) { + _eval_dep_u1(i,1) = (-_u1(i,0)+_u1(i-1,0))*_ax/_dx+(-_u1(i,0)*_ay/_dy); + + } + } +} + +void MOD_BDF_definition(double *x, double *d, double *a, double t, double *dx, int *BDFMap, int nBDF) +{ + int idx; + int __bdf_it; + for(__bdf_it = 0; __bdf_it < nBDF; __bdf_it++) { + idx = BDFMap[__bdf_it]; + int _d1; + int i; + switch(idx) { + case _eval_u1(1,0): { + _eval_dep_u1(1,1) = (-_u1(1,0)*_ax/_dx)+(-_u1(1,0)*_ay/_dy); + + + continue; + } + } + if (_is_var_u1(idx)) { + _get_u1_idxs(idx); + _apply_usage_eq_2(_d1); + if ((i >= 2 && i <= 2)) { + _eval_dep_u1(i,1) = (-_u1(i,0)+_u1(i-1,0))*_ax/_dx+(-_u1(i,0)*_ay/_dy); + + + } + continue; + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(2,0,0,0,0,2,0,"testFor"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* states = (int*) malloc(2*sizeof(int)); + int* outputs = (int*) malloc(2*sizeof(int)); + int row, eq_var, c_row; + int x_ind; + int _d1; + int _rg_d1; + int i; + _ax = 1; + _ay = 1; + _dx = 10/(double)100; + _dy = 10/(double)100; + _r = 1000; + for(i = 1; i<=2; i+=1) { + _init_u1(i,0) = 1; + } + modelData->nSD[_idx_u1(1,0)]++; + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->nSD[_idx_u1(_d1,0)]++; + } + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->nSD[_idx_u1(_d1-1,0)]++; + } + modelData->nDS[_idx_u1(1,0)]++; + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->nDS[_idx_u1(_d1,0)]++; + } + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->nDS[_idx_u1(_d1,0)]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + modelData->jac_matrices->df_dx[0]->size[c_row]++; + } + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u1_idxs(eq_var); + if((2 <= _d1 && _d1 <= 2)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + if((1 <= _d1-1 && _d1-1 <= 1)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + } + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 2); + modelData->SD[_idx_u1(1,0)][states[_idx_u1(1,0)]++] = _idx_u1(1,0); + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->SD[_idx_u1(_d1,0)][states[_idx_u1(_d1,0)]++] = _idx_u1(_d1,0); + } + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->SD[_idx_u1(_d1-1,0)][states[_idx_u1(_d1-1,0)]++] = _idx_u1(_d1,0); + } + cleanVector(states, 0, 2); + modelData->DS[_idx_u1(1,0)][states[_idx_u1(1,0)]++] = _idx_u1(1,0); + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->DS[_idx_u1(_d1,0)][states[_idx_u1(_d1,0)]++] = _idx_u1(_d1,0); + } + for(_d1 = 2; _d1<=2; _d1+=1) { + modelData->DS[_idx_u1(_d1,0)][states[_idx_u1(_d1,0)]++] = _idx_u1(_d1-1,0); + } + cleanVector(states, 0, 2); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u1(1,0); + if(in(modelData->jac_matrices->df_dx[0]->index[c_row],modelData->jac_matrices->df_dx[0]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[0]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[0]->index[c_row][states[c_row]++] = x_ind; + } + } + cleanVector(states, 0, 2); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u1_idxs(eq_var); + if((2 <= _d1 && _d1 <= 2)) { + x_ind = _idx_u1(_d1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + if((1 <= _d1-1 && _d1-1 <= 1)) { + x_ind = _idx_u1(_d1-1,0); + if(in(modelData->jac_matrices->df_dx[1]->index[c_row],modelData->jac_matrices->df_dx[1]->size[c_row], x_ind)){ + modelData->jac_matrices->df_dx[1]->size[c_row]--; + } else { + modelData->jac_matrices->df_dx[1]->index[c_row][states[c_row]++] = x_ind; + } + } + } + SD_setupJacMatrices(modelData->jac_matrices); + simulator->time = QSS_Time(2,0,0,0,ST_Binary, NULL); + simulator->output = SD_Output("testFor",2,0,2,NULL,0,0,CI_Step,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + for(_d1 = 1; _d1<=2; _d1+=1) { + modelOutput->nOS[_idx_out_exp_1(_d1)]++; + } + for(_d1 = 1; _d1<=2; _d1+=1) { + modelOutput->nSO[_idx_u1(_d1,0)]++; + } + SD_allocOutputMatrix(modelOutput, 2, 0); + for(_d1 = 1; _d1<=2; _d1+=1) { + sprintf(modelOutput->variable[_idx_out_exp_1(_d1)].name, "u1[%d]",_d1); + } + cleanVector(outputs, 0, 2); + for(_d1 = 1; _d1<=2; _d1+=1) { + modelOutput->OS[_idx_out_exp_1(_d1)][outputs[_idx_out_exp_1(_d1)]++] = _idx_u1(_d1,0); + } + cleanVector(states, 0, 2); + for(_d1 = 1; _d1<=2; _d1+=1) { + modelOutput->SO[_idx_u1(_d1,0)][states[_idx_u1(_d1,0)]++] = _idx_out_exp_1(_d1); + } + simulator->model = QSS_Model(MOD_definition, MOD_dependencies, MOD_zeroCrossing, MOD_handlerPos, MOD_handlerNeg, MOD_jacobian, MOD_BDF_definition); + free(states); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/testFor/testFor.h b/src/mmoc/tests/system/gt_data/testFor/testFor.h new file mode 100644 index 00000000..cf5c1430 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/testFor/testFor.h @@ -0,0 +1,95 @@ +// Model data access macro. + +#define MODEL_DATA_ACCESS(m) \ + double* x = m->x; + +// Coeff multipliers definition. + +#define COEFF_MULTIPLIER(c) COEFF_MULTIPLIER_##c +#define COEFF_MULTIPLIER_0 1 +#define COEFF_MULTIPLIER_1 1 +#define COEFF_MULTIPLIER_2 2 + +// Model Variables Macros + +// Macros definition for variable: _out_exp_1 +#define _idx_out_exp_1(d1) ((d1-1)) +#define _eval_out_exp_1(d1) ((d1-1)) +#define _is_var_out_exp_1(idx) idx >= 0 && idx < 2 +#define _get_out_exp_1_idxs(idx)\ + _d1 = (idx)+ 1; + +// Macros definition for variable: ax +#define _ax __PAR__ax + +// Macros definition for variable: ay +#define _ay __PAR__ay + +// Macros definition for variable: dx +#define _dx __PAR__dx + +// Macros definition for variable: dy +#define _dy __PAR__dy + +// Macros definition for variable: r +#define _r __PAR__r + +// Macros definition for variable: u1 +#define _idx_u1(d1,coeff) ((d1-1)) +#define _state_idx_u1(d1,coeff) ((d1-1))*3 + coeff +#define _u1(d1,coeff) x[_state_idx_u1(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_u1(d1,coeff) x[_state_idx_u1(d1,coeff)] +#define _q_u1(d1,coeff) q[_state_idx_u1(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_u1(d1,coeff) ((d1-1)) +#define _is_var_u1(idx) idx >= 0 && idx < 2 +#define _get_u1_idxs(idx)\ + _d1 = (idx)+ 1; +#define _eval_dep_u1(d1,coeff) dx[_state_idx_u1(d1,coeff)] + + +// Model Parameters Declaration + +// Macro for parameter: ax +double __PAR__ax; +// Macro for parameter: ay +double __PAR__ay; +// Macro for parameter: dx +double __PAR__dx; +// Macro for parameter: dy +double __PAR__dy; +// Macro for parameter: r +double __PAR__r; + +// Derivative Equations Macros + +// Macros for equation: 1 + +// Macros for equation: 2 +#define _apply_usage_eq_2(_d1) \ + i = _d1; +#define _get_eq_2_var_idxs(row, var)\ + _rg_d1 = 1 + (row-1)+ 1;\ + var = _idx_u1(_rg_d1,0); + +// Output Equations Macros + +// Macros for output equation: 1 +#define _apply_usage_out_exp_1(_d1) \ + _d1 = _d1; +#define _get_out_exp_1_var_idxs(row, var)\ + _rg_d1 = 0 + (row-1)+ 1;\ + var = _idx_out_exp_1(_rg_d1); +#define _out out[0] + +// Jacobian Macros definition. +#define _assign_jac(r, val) \ + col_t = dvdx->df_dx_t->size[r] + dvdx->df_dx_t->index[r][0]; \ + dvdx->df_dx_t->index[r][0]++; \ + jac[col_t] = val; +#define _c_index(i) (i-1) + +#define _time t + +// Derivative Macros definition. +// Derivative definition for variable: u1 +#define _der_u1(d1,coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/testFor/testFor.ini b/src/mmoc/tests/system/gt_data/testFor/testFor.ini new file mode 100644 index 00000000..0995aa8c --- /dev/null +++ b/src/mmoc/tests/system/gt_data/testFor/testFor.ini @@ -0,0 +1,15 @@ +minstep=1.00000e-14; +zchyst=1.00000e-12; +derdelta=1.00000e-08; +symdiff=0; +lps=0; +nodesize=10000; +jacobian=1; +it=0.00000e+00; +ft=1.00000e+00; +sol="LIQSS2"; +dqmin=(1.00000e-03); +dqrel=(1.00000e-03); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/testFor/testFor.mo b/src/mmoc/tests/system/gt_data/testFor/testFor.mo new file mode 100644 index 00000000..a83352f5 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/testFor/testFor.mo @@ -0,0 +1,33 @@ +model testFor + Real u1[2]; + parameter Real ax=1,ay=1,r=1000; + constant Integer N = 100, M=100; + parameter Real dx=10/N; + parameter Real dy=10/M; + +initial algorithm + for i in 1:2 loop + u1[i]:=1; + end for; +equation + der(u1[1])=(-u1[1]*ax/dx)+(-u1[1]*ay/dy) /*+ r*(u1[1]^2- u1[1]^3)*/; + for i in 2:2 loop + der(u1[i])=(-u1[i]+u1[i-1])*ax/dx+(-u1[i]*ay/dy) /*+ r*(u1[1]^2- u1[1]^3)*/; +end for; + annotation( + + experiment( + MMO_Description="", + MMO_Solver=LIQSS2, + MMO_SymDiff=false, + MMO_PartitionMethod=Metis, + MMO_Output={u1[:]}, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime=0.0, + StopTime=1.0, + Tolerance={1e-3}, + AbsTolerance={1e-3} + )); +end testFor;