Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » __Markus
  • » Profile

Posts

Posts

Hi,

I came across the following error when using OMEdit / OpenModelica (r16584)
with the following model:

// -------------------------------------------------------------------------

model WithTernGas2 "Test ternary gas medium definitions"
  extends Modelica.Icons.Example;
  parameter Modelica.SIunits.MoleFraction x1=0;
  parameter Modelica.SIunits.MoleFraction x2=1;
  Modelica.SIunits.MolarMass M;
equation
  M = Media.MolarMassMoistAir(x1, x2);
end WithTernGas2;

function MolarMassMoistAir
  "Molar Mass of moist Air (ternary gas mixture)"
  parameter TernaryGas TernGas=MoistAir() "Medium definition";
  input Modelica.SIunits.MoleFraction x1 "Mole fraction of oxygen in mixture";
  input Modelica.SIunits.MoleFraction x2
    "Mole fraction of water vapor in mixture";
  output Modelica.SIunits.MolarMass M "Molar mass of gas mixture";
algorithm
  M := TernGas.Comp1.M*x1 + TernGas.Comp2.M*x2 + TernGas.Comp3.M*(1 - x1 - x2);
  assert((1 - x1 - x2) >= 0 and (1 - x1 - x2) <= 1, "Mole fraction out of bounds!");
end MolarMassMoistAir;

record MoistAir "Medium: Moist Air Definition as Ternary Gas"
  extends Modelica.Icons.Record;
   extends TernaryGas(
     Comp1=Oxygen(),
     Comp2=WaterVapor(),
     Comp3=Nitrogen());
//   extends TernaryGas(
//     Comp1(
//       M=0.032,
//       A={2122.2098,3.5302,-7.1076,-1.4542,30.6057,-83.6696,79.4375},
//       B={-0.10257E-5,0.92625E-7,-0.80657E-10,0.05113E-12,-0.01295E-15}),
//     Comp2(
//       M=0.018,
//       A={706.3032,5.1703,-6.0865,-6.6011,36.2723,-63.0965,46.2085},
//       B={-0.10718E-5,0.35248E-7,0.03575E-10,0,0}),
//     Comp3(
//       M=0.028,
//       A={432.2027,3.515,2.801,-4.1924,42.0153,-114.25,111.1019},
//       B={-0.0102E-5,0.74785E-7,-0.59037E-10,0.0323E-12,-0.00673E-15}));
end MoistAir;

record TernaryGas
  "Record containing Model Parameter used for the Ternary Gas Mixtures"
  extends Modelica.Icons.Record;
  parameter PureGas Comp1 "Component 1";
  parameter PureGas Comp2 "Component 2";
  parameter PureGas Comp3 "Component 3";
end TernaryGas;

record Oxygen "Medium: O2"
  extends Modelica.Icons.Record;
  extends PureGas(
    M=0.032,
    A={2122.2098,3.5302,-7.1076,-1.4542,30.6057,-83.6696,79.4375},
    B={-0.10257E-5,0.92625E-7,-0.80657E-10,0.05113E-12,-0.01295E-15});
end Oxygen;

record WaterVapor "Medium: H2O(g)"
  extends Modelica.Icons.Record;
  extends PureGas(
    M=0.018,
    A={706.3032,5.1703,-6.0865,-6.6011,36.2723,-63.0965,46.2085},
    B={-0.10718E-5,0.35248E-7,0.03575E-10,0,0});
end WaterVapor;

record Nitrogen "Medium: N2"
  extends Modelica.Icons.Record;
  extends PureGas(
    M=0.028,
    A={432.2027,3.515,2.801,-4.1924,42.0153,-114.25,111.1019},
    B={-0.0102E-5,0.74785E-7,-0.59037E-10,0.0323E-12,-0.00673E-15});
end Nitrogen;

record PureGas
  "Record containing Model Parameters for the used Pure Gases"
  extends Modelica.Icons.Record;
  parameter Modelica.SIunits.MolarMass M=1 "Molar Mass";
  parameter Real A[7]={1,1,1,1,1,1,1}
    "Model parameters spec. heat cap. const. pres.";
  parameter Real B[5]={1,1,1,1,1} "Model parameters dyn. viscosity";
end PureGas;

// ----------------------------------------------------------------------------

The error reads:

// ----------------------------------------------------------------------------

