Skip to content

Commit

Permalink
- Tiny update. It won't break anything. I promise.
Browse files Browse the repository at this point in the history
- Moved some of the debug information to reading the generated xml-file instead of compiling it into the C-code
  - TODO: Read the names of all systems, instead of only nonlinear. Populate the FILE_INFO, etc


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15072 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 6, 2013
1 parent ffaefb0 commit 9b7d846
Show file tree
Hide file tree
Showing 23 changed files with 500 additions and 210 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/SimCodeMain.mo
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ algorithm
then ();
case (_,_,"C")
equation
Tpl.tplNoret(SimCodeDump.dumpSimCode, simCode);
Tpl.tplNoret(CodegenC.translateModel, simCode);
then ();
case (_,_,"Dump")
Expand Down
16 changes: 9 additions & 7 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3436,7 +3436,7 @@ algorithm
disc_var = List.map1r(ivars, BackendVariable.getVarAt, vars);
(_, {equation_}, uniqueEqIndex, tempvars) = createEquations(true, false, false, skipDiscInAlgorithm, false, syst, shared, {comp1}, iuniqueEqIndex, itempvars);
simVarsDisc = List.map2(disc_var, dlowvarToSimvar, NONE(), knvars);
discEqs = extractDiscEqs(disc_eqn, disc_var);
(discEqs,uniqueEqIndex) = extractDiscEqs(disc_eqn, disc_var, uniqueEqIndex);
//was madness
then ({SimCode.SES_MIXED(uniqueEqIndex, equation_, simVarsDisc, discEqs)}, {equation_}, uniqueEqIndex+1, tempvars);

