Skip to content

Commit

Permalink
- Susan updated tests to be all OK
Browse files Browse the repository at this point in the history
- C# codegen for non-linear strong components

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7064 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed Nov 17, 2010
1 parent e2bbc5b commit c3c75be
Show file tree
Hide file tree
Showing 11 changed files with 735 additions and 451 deletions.
784 changes: 500 additions & 284 deletions Compiler/SimCodeCSharp.mo

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions Compiler/TplMain.mo
Expand Up @@ -371,8 +371,6 @@ input Pa.Li inSusan;", true, true, "typedIdentsEx", notPassedCnt);
notPassedCnt = testStringEquality(str,
"package Susan

protected constant Tpl.Text emptyTxt = Tpl.MEM_TEXT({}, {});

public import Tpl;

public import Pa.Li.Ko;
Expand Down Expand Up @@ -525,8 +523,6 @@ typedIdents(TypedIdents decls) <>=
notPassedCnt = testStringEquality(str,
"package Susan

protected constant Tpl.Text emptyTxt = Tpl.MEM_TEXT({}, {});

public import Tpl;

public import TplAbsyn;
Expand Down Expand Up @@ -613,7 +609,7 @@ public function typedIdents

output Tpl.Text out_txt;
algorithm
out_txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0,NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
out_txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
out_txt := lm_2(out_txt, i_decls);
out_txt := Tpl.popIter(out_txt);
end typedIdents;
Expand Down
12 changes: 6 additions & 6 deletions Compiler/susan_codegen/SimCode/GenTest/Makefile
Expand Up @@ -24,8 +24,8 @@ tplmode :
csharp :
@echo " ** Generate RightHeartStarling Test CSharp target ** "
(cd RightHeartStarling && ../$(OMC) +d=tplmode,CSharp generate.mos)
@echo " ** Generate TrapezUnderground Test CSharp target ** "
(cd TrapezUnderground && ../$(OMC) +d=tplmode,CSharp generate.mos)
#@echo " ** Generate TrapezUnderground Test CSharp target ** "
#(cd TrapezUnderground && ../$(OMC) +d=tplmode,CSharp generate.mos)

cppOrig :
#@echo " ** Generate TrapezTest original original C/C++ target ** "
Expand All @@ -40,9 +40,9 @@ cppOrig :
QHP:
@echo " ** Simulate QHP original C/C++ ** "
#(cd QHP && ../$(OMC) +showErrorMessages +d=perfTimes,failtrace simulate.mos > debug-trace-C.txt 2>&1)
(cd QHP && ../$(OMC) +showErrorMessages +d=perfTimes simulate.mos > debug-trace-C.txt 2>&1)
#(cd QHP && ../$(OMC) +showErrorMessages +d=perfTimes simulate.mos > debug-trace-C.txt 2>&1)
(cd QHP && ../$(OMC) +d=perfTimes simulate.mos > debug-trace-C.txt 2>&1)
@echo " ** Generate QHP CSharp target ** "
#,failtrace
(cd QHP && ../$(OMC) +showErrorMessages +d=perfTimes,CSharp generate.mos > debug-trace-CSharp.txt 2>&1)


Expand All @@ -51,8 +51,8 @@ csCopy:
#(cp -pf ./QHP/QHP_Blood_BlooodVolume_ExpandableConnectorPatch_T.cs "/d/Modelica/_svn_Solvers/Compiled Solvers/Simulation/ModelsDotNet/")
#(cp -pf ./QHP/QHP_Electrolytes_ExpandableConnectorPatch_T.cs "/d/Modelica/_svn_Solvers/Compiled Solvers/Simulation/ModelsDotNet/")
#(cp -pf ./QHP/QHP_test_TestRedCells.cs "/d/Modelica/_svn_Solvers/Compiled Solvers/Simulation/ModelsDotNet/")
(cp -pf TrapezUnderground/*.cs $(ModelsNET))
(cp -pf RightHeartStarling/*.cs $(ModelsNET))
#(cp -pf TrapezUnderground/*.cs $(ModelsNET))
#(cp -pf RightHeartStarling/*.cs $(ModelsNET))
(cp -pf ./QHP/*.cs $(ModelsNET))

#RightHeartStarling/RightHeartStarling.cpp : RightHeartStarling/RightHeartStarling.mo
Expand Down
28 changes: 28 additions & 0 deletions Compiler/susan_codegen/SimCode/GenTest/QHP/generate.mos
@@ -1,5 +1,33 @@
getErrorString();

loadFile("D:/Modelica/_modely/HeartSystem/HeartSystem.mo");
loadFile("D:/Modelica/_modely/HeartSystem/VenousPrinciple.mo");
getErrorString();
//translateModel(VenousPrinciples.TwoElasticities);
translateModel(VenousPrinciples.VenousReturnCircuit);
getErrorString();

/*
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/LeftHeartStarling.mo");
getErrorString();
translateModel(LeftHeartStarling);
getErrorString();

loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/RightHeartStarling.mo");
getErrorString();
translateModel(RightHeartStarling);
getErrorString();
*/
/*
loadFile("NonLinSys3.mo");
translateModel(NonLinSys3);


loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/VenousReturn.mo");
getErrorString();
translateModel(VenousReturn);
getErrorString();
*/
/*
getErrorString();
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/TSystemicCirculationTotal.mo");
Expand Down
50 changes: 35 additions & 15 deletions Compiler/susan_codegen/SimCode/GenTest/QHP/simulate.mos
@@ -1,25 +1,53 @@
getErrorString();

/*
//loadModel(Modelica);
getErrorString();
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/TSystemicCirculationTotal.mo");
loadFile("d:/Modelica/_modely/HumMod - Habilitacna Prednaska/HumMod_OMCTotal.mo");
//loadFile("d:/Modelica/_modely/HumMod/for testing/HumModOMCTotal.mo");
getErrorString();
//checkModel(HumMod_HumMod_GolemEdition);
translateModel(HumMod_HumMod_GolemEdition);
getErrorString();
*/

/*
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/LeftHeartStarling.mo");
getErrorString();
simulate(LeftHeartStarling, stopTime=15);
getErrorString();
*/
/*
loadFile("NonLinSys3.mo");
simulate(NonLinSys3, tolerance=1e-10, stopTime=10);
//val(x,0.0);
//val(x,0.5);
//val(x,1.0);
//val(y,0.0);
//val(y,0.5);
//val(y,1.0);
*/
/*
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/VenousReturn.mo");
getErrorString();
//simulate(HumMod_GolemEdition, stopTime=1);
//instantiateModel(HumMod_Blood_test_TSystemicCirculation);
//checkModel(HumMod_Blood_test_TSystemicCirculation);
simulate(HumMod_Blood_test_TSystemicCirculation, stopTime=1);
simulate(VenousReturn, stopTime=15);
//simulate(Pokus, stopTime=15);
getErrorString();
*/

/*
//loadModel(Modelica);
getErrorString();
loadFile("d:/Modelica/_modely/HumMod/for testing/HumModOMCTotal.mo");
loadFile("d:/Modelica/_modely/HumMod/for testing/CVS/TSystemicCirculationTotal.mo");
getErrorString();
//simulate(QHP_Electrolytes_test_T2, stopTime=1);
//simulate(HumMod_GolemEdition, stopTime=1);
simulate(HumMod_HumMod_GolemEdition, stopTime=1);
//instantiateModel(HumMod_Blood_test_TSystemicCirculation);
//checkModel(HumMod_Blood_test_TSystemicCirculation);
simulate(HumMod_Blood_test_TSystemicCirculation, stopTime=1);
getErrorString();
*/

/*
loadFile("ElectrolytesT2Total.mo");
getErrorString();
Expand Down Expand Up @@ -99,14 +127,6 @@ simulate(BloodCircuit, stopTime=10);
getErrorString();
*/

//loadFile("NonLinSys3.mo");
//simulate(NonLinSys3, tolerance=1e-10, numberOfIntervals=100);
//val(x,0.0);
//val(x,0.5);
//val(x,1.0);
//val(y,0.0);
//val(y,0.5);
//val(y,1.0);


//loadFile("TestAmoniakTotal.mo");
Expand Down
76 changes: 56 additions & 20 deletions Compiler/susan_codegen/SimCode/SimCodeCSharp.tpl
Expand Up @@ -71,7 +71,7 @@ namespace Bodylight.Models<%modelNameSpace(modelInfo.name)%>
<%functionInitialResidual(residualEquations, simCode)%>
<%functionExtraResudials(allEquations, simCode)%>
<%functionExtraResiduals(allEquations, simCode)%>
<%functionBoundParameters(parameterEquations, simCode)%>
Expand Down Expand Up @@ -281,7 +281,7 @@ public double <%cref(name, simCode)%> { get { return parameters[<%index%>]; } se


#region VariableInfos
private static readonly SimVarInfo[] VariableInfosStatic = new[] {
public static readonly SimVarInfo[] VariableInfosStatic = new[] {
<%{
varInfos("State", vars.stateVars, false, simCode),
varInfos("StateDer", vars.derivativeVars, false, simCode),
Expand Down Expand Up @@ -711,23 +711,29 @@ public override void InitialResidual()
>>
end functionInitialResidual;

template functionExtraResudials(list<SimEqSystem> allEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
(allEquations |> SES_NONLINEAR(__) =>
<<
void ResidualFun<%index%>(int n, double[] xloc, double[] res, int iflag)
{
<% localRepresentationArrayDefines %>
<%eqs |> SES_RESIDUAL(__) hasindex i0 =>
let &preExp = buffer ""
let expPart = daeExp(exp, contextSimulationDiscrete, &preExp, simCode)
<<
<%preExp%>
res[<%i0%>] = <%expPart%>;
>> ;separator="\n"%>
}
>> ;separator="\n")
end functionExtraResudials;
template functionExtraResiduals(list<SimEqSystem> allEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
(allEquations |> SES_NONLINEAR(__) =>
<<
int ResidualFun<%index%>(int n, double[] xloc, double[] res, int iflag)
{
<% localRepresentationArrayDefines %>
<%eqs |> saeq as SES_SIMPLE_ASSIGN(__) =>
equation_(saeq, contextOther, simCode)
;separator="\n"
%>
<%eqs |> SES_RESIDUAL(__) hasindex i0 =>
let &preExp = buffer ""
let expPart = daeExp(exp, contextSimulationDiscrete, &preExp, simCode)
<<
<%preExp%>
res[<%i0%>] = <%expPart%>;
>> ;separator="\n"
%>
return 0;
}
>> ;separator="\n")
end functionExtraResiduals;

template functionBoundParameters(list<SimEqSystem> parameterEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
Expand Down Expand Up @@ -923,7 +929,26 @@ case SES_MIXED(__) then
} // *** mixed_equation_system_end(<%numDiscVarsStr%>) ***
>>

case SES_NONLINEAR(__) then "SES_NONLINEAR"
case SES_NONLINEAR(__) then
let size = listLength(crefs)
<<
//start_nonlinear_system(<%size%>);
{ var oldX = oldStates; var oldXd = oldStatesDerivatives; var old2X = oldStates2; var old2Xd = oldStatesDerivatives2;
var oldY = oldAlgebraics; var old2Y = oldAlgebraics2; var oldTimeDelta = oldTime - oldTime2;
var nls_x = new double[<%size%>]; var nls_xold = new double[<%size%>];
<%crefs |> name hasindex i0 =>
<<
nls_x[<%i0%>] = /*extraPolate(<%crefStr(name, simCode)%>)*/ oldTimeDelta == 0.0 ? <%cref(name, simCode)%> : (time * (<%oldCref(name, simCode)%> - <%old2Cref(name, simCode)%>) + (oldTime * <%old2Cref(name, simCode)%> - oldTime2 * <%oldCref(name, simCode)%>)) / oldTimeDelta;
nls_xold[<%i0%>] = <%oldCref(name, simCode)%>;
>> ;separator="\n"
%>
SolveNonlinearSystem(ResidualFun<%index%>, nls_x, nls_xold, <%index%>);
<%crefs |> name hasindex i0 =>
'<%cref(name, simCode)%> = nls_x[<%i0%>];' ;separator="\n"
%>
} //end_nonlinear_system();
>>

case SES_WHEN(__) then
let &preExp = buffer ""
let helpIf = (conditions |> (e, hidx) =>
Expand Down Expand Up @@ -1001,6 +1026,15 @@ template derCref(ComponentRef cr, SimCode simCode) ::=
'/*derCall!!(<% crefStr(cr, simCode) %>)*/<%representationCref(derComponentRef(cr), simCode)%>'
end derCref;

template oldCref(ComponentRef cr, SimCode simCode) ::=
'/*old(<%crefStr(cr, simCode)%>)*/old<%representationCref(cr, simCode)%>'
end oldCref;

template old2Cref(ComponentRef cr, SimCode simCode) ::=
'/*old2(<%crefStr(cr, simCode)%>)*/old2<%representationCref(cr, simCode)%>'
end old2Cref;


template contextCref(ComponentRef cr, Context context, SimCode simCode)
"Generates code for a component reference depending on which context we're in."
::=
Expand Down Expand Up @@ -1301,6 +1335,7 @@ template daeExp(Exp inExp, Context context, Text &preExp, SimCode simCode) ::=
case CODE(__) then "CODE_NOT_IMPLEMENTED"
case REDUCTION(__) then "REDUCTION_NOT_IMPLEMENTED"
case END(__) then "END_NOT_IMPLEMENTED"
//case VALUEBLOCK(__) then "VALUEBLOCK_NOT_IMPLEMENTED"
case LIST(__) then "LIST_NOT_IMPLEMENTED"
case CONS(__) then "CONS_NOT_IMPLEMENTED"
// META_TUPLE
Expand Down Expand Up @@ -1908,5 +1943,6 @@ template dimension(Dimension d)
else "INVALID_DIMENSION"
end dimension;


end SimCodeCSharp;
// vim: filetype=susan sw=2 sts=2

0 comments on commit c3c75be

Please sign in to comment.