Skip to content

Commit

Permalink
- removed redundant equations for initialization
Browse files Browse the repository at this point in the history
- removed unused code
- renamed SIMCODE attribute initialEquations to startValueEquations (in order to avoid confusion)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10971 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jan 27, 2012
1 parent 7f04f5f commit 941864b
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 174 deletions.
208 changes: 54 additions & 154 deletions Compiler/BackEnd/SimCode.mo

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Compiler/susan_codegen/SimCode/CodegenC.tpl
Expand Up @@ -158,7 +158,7 @@ case simCode as SIMCODE(__) then
<%functionStoreDelayed(delayedExps)%>
<%functionUpdateBoundStartValues(initialEquations)%>
<%functionUpdateBoundStartValues(startValueEquations)%>
<%functionInitialResidual(residualEquations)%>
Expand Down Expand Up @@ -655,12 +655,12 @@ template functionSampleEquations(list<SimEqSystem> sampleEqns)
>>
end functionSampleEquations;

template functionUpdateBoundStartValues(list<SimEqSystem> initialEquations)
template functionUpdateBoundStartValues(list<SimEqSystem> startValueEquations)
"Generates function in simulation file."
::=
let &varDecls = buffer "" /*BUFD*/
let &tmp = buffer ""
let eqPart = (initialEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
let eqPart = (startValueEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
equation_(eq, contextOther, &varDecls /*BUFD*/, &tmp)
;separator="\n")
<<
Expand All @@ -672,7 +672,7 @@ template functionUpdateBoundStartValues(list<SimEqSystem> initialEquations)
<%eqPart%>
DEBUG_INFO(LOG_INIT, "updating start-values:");
<%initialEquations |> SES_SIMPLE_ASSIGN(__) =>
<%startValueEquations |> SES_SIMPLE_ASSIGN(__) =>
'DEBUG_INFO_AL2(LOG_INIT, " %s(start=%f)", <%cref(cref)%>__varInfo.name, (<%crefType(cref)%>) <%cref(cref)%>);
$P$START<%cref(cref)%> = <%cref(cref)%>;'
;separator="\n"%>
Expand Down
6 changes: 3 additions & 3 deletions Compiler/susan_codegen/SimCode/SimCodeAdevs.tpl
Expand Up @@ -510,7 +510,7 @@ case SIMCODE(modelInfo = MODELINFO(vars = vars as SIMVARS(__))) then
for (int i = 0; i < numHelpVars(); i++)
helpVars_saved[i] = false;
// Calculate any equations that provide initial values
<%makeInitialEqns(initialEquations)%>
<%makeInitialEqns(startValueEquations)%>
bound_params();
// Save again after calculating initial equations and algorithms
save_vars();
Expand All @@ -527,10 +527,10 @@ case SIMCODE(modelInfo = MODELINFO(vars = vars as SIMVARS(__))) then
>>
end makeInit;

template makeInitialEqns(list<SimEqSystem> initialEquations)
template makeInitialEqns(list<SimEqSystem> startValueEquations)
::=
let &varDecls = buffer "" /*BUFD*/
let eqPart = (initialEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
let eqPart = (startValueEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
equation_(eq, contextOther, &varDecls /*BUFD*/)
;separator="\n")
<<
Expand Down
8 changes: 4 additions & 4 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -140,7 +140,7 @@ case simCode as SIMCODE(__) then
<%functionStoreDelayed(delayedExps)%>
<%functionInitial(initialEquations)%>
<%functionInitial(startValueEquations)%>
<%functionInitialResidual(residualEquations)%>
Expand Down Expand Up @@ -765,12 +765,12 @@ template functionSampleEquations(list<SimEqSystem> sampleEqns)
>>
end functionSampleEquations;

template functionInitial(list<SimEqSystem> initialEquations)
template functionInitial(list<SimEqSystem> startValueEquations)
"Generates function in simulation file."
::=
let &varDecls = buffer "" /*BUFD*/
let &tmp = buffer ""
let eqPart = (initialEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
let eqPart = (startValueEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
equation_(eq, contextOther, &varDecls /*BUFD*/, &tmp)
;separator="\n")
<<
Expand All @@ -781,7 +781,7 @@ template functionInitial(list<SimEqSystem> initialEquations)
<%eqPart%>
<%initialEquations |> SES_SIMPLE_ASSIGN(__) =>
<%startValueEquations |> SES_SIMPLE_ASSIGN(__) =>
'if (sim_verbose >= LOG_INIT) { printf("Setting variable start value: %s(start=%f)\n", "<%cref(cref)%>", (<%crefType(cref)%>) <%cref(cref)%>); }'
;separator="\n"%>
Expand Down
8 changes: 4 additions & 4 deletions Compiler/susan_codegen/SimCode/SimCodeCSharp.tpl
Expand Up @@ -56,7 +56,7 @@ namespace Bodylight.Models<%modelNameSpace(modelInfo.name)%>
<%functionStoreDelayed(simCode)%>
<%functionInitial(initialEquations, simCode)%>
<%functionInitial(startValueEquations, simCode)%>
<%functionInitialResidual(residualEquations, simCode)%>
Expand Down Expand Up @@ -818,16 +818,16 @@ public override void FunODE()
end functionODE;

//TODO:??there is st more in the trunk
template functionInitial(list<SimEqSystem> initialEquations, SimCode simCode) ::=
template functionInitial(list<SimEqSystem> startValueEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
<<
public override void InitialFun()
{
<% localRepresentationArrayDefines %>
<%initialEquations |> saeq as SES_SIMPLE_ASSIGN(__) => equation_(saeq, contextOther, simCode) ;separator="\n"%>
<%startValueEquations |> saeq as SES_SIMPLE_ASSIGN(__) => equation_(saeq, contextOther, simCode) ;separator="\n"%>
//if (sim_verbose) {
<%initialEquations |> SES_SIMPLE_ASSIGN(__) =>
<%startValueEquations |> SES_SIMPLE_ASSIGN(__) =>
<<
//Debug.WriteLine("Setting variable start value: {0}(start={1})", "<%cref(cref, simCode)%>", <%cref(cref, simCode)%>);
>> ;separator="\n"%>
Expand Down
6 changes: 3 additions & 3 deletions Compiler/susan_codegen/SimCode/SimCodeCpp.tpl
Expand Up @@ -1177,7 +1177,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
let () = System.tmpTickReset(0)
let &varDecls = buffer "" /*BUFD*/
let initVariables = initvar(modelInfo,simCode)
let initFunctions = functionInitial(initialEquations,varDecls,simCode)
let initFunctions = functionInitial(startValueEquations,varDecls,simCode)
let initZeroCrossings = functionOnlyZeroCrossing(zeroCrossings,varDecls,simCode)
let initTimeEventFunctions = timeEventCondition(sampleConditions,varDecls,simCode)
let initEventHandling = eventHandlingInit(simCode)
Expand Down Expand Up @@ -3404,12 +3404,12 @@ template crefFunctionName(ComponentRef cr)
'<%System.stringReplace(unquoteIdentifier(ident), "_", "__")%>_<%crefFunctionName(componentRef)%>'
end crefFunctionName;
template functionInitial(list<SimEqSystem> initialEquations,Text &varDecls,SimCode simCode)
template functionInitial(list<SimEqSystem> startValueEquations,Text &varDecls,SimCode simCode)
::=
let eqPart = (initialEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
let eqPart = (startValueEquations |> eq as SES_SIMPLE_ASSIGN(__) =>
equation_(eq, contextOther, &varDecls,simCode)
;separator="\n")
<<
Expand Down
2 changes: 1 addition & 1 deletion Compiler/susan_codegen/SimCode/SimCodeQSS.tpl
Expand Up @@ -296,7 +296,7 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(varInfo=varInfo as VARINFO(__)))

<%SimCodeC.functionStoreDelayed(delayedExps)%>

<%SimCodeC.functionInitial(initialEquations)%>
<%SimCodeC.functionInitial(startValueEquations)%>

<%SimCodeC.functionBoundParameters(parameterEquations)%>

Expand Down
2 changes: 1 addition & 1 deletion Compiler/susan_codegen/SimCode/SimCodeTV.mo
Expand Up @@ -90,7 +90,7 @@ package SimCode
list<list<SimEqSystem>> odeEquations;
list<SimEqSystem> algebraicEquations;
list<SimEqSystem> residualEquations;
list<SimEqSystem> initialEquations;
list<SimEqSystem> startValueEquations;
list<SimEqSystem> parameterEquations;
list<SimEqSystem> removedEquations;
list<DAE.Statement> algorithmAndEquationAsserts;
Expand Down

0 comments on commit 941864b

Please sign in to comment.