Skip to content

Commit

Permalink
[newSimulationRuntime]
Browse files Browse the repository at this point in the history
 - removed old globalData object
 - adjust most files
 - most test cases are working now (only some fails most due to different output)
 - more work on initialization needs to be done


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10593 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Nov 29, 2011
1 parent 896f16a commit 4c39590
Show file tree
Hide file tree
Showing 37 changed files with 1,124 additions and 2,038 deletions.
6 changes: 3 additions & 3 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -5732,7 +5732,7 @@ algorithm

e = Expression.crefExp(cref);
tp = Expression.typeof(e);
startExp = Expression.makeBuiltinCall("pre", {e}, tp);
startExp = Expression.makeBuiltinCall("start", {e}, tp);
e2 = DAE.BINARY(crefExp, DAE.SUB(DAE.ET_REAL()), startExp);

e1 = DAE.BINARY(e1, DAE.MUL(DAE.ET_REAL()), e2);
Expand Down Expand Up @@ -7626,7 +7626,7 @@ algorithm
//startv = DAEUtil.getStartAttr(attr);
e = Expression.crefExp(cr);
tp = Expression.typeof(e);
startv = Expression.makeBuiltinCall("pre", {e}, tp);
startv = Expression.makeBuiltinCall("start", {e}, tp);
then
((v,(BackendDAE.EQUATION(e,startv,source)::eqns,av)));
case (((v as BackendDAE.VAR(varName = cr,varKind = BackendDAE.STATE(),values = attr,source=source)),(eqns,av))) /* add equations for variables with fixed = true */
Expand All @@ -7637,7 +7637,7 @@ algorithm
//startv = DAEUtil.getStartAttr(attr);
e = Expression.crefExp(cr);
tp = Expression.typeof(e);
startv = Expression.makeBuiltinCall("pre", {e}, tp);
startv = Expression.makeBuiltinCall("start", {e}, tp);
then
((v,(BackendDAE.EQUATION(e,startv,source)::eqns,av)));
case ((inTpl)) then inTpl;
Expand Down
409 changes: 134 additions & 275 deletions Compiler/susan_codegen/SimCode/CodegenC.tpl

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -5217,6 +5217,8 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
error(sourceInfo(), 'Code generation does not support der(<%printExpStr(exp)%>)')
case CALL(path=IDENT(name="pre"), expLst={arg}) then
daeExpCallPre(arg, context, preExp, varDecls)
case CALL(path=IDENT(name="start"), expLst={arg}) then
daeExpCallPre(arg, context, preExp, varDecls)
case CALL(path=IDENT(name="edge"), expLst={arg as CREF(__)}) then
'(<%cref(arg.componentRef)%> && !$P$PRE<%cref(arg.componentRef)%>)'
case CALL(path=IDENT(name="edge"), expLst={exp}) then
Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Expand Up @@ -47,7 +47,7 @@ newc_runtime: mkbuilddirs
# Depends on libinteractive.a
$(MAKE) -C SimulationRuntime/c -f $(defaultMakefileTarget)

c_runtime: oldc_runtime
c_runtime: oldc_runtime newc_runtime

docs: mkbuilddirs omlibrary
(cp -p doc/*.pdf doc/*.txt doc/OpenModelicaAPI-Howto/*.pdf $(builddir_doc)/omc)
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/Makefile.common
Expand Up @@ -8,7 +8,7 @@ AR = ar -ru
ANSI= #-ansi
CXXFLAGS := $(CFLAGS) -Wall $(ANSI) $(EXTRA_CFLAGS)
CFLAGS := $(CFLAGS) -Wall $(ANSI) -pedantic $(EXTRA_CFLAGS)
CPPFLAGS = -I. -Iinteractive/ -Imeta/ -I../
CPPFLAGS = -I. -Imeta/ -I../
FFLAGS = -O -fexceptions
# P.A: before, g77 had -O3 or -O2 but that caused a bug in DDASRT, giving infinite loop.

Expand Down
26 changes: 13 additions & 13 deletions SimulationRuntime/c/linearization/linearize.cpp
Expand Up @@ -61,13 +61,13 @@ string array2string(double* array, int row, int col){
}


int linearize(int nstates, int ninputs, int noutputs)
int linearize(_X_DATA* data)
{

/* init Matrix A */
int size_A = nstates;
int size_Inputs = ninputs;
int size_Outputs = noutputs;
int size_A = data->modelData.nStates;
int size_Inputs = data->modelData.nInputVars;
int size_Outputs = data->modelData.nOutputVars;
double* matrixA = (double*)calloc(size_A*size_A,sizeof(double));
double* matrixB = (double*)calloc(size_A*size_Inputs,sizeof(double));
double* matrixC = (double*)calloc(size_Outputs*size_A,sizeof(double));
Expand All @@ -80,23 +80,23 @@ int linearize(int nstates, int ninputs, int noutputs)
ASSERT(matrixD,"Calloc");

/* Determine Matrix A */
if (functionJacA(matrixA)){
if (functionJacA(data, matrixA)){
THROW("Error, can not get Matrix A ");
}
strA = array2string(matrixA,size_A,size_A);

/* Determine Matrix B */
if (functionJacB(matrixB)){
if (functionJacB(data, matrixB)){
THROW("Error, can not get Matrix B ");
}
strB = array2string(matrixB,size_A,size_Inputs);
/* Determine Matrix C */
if (functionJacC(matrixC)){
if (functionJacC(data, matrixC)){
THROW("Error, can not get Matrix C ");
}
strC = array2string(matrixC,size_Outputs,size_A);
/* Determine Matrix D */
if (functionJacD(matrixD)){
if (functionJacD(data, matrixD)){
THROW("Error, can not get Matrix D ");
}
strD = array2string(matrixD,size_Outputs,size_Inputs);
Expand All @@ -105,13 +105,13 @@ int linearize(int nstates, int ninputs, int noutputs)
inside the curly braces for x0 and u0. {for i in in 1:0} will create an
empty array if needed. */
if(size_A) {
strX = array2string(globalData->states,1,size_A);
strX = array2string(data->localData[0]->realVars,1,size_A);
} else {
strX = "i for i in 1:0";
}

if(size_Inputs) {
strU = array2string(globalData->inputVars,1,size_Inputs);
strU = array2string(data->simulationInfo.inputVars,1,size_Inputs);
} else {
strU = "i for i in 1:0";
}
Expand All @@ -121,13 +121,13 @@ int linearize(int nstates, int ninputs, int noutputs)
free(matrixC);
free(matrixD);

filename = "linear_" + string(globalData->modelName) + ".mo";
filename = "linear_" + string(data->modelData.modelName) + ".mo";

FILE *fout = fopen(filename.c_str(),"wb");
ASSERT1(fout,"Cannot open File %s",filename.c_str());
fprintf(fout, linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if (sim_verbose>=LOG_STATS)
printf(linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if (DEBUG_FLAG(LOG_STATS))
DEBUG_INFO6(LOG_STATS, linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
fflush(fout);
fclose(fout);

Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/linearization/linearize.h
Expand Up @@ -40,7 +40,7 @@

using namespace std;

int linearize(int nstates, int ninputs, int noutputs);
int linearize(_X_DATA* data);
//int argc, char** argv, string method, double start,
//double stop, double stepSize , long outputSteps, double tolerance);

Expand Down

0 comments on commit 4c39590

Please sign in to comment.