Translation    17:59:07        0:0-0:0    Error building simulator. Build log: gcc   -falign-functions -march=native -mfpmath=sse -fPIC   -I"/usr/include/omc" -I. -L"/home/mgroetsch/work/win/models/Libraries/PemFcSysLib/Test/GasMedDef"  -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o PemFcSysLib.Test.GasMedDef.WithTernGas2.o PemFcSysLib.Test.GasMedDef.WithTernGas2.c
In file included from PemFcSysLib.Test.GasMedDef.WithTernGas2.c:17:0:
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.c: In function 'omc_PemFcSysLib_Media_MolarMassMoistAir':
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.c:122:3: error: incompatible type for argument 1 of 'omc_PemFcSysLib_Media_TernaryGas'
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.h:113:38: note: expected 'PemFcSysLib_Media_PureGas' but argument is of type 'PemFcSysLib_Media_Oxygen'
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.c:122:3: error: incompatible type for argument 2 of 'omc_PemFcSysLib_Media_TernaryGas'
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.h:113:38: note: expected 'PemFcSysLib_Media_PureGas' but argument is of type 'PemFcSysLib_Media_WaterVapor'
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.c:122:3: error: incompatible type for argument 3 of 'omc_PemFcSysLib_Media_TernaryGas'
PemFcSysLib.Test.GasMedDef.WithTernGas2_functions.h:113:38: note: expected 'PemFcSysLib_Media_PureGas' but argument is of type 'PemFcSysLib_Media_Nitrogen'
make: *** [PemFcSysLib.Test.GasMedDef.WithTernGas2.o] Error 1

// ----------------------------------------------------------------------------

Probably, the assignment of the derived records Oxygen, WaterVapor and Nitrogen
to their base class PureGas in record MoistAir raises this error.

If the current extends declaration above in record MoistAir is substituted by
the direct and currently commented definition the error vanishes and the
simulation takes place.

Regards,
Markus.

May-06-13 16:44:51
FMI model description scheme in OpenModelica - Customization possible?

Hi,

is it possible to customize the model description scheme for FMU export in OpenModelica?
For example, is it possible to add quantities, units, displayUnits, min and max values as well as
start values of scalar variables of type Real to the modelDescription.xml file by customizing the
FMU export of OpenModelica?

Thanks.
Kind regards,
Markus.

Apr-16-13 16:50:14
Translation Error: Connection Equations for Parameters
Category: Developer

Hi,

I have encountered an error at the translation of connection equations containing parameters (records) using OpenModelica.
In the following, the instantiated / flattend model is given. The bold part should be put inside an assert() statement as is done
with the scalar parameter xi.

Hope this helps.
Regards,
Markus.

// ------------------------------------------------------------------------------------------------------------------------------------------------------------

function PemFcSysLib.Media.CoolLiq "Automatically generated record constructor for PemFcSysLib.Media.CoolLiq"
  input Real[5] A = {1.0, 1.0, 1.0, 1.0, 1.0};
  input Real[5] B = {1.0, 1.0, 1.0, 1.0, 1.0};
  input Real[5] C = {1.0, 1.0, 1.0, 1.0, 1.0};
  input Real xi = 0.0;
  output CoolLiq res;
end PemFcSysLib.Media.CoolLiq;

function PemFcSysLib.Media.FcGlysantin "Automatically generated record constructor for PemFcSysLib.Media.FcGlysantin"
  input Real[5] A = {651.9132675, -54.2668599, 658.0692657, 230.3987895, -319.3904439};
  input Real[5] B = {5.23037775, 0.76891425, -2.52525975, -2.66357325, 1.4016502499999999};
  input Real[5] C = {-4.2598208, -1.9763164, -11.6849752, 4.9729312000000006, 10.110708};
  input Real xi = 0.5;
  output FcGlysantin res;
end PemFcSysLib.Media.FcGlysantin;

