Opened 9 years ago

Last modified 8 years ago

#3857 accepted defect

Error in Generated XML from Modelica

Reported by: karan.singh@… Owned by: Adrian Pop
Priority: critical Milestone: Future
Component: Code Generation Version:
Keywords: xml, modelica Cc:

Description

Hi there,

I am using the XML file generated by Modelica for modeling. I am getting the following error in the format each time-

In bouncing ball, line 162 of generated xml file, <eq: Equation> is generated within the <when>, whereas it should be <equ: Equation> as per the schema.

Please let me know how/ when this can be resolved. I have attached the modelica model and the generated xml file.

Attachments (4)

BouncingBall.mo (396 bytes ) - added by anonymous 9 years ago.
Modelica.Fluid.Examples.PumpingSystem.xml (3.8 MB ) - added by anonymous 8 years ago.
PumpingSystem.mo (7.4 KB ) - added by anonymous 8 years ago.
Modelica.Fluid.Examples.PumpingSystem.2.xml (3.8 MB ) - added by anonymous 8 years ago.

Change History (37)

by anonymous, 9 years ago

Attachment: BouncingBall.mo added

comment:1 by karan.singh@…, 9 years ago

<equ:When> instead of <when> above

comment:2 by Adrian Pop, 9 years ago

Owner: changed from Lennart Ochel to Adrian Pop
Status: newaccepted

comment:3 by Adrian Pop, 9 years ago

This is about to be fixed with PR:
https://github.com/OpenModelica/OMCompiler/pull/816/

comment:4 by karan.singh@…, 9 years ago

Also the following errors in the same model-

1.<fun:Algorithm> (Line 187)

</fun:Algorithm>

tags are generated but are not supported by JModelica schema

  1. <fun:FunctionList> (Line 193) </fun:FunctionList>

tags are misspelled. Should in fact be

<fun:Function'''s'''List>
</fun:Function'''s'''List>

in reply to:  4 ; comment:5 by Adrian Pop, 9 years ago

Replying to karan.singh@…:

Also the following errors in the same model-

1.<fun:Algorithm> (Line 187)

</fun:Algorithm>

tags are generated but are not supported by JModelica schema

  1. <fun:FunctionList> (Line 193) </fun:FunctionList>

tags are misspelled. Should in fact be

<fun:Function'''s'''List>
</fun:Function'''s'''List>

What should I do for 1.? I will fix 2. when the PR finishes to run.

in reply to:  5 comment:6 by Adrian Pop, 9 years ago

Replying to adrpo:

Replying to karan.singh@…:

Also the following errors in the same model-

1.<fun:Algorithm> (Line 187)

</fun:Algorithm>

tags are generated but are not supported by JModelica schema

  1. <fun:FunctionList> (Line 193) </fun:FunctionList>

tags are misspelled. Should in fact be

<fun:Function'''s'''List>
</fun:Function'''s'''List>

What should I do for 1.? I will fix 2. when the PR finishes to run.

Ok, I amended the commit in the previous PR:
https://github.com/OpenModelica/OMCompiler/pull/816/
to fix the change from fun:FunctionList to fun:FunctionsList.

I'm not sure how to fix the fun:Algorithm issue. If you have any suggestions, please let me know.

comment:7 by karan.singh@…, 9 years ago

Is there any way you could fix the Schema? Also, while we are on the topic, the schema also lacks any information about IfEquation- an example model for it:

model NewtonCoolingDynamic "Cooling example with fluctuating ambient conditions"
  // Types
  type Temperature = Real(unit = "K", min = 0);
  type ConvectionCoefficient = Real(unit = "W/(m2.K)", min = 0);
  type Area = Real(unit = "m2", min = 0);
  type Mass = Real(unit = "kg", min = 0);
  type SpecificHeat = Real(unit = "J/(K.kg)", min = 0);
  // Parameters
  parameter Temperature T0 = 363.15 "Initial temperature";
  parameter ConvectionCoefficient h = 0.7 "Convective cooling coefficient";
  parameter Area A = 1.0 "Surface area";
  parameter Mass m = 0.1 "Mass of thermal capacitance";
  parameter SpecificHeat c_p = 1.2 "Specific heat";
  // Variables
  Temperature T_inf "Ambient temperature";
  Temperature T "Temperature";
initial equation
  T = T0 "Specify initial value for T";
equation
  if time <= 0.5 then
    T_inf = 298.15 "Constant temperature when time<=0.5";
  else
    T_inf = 298.15 - 20 * (time - 0.5) "Otherwise, increasing";
  end if;
  m * c_p * der(T) = h * A * (T_inf - T) "Newton's law of cooling";
end NewtonCoolingDynamic;
Last edited 9 years ago by Adrian Pop (previous) (diff)

comment:8 by Adrian Pop, 9 years ago

I cannot fix the schema as that was developed by the JModelica people.
Maybe you can open a ticket about that here:
http://trac.jmodelica.org/timeline
and when they change it, we can use the changes.

comment:9 by Adrian Pop, 9 years ago

I fixed the things I could fix in this commit: d0a958/OMCompiler.
I'll leave this ticket opened so we can fix the remaining issues when the schema will be updated.

