Opened 12 years ago

Closed 11 years ago

#2012 closed enhancement (fixed)

FrontEnd generate wrong record constructor function for records with constants

Reported by: Jens Frenkel Owned by: Mahder Alemseged Gebremedhin
Priority: normal Milestone: 1.9.0
Component: Frontend Version: trunk
Keywords: constant record to functions Cc: christian.schubert@…

Description

For the models

Modelica.Electrical.Spice3.Examples.FourInverters
Modelica.Electrical.Spice3.Examples.InvertersApartRecord
Modelica.Electrical.Spice3.Examples.InvertersExtendedModel
Modelica.Electrical.Spice3.Examples.Nor
Modelica.Electrical.Spice3.Examples.Oscillator
Modelica.Electrical.Spice3.Examples.Spice3BenchmarkDifferentialPair
Modelica.Electrical.Spice3.Examples.Inverter

of MSL3.2.1

codegeneration fails to hand over records of constants because the record constructor funktion has no paramater values in declaration

For example the record

record SpiceConstants "General constants of SPICE simulator"
  extends Modelica.Icons.Record;
  constant Real EPSSIL =     (11.7 * 8.854214871e-12);
  constant Real EPSOX =      3.453133e-11;
  constant SI.Charge CHARGE =     (1.6021918e-19);
  constant SI.Temp_K CONSTCtoK =  (273.15);
  constant SI.HeatCapacity CONSTboltz = (1.3806226e-23); // J/K
  constant SI.Temp_K REFTEMP =    300.15;  /* 27 deg C */

  constant Real CONSTroot2 =  sqrt(2.0);
  constant Real CONSTvt0(   final unit= "(J/K)/(A.s)") = Modelica.Constants.k * Modelica.SIunits.Conversions.from_degC(27)  / CHARGE; // deg C
  constant Real CONSTKoverQ(  final unit= "(J/K)/(A.s)")= Modelica.Constants.k / CHARGE;
  constant Real CONSTe =      exp(1.0);

  // options

  constant SI.Conductance CKTgmin =         1e-12;
  constant SI.Temp_K CKTnomTemp =      300.15;
  constant SI.Temp_K CKTtemp =         300.15;
  constant SI.Area CKTdefaultMosAD = 0.0;
  constant SI.Area CKTdefaultMosAS = 0.0;
  constant SI.Length CKTdefaultMosL =  100e-6;
  constant SI.Length CKTdefaultMosW =  100e-6;
  constant Real CKTreltol =       1e-10;
  constant Real CKTabstol =       1e-15;
  constant Real CKTvolttol =      1e-10;
  constant Real CKTtemptol =      1e-3;
 annotation (Documentation(info="<html>
<p>General constants used by SPICE</p>
<p>The package Internal is not for user access. There all function, records and data are stored, that are needed for the semiconductor models of the package Semiconductors.</p>
</html>"));
end SpiceConstants;

get the following record function

Modelica_Electrical_Spice3_Internal_SpiceConstants_rettype
omc_Modelica_Electrical_Spice3_Internal_SpiceConstants()
{
  Modelica_Electrical_Spice3_Internal_SpiceConstants_rettype tmp1;
  struct Modelica_Electrical_Spice3_Internal_SpiceConstants tmp2;
  tmp1.c1 = tmp2;
  return tmp1;
}

and the call

  cc = Mos.mosCalcNoBypassCode(
    m,
    m_type,
    c2,
    p,
    C,
    vp,
    m_bInit,
    {G.v, B.v, Dinternal, Sinternal});

with

  tmp55 = omc_Modelica_Electrical_Spice3_Internal_SpiceConstants(0.00000000010359431399069999, 0.00000000003453133, 0.00000000000000000016021918, 273.15, 0.000000000000000000000013806226, 300.15, 1.4142135623730951, 2.718281828459045, 0.000000000001, 300.15, 300.15, 0.0, 0.0, 0.0001, 0.0001, 0.0000000001, 0.000000000000001, 0.0000000001, 0.001, 0.025864709055120616, 0.0000861726105451295);

will fail because the elements of tmp55 are not set.

Attachments (1)

Modelica.Electrical.Spice3.Examples.FourInverters.mos (338.4 KB ) - added by Jens Frenkel 12 years ago.
fixed flattened output

Download all attachments as: .zip

Change History (7)

comment:1 by Jens Frenkel, 12 years ago

Component: Code GenerationFrontend
Owner: changed from Martin Sjölund to Adrian Pop
Status: newassigned

According to the Spec.

Component declarations which do not allow a modification [such as constant Real c=1 or final
parameter Real] are declared as protected components in the record constructor function.

the Recordconstructor function of SpiceConstants seems not to be fine because the constants are not marked as protected

function Modelica.Electrical.Spice3.Internal.SpiceConstants \"Automatically generated record constructor for Modelica.Electrical.Spice3.Internal.SpiceConstants\"
  constant Real EPSSIL = 0.00000000010359431399069999;
  constant Real EPSOX = 0.00000000003453133;
  constant Real(quantity=\"ElectricCharge\", unit=\"C\") CHARGE = 0.00000000000000000016021918;
  constant Real(quantity=\"ThermodynamicTemperature\", unit=\"K\", min=0.0, start=288.15, nominal=300.0, displayUnit=\"degC\") CONSTCtoK = 273.15;
  constant Real(quantity=\"HeatCapacity\", unit=\"J/K\") CONSTboltz = 0.000000000000000000000013806226;
  constant Real(quantity=\"ThermodynamicTemperature\", unit=\"K\", min=0.0, start=288.15, nominal=300.0, displayUnit=\"degC\") REFTEMP = 300.15;
  constant Real CONSTroot2 = 1.4142135623730951;
  constant Real CONSTe = 2.718281828459045;
  constant Real(quantity=\"Conductance\", unit=\"S\") CKTgmin = 0.000000000001;
  constant Real(quantity=\"ThermodynamicTemperature\", unit=\"K\", min=0.0, start=288.15, nominal=300.0, displayUnit=\"degC\") CKTnomTemp = 300.15;
  constant Real(quantity=\"ThermodynamicTemperature\", unit=\"K\", min=0.0, start=288.15, nominal=300.0, displayUnit=\"degC\") CKTtemp = 300.15;
  constant Real(quantity=\"Area\", unit=\"m2\") CKTdefaultMosAD = 0.0;
  constant Real(quantity=\"Area\", unit=\"m2\") CKTdefaultMosAS = 0.0;
  constant Real(quantity=\"Length\", unit=\"m\") CKTdefaultMosL = 0.0001;
  constant Real(quantity=\"Length\", unit=\"m\") CKTdefaultMosW = 0.0001;
  constant Real CKTreltol = 0.0000000001;
  constant Real CKTabstol = 0.000000000000001;
  constant Real CKTvolttol = 0.0000000001;
  constant Real CKTtemptol = 0.001;
  constant Real(unit=\"(J/K)/(A.s)\") CONSTvt0 = 0.025864709055120616;
  constant Real(unit=\"(J/K)/(A.s)\") CONSTKoverQ = 0.0000861726105451295;
  output SpiceConstants res;
end Modelica.Electrical.Spice3.Internal.SpiceConstants;

in addition the function call in Modelica.Electrical.Spice3.Internal.MOS

...
  constant SpiceConstants C "General constants of SPICE simulator";
...
equation
....
  cc = Mos.mosCalcNoBypassCode(
    m,
    m_type,
    c2,
    p,
    C,
    vp,
    m_bInit,
    {G.v, B.v, Dinternal, Sinternal});

seems not to be flattend correct because the function call to Modelica.Electrical.Spice3.Internal.SpiceConstants should have no parameter, because all the constants are protected.

  mn4.cc = Modelica.Electrical.Spice3.Internal.Mos.mosCalcNoBypassCode(mn4.m, mn4.m_type, mn4.c2, mn4.p, Modelica.Electrical.Spice3.Internal.SpiceConstants(0.00000000010359431399069999, 0.00000000003453133, 0.00000000000000000016021918, 273.15, 0.000000000000000000000013806226, 300.15, 1.4142135623730951, 2.718281828459045, 0.000000000001, 300.15, 300.15, 0.0, 0.0, 0.0001, 0.0001, 0.0000000001, 0.000000000000001, 0.0000000001, 0.001, 0.025864709055120616, 0.0000861726105451295), mn4.vp, false, {mn4.G.v, mn4.B.v, mn4.Dinternal, mn4.Sinternal});

Hence it is looks like a FrontEnd issue and not a code generation issue.

by Jens Frenkel, 12 years ago

fixed flattened output

comment:2 by Jens Frenkel, 12 years ago

Summary: Codegeneration does not handle record of constants to funktionsFrontEnd generate wrong record constructor function for records with constants

comment:3 by Jens Frenkel, 12 years ago

Priority: blockernormal
Type: defectenhancement
  • Further investigations have shown that the division by zero is not because of the handling of constants in recordconstruktor funktions but problems with the initial system solving in the simulation runtime. Hence the issue is less importent and the handling of constants of recordconstruktor funktins is only not conform with the specification.

comment:4 by Mahder Alemseged Gebremedhin, 12 years ago

Owner: changed from Adrian Pop to Mahder Alemseged Gebremedhin
Status: assignedaccepted

comment:5 by Mahder Alemseged Gebremedhin, 11 years ago

Fixed in r14958.

comment:6 by Mahder Alemseged Gebremedhin, 11 years ago

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.