class PemFcSysLib.Test.CoolPort.TestSource
  output Real p.y "Connector of Real output signal";
  parameter Real p.k(start = 1.0) = 150000.0 "Constant output value";
  output Real T.y "Connector of Real output signal";
  parameter Real T.k(start = 1.0) = 323.0 "Constant output value";
  output Real j_p.y "Connector of Real output signal";
  parameter Real j_p.k(start = 1.0) = 0.2 "Constant output value";
  parameter Real coolSourcePTJ.medium.A[1] = 651.9132675 "Model parameters density";
  parameter Real coolSourcePTJ.medium.A[2] = -54.2668599 "Model parameters density";
  parameter Real coolSourcePTJ.medium.A[3] = 658.0692657 "Model parameters density";
  parameter Real coolSourcePTJ.medium.A[4] = 230.3987895 "Model parameters density";
  parameter Real coolSourcePTJ.medium.A[5] = -319.3904439 "Model parameters density";
  parameter Real coolSourcePTJ.medium.B[1] = 5.23037775 "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.medium.B[2] = 0.76891425 "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.medium.B[3] = -2.52525975 "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.medium.B[4] = -2.66357325 "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.medium.B[5] = 1.4016502499999999 "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.medium.C[1] = -4.2598208 "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.medium.C[2] = -1.9763164 "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.medium.C[3] = -11.6849752 "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.medium.C[4] = 4.9729312000000006 "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.medium.C[5] = 10.110708 "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.medium.xi = 0.5 "Mass fraction Ethylen Glycol in solution";
  input Real coolSourcePTJ.p "Source pressure";
  input Real coolSourcePTJ.T "Source temperature";
  input Real coolSourcePTJ.j "Source flow rate, defined pos. outwards";
  parameter Real coolSourcePTJ.CpII.medium.A[1] = coolSourcePTJ.medium.A[1] "Model parameters density";
  parameter Real coolSourcePTJ.CpII.medium.A[2] = coolSourcePTJ.medium.A[2] "Model parameters density";
  parameter Real coolSourcePTJ.CpII.medium.A[3] = coolSourcePTJ.medium.A[3] "Model parameters density";
  parameter Real coolSourcePTJ.CpII.medium.A[4] = coolSourcePTJ.medium.A[4] "Model parameters density";
  parameter Real coolSourcePTJ.CpII.medium.A[5] = coolSourcePTJ.medium.A[5] "Model parameters density";
  parameter Real coolSourcePTJ.CpII.medium.B[1] = coolSourcePTJ.medium.B[1] "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.CpII.medium.B[2] = coolSourcePTJ.medium.B[2] "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.CpII.medium.B[3] = coolSourcePTJ.medium.B[3] "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.CpII.medium.B[4] = coolSourcePTJ.medium.B[4] "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.CpII.medium.B[5] = coolSourcePTJ.medium.B[5] "Model parameters spec. heat cap. const. pres.";
  parameter Real coolSourcePTJ.CpII.medium.C[1] = coolSourcePTJ.medium.C[1] "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.CpII.medium.C[2] = coolSourcePTJ.medium.C[2] "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.CpII.medium.C[3] = coolSourcePTJ.medium.C[3] "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.CpII.medium.C[4] = coolSourcePTJ.medium.C[4] "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.CpII.medium.C[5] = coolSourcePTJ.medium.C[5] "Model parameters dyn. viscosity";
  parameter Real coolSourcePTJ.CpII.medium.xi = coolSourcePTJ.medium.xi "Mass fraction Ethylen Glycol in solution";
  Real coolSourcePTJ.CpII.j(quantity = "MassFlowRate", unit = "kg/s") "Mass flow rate, define towards interface";
  Real coolSourcePTJ.CpII.p(quantity = "Pressure", unit = "Pa", displayUnit = "bar", start = 100000.0) "Fluid pressure";
  Real coolSourcePTJ.CpII.T(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 0.0, start = 293.0, nominal = 300.0) "Fluid temperature";
  parameter Real Boundary.medium.A[1] = 651.9132675 "Model parameters density";
  parameter Real Boundary.medium.A[2] = -54.2668599 "Model parameters density";
  parameter Real Boundary.medium.A[3] = 658.0692657 "Model parameters density";
  parameter Real Boundary.medium.A[4] = 230.3987895 "Model parameters density";
  parameter Real Boundary.medium.A[5] = -319.3904439 "Model parameters density";
  parameter Real Boundary.medium.B[1] = 5.23037775 "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.medium.B[2] = 0.76891425 "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.medium.B[3] = -2.52525975 "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.medium.B[4] = -2.66357325 "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.medium.B[5] = 1.4016502499999999 "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.medium.C[1] = -4.2598208 "Model parameters dyn. viscosity";
  parameter Real Boundary.medium.C[2] = -1.9763164 "Model parameters dyn. viscosity";
  parameter Real Boundary.medium.C[3] = -11.6849752 "Model parameters dyn. viscosity";
  parameter Real Boundary.medium.C[4] = 4.9729312000000006 "Model parameters dyn. viscosity";
  parameter Real Boundary.medium.C[5] = 10.110708 "Model parameters dyn. viscosity";
  parameter Real Boundary.medium.xi = 0.5 "Mass fraction Ethylen Glycol in solution";
  Real Boundary.p(quantity = "Pressure", unit = "Pa", displayUnit = "bar") "Sink pressure";
  Real Boundary.T(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 0.0, start = 288.15, nominal = 300.0) "Sink temperature";
  parameter Real Boundary.CpI.medium.A[1] = Boundary.medium.A[1] "Model parameters density";
  parameter Real Boundary.CpI.medium.A[2] = Boundary.medium.A[2] "Model parameters density";
  parameter Real Boundary.CpI.medium.A[3] = Boundary.medium.A[3] "Model parameters density";
  parameter Real Boundary.CpI.medium.A[4] = Boundary.medium.A[4] "Model parameters density";
  parameter Real Boundary.CpI.medium.A[5] = Boundary.medium.A[5] "Model parameters density";
  parameter Real Boundary.CpI.medium.B[1] = Boundary.medium.B[1] "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.CpI.medium.B[2] = Boundary.medium.B[2] "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.CpI.medium.B[3] = Boundary.medium.B[3] "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.CpI.medium.B[4] = Boundary.medium.B[4] "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.CpI.medium.B[5] = Boundary.medium.B[5] "Model parameters spec. heat cap. const. pres.";
  parameter Real Boundary.CpI.medium.C[1] = Boundary.medium.C[1] "Model parameters dyn. viscosity";
  parameter Real Boundary.CpI.medium.C[2] = Boundary.medium.C[2] "Model parameters dyn. viscosity";
  parameter Real Boundary.CpI.medium.C[3] = Boundary.medium.C[3] "Model parameters dyn. viscosity";
  parameter Real Boundary.CpI.medium.C[4] = Boundary.medium.C[4] "Model parameters dyn. viscosity";
  parameter Real Boundary.CpI.medium.C[5] = Boundary.medium.C[5] "Model parameters dyn. viscosity";
  parameter Real Boundary.CpI.medium.xi = Boundary.medium.xi "Mass fraction Ethylen Glycol in solution";
  Real Boundary.CpI.j(quantity = "MassFlowRate", unit = "kg/s") "Mass flow rate, define towards interface";
  Real Boundary.CpI.p(quantity = "Pressure", unit = "Pa", displayUnit = "bar", start = 100000.0) "Fluid pressure";
  Real Boundary.CpI.T(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 0.0, start = 293.0, nominal = 300.0) "Fluid temperature";