comment:10 by Adrian Pop, 9 years ago

Added a test for the things I fixed in 0cd621/OpenModelica-testsuite.

comment:11 by karan.singh@…, 9 years ago

Hi There,

I would also like to report the following bugs-

  1. No escape sequences in the attribute values of the type “string”

Example model: Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum
Exported by OMC: <String start=""cylinder"" fixed="true"/>
JModelica XSD definition: <String start="&quot;cylinder&quot;" fixed="true"/>
Example model: Modelica.Blocks.Examples.PID_Controller
Exported by OMC: <exp:StringLiteral>") < yMin (="</exp:StringLiteral>
JModelica XSD definition: <exp:StringLiteral>") &lt; yMin (="</exp:StringLiteral>

  1. OpenModelicaModelDescription variableNamingConvention attribute value deviates from the XML schema definition

Example model: Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum
Exported by OMC: <OpenModelicaModelDescription variableNamingConvention="Structured">
JModelica XSD definition: <OpenModelicaModelDescription variableNamingConvention="structured">

  1. XML tag deviates from the XML schema definition

Example model:

model VanDerPol "Van der Pol oscillator model"
  // Van der Pol model
  Real x(start = 1);
  Real y(start = 1);
  parameter Real lambda = 0.3;
equation
  der(x) = y;
  der(y) = (-x) + lambda * (1 - x * x) * y;
end VanDerPol;

Exported by OMC: <defaultExperiment startTime="0.0" stopTime="1.0" tolerance="1e-006"/>
JModelica XSD definition: <DefaultExperiment startTime="0.0" stopTime="1.0" tolerance="1e-006"/>

  1. XML tag deviates from the XML schema definition

Example model: Modelica.Blocks.Examples.PID_Controller
Exported by OMC: <exp:Builtin Function is not yet implemented >
JModelica XSD definition: no definition

  1. XML tag deviates from the XML schema definition

Example model: Modelica.Blocks.Examples.PID_Controller
Exported by OMC: <Real start="*ERROR* initial value of unknown type" fixed="false" />
JModelica XSD definition: <Real start="0.0" fixed="false" />

  1. XML tag deviates from the XML schema definition

Example model: Modelica.Blocks.Examples.PID_Controller
Exported by OMC: <Real start="4/*ENUM:StateSelect.prefer*/" fixed="true"/>
JModelica XSD definition: <Real start="4" fixed="true"/>

  1. equ:InitialEquations are not exported for the Modelica initial equation

Example model:

model BouncingBall "The 'classic' bouncing ball model"
  type Height=Real(unit="m");
  type Velocity=Real(unit="m/s");
  parameter Real e=0.8 "Coefficient of restitution";
  parameter Height h0=1.0 "Initial height";
  Height h;
  Velocity v;
initial equation
  h = h0;
equation
  v = der(h);
  der(v) = -9.81;
  when h<0 then
    reinit(v, -e*pre(v));
  end when;
end BouncingBall;

Exported by OMC:

<equ:InitialEquations>
</equ:InitialEquations>

Thanks again for your help :)

Last edited 9 years ago by Adrian Pop (previous) (diff)

comment:12 by Adrian Pop, 9 years ago

I don't get number 3.) above, they seem to be exactly the same!

in reply to:  12 comment:13 by anonymous, 9 years ago

Replying to adrpo:

I don't get number 3.) above, they seem to be exactly the same!

Sorry about that, the correct one should be DefaultExperiment.

comment:14 by karan.singh@…, 9 years ago

I would like to report another bug-

In generated XML(given below) for the below Model. The tag
<fun:OutputVariable type="real"> each time does not follow the schema and should instead be
<fun:OutputVariable type="'Real">

<fun:FunctionList>
    <fun:Function>
      <fun:Name>
        <exp:QualifiedNamePart name="computeHeat"/>
      </fun:Name>
      <fun:OutputVariable type="real">
        <fun:Name>
          <exp:QualifiedNamePart name="heat"/>
        </fun:Name>
      </fun:OutputVariable>
      <fun:InputVariable type="real">
        <fun:Name>
          <exp:QualifiedNamePart name="T"/>
        </fun:Name>
      </fun:InputVariable>
      <fun:InputVariable type="real">
        <fun:Name>
          <exp:QualifiedNamePart name="Tbar"/>
        </fun:Name>
      </fun:InputVariable>
      <fun:InputVariable type="real">
        <fun:Name>
          <exp:QualifiedNamePart name="Q"/>
        </fun:Name>
      </fun:InputVariable>
      <fun:Algorithm>
        <fun:Assign>
          <exp:Identifier>
            <exp:QualifiedNamePart name="heat"/>
          </exp:Identifier> 
          <exp:Expression>
            <exp:FunctionCall>
              <exp:Name>
                <exp:QualifiedNamePart name="computeHeat" />
              </exp:Name>
              <exp:Arguments>
                <exp:Identifier>
                  <exp:QualifiedNamePart name="T"/>
                </exp:Identifier>
                 <exp:Identifier>
                  <exp:QualifiedNamePart name="Tbar"/>
                </exp:Identifier>
                 <exp:Identifier>
                  <exp:QualifiedNamePart name="Q"/>
                </exp:Identifier>
              </exp:Arguments>
            </exp:FunctionCall>
          </exp:Expression>
        </fun:Assign>
      </fun:Algorithm>
    </fun:Function> 
  </fun:FunctionList>

