Skip to content

Commit

Permalink
Updating code for QSS
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10549 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
fbergero committed Nov 18, 2011
1 parent fc230f8 commit 287ba6b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
37 changes: 33 additions & 4 deletions Compiler/BackEnd/BackendQSS.mo
Expand Up @@ -73,6 +73,7 @@ uniontype QSSinfo "- equation indices in static blocks and DEVS structure"
list<list<SimCode.SimEqSystem>> eqs;
list<BackendDAE.Var> outVarLst;
list<Integer> zcSamplesInd;
list<BackendDAE.Var> stateVarLst;
end QSSINFO;
end QSSinfo;

Expand Down Expand Up @@ -142,6 +143,10 @@ algorithm

orderedVars = BackendVariable.daeVars(syst);
varlst = BackendDAEUtil.varList(orderedVars);
print("\n ----------------------------\n");
print(" Variable list ");
print("\n ----------------------------\n");
printVars(stateVarsList,0);

// ZERO-CROSSES
(zeroCrossList, zc_inVars, samplesList, zcSamplesInd) = getListofZeroCrossings(dlow);
Expand Down Expand Up @@ -321,7 +326,7 @@ algorithm
dumpDEVSstructs(DEVS_structure);


qssInfo = QSSINFO(stateEq_blt, DEVS_structure,eqs,varlst,zcSamplesInd);
qssInfo = QSSINFO(stateEq_blt, DEVS_structure,eqs,varlst,zcSamplesInd,stateVarsList);
conns = generateConnections(qssInfo);
print("CONNECTIONS");
printListOfLists(conns);
Expand Down Expand Up @@ -3288,9 +3293,9 @@ algorithm
states :=
match qssInfo
local
list<BackendDAE.Var> outVarLst;
case QSSINFO(outVarLst=outVarLst)
then List.filterOnTrue(outVarLst,BackendVariable.isStateVar);
list<BackendDAE.Var> states;
case QSSINFO(stateVarLst=states)
then states;
end match;
end getStates;

Expand Down Expand Up @@ -3918,6 +3923,30 @@ algorithm
end matchcontinue;
end findElementInList;


public function printVars
input list<BackendDAE.Var> varlst;
input Integer index;
algorithm
_ := matchcontinue (varlst,index)
local
list<BackendDAE.Var> rest;
DAE.ComponentRef cr;
String s;
case (BackendDAE.VAR(varName = cr)::rest,index)
equation
s = ComponentReference.printComponentRefStr(cr);
print(intString(index));
print(": ");
print(s);
print("\n");
printVars(rest,index+1);
then ();
case ({},_)
then ();
end matchcontinue;
end printVars;

////////////////////////////////////////////////////////////////////////////////////////////////////
///// END OF PACKAGE
////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
22 changes: 16 additions & 6 deletions Compiler/susan_codegen/SimCode/SimCodeQSS.tpl
Expand Up @@ -62,7 +62,7 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
let guid = getUUIDStr()
let()= textFile(simulationFile(simCode,qssInfo,guid), 'modelica_funcs.cpp')
let()= textFile(SimCodeC.simulationFunctionsHeaderFile(fileNamePrefix, modelInfo.functions, recordDecls), 'model_functions.h')
let()= textFile(simulationFunctionsFile(fileNamePrefix, modelInfo.functions, literals), 'model_functions.cpp')
let()= textFile(simulationFunctionsFile(fileNamePrefix, modelInfo.functions, literals), 'model_functions.c')
let()= textFile(SimCodeC.recordsFile(fileNamePrefix, recordDecls), 'model_records.c')
let()= textFile(simulationMakefile(simCode), '<%fileNamePrefix%>.makefile')
let()= textFile(structureFile(simCode,qssInfo), 'modelica_structure.pds')
Expand All @@ -82,6 +82,12 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(varInfo=varInfo as VARINFO(__)))
<<

<%simulationFileHeader(simCode)%>
#include "model_functions.c"
#define _OMC_SEED_HACK
#define _OMC_SEED_HACK_2
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _OMC_QSS
extern "C" { // adrpo: this is needed for Visual C++ compilation to work!
Expand Down Expand Up @@ -313,6 +319,8 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(varInfo=varInfo as VARINFO(__)))
<%SimCodeC.functionlinearmodel(modelInfo)%>

