From 702244c0a2bb8672c6fe51675f1378c9e897093c Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Fri, 14 Apr 2023 11:50:21 -0300 Subject: [PATCH] Added quoted string system test. --- .../advection_quoted/advection_quoted.c | 293 ++++++++++++++++++ .../advection_quoted/advection_quoted.h | 73 +++++ .../advection_quoted/advection_quoted.ini | 15 + .../advection_quoted/advection_quoted.mo | 32 ++ 4 files changed, 413 insertions(+) create mode 100644 src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.c create mode 100644 src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.h create mode 100644 src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.ini create mode 100644 src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.mo diff --git a/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.c b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.c new file mode 100644 index 00000000..73b96f47 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.c @@ -0,0 +1,293 @@ +#include +#include +#include +#include + +#include "advection_quoted.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_a(1,0): { + _der_u_a(1,0) = (-_u_a(1,0)+1)*20000-_mu*_u_a(1,0)*(_u_a(1,0)-_alpha)*(_u_a(1,0)-1); + _der_u_a(1,1) = (0)/2; + + return; + } + } + if (_is_var_u_a(idx)) { + _get_u_a_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 20000)) { + _der_u_a(j,0) = (-_u_a(j,0)+_u_a(j-1,0))*20000-_mu*_u_a(j,0)*(_u_a(j,0)-_alpha)*(_u_a(j,0)-1); + _der_u_a(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_a(20000,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_a(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 <= 19999; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_a_idxs(eq_var); + if((2 <= _d1 && _d1 <= 20000)) { + x_ind = _idx_u_a(_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 <= 19999)) { + x_ind = _idx_u_a(_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 < 19999; 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_a(1,0): { + _eval_dep_u_a(1,1) = (-_u_a(1,0)+1)*20000-_mu*_u_a(1,0)*(_u_a(1,0)-_alpha)*(_u_a(1,0)-1); + _eval_dep_u_a(1,2) = (0)/2; + break; + } + } + if (_is_var_u_a(idx)) { + _get_u_a_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 20000)) { + _eval_dep_u_a(j,1) = (-_u_a(j,0)+_u_a(j-1,0))*20000-_mu*_u_a(j,0)*(_u_a(j,0)-_alpha)*(_u_a(j,0)-1); + _eval_dep_u_a(j,2) = (0)/2; + } + } + if (_is_var_u_a(idx)) { + _get_u_a_idxs(idx); + _apply_usage_eq_2(_d1+1); + if ((j >= 2 && j <= 20000)) { + _eval_dep_u_a(j,1) = (-_u_a(j,0)+_u_a(j-1,0))*20000-_mu*_u_a(j,0)*(_u_a(j,0)-_alpha)*(_u_a(j,0)-1); + _eval_dep_u_a(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_a(1,0): { + _eval_dep_u_a(1,1) = (-_u_a(1,0)+1)*20000-_mu*_u_a(1,0)*(_u_a(1,0)-_alpha)*(_u_a(1,0)-1); + + + continue; + } + } + if (_is_var_u_a(idx)) { + _get_u_a_idxs(idx); + _apply_usage_eq_2(_d1); + if ((j >= 2 && j <= 20000)) { + _eval_dep_u_a(j,1) = (-_u_a(j,0)+_u_a(j-1,0))*20000-_mu*_u_a(j,0)*(_u_a(j,0)-_alpha)*(_u_a(j,0)-1); + + + } + continue; + } + } +} + +void QSS_initializeDataStructs(QSS_simulator simulator) +{ + simulator->data = QSS_Data(20000,0,0,0,0,2,0,"advection_quoted"); + QSS_data modelData = simulator->data; + MODEL_DATA_ACCESS(modelData) + int* states = (int*) malloc(20000*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; + _alpha = 5.000000e-01; + _mu = 1000; + for(i = 1; i<=6666; i+=1) { + _init_u_a(i,0) = 1; + } + modelData->nSD[_idx_u_a(1,0)]++; + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->nSD[_idx_u_a(_d1,0)]++; + } + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->nSD[_idx_u_a(_d1-1,0)]++; + } + modelData->nDS[_idx_u_a(1,0)]++; + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->nDS[_idx_u_a(_d1,0)]++; + } + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->nDS[_idx_u_a(_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 <= 19999; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_a_idxs(eq_var); + if((2 <= _d1 && _d1 <= 20000)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + if((1 <= _d1-1 && _d1-1 <= 19999)) { + modelData->jac_matrices->df_dx[1]->size[c_row]++; + } + } + QSS_allocDataMatrix(modelData); + cleanVector(states, 0, 20000); + modelData->SD[_idx_u_a(1,0)][states[_idx_u_a(1,0)]++] = _idx_u_a(1,0); + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->SD[_idx_u_a(_d1,0)][states[_idx_u_a(_d1,0)]++] = _idx_u_a(_d1,0); + } + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->SD[_idx_u_a(_d1-1,0)][states[_idx_u_a(_d1-1,0)]++] = _idx_u_a(_d1,0); + } + cleanVector(states, 0, 20000); + modelData->DS[_idx_u_a(1,0)][states[_idx_u_a(1,0)]++] = _idx_u_a(1,0); + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->DS[_idx_u_a(_d1,0)][states[_idx_u_a(_d1,0)]++] = _idx_u_a(_d1,0); + } + for(_d1 = 2; _d1<=20000; _d1+=1) { + modelData->DS[_idx_u_a(_d1,0)][states[_idx_u_a(_d1,0)]++] = _idx_u_a(_d1-1,0); + } + cleanVector(states, 0, 20000); + for(row = 1; row <= 1; row++) { + c_row = _c_index(row); + x_ind = _idx_u_a(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, 20000); + for(row = 1; row <= 19999; row++) { + c_row = _c_index(row); + _get_eq_2_var_idxs(row, eq_var); + _get_u_a_idxs(eq_var); + if((2 <= _d1 && _d1 <= 20000)) { + x_ind = _idx_u_a(_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 <= 19999)) { + x_ind = _idx_u_a(_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(20000,0,0,0,ST_Binary, NULL); + simulator->output = SD_Output("advection_quoted",1,0,20000,NULL,0,0,CI_Step,SD_Memory,MOD_output); + SD_output modelOutput = simulator->output; + modelOutput->nOS[_idx_out_exp_1]++; + modelOutput->nSO[_idx_u_a(20000,0)]++; + SD_allocOutputMatrix(modelOutput, 20000, 0); + sprintf(modelOutput->variable[_idx_out_exp_1].name, "u_a[20000]"); + cleanVector(outputs, 0, 1); + modelOutput->OS[_idx_out_exp_1][outputs[_idx_out_exp_1]++] = _idx_u_a(20000,0); + cleanVector(states, 0, 20000); + modelOutput->SO[_idx_u_a(20000,0)][states[_idx_u_a(20000,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(states); + free(outputs); +} + +void CLC_initializeDataStructs(CLC_simulator simulator) +{ +} + diff --git a/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.h b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.h new file mode 100644 index 00000000..5159065e --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.h @@ -0,0 +1,73 @@ +// 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 0 +#define _eval_out_exp_1 0 + +// Macros definition for variable: alpha +#define _alpha __PAR__alpha + +// Macros definition for variable: mu +#define _mu __PAR__mu + +// Macros definition for variable: u_a +#define _idx_u_a(d1,coeff) ((d1-1)) +#define _state_idx_u_a(d1,coeff) ((d1-1))*3 + coeff +#define _u_a(d1,coeff) x[_state_idx_u_a(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _init_u_a(d1,coeff) x[_state_idx_u_a(d1,coeff)] +#define _q_u_a(d1,coeff) q[_state_idx_u_a(d1,coeff)] * COEFF_MULTIPLIER(coeff) +#define _eval_u_a(d1,coeff) ((d1-1)) +#define _is_var_u_a(idx) idx >= 0 && idx < 20000 +#define _get_u_a_idxs(idx)\ + _d1 = (idx)+ 1; +#define _eval_dep_u_a(d1,coeff) dx[_state_idx_u_a(d1,coeff)] + + +// Model Parameters Declaration + +// Macro for parameter: alpha +double __PAR__alpha; +// Macro for parameter: mu +double __PAR__mu; + +// 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_a(_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_a +#define _der_u_a(d1,coeff) dx[coeff+1] diff --git a/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.ini b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.ini new file mode 100644 index 00000000..36afc887 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.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-03); +dqrel=(1.00000e-03); +bdf=0; +BDFPartitionDepth=1; +BDFMaxStep=0.00000e+00; diff --git a/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.mo b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.mo new file mode 100644 index 00000000..fcf9af27 --- /dev/null +++ b/src/mmoc/tests/system/gt_data/advection_quoted/advection_quoted.mo @@ -0,0 +1,32 @@ +model advection_quoted + parameter Real alpha=0.5,mu=1000; + constant Integer N = 20000; + Real 'u.a'[N]; + initial algorithm + for i in 1:N/3 loop + 'u.a'[i]:=1; + end for; + + equation + der('u.a'[1])=(-'u.a'[1]+1)*N-mu*'u.a'[1]*('u.a'[1]-alpha)*('u.a'[1]-1); + for j in 2:N loop + der('u.a'[j])=(-'u.a'[j]+'u.a'[j-1])*N-mu*'u.a'[j]*('u.a'[j]-alpha)*('u.a'[j]-1); + end for; + annotation( + + experiment( + MMO_Description="", + MMO_Solver=LIQSS2, + MMO_PartitionMethod=Scotch, + MMO_LPS=2, + MMO_DT_Min=2, + MMO_Output={'u.a'[N]}, + Jacobian=Dense, + MMO_BDF_PDepth=1, + MMO_BDF_Max_Step=0, + StartTime=0.0, + StopTime=1.0, + Tolerance={1e-3}, + AbsTolerance={1e-3} + )); +end advection_quoted;