equation
  p.y = p.k;
  T.y = T.k;
  j_p.y = j_p.k;
  0.0 = (-coolSourcePTJ.CpII.j) - coolSourcePTJ.j;
  0.0 = coolSourcePTJ.p - coolSourcePTJ.CpII.p;
  0.0 = coolSourcePTJ.T - coolSourcePTJ.CpII.T;
  0.0 = Boundary.p - Boundary.CpI.p;
  0.0 = Boundary.T - Boundary.CpI.T;
  assert(coolSourcePTJ.CpII.medium.xi == Boundary.CpI.medium.xi,"automatically generated from connect");
  coolSourcePTJ.CpII.j + Boundary.CpI.j = 0.0;
  coolSourcePTJ.j = j_p.y;
  coolSourcePTJ.p = p.y;
  T.y = coolSourcePTJ.T;
Boundary.CpI.medium.A[1] = coolSourcePTJ.CpII.medium.A[1];
  Boundary.CpI.medium.A[2] = coolSourcePTJ.CpII.medium.A[2];
  Boundary.CpI.medium.A[3] = coolSourcePTJ.CpII.medium.A[3];
  Boundary.CpI.medium.A[4] = coolSourcePTJ.CpII.medium.A[4];
  Boundary.CpI.medium.A[5] = coolSourcePTJ.CpII.medium.A[5];
  Boundary.CpI.medium.B[1] = coolSourcePTJ.CpII.medium.B[1];
  Boundary.CpI.medium.B[2] = coolSourcePTJ.CpII.medium.B[2];
  Boundary.CpI.medium.B[3] = coolSourcePTJ.CpII.medium.B[3];
  Boundary.CpI.medium.B[4] = coolSourcePTJ.CpII.medium.B[4];
  Boundary.CpI.medium.B[5] = coolSourcePTJ.CpII.medium.B[5];
  Boundary.CpI.medium.C[1] = coolSourcePTJ.CpII.medium.C[1];
  Boundary.CpI.medium.C[2] = coolSourcePTJ.CpII.medium.C[2];
  Boundary.CpI.medium.C[3] = coolSourcePTJ.CpII.medium.C[3];
  Boundary.CpI.medium.C[4] = coolSourcePTJ.CpII.medium.C[4];
  Boundary.CpI.medium.C[5] = coolSourcePTJ.CpII.medium.C[5];
  Boundary.CpI.p = coolSourcePTJ.CpII.p;
  Boundary.CpI.T = coolSourcePTJ.CpII.T;
end PemFcSysLib.Test.CoolPort.TestSource;

// ------------------------------------------------------------------------------------------------------------------------------------------------------------

  • Index
  • » Users
  • » __Markus
  • » Profile
You are here: