- Index
- » Programming
- » Modelica Language
- » OM compiler : generating a new xml file
OM compiler : generating a new xml file
OM compiler : generating a new xml file
Hi every one,
First, thank you for the attention and help you'll give to this post.
My problem is the following one :
How can modify the openModelica compiler to add a function that dumps
variables into an xml file in a certain way ?
I have already modified some source files of the OM compiler and
obtained an xml file, but i'm not
satisfied with the results (see further).
More precisely, i have a "a_model.mo" file that contains the definition
of a connector objet PwPin and a class "a_model". This class "a_model"
contains the declaration of a PwPin as well as declaration of parameters,
real variables, etc, used in the equation section of the model.
The purpose is to generate an xml file that gives, for each variable
or object, its structure :
- if it's a simple (or classic) variable, like paramater or real
variable, then it is pointed in the xml file as a "terminal" ;
- if it's a more complex instance, like a PwPin, then it is pointed
in the xml file as a "struct" and its components are displayed.
Here is an idea of the "a_model.mo" i've got and the xml file i want to
build :
// ----------------------------------------------
// a_model.mo
// ----------------------------------------------
...
connector PwPin
Real vr;
Real vi;
flow Real ir;
flow Real ii;
end PwPin;
...
class a_model
// Declaration of parameters, real variables (like var_1), ...
...
Real var_1;
...
// Declaration of a PwPin
PwPin var_2(vr(start=ur0),vi(start=ui0), ir(start=-ir0), ii(start=-ii0));
equation
...
end a_model;
// ----------------------------------------------
// The xml file
// ----------------------------------------------
<model>
<name>a_model</name>
<elements>
<terminal>
<name>var_1</name>
<id>var_1</id>
<flow value="false"/>
</terminal>
<struct>
<name>var_2</name>
<subnodes>
<terminal>
<name>vr</name>
<id>var_2.vr</id>
<flow value="false"/>
</terminal>
<terminal>
Same thing for var_2.vi, because it's a real var too.
</terminal>
<terminal>
<name>ir</name>
<id>var_2.ir</id>
<flow value="true"/>
</terminal>
<terminal>
Same thing for var_2.ii, because it's a flow too.
</terminal>
</subnodes>
</struct>
</elements>
</model>
Here i explain a try i gave to my problem, reading it is not absolutly
necessary.
To do this, i took a look in the source files of the OM compiler
(1.9.1.BETA.1) and tried the following (not satisfying) solution :
- I followed the example of function "dumpXMLDAE" in "CevalScript.mo",
to create a new "dumpXMLDAE_2" function in the same file (this
function no longer calls "XMLDump.dumpBackendDAE" but calls the
new XMLDumpDynamo.dumpBackendDAE2Dynamo).
- I built the OM compiler with the above modified source files and
obtained a new executable.
- I wrote a small *.mos script that calls this new "dumpXMLDAE_2"
function :
loadModel(Modelica);
loadFile("a_model.mo");
dumpXMLDAE_2(a_model,"flat",false,true,false,false,false,false,false,false,false,"flat-a_model");
- I run the *.mos with the new OM compiler executable.
Doing like this, il seems impossible to keep the components of a PwPin
(vr, vi, ir, ii) all together in the xml file, they are split
into 2 parts : vr and vi appear in the "ordered variables" of the xml
file, and ir and ii appear in the "known variables" part.
How can i do to avoid the splitting into "ordered variables"
and "known variables" ?
But mainly, how can i do to give my xml file the structure
displayed above ?
Re: OM compiler : generating a new xml file
You will need to do some processing of the DAE variables because they are already flattened (no structure present anymore) when they reach the XML dump.
You will need to merge the variables based on their types (if they have connector type) then you put them in the same struct in the XML file as you want.
It might not be easy if you're not familiar with the compiler code and structures but is possible to do.
Cheers,
Adrian Pop/
- adrpo
- 885 Posts
Re: OM compiler : generating a new xml file
The splitting into ordered and known variables is done by various optimizations in the backend. Pretty much all of them are essential for getting a working simulation. So you might want to dump an earlier stage in the compilation if you want to keep more structure as it used to be.
- sjoelund.se
- 1700 Posts
- Index
- » Programming
- » Modelica Language
- » OM compiler : generating a new xml file