model HysteresisEmbeddedControlNoWhen "A control strategy that uses embedded C code"
  type HeatCapacitance = Real(unit = "J/K");
  type Temperature = Real(unit = "K");
  type Heat = Real(unit = "W");
  type Mass = Real(unit = "kg");
  type HeatTransferCoefficient = Real(unit = "W/K");
  parameter HeatCapacitance C = 1.0;
  parameter HeatTransferCoefficient h = 2.0;
  parameter Heat Qcapacity = 25.0;
  parameter Temperature Tamb = 285;
  parameter Temperature Tbar = 295;
  Temperature T (start = 390);
  Heat Q;
equation
  Q = computeHeat(T, Tbar, Qcapacity);
  C * der(T) = Q - h * (T - Tamb);
end HysteresisEmbeddedControlNoWhen;

with Funtion

function computeHeat "Modelica wrapper for an embedded C controller"
  input Real T;
  input Real Tbar;
  input Real Q;
  output Real heat;

  external "C"  annotation(Include = "#include \"ComputeHeat.c\"");
end computeHeat;

and C Code-

#ifndef _COMPUTE_HEAT_C_
#define _COMPUTE_HEAT_C_

#define UNINITIALIZED -1
#define ON 1
#define OFF 0

double
computeHeat(double T, double Tbar, double Q) {
  static int state = UNINITIALIZED;
  if (state == UNINITIALIZED) {
    if (T>Tbar) state = OFF;
    else state = ON;
  }
  if (state == OFF && T<Tbar - 2) state = ON;
  if (state == ON && T>Tbar + 2) state = OFF;

  if (state == ON) return Q;
  else return 0;
}

#endif
Last edited 9 years ago by Adrian Pop (previous) (diff)

comment:15 by Adrian Pop, 9 years ago

I fixed all these things in 17c031/OMCompiler and added tests in ac9052/OpenModelica-testsuite.

in reply to:  15 comment:16 by karan.singh@…, 9 years ago

Replying to adrpo:

I fixed all these things in 17c031/OMCompiler and added tests in ac9052/OpenModelica-testsuite.

Thanks a ton! So will I have to recompile? When is the next release coming out?

comment:17 by Adrian Pop, 9 years ago

Or you can use the next nightly builds from here (take the build from tomorrow):
https://build.openmodelica.org/omc/builds/windows/nightly-builds/

comment:18 by karan.singh@…, 9 years ago

Hi there,

Some more bugs coming your way- (these are rather major)

For the original Modelica Model-

model NewtonCoolingDynamic "Cooling example with fluctuating ambient conditions"
  // Types
  type Temperature = Real(unit = "K", min = 0);
  type ConvectionCoefficient = Real(unit = "W/(m2.K)", min = 0);
  type Area = Real(unit = "m2", min = 0);
  type Mass = Real(unit = "kg", min = 0);
  type SpecificHeat = Real(unit = "J/(K.kg)", min = 0);
  // Parameters
  parameter Temperature T0 = 363.15 "Initial temperature";
  parameter ConvectionCoefficient h = 0.7 "Convective cooling coefficient";
  parameter Area A = 1.0 "Surface area";
  parameter Mass m = 0.1 "Mass of thermal capacitance";
  parameter SpecificHeat c_p = 1.2 "Specific heat";
  // Variables
  Temperature T_inf "Ambient temperature";
  Temperature T "Temperature";
initial equation
  T = T0 "Specify initial value for T";
equation
  if time <= 0.5 then
    T_inf = 298.15 "Constant temperature when time<=0.5";
  else
    T_inf = 298.15 - 20 * (time - 0.5) "Otherwise, increasing";
  end if;
  m * c_p * der(T) = h * A * (T_inf - T) "Newton's law of cooling";
end NewtonCoolingDynamic;

if-equation does not make sense, because <exp:Sub> is a binary operations and cannot have more than two operands. Here we have 4
<exp:Identifier>, <exp:LogLeq>, <fun:If>, and <fun:Else>.
In generated XML-

    <equ:Equation>
      <exp:Sub>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T_inf"/>
        </exp:Identifier>
        <exp:LogLeq>
          <exp:Time>time</exp:Time>
          <exp:RealLiteral>0.5</exp:RealLiteral>
        </exp:LogLeq> 
        <fun:If>
          <fun:Condition>
            tmp0
           </fun:Condition>
           <fun:Statements>
             <exp:RealLiteral>298.15</exp:RealLiteral>
           </fun:Statements>
        </fun:If>
        <fun:Else>
          <exp:Add>
            <exp:RealLiteral>298.15</exp:RealLiteral>
            <exp:Mul>
              <exp:RealLiteral>-20.0</exp:RealLiteral>
              <exp:Add>
                <exp:RealLiteral>-0.5</exp:RealLiteral>
                <exp:Time>time</exp:Time>
              </exp:Add>
            </exp:Mul>
          </exp:Add>
        </fun:Else>
      </exp:Sub>
    </equ:Equation>