Expand Down Expand Up @@ -5841,10 +5841,12 @@ end generateTearingOtherEqns;
protected function extractDiscEqs
input list<BackendDAE.Equation> disc_eqn;
input list<BackendDAE.Var> disc_var;
input Integer inUniqueEqIndex;
output list<SimCode.SimEqSystem> discEqsOut;
output Integer uniqueEqIndex;
algorithm
discEqsOut :=
match (disc_eqn, disc_var)
(discEqsOut,uniqueEqIndex) :=
match (disc_eqn, disc_var, inUniqueEqIndex)
local
list<SimCode.SimEqSystem> restEqs;
DAE.ComponentRef cr;
Expand All @@ -5853,15 +5855,15 @@ algorithm
BackendDAE.Var v;
list<BackendDAE.Var> vs;
DAE.ElementSource source;
case ({}, _) then {};
case ((BackendDAE.EQUATION(exp = e1, scalar = e2, source = source) :: eqns), (v :: vs))
case ({}, _, _) then ({},inUniqueEqIndex);
case ((BackendDAE.EQUATION(exp = e1, scalar = e2, source = source) :: eqns), (v :: vs), _)
equation
cr = BackendVariable.varCref(v);
varexp = Expression.crefExp(cr);
(expr, _) = solve(e1, e2, varexp);
restEqs = extractDiscEqs(eqns, vs);
(restEqs,uniqueEqIndex) = extractDiscEqs(eqns, vs, inUniqueEqIndex);
then
SimCode.SES_SIMPLE_ASSIGN(0, cr, expr, source) :: restEqs;
(SimCode.SES_SIMPLE_ASSIGN(uniqueEqIndex, cr, expr, source) :: restEqs,uniqueEqIndex+1);
// failure
else
equation
Expand Down
40 changes: 20 additions & 20 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ template simulationFile(SimCode simCode, String guid)
<%functionInitializeDataStruc(modelInfo, fileNamePrefix, guid, allEquations, jacobianMatrixes, delayedExps)%>
<%functionInitializeDataStruc2(modelInfo, SimCodeUtil.sortEqSystems(
<% /* functionInitializeDataStruc2(modelInfo, SimCodeUtil.sortEqSystems(
listAppend(residualEquations,
listAppend(inlineEquations,
listAppend(startValueEquations,
listAppend(parameterEquations,
listAppend(initialEquations,
listAppend(algorithmAndEquationAsserts,
allEquations))))))),
stateSets)%>
stateSets) */ %>
<%functionCallExternalObjectConstructors(extObjInfo)%>
Expand Down Expand Up @@ -233,7 +233,8 @@ template simulationFileHeader(SimCode simCode)

#include "openmodelica.h"
#include "openmodelica_func.h"
#include "simulation_data.h"
#include "simulation_data.h"
#include "simulation_info_xml.h"
#include "simulation_runtime.h"
#include "omc_error.h"
#include "model_help.h"
Expand Down Expand Up @@ -284,8 +285,10 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
data->modelData.nInitAlgorithms = <%varInfo.numInitialAlgorithms%>;
data->modelData.nInitResiduals = <%varInfo.numInitialResiduals%>; /* data->modelData.nInitEquations + data->modelData.nInitAlgorithms */
data->modelData.nExtObjs = <%varInfo.numExternalObjects%>;
data->modelData.nFunctions = <%listLength(functions)%>;
data->modelData.nEquations = <%varInfo.numEquations%>;
data->modelData.modelDataXml.fileName = "<%fileNamePrefix%>_info.xml";
data->modelData.modelDataXml.nFunctions = <%listLength(functions)%>;
data->modelData.modelDataXml.nProfileBlocks = 0;
data->modelData.modelDataXml.nEquations = <%varInfo.numEquations%>;
data->modelData.nNonLinearSystems = <%varInfo.numNonLinearResFunctions%>;
data->modelData.nStateSets = <%varInfo.numStateSets%>;
data->modelData.nInlineVars = <%varInfo.numInlineVars%>;
Expand Down Expand Up @@ -799,7 +802,7 @@ template functionInitialNonLinearSystemsTemp(list<SimEqSystem> allEquations)
let initialJac = match jacobianMatrix case SOME(__) then 'initialAnalyticJacobianNLSJac<%eq.index%>' case NONE() then 'NULL'
let jacIndex = match jacobianMatrix case SOME(__) then 'INDEX_JAC_NLSJac<%eq.index%>' case NONE() then '-1'
<<
nonLinearSystemData[<%indexNonLinear%>].simProfEqNr = SIM_PROF_EQ_<%index%>;
nonLinearSystemData[<%indexNonLinear%>].equationIndex = <%index%>;
nonLinearSystemData[<%indexNonLinear%>].size = <%size%>;
nonLinearSystemData[<%indexNonLinear%>].method = <%newtonStep%>;
nonLinearSystemData[<%indexNonLinear%>].residualFunc = residualFunc<%index%>;
Expand Down Expand Up @@ -876,7 +879,7 @@ template functionExtraResiduals(list<SimEqSystem> allEquations)
state mem_state;
<%varDecls%>
#ifdef _OMC_MEASURE_TIME
SIM_PROF_ADD_NCALL_EQ(SIM_PROF_EQ_<%index%>,1);
SIM_PROF_ADD_NCALL_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex,1);
#endif
mem_state = get_memory_state();
<%xlocs%>
Expand Down Expand Up @@ -2310,7 +2313,7 @@ case SES_LINEAR(__) then
<% if not partOfMixed then
<<
#ifdef _OMC_MEASURE_TIME
SIM_PROF_TICK_EQ(SIM_PROF_EQ_<%index%>);<%\n%>
SIM_PROF_TICK_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);<%\n%>
#endif<%\n%>
>> %>
/* Linear equation system */
Expand All @@ -2331,7 +2334,7 @@ case SES_LINEAR(__) then
<% if not partOfMixed then
<<
#ifdef _OMC_MEASURE_TIME
SIM_PROF_ACC_EQ(SIM_PROF_EQ_<%index%>);
SIM_PROF_ACC_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
#endif<%\n%>
>> %>
>>
Expand All @@ -2355,7 +2358,7 @@ case SES_MIXED(__) then
;separator="\n")
<<
#ifdef _OMC_MEASURE_TIME
SIM_PROF_TICK_EQ(SIM_PROF_EQ_<%index%>);
SIM_PROF_TICK_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
#endif
modelica_boolean boolVar_<%index%>[<%numDiscVarsStr%>] = { 0 };
mixed_equation_system(<%numDiscVarsStr%>);
Expand All @@ -2372,7 +2375,7 @@ case SES_MIXED(__) then
}
mixed_equation_system_end(<%numDiscVarsStr%>);
#ifdef _OMC_MEASURE_TIME
SIM_PROF_ACC_EQ(SIM_PROF_EQ_<%index%>);
SIM_PROF_ACC_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
#endif<%\n%>
>>
end equationMixed;
Expand All @@ -2389,8 +2392,8 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls /*BUF
let nonlinindx = indexNonLinear
<<
#ifdef _OMC_MEASURE_TIME
SIM_PROF_TICK_EQ(SIM_PROF_EQ_<%index%>);
SIM_PROF_ADD_NCALL_EQ(SIM_PROF_EQ_<%index%>,-1);
SIM_PROF_TICK_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
SIM_PROF_ADD_NCALL_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex,-1);
#endif<%\n%>
/* extrapolate data */
<%crefs |> name hasindex i0 =>
Expand All @@ -2408,7 +2411,7 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls /*BUF
<%eqncalls%>
<%otherinlines%>
#ifdef _OMC_MEASURE_TIME
SIM_PROF_ACC_EQ(SIM_PROF_EQ_<%index%>);
SIM_PROF_ACC_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
#endif<%\n%>
>>
end equationNonlinear;
Expand All @@ -2425,11 +2428,6 @@ template equationNamesExtraResidualsPreBodyInline(SimEqSystem eq, Context contex
end match
end equationNamesExtraResidualsPreBodyInline;

template reverseLookupEquationNumber(Integer index)
::=
'data->modelData.equationInfo[data->modelData.omc_equationInfo_reverse_prof_index[SIM_PROF_EQ_<%index%>]]'
end reverseLookupEquationNumber;

template equationWhen(SimEqSystem eq, Context context, Text &varDecls /*BUFP*/)
"Generates a when equation."
::=
Expand Down Expand Up @@ -2834,7 +2832,7 @@ template simulationInitFile(SimCode simCode, String guid)
::=
match simCode
case SIMCODE(modelInfo = MODELINFO(functions = functions, varInfo = vi as VARINFO(__), vars = vars as SIMVARS(__)),
simulationSettingsOpt = SOME(s as SIMULATION_SETTINGS(__)))
simulationSettingsOpt = SOME(s as SIMULATION_SETTINGS(__)), makefileParams = makefileParams as MAKEFILE_PARAMS(__))
then
<<
<?xml version = "1.0" encoding="UTF-8"?>
Expand All @@ -2846,6 +2844,8 @@ case SIMCODE(modelInfo = MODELINFO(functions = functions, varInfo = vi as VARINF
modelName = "<%dotPath(modelInfo.name)%>"
modelIdentifier = "<%underscorePath(modelInfo.name)%>"

OPENMODELICAHOME = "<%makefileParams.omhome%>"

guid = "{<%guid%>}"

generationTool = "OpenModelica Compiler <%getVersionNr()%>"
Expand Down

0 comments on commit 9b7d846

Please sign in to comment.