<%\n%>

}
>>
/* adrpo: leave a newline at the end of file to get rid of the warning */
end simulationFile;
Expand Down Expand Up @@ -496,17 +504,19 @@ template functionQssStaticBlocks(list<list<SimEqSystem>> derivativEquations,list
match qssInfo
case BackendQSS.QSSINFO(__) then
let &varDecls = buffer "" /*BUFD*/
let &tmp = buffer ""
let numStatic = intAdd(listLength(eqs),listLength(zeroCrossings))
let numPureStatic = listLength(eqs)
let numZeroCross = listLength(zeroCrossings)
let staticFun = generateStaticFunc(derivativEquations,zeroCrossings,varDecls,DEVSstructure,eqs,outVarLst,nStates)
let staticFun = generateStaticFunc(derivativEquations,zeroCrossings,varDecls,DEVSstructure,eqs,outVarLst,nStates,tmp)
let zeroCross = generateZeroCrossingsEq(listLength(eqs),zeroCrossings,varDecls,DEVSstructure,outVarLst,nStates)

<<
int staticBlocks = <% numStatic %>;
int staticPureBlocks = <% numPureStatic %>;
int zeroCrossings = <% numZeroCross %>;

<%tmp%>
void function_staticBlocks(int staticFunctionIndex, double t, double *in, double *out)
{
state mem_state;
Expand Down Expand Up @@ -549,7 +559,7 @@ template generateInputs(BackendQSS.DevsStruct devsst, Integer index, list<Backen
end generateInputs;

template generateStaticFunc(list<list<SimEqSystem>> odeEq,list<ZeroCrossing> zeroCrossings,
Text &varDecls /*BUFP*/, BackendQSS.DevsStruct devsst,list<list<SimCode.SimEqSystem>> BLTblocks, list<BackendDAE.Var> varLst, Integer nStates)
Text &varDecls /*BUFP*/, BackendQSS.DevsStruct devsst,list<list<SimCode.SimEqSystem>> BLTblocks, list<BackendDAE.Var> varLst, Integer nStates, Text &tmp)
"Generate the cases for the static function "
::=
(BLTblocks |> eqs hasindex i0 =>
Expand All @@ -563,7 +573,7 @@ template generateStaticFunc(list<list<SimEqSystem>> odeEq,list<ZeroCrossing> zer
#endif
// Evalute the static function
<% /* (eqs |> eq => SimCodeC.equation_(BackendQSS.replaceZC(eq,zeroCrossings), contextSimulationNonDiscrete, &varDecls ); separator="\n") */ %>
<% (eqs |> eq => SimCodeC.equation_(BackendQSS.replaceZC(eq,zeroCrossings), contextSimulationNonDiscrete, &varDecls, &tmp ); separator="\n") %>
// Write outputs to out[]
#ifdef _OMC_OMPD
Expand Down Expand Up @@ -833,8 +843,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
PERL=perl

.PHONY: <%fileNamePrefix%>
<%fileNamePrefix%>: <%fileNamePrefix%>.conv.cpp model_functions.cpp model_functions.h model_records.c
<%\t%> $(CXX) -I. -o <%fileNamePrefix%>$(EXEEXT) <%fileNamePrefix%>.conv.cpp model_functions.cpp <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -linteractive $(SENDDATALIBS) <%match System.os() case "OSX" then "-lf2c" else "-Wl,-Bstatic -lf2c -Wl,-Bdynamic"%> model_records.c
<%fileNamePrefix%>: <%fileNamePrefix%>.conv.cpp model_functions.c model_functions.h model_records.c
<%\t%> $(CXX) -I. -o <%fileNamePrefix%>$(EXEEXT) <%fileNamePrefix%>.conv.cpp model_functions.c <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -linteractive $(SENDDATALIBS) <%match System.os() case "OSX" then "-lf2c" else "-Wl,-Bstatic -lf2c -Wl,-Bdynamic"%> model_records.c
<%fileNamePrefix%>.conv.cpp: modelica_funcs.cpp
<%\t%> $(PERL) <%makefileParams.omhome%>/share/omc/scripts/convert_lines.pl $< $@.tmp
<%\t%> @mv $@.tmp $@
Expand Down

0 comments on commit 287ba6b

Please sign in to comment.