Also <fun:Else> does not comply with the operand type for a binary operation that can be only an expression (<exp:---->)

comment:19 by Adrian Pop, 9 years ago

I also fixed this in my latest commits as <fun:Else> should be part of <fun:If> and got rid of "tmpNN" which are not defined anywhere.

comment:20 by Adrian Pop, 9 years ago

This is what you get with the latest omc:

    <equ:Equation>
      <exp:Sub>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T_inf"/>
        </exp:Identifier>
        <fun:If>
          <fun:Condition>
            <exp:LogLeq>
              <exp:Time>time</exp:Time>
              <exp:RealLiteral>0.5</exp:RealLiteral>
            </exp:LogLeq> 
          </fun:Condition>
          <fun:Statements>
            <exp:RealLiteral>298.15</exp:RealLiteral>
          </fun:Statements>
          <fun:Else>
            <exp:Add>
              <exp:RealLiteral>298.15</exp:RealLiteral>
              <exp:Mul>
                <exp:RealLiteral>-20.0</exp:RealLiteral>
                <exp:Add>
                  <exp:RealLiteral>-0.5</exp:RealLiteral>
                  <exp:Time>time</exp:Time>
                </exp:Add>
              </exp:Mul>
            </exp:Add>
          </fun:Else>
        </fun:If>
      </exp:Sub>
    </equ:Equation>  

comment:21 by karan.singh@…, 9 years ago

I downloaded the latest nightly build yesterday and it seems to be broken. The Model doesn't simulate when I hit the simulate button (Nothing happens) and the same goes for Export -> ExportXML

comment:22 by Adrian Pop, 9 years ago

Hm, I just installed the latest 64 bit build:
https://build.openmodelica.org/omc/builds/windows/nightly-builds/64bit/
and everything is working fine.

Did you uninstall the old OpenModelica?
Do you have OMDev installed?
Did you logout or restart after install (should not be needed but sometimes it helps)?

in reply to:  22 comment:23 by anonymous, 9 years ago

Got it to work, thanks!
Replying to adrpo:

Hm, I just installed the latest 64 bit build:
https://build.openmodelica.org/omc/builds/windows/nightly-builds/64bit/
and everything is working fine.

Did you uninstall the old OpenModelica?
Do you have OMDev installed?
Did you logout or restart after install (should not be needed but sometimes it helps)?

comment:24 by karan.singh@…, 9 years ago

Hi there,

Initial Equations are now being exported however, they have way too many equations in the Exported XML now. For the below code-

model NewtonCoolingDynamic "Cooling example with fluctuating ambient conditions"
  // Types
  type Temperature = Real(unit = "K", min = 0);
  type ConvectionCoefficient = Real(unit = "W/(m2.K)", min = 0);
  type Area = Real(unit = "m2", min = 0);
  type Mass = Real(unit = "kg", min = 0);
  type SpecificHeat = Real(unit = "J/(K.kg)", min = 0);
  // Parameters
  parameter Temperature T0 = 363.15 "Initial temperature";
  parameter ConvectionCoefficient h = 0.7 "Convective cooling coefficient";
  parameter Area A = 1.0 "Surface area";
  parameter Mass m = 0.1 "Mass of thermal capacitance";
  parameter SpecificHeat c_p = 1.2 "Specific heat";
  // Variables
  Temperature T_inf "Ambient temperature";
  Temperature T "Temperature";
initial equation
  T = T0 "Specify initial value for T";
equation
  if time <= 0.5 then
    T_inf = 298.15 "Constant temperature when time<=0.5";
  else
    T_inf = 298.15 - 20 * (time - 0.5) "Otherwise, increasing";
  end if;
  m * c_p * der(T) = h * A * (T_inf - T) "Newton's law of cooling";
end NewtonCoolingDynamic;

we get the following XML that should only have 1 initial equation in it. But has 4 instead.

