-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d64dc80
commit 5659043
Showing
5 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
#include "test_input.h" | ||
#include <common/utils.h> | ||
#include <common/model.h> | ||
#include <common/commands.h> | ||
#include <qss/qss_model.h> | ||
#include <classic/classic_model.h> | ||
|
||
void MOD_settings(SD_simulationSettings settings) | ||
{ | ||
settings->debug = 0; | ||
settings->parallel = FALSE; | ||
settings->hybrid = FALSE; | ||
settings->method = 6; | ||
} | ||
|
||
void MOD_definition(int idx, double *x, double *d, double *a, double t, double *dx) | ||
{ | ||
switch(idx) { | ||
case _eval_y(0): { | ||
_der_y(0) = cos(_time); | ||
_der_y(1) = (0)/2; | ||
_der_y(2) = (0)/6; | ||
|
||
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 = _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); | ||
} | ||
// 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]); | ||
} | ||
} | ||
} | ||
|
||
void MOD_dependencies(int idx, double *x, double *d, double *a, double t, double *dx, int *map) | ||
{ | ||
} | ||
|
||
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_y(0): { | ||
_eval_dep_y(1) = cos(_time); | ||
|
||
|
||
continue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void QSS_initializeDataStructs(QSS_simulator simulator) | ||
{ | ||
simulator->data = QSS_Data(1,0,0,1,0,1,0,"test_input"); | ||
QSS_data modelData = simulator->data; | ||
MODEL_DATA_ACCESS(modelData) | ||
int* states = (int*) malloc(1*sizeof(int)); | ||
int* outputs = (int*) malloc(1*sizeof(int)); | ||
int row, eq_var, c_row; | ||
int x_ind; | ||
for(row = 1; row <= 1; row++) { | ||
c_row = _c_index(row); | ||
} | ||
QSS_allocDataMatrix(modelData); | ||
cleanVector(states, 0, 1); | ||
for(row = 1; row <= 1; row++) { | ||
c_row = _c_index(row); | ||
} | ||
SD_setupJacMatrices(modelData->jac_matrices); | ||
simulator->time = QSS_Time(1,0,1,0,ST_Binary, NULL); | ||
modelData->IT[_input_1] = _idx_y(0); | ||
simulator->output = SD_Output("test_input",1,0,1,NULL,0,0,CI_Step,SD_Memory,MOD_output); | ||
SD_output modelOutput = simulator->output; | ||
modelOutput->nOS[_idx_out_exp_1]++; | ||
modelOutput->nSO[_idx_y(0)]++; | ||
SD_allocOutputMatrix(modelOutput, 1, 0); | ||
sprintf(modelOutput->variable[_idx_out_exp_1].name, "y"); | ||
cleanVector(outputs, 0, 1); | ||
modelOutput->OS[_idx_out_exp_1][outputs[_idx_out_exp_1]++] = _idx_y(0); | ||
cleanVector(states, 0, 1); | ||
modelOutput->SO[_idx_y(0)][states[_idx_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(states); | ||
free(outputs); | ||
} | ||
|
||
void CLC_initializeDataStructs(CLC_simulator simulator) | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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 | ||
#define COEFF_MULTIPLIER_3 6 | ||
|
||
// 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: y | ||
#define _idx_y(coeff) 0 | ||
#define _state_idx_y(coeff) 0*4 + 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) 0 | ||
#define _eval_dep_y(coeff) dx[_state_idx_y(coeff)] | ||
|
||
|
||
// Derivative Equations Macros | ||
|
||
// Macros for equation: 1 | ||
|
||
|
||
// Output Equations Macros | ||
|
||
// Macros for output equation: 1 | ||
|
||
#define _out out[0] | ||
|
||
// Input Matrix Macros | ||
|
||
#define _input_1 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: y | ||
#define _der_y(coeff) dx[coeff+1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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+02; | ||
sol="QSS3"; | ||
dqmin=(1.00000e-06); | ||
dqrel=(1.00000e-03); | ||
bdf=0; | ||
BDFPartitionDepth=1; | ||
BDFMaxStep=0.00000e+00; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
model test_input | ||
|
||
Real y; | ||
|
||
equation | ||
der(y) = cos(time); | ||
annotation( | ||
experiment( | ||
MMO_Description="", | ||
MMO_Solver=QSS3, | ||
MMO_PartitionMethod=Metis, | ||
MMO_Output={y}, | ||
Jacobian=Dense, | ||
MMO_BDF_PDepth=1, | ||
MMO_BDF_Max_Step=0, | ||
StartTime=0.0, | ||
StopTime=100, | ||
Tolerance={1e-3}, | ||
AbsTolerance={1e-6} | ||
)); | ||
end test_input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters