Skip to content

Commit

Permalink
properly fix #4851 and #12055 (#12057)
Browse files Browse the repository at this point in the history
- forward the equation functions in the main file 16dae.c file from the part files.
  • Loading branch information
adrpo committed Mar 3, 2024
1 parent 2e82712 commit 23752f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions OMCompiler/Compiler/Template/CodegenC.tpl
Expand Up @@ -4473,6 +4473,7 @@ end functionXXX_systems;
template functionDAEModeEquationsMultiFiles(list<SimEqSystem> inEqs, Integer numEqs, Integer equationsPerFile, Context context, String fileNamePrefix, String fullPathPrefix, String modelNamePrefix, String funcName, String partName, Text &eqFuncs, Boolean static, Boolean noOpt, Boolean init)
::=
let &file = buffer ""
let &forwardEqs = buffer ""
let multiFile = if intGt(numEqs, equationsPerFile) then "x"
let fncalls = (List.balancedPartition(inEqs, equationsPerFile) |> eqs hasindex i0 =>
// To file
Expand All @@ -4485,7 +4486,8 @@ template functionDAEModeEquationsMultiFiles(list<SimEqSystem> inEqs, Integer num
extern "C" {
#endif<%\n%>
>>)) +
(eqs |> eq => equation_impl_options(-1, -1, eq, context, modelNamePrefix, static, noOpt, init); separator="\n") +
(eqs |> eq => (equation_impl_options(-1, -1, eq, context, modelNamePrefix, static, noOpt, init); separator="\n")
) +
<<
>>
+
Expand All @@ -4498,12 +4500,19 @@ template functionDAEModeEquationsMultiFiles(list<SimEqSystem> inEqs, Integer num
>> +
closeFile())))

let &forwardEqs +=
if multiFile then
("\n/* --- forward equations --- */\n" +
(eqs |> eq => equationForward_(eq, context, modelNamePrefix); separator="\n") +
"\n\n")

// fncalls
'<%(eqs |> eq => equationNames_(eq, context, modelNamePrefix); separator="\n")%>'

)

let &eqFuncs += file

let &eqFuncs += forwardEqs + file
fncalls
end functionDAEModeEquationsMultiFiles;

Expand Down
Expand Up @@ -7,14 +7,14 @@ loadFile("pg.mo");
getErrorString();

setCommandLineOptions("--daeMode");
translateModel(PowerGrids.Examples.IEEE14bus.IEEE14busGen2Disconnection); getErrorString();
system("ls *16dae_part*"); getErrorString();
buildModel(PowerGrids.Examples.IEEE14bus.IEEE14busGen2Disconnection); getErrorString();
system("ls *16dae_part*.c"); getErrorString();

// Result:
// true
// ""
// true
// true
// {"PowerGrids.Examples.IEEE14bus.IEEE14busGen2Disconnection","PowerGrids.Examples.IEEE14bus.IEEE14busGen2Disconnection_init.xml"}
// "Warning: The model contains alias variables with redundant start and/or conflicting nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: The hideResult annotation could not be evaluated, probably due to missing annotation(Evaluate=true). It is removed.
// "
Expand Down

0 comments on commit 23752f8

Please sign in to comment.