<equ:InitialEquations>
    <equ:Equation>
      <exp:Sub>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T_inf"/>
        </exp:Identifier>
        <exp:RealLiteral>298.15</exp:RealLiteral>
      </exp:Sub>
    </equ:Equation>
    <equ:Equation>
      <exp:Sub>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T_inf"/>
        </exp:Identifier>
        <fun:If>
          <fun:Condition>
            <exp:LogLeq>
              <exp:Time>time</exp:Time>
              <exp:RealLiteral>0.5</exp:RealLiteral>
            </exp:LogLeq> 
          </fun:Condition>
          <fun:Statements>
            <exp:RealLiteral>298.15</exp:RealLiteral>
          </fun:Statements>
          <fun:Else>
            <exp:Add>
              <exp:RealLiteral>298.15</exp:RealLiteral>
              <exp:Mul>
                <exp:RealLiteral>-20.0</exp:RealLiteral>
                <exp:Add>
                  <exp:RealLiteral>-0.5</exp:RealLiteral>
                  <exp:Time>time</exp:Time>
                </exp:Add>
              </exp:Mul>
            </exp:Add>
          </fun:Else>
        </fun:If>
      </exp:Sub>
    </equ:Equation>  
    <equ:Equation>
      <exp:Sub>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T"/>
        </exp:Identifier>
        <exp:Identifier>
          <exp:QualifiedNamePart name="T0"/>
        </exp:Identifier>
      </exp:Sub>
    </equ:Equation>  
    <equ:Equation>
      <exp:Sub>
        <exp:Der>
          <exp:Identifier>
            <exp:QualifiedNamePart name="T"/>
          </exp:Identifier>
        </exp:Der>
        <exp:Div>
          <exp:Mul>
            <exp:Identifier>
              <exp:QualifiedNamePart name="h"/>
            </exp:Identifier>
            <exp:Mul>
              <exp:Identifier>
                <exp:QualifiedNamePart name="A"/>
              </exp:Identifier>
              <exp:Sub>
                <exp:Identifier>
                  <exp:QualifiedNamePart name="T_inf"/>
                </exp:Identifier>
                <exp:Identifier>
                  <exp:QualifiedNamePart name="T"/>
                </exp:Identifier>
              </exp:Sub>
            </exp:Mul>
          </exp:Mul>
          <exp:Mul>
            <exp:Identifier>
              <exp:QualifiedNamePart name="m"/>
            </exp:Identifier>
            <exp:Identifier>
              <exp:QualifiedNamePart name="c_p"/>
            </exp:Identifier>
          </exp:Mul>
        </exp:Div>
      </exp:Sub>
    </equ:Equation>  
  </equ:InitialEquations>

comment:25 by Adrian Pop, 9 years ago

That's correct, the initial system of equations has 4 equations. We don't generate the XML for the DAE but we generate the XML for the final systems: one for the dynamic part and one for the initialization part. That's what you get in the generated code too.

comment:26 by Vitalij Ruge, 9 years ago

It would seem that

T_inf = 298.15; // ??
T_inf = if time <= 0.5 then 298.15 else 298.15 - 20 * (time - 0.5);

is redundant in the XML. (interduce 3x4 nonlinear equationsystem ???)

comment:27 by karan.singh@…, 9 years ago

Hi there,

I understand that this might be beyond the scope of what you help with but I was wondering if you were aware of the command line options to include Packages? For example for the given model (from Modelica examples)-

within Modelica.Electrical.Analog.Examples;
encapsulated model ChuaCircuit "Chua's circuit, ns, V, A"
  import Modelica.Electrical.Analog.Basic;
  import Modelica.Electrical.Analog.Examples.Utilities;
  import Modelica.Icons;
  extends Icons.Example;

  Basic.Inductor L(L=18, i(start=0, fixed=true)) annotation (Placement(transformation(
        origin={-75,38},
        extent={{-25,-25},{25,25}},
        rotation=270)));
  Basic.Resistor Ro(R=12.5e-3) annotation (Placement(transformation(
        origin={-75,-17},
        extent={{-25,-25},{25,25}},
        rotation=270)));
  Basic.Conductor G(G=0.565) annotation (Placement(transformation(extent={{-25,38},
            {25,88}})));
  Basic.Capacitor C1(C=10, v(start=4, fixed=true))                          annotation (Placement(transformation(
        origin={25,3},
        extent={{-25,-25},{25,25}},
        rotation=270)));
  Basic.Capacitor C2(C=100, v(start=0, fixed=true)) annotation (Placement(transformation(
        origin={-25,3},
        extent={{-25,-25},{25,25}},
        rotation=270)));
  Utilities.NonlinearResistor Nr(
    Ga(min=-1) = -0.757576,
    Gb(min=-1) = -0.409091,
    Ve=1) annotation (Placement(transformation(
        origin={75,3},
        extent={{-25,-25},{25,25}},
        rotation=270)));
  Basic.Ground Gnd annotation (Placement(transformation(extent={{-25,-112},{25,
            -62}})));
