Skip to content

Commit 14067e6

Browse files
committed
- dump a short comment above all equations (containing the modelica representation)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16192 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d7ab0c4 commit 14067e6

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

Compiler/Template/CodegenC.tpl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,112 @@ template equationIndex(SimEqSystem eq)
22692269
then index
22702270
end equationIndex;
22712271

2272+
template dumpEqs(list<SimEqSystem> eqs)
2273+
::= eqs |> eq hasindex i0 =>
2274+
match eq
2275+
case e as SES_RESIDUAL(__) then
2276+
<<
2277+
equation index: <%equationIndex(eq)%>
2278+
type: RESIDUAL
2279+
2280+
<%System.stringReplace(System.stringReplace(printExpStr(e.exp), "/*", "(*"), "*/", "*)")%>
2281+
>>
2282+
case e as SES_SIMPLE_ASSIGN(__) then
2283+
<<
2284+
equation index: <%equationIndex(eq)%>
2285+
type: SIMPLE_ASSIGN
2286+
2287+
<%crefStr(e.cref)%> = <%System.stringReplace(System.stringReplace(printExpStr(e.exp), "/*", "(*"), "*/", "*)")%>
2288+
>>
2289+
case e as SES_ARRAY_CALL_ASSIGN(__) then
2290+
<<
2291+
equation index: <%equationIndex(eq)%>
2292+
type: ARRAY_CALL_ASSIGN
2293+
2294+
<%crefStr(e.componentRef)%> = <%System.stringReplace(System.stringReplace(printExpStr(e.exp), "/*", "(*"), "*/", "*)")%>
2295+
>>
2296+
case e as SES_ALGORITHM(statements={}) then
2297+
<<
2298+
empty algorithm
2299+
>>
2300+
case e as SES_ALGORITHM(statements=first::_) then
2301+
<<
2302+
equation index: <%equationIndex(eq)%>
2303+
type: ALGORITHM
2304+
2305+
<%e.statements |> stmt => System.stringReplace(System.stringReplace(ppStmtStr(stmt,2), "/*", "(*"), "*/", "*)")%>
2306+
>>
2307+
case e as SES_LINEAR(__) then
2308+
<<
2309+
equation index: <%equationIndex(eq)%>
2310+
type: LINEAR
2311+
2312+
<%e.vars |> SIMVAR(name=cr) => '<var><%crefStr(cr)%></var>' ; separator = "\n" %>
2313+
<row>
2314+
<%beqs |> exp => '<cell><%System.stringReplace(System.stringReplace(printExpStr(exp), "/*", "(*"), "*/", "*)")%></cell>' ; separator = "\n" %><%\n%>
2315+
</row>
2316+
<matrix>
2317+
<%simJac |> (i1,i2,eq) =>
2318+
<<
2319+
<cell row="<%i1%>" col="<%i2%>">
2320+
<%match eq case e as SES_RESIDUAL(__) then
2321+
<<
2322+
<residual><%System.stringReplace(System.stringReplace(printExpStr(e.exp), "/*", "(*"), "*/", "*)")%></residual>
2323+
>>
2324+
%>
2325+
</cell>
2326+
>>
2327+
%>
2328+
</matrix>
2329+
>>
2330+
case e as SES_NONLINEAR(__) then
2331+
<<
2332+
equation index: <%equationIndex(eq)%>
2333+
indexNonlinear: <%indexNonLinearSystem%>
2334+
type: NONLINEAR
2335+
2336+
vars: {<%e.crefs |> cr => '<%crefStr(cr)%>' ; separator = ", "%>}
2337+
eqns: {<%e.eqs |> eq => '<%equationIndex(eq)%>' ; separator = ", "%>}
2338+
>>
2339+
case e as SES_MIXED(__) then
2340+
<<
2341+
equation index: <%equationIndex(eq)%>
2342+
type: MIXED
2343+
2344+
<%dumpEqs(fill(e.cont,1))%>
2345+
<%dumpEqs(e.discEqs)%><%\n%>
2346+
2347+
<mixed>
2348+
<continuous index="<%equationIndex(e.cont)%>" />
2349+
<%e.discVars |> SIMVAR(name=cr) => '<var><%crefStr(cr)%></var>' ; separator = ","%>
2350+
<%e.discEqs |> eq => '<discrete index="<%equationIndex(eq)%>" />'%>
2351+
</mixed>
2352+
>>
2353+
case e as SES_WHEN(__) then
2354+
<<
2355+
equation index: <%equationIndex(eq)%>
2356+
type: WHEN
2357+
2358+
when {<%conditions |> cond => '<%crefStr(cond)%>' ; separator=", " %>} then
2359+
<%crefStr(e.left)%> = <%System.stringReplace(System.stringReplace(printExpStr(e.right), "/*", "(*"), "*/", "*)")%>;
2360+
end when;
2361+
>>
2362+
case e as SES_IFEQUATION(__) then
2363+
let branches = ifbranches |> (_,eqs) => dumpEqs(eqs)
2364+
let elsebr = dumpEqs(elsebranch)
2365+
<<
2366+
equation index: <%equationIndex(eq)%>
2367+
type: IFEQUATION
2368+
2369+
<%branches%>
2370+
<%elsebr%>
2371+
>>
2372+
else
2373+
<<
2374+
unknown equation
2375+
>>
2376+
end dumpEqs;
2377+
22722378
template equation_(SimEqSystem eq, Context context, Text &varDecls /*BUFP*/, Text &eqs)
22732379
"Generates an equation.
22742380
This template should not be used for a SES_RESIDUAL.
@@ -2314,6 +2420,9 @@ template equation_(SimEqSystem eq, Context context, Text &varDecls /*BUFP*/, Tex
23142420
<<
23152421

23162422
<%tempeqns%>
2423+
/*
2424+
<%dumpEqs(fill(eq,1))%>
2425+
*/
23172426
static void eqFunction_<%ix%>(DATA *data)
23182427
{
23192428
<%&varD%>

0 commit comments

Comments
 (0)