equation
  connect(L.n, Ro.p) annotation (Line(points={{-75,13},{-75,8}}));
  connect(C2.p, G.p) annotation (Line(
      points={{-25,28},{-25,45.5},{-25,45.5},{-25,63}},
      color={0,0,255}));
  connect(L.p, G.p) annotation (Line(
      points={{-75,63},{-25,63}},
      color={0,0,255}));
  connect(G.n, Nr.p) annotation (Line(
      points={{25,63},{75,63},{75,28}},
      color={0,0,255}));
  connect(C1.p, G.n) annotation (Line(
      points={{25,28},{25,45.5},{25,45.5},{25,63}},
      color={0,0,255}));
  connect(Ro.n, Gnd.p) annotation (Line(
      points={{-75,-42},{-75,-62},{0,-62}},
      color={0,0,255}));
  connect(C2.n, Gnd.p) annotation (Line(
      points={{-25,-22},{-24,-22},{-24,-62},{0,-62}},
      color={0,0,255}));
  connect(Gnd.p, C1.n) annotation (Line(
      points={{0,-62},{25,-62},{25,-22}},
      color={0,0,255}));
  connect(Gnd.p, Nr.n) annotation (Line(
      points={{0,-62},{75,-62},{75,-22}},
      color={0,0,255}));
  annotation (
    Documentation(info="<html>
<p>Chua&#39;;s circuit is the most simple nonlinear circuit which shows chaotic behaviour. The circuit consists of linear basic elements (capacitors, resistor, conductor, inductor), and one nonlinear element, which is called Chua&#39;;s diode. The chaotic behaviour is simulated.</p>
<p>The simulation end time should be set to 5e4. To get the chaotic behaviour please plot C1.v. Choose C2.v as the independent variable .</p>
<p><b>Reference:</b></p>
<p>Kennedy, M.P.: Three Steps to Chaos - Part I: Evolution. IEEE Transactions on CAS I 40 (1993)10, 640-656</p>
</html>",
   revisions="<html>
<dl>
<dt>
<b>Main Authors:</b>
</dt>
<dd>
Christoph Clau&szlig;
    &lt;<a href=\"mailto:Christoph.Clauss@eas.iis.fraunhofer.de\">Christoph.Clauss@eas.iis.fraunhofer.de</a>&gt;<br>
    Andr&eacute; Schneider
    &lt;<a href=\"mailto:Andre.Schneider@eas.iis.fraunhofer.de\">Andre.Schneider@eas.iis.fraunhofer.de</a>&gt;<br>
    Fraunhofer Institute for Integrated Circuits<br>
    Design Automation Department<br>
    Zeunerstra&szlig;e 38<br>
    D-01069 Dresden<br>
</dd>
</dl>
</html>"),
    experiment(StopTime=5e4, Interval=1),
    Diagram(coordinateSystem(preserveAspectRatio=true,  extent={{-100,-100},{
            100,100}}), graphics={Text(
          extent={{-98,104},{-32,72}},
          lineColor={0,0,255},
          textString="Chua Circuit")}));
end ChuaCircuit;

How would I compile this in the command line?

Thanks a ton!

in reply to:  27 ; comment:28 by Adrian Pop, 9 years ago

I don't quite get what you mean. Include packages where?
If you mean that you want to build an XML from the command line you do it via a script, say translateToXML.mos:

// translateToXML.mos
// set the command line options:
setCommandLineOptions("+simCodeTarget=XML");
// load the library you want
loadModel(Modelica); getErrorString();
// loadFile or loadModel additional files or libraries if needed
// build the model in XML form:
translateModel(Modelica.Electrical.Analog.Examples.ChuaCircuit);

Then call omc from command line (for example cmd in Windows):

> %OPENMODELICAHOME%\bin\omc translate.mos

And you will get a file called Modelica.Electrical.Analog.Examples.ChuaCircuit.xml in your working directory.

in reply to:  28 comment:29 by karan.singh@…, 9 years ago

That's very helpful! I guess I meant how to include the additional files and libraries

Thank you

Replying to adrpo:

I don't quite get what you mean. Include packages where?
If you mean that you want to build an XML from the command line you do it via a script, say translateToXML.mos:

// translateToXML.mos
// set the command line options:
setCommandLineOptions("+simCodeTarget=XML");
// load the library you want
loadModel(Modelica); getErrorString();
// loadFile or loadModel additional files or libraries if needed
// build the model in XML form:
translateModel(Modelica.Electrical.Analog.Examples.ChuaCircuit);

Then call omc from command line (for example cmd in Windows):

> %OPENMODELICAHOME%\bin\omc translate.mos

And you will get a file called Modelica.Electrical.Analog.Examples.ChuaCircuit.xml in your working directory.

comment:30 by Adrian Pop, 9 years ago

You just load the libraries via loadModel(Library); or if there are files via loadFile("Model.mo");. You can also use loadFile("path/to/Library/package.mo"); to load libraries that are someplace else than OPENMODELICALIBRARY directory.

Last edited 9 years ago by Adrian Pop (previous) (diff)

comment:31 by karan.singh@…, 9 years ago

Gotcha, thanks for that. Please take a look at the following bug-

For the above Model (Modelica.Electrical.Analog.Examples.ChuaCircuit). The exported XML has the following-

25: <ScalarVariable name="C1.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="0" variability="continuous" causality="internal" alias="noAlias">  
37: <ScalarVariable name="C2.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="1" variability="continuous" causality="internal" alias="noAlias">  
49: <ScalarVariable name="L.i" description="Current flowing from pin p to pin n" valueReference="2" variability="continuous" causality="internal" alias="noAlias">  
60: <ScalarVariable name="der(C1.v)" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="3" variability="continuous" causality="internal" alias="noAlias">  
72: <ScalarVariable name="der(C2.v)" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="4" variability="continuous" causality="internal" alias="noAlias">  
84: <ScalarVariable name="der(L.i)" description="Current flowing from pin p to pin n" valueReference="5" variability="continuous" causality="internal" alias="noAlias">  
95: <ScalarVariable name="C1.i" description="Current flowing from pin p to pin n" valueReference="6" variability="continuous" causality="internal" alias="noAlias">  
107: <ScalarVariable name="C2.i" description="Current flowing from pin p to pin n" valueReference="7" variability="continuous" causality="internal" alias="noAlias">  
119: <ScalarVariable name="G.G_actual" description="Actual conductance = G_ref/(1 + alpha*(T_heatPort - T_ref))" valueReference="8" variability="continuous" causality="internal" alias="noAlias">  
131: <ScalarVariable name="G.LossPower" description="Loss power leaving component via heatPort" valueReference="9" variability="continuous" causality="internal" alias="noAlias">  
143: <ScalarVariable name="G.i" description="Current flowing from pin p to pin n" valueReference="10" variability="continuous" causality="internal" alias="noAlias">  
155: <ScalarVariable name="G.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="11" variability="continuous" causality="internal" alias="noAlias">  
167: <ScalarVariable name="Gnd.p.i" description="Current flowing into the pin" valueReference="12" variability="continuous" causality="internal" alias="noAlias">  
180: <ScalarVariable name="Gnd.p.v" description="Potential at the pin" valueReference="13" variability="continuous" causality="internal" alias="noAlias">  
193: <ScalarVariable name="L.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="14" variability="continuous" causality="internal" alias="noAlias">  
205: <ScalarVariable name="Nr.i" description="Current flowing from pin p to pin n" valueReference="15" variability="continuous" causality="internal" alias="noAlias">  
217: <ScalarVariable name="Ro.LossPower" description="Loss power leaving component via heatPort" valueReference="16" variability="continuous" causality="internal" alias="noAlias">  
229: <ScalarVariable name="Ro.R_actual" description="Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))" valueReference="17" variability="continuous" causality="internal" alias="noAlias">  
241: <ScalarVariable name="Ro.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="18" variability="continuous" causality="internal" alias="noAlias">  
252: <ScalarVariable name="C1.n.i" description="Current flowing into the pin" valueReference="19" variability="continuous" causality="internal" alias="-C1.i">  
265: <ScalarVariable name="C1.n.v" description="Potential at the pin" valueReference="20" variability="continuous" causality="internal" alias="Gnd.p.v">  
278: <ScalarVariable name="C1.p.i" description="Current flowing into the pin" valueReference="21" variability="continuous" causality="internal" alias="C1.i">  
291: <ScalarVariable name="C1.p.v" description="Potential at the pin" valueReference="22" variability="continuous" causality="internal" alias="C1.v">  
304: <ScalarVariable name="C2.n.i" description="Current flowing into the pin" valueReference="23" variability="continuous" causality="internal" alias="-C2.i">  
317: <ScalarVariable name="C2.n.v" description="Potential at the pin" valueReference="24" variability="continuous" causality="internal" alias="Gnd.p.v">  
330: <ScalarVariable name="C2.p.i" description="Current flowing into the pin" valueReference="25" variability="continuous" causality="internal" alias="C2.i">  
343: <ScalarVariable name="C2.p.v" description="Potential at the pin" valueReference="26" variability="continuous" causality="internal" alias="C2.v">  
356: <ScalarVariable name="G.T_heatPort" description="Temperature of heatPort" valueReference="27" variability="continuous" causality="internal" alias="G.T">  
368: <ScalarVariable name="G.n.i" description="Current flowing into the pin" valueReference="28" variability="continuous" causality="internal" alias="-G.i">  
381: <ScalarVariable name="G.n.v" description="Potential at the pin" valueReference="29" variability="continuous" causality="internal" alias="C1.v">  
394: <ScalarVariable name="G.p.i" description="Current flowing into the pin" valueReference="30" variability="continuous" causality="internal" alias="G.i">  
407: <ScalarVariable name="G.p.v" description="Potential at the pin" valueReference="31" variability="continuous" causality="internal" alias="C2.v">  
420: <ScalarVariable name="L.n.i" description="Current flowing into the pin" valueReference="32" variability="continuous" causality="internal" alias="-L.i">  
433: <ScalarVariable name="L.n.v" description="Potential at the pin" valueReference="33" variability="continuous" causality="internal" alias="Ro.v">  
446: <ScalarVariable name="L.p.i" description="Current flowing into the pin" valueReference="34" variability="continuous" causality="internal" alias="L.i">  
459: <ScalarVariable name="L.p.v" description="Potential at the pin" valueReference="35" variability="continuous" causality="internal" alias="C2.v">  
472: <ScalarVariable name="Nr.n.i" description="Current flowing into the pin" valueReference="36" variability="continuous" causality="internal" alias="-Nr.i">  
485: <ScalarVariable name="Nr.n.v" description="Potential at the pin" valueReference="37" variability="continuous" causality="internal" alias="Gnd.p.v">  
498: <ScalarVariable name="Nr.p.i" description="Current flowing into the pin" valueReference="38" variability="continuous" causality="internal" alias="Nr.i">  
511: <ScalarVariable name="Nr.p.v" description="Potential at the pin" valueReference="39" variability="continuous" causality="internal" alias="C1.v">  
524: <ScalarVariable name="Nr.v" description="Voltage drop between the two pins (= p.v - n.v)" valueReference="40" variability="continuous" causality="internal" alias="C1.v">  
536: <ScalarVariable name="Ro.T_heatPort" description="Temperature of heatPort" valueReference="41" variability="continuous" causality="internal" alias="Ro.T">  
548: <ScalarVariable name="Ro.i" description="Current flowing from pin p to pin n" valueReference="42" variability="continuous" causality="internal" alias="L.i">  
560: <ScalarVariable name="Ro.n.i" description="Current flowing into the pin" valueReference="43" variability="continuous" causality="internal" alias="-L.i">  
573: <ScalarVariable name="Ro.n.v" description="Potential at the pin" valueReference="44" variability="continuous" causality="internal" alias="Gnd.p.v">  
586: <ScalarVariable name="Ro.p.i" description="Current flowing into the pin" valueReference="45" variability="continuous" causality="internal" alias="L.i">  
599: <ScalarVariable name="Ro.p.v" description="Potential at the pin" valueReference="46" variability="continuous" causality="internal" alias="Ro.v">  
611: <ScalarVariable name="C1.C" description="Capacitance" valueReference="47" variability="parameter" causality="internal" alias="noAlias">  
623: <ScalarVariable name="C2.C" description="Capacitance" valueReference="48" variability="parameter" causality="internal" alias="noAlias">  
635: <ScalarVariable name="G.G" description="Conductance at temperature T_ref" valueReference="49" variability="parameter" causality="internal" alias="noAlias">  
647: <ScalarVariable name="G.T" description="Fixed device temperature if useHeatPort = false" valueReference="50" variability="parameter" causality="internal" alias="noAlias">  
659: <ScalarVariable name="G.T_ref" description="Reference temperature" valueReference="51" variability="parameter" causality="internal" alias="noAlias">  
671: <ScalarVariable name="G.alpha" description="Temperature coefficient of conductance (G_actual = G_ref/(1 + alpha*(T_heatPort - T_ref))" valueReference="52" variability="parameter" causality="internal" alias="noAlias">  
683: <ScalarVariable name="L.L" description="Inductance" valueReference="53" variability="parameter" causality="internal" alias="noAlias">  
695: <ScalarVariable name="Nr.Ga" description="Conductance in inner voltage range" valueReference="54" variability="parameter" causality="internal" alias="noAlias">  
707: <ScalarVariable name="Nr.Gb" description="Conductance in outer voltage range" valueReference="55" variability="parameter" causality="internal" alias="noAlias">  
719: <ScalarVariable name="Nr.Ve" description="Inner voltage range limit" valueReference="56" variability="parameter" causality="internal" alias="noAlias">  
731: <ScalarVariable name="Ro.R" description="Resistance at temperature T_ref" valueReference="57" variability="parameter" causality="internal" alias="noAlias">  
743: <ScalarVariable name="Ro.T" description="Fixed device temperature if useHeatPort = false" valueReference="58" variability="parameter" causality="internal" alias="noAlias">  
755: <ScalarVariable name="Ro.T_ref" description="Reference temperature" valueReference="59" variability="parameter" causality="internal" alias="noAlias">  
767: <ScalarVariable name="Ro.alpha" description="Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))" valueReference="60" variability="parameter" causality="internal" alias="noAlias">  
778: <ScalarVariable name="G.useHeatPort" description="=true, if heatPort is enabled" valueReference="61" variability="parameter" causality="internal" alias="noAlias">  
790: <ScalarVariable name="Ro.useHeatPort" description="=true, if heatPort is enabled" valueReference="62" variability="parameter" causality="internal" alias="noAlias">  

If you scroll to the end of these tags, you will see the alias. It seems to be inconsistent. "noAlias" is an enum type whereas in other cases there is a string used as an Alias. One possible fix is to just change to string type and leave it blank for noAlias

comment:32 by anonymous, 8 years ago

Hi guys, it seems omc have some inconsistency when generating xml files. Here is the link: https://trac.openmodelica.org/OpenModelica/ticket/3980

by anonymous, 8 years ago

Attachment: PumpingSystem.mo added

comment:33 by anonymous, 8 years ago

Hi guys, I found several new bugs for OpenModelica v1.11.0-dev-54-g4ec62d0. I attached the xml file and model file.

  1. On line 159 of xml file, I think we should exchange line 159 and line 160, since 'exp:QualifiedNamePart' on line 153 does not close.
150:      <QualifiedName>
151:        <exp:QualifiedNamePart name="pipe"/>
152:        <exp:QualifiedNamePart name="flowModel"/>
153:        <exp:QualifiedNamePart name="states">
154:          <exp:ArraySubscripts>
155:            <exp:IndexExpression>
156:              <exp:IntegerLiteral>1</exp:IntegerLiteral>
157:            </exp:IndexExpression>
158:          </exp:ArraySubscripts>
159:        <exp:QualifiedNamePart name="h"/>
160:        </exp:QualifiedNamePart>
161:      </QualifiedName>
  1. On line 2985, the 'min' attribute should be '-100000.0'.
2985:      <Real  min="*ERROR* initial value of unknown type" max="100000.0" unit="kg/s" />
  1. On line 10160, based on the schema 'https://svn.jmodelica.org/trunk/XML/daeEquations.xsd', 'equ:Equation' is not allowed inside 'exp:Sub'.
10158:    <equ:Equation>
10159:      <exp:Sub>
10160:        <equ:Equation>
10161:          <exp:Sub>
10162:            <exp:Identifier>
  1. On line 31810, it is illegal based on schema 'https://svn.jmodelica.org/trunk/XML/daeFunctions.xsd'
31810:          <fun:Expression>
Note: See TracTickets for help on using tickets.