Changeset 12092


Ignore:
Timestamp:
Dec 4, 2018 1:54:40 PM (12 months ago)
Author:
Jonathan Kämpe
Message:

#5714 Alias elimination now prioritizes public over protected for model variables

Location:
branches/dev-jk-alias/Compiler
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-jk-alias/Compiler/ModelicaFrontEnd/src/jastadd/util/Util.jrag

    r11971 r12092  
    12071207    eq FVariable.isTemporary()                  = getVisibilityType().isTemporary();
    12081208
     1209    syn boolean FAbstractVariable.isInterface() = false;
     1210    eq FVariable.isInterface()                  = getVisibilityType().isInterface();
     1211
    12091212    syn boolean FAbstractVariable.isFromExpandableConnector() = false;
    12101213    eq FVariable.isFromExpandableConnector()                  =
  • branches/dev-jk-alias/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/ast/prefixes/VisibilityType.java

    r11419 r12092  
    22
    33public enum VisibilityType {
    4 
    5     PUBLIC,
    6     PROTECTED,
     4    /*
     5     * ordinal() is used for alias elimination so the order
     6     * here is important.
     7     */
     8    HIDDEN,
    79    TEMPORARY,
    810    EXPANDABLE,
     11    PROTECTED,
     12    PUBLIC,
    913    RUNTIME_OPTION,
    10     HIDDEN;
     14    INTERFACE;
     15   
     16    public boolean isInterface() {
     17        return this == INTERFACE;
     18    }
    1119   
    1220    public boolean isPublic() {
  • branches/dev-jk-alias/Compiler/ModelicaMiddleEnd/src/jastadd/optimizations/AliasElimination.jrag

    r12006 r12092  
    165165    eq FVariable.canBeAlias() = !getFAccess().myDerFV(order() + 1).isDummyDerivativeVariable()
    166166            && !isPreVariable() && !isNonDummyDerivativeVariable()
    167             && !isInput() && !isOutput() && !isIndependentParameter();
     167            && !isInput() && !isOutput() && !isIndependentParameter()
     168            && !isInterface();
    168169
    169170    syn int FExp.aliasSign() = 1;
  • branches/dev-jk-alias/Compiler/ModelicaMiddleEnd/src/jastadd/optimizations/AliasVariables.jadd

    r11753 r12092  
    923923    syn long FVariable.aliasHeuristicScore() {
    924924        long score = 0;
    925 
    926         if (!getVisibilityType().isHidden()) {
    927             score += 1;
    928         }
    929 
    930         // Temporary variables added during transformations or in expandable connectors.
    931         score *= 10;
    932         if (isFromExpandableConnector()) {
    933             score += 1;
    934         } else if (!isTemporary()) {
    935             score += 2;
    936         }
    937 
    938         // Input
    939         score *= 10;
    940         if (isInput()) {
    941             score += 1;
    942         }
    943 
     925       
     926        score += getVisibilityType().ordinal();
     927       
    944928        // Parameter
    945929        score *= 10;
  • branches/dev-jk-alias/Compiler/ModelicaMiddleEnd/test/modelica/IndexReduction.mo

    r10859 r12092  
    137137 eval parameter Boolean torque.useSupport = true \"= true, if support flange enabled, otherwise implicitly grounded\" /* true */;
    138138 parameter Modelica.SIunits.MomentOfInertia inertia1.J(min = 0,start = 1) \"Moment of inertia\";
    139  parameter Real idealGear.ratio(start = 1) \"Transmission ratio (flange_a.phi/flange_b.phi)\";
    140139 parameter StateSelect inertia1.stateSelect = StateSelect.default \"Priority to use phi and w as states\" /* StateSelect.default */;
    141140 Modelica.SIunits.Angle inertia1.phi(stateSelect = inertia1.stateSelect) \"Absolute rotation angle of component\";
    142141 Modelica.SIunits.AngularVelocity inertia1.w(stateSelect = inertia1.stateSelect) \"Absolute angular velocity of component (= der(phi))\";
    143142 Modelica.SIunits.AngularAcceleration inertia1.a \"Absolute angular acceleration of component (= der(w))\";
    144  parameter Modelica.SIunits.MomentOfInertia inertia3.J(min = 0,start = 1) \"Moment of inertia\";
     143 parameter Real idealGear.ratio(start = 1) \"Transmission ratio (flange_a.phi/flange_b.phi)\";
    145144 Modelica.SIunits.Angle idealGear.phi_a \"Angle between left shaft flange and support\";
    146145 Modelica.SIunits.Torque idealGear.flange_a.tau \"Cut torque in the flange\";
     
    158157 Modelica.SIunits.Torque spring.tau \"Torque between flanges (= flange_b.tau)\";
    159158 constant Modelica.SIunits.Torque inertia3.flange_b.tau = 0.0 \"Cut torque in the flange\";
    160  parameter Modelica.SIunits.RotationalDampingConstant damper.d(final min = 0,start = 0) \"Damping constant\";
     159 parameter Modelica.SIunits.MomentOfInertia inertia3.J(min = 0,start = 1) \"Moment of inertia\";
    161160 parameter StateSelect inertia3.stateSelect = StateSelect.default \"Priority to use phi and w as states\" /* StateSelect.default */;
    162161 Modelica.SIunits.Angle inertia3.phi(stateSelect = inertia3.stateSelect) \"Absolute rotation angle of component\";
    163162 Modelica.SIunits.AngularVelocity inertia3.w(fixed = true,start = 0,stateSelect = inertia3.stateSelect) \"Absolute angular velocity of component (= der(phi))\";
    164163 Modelica.SIunits.AngularAcceleration inertia3.a \"Absolute angular acceleration of component (= der(w))\";
    165  parameter Real sine.amplitude \"Amplitude of sine wave\";
     164 parameter Modelica.SIunits.RotationalDampingConstant damper.d(final min = 0,start = 0) \"Damping constant\";
    166165 Modelica.SIunits.Angle damper.phi_rel(stateSelect = StateSelect.always,start = 0,nominal = if damper.phi_nominal >= 1.0E-15 then damper.phi_nominal else 1) \"Relative rotation angle (= flange_b.phi - flange_a.phi)\";
    167166 Modelica.SIunits.AngularVelocity damper.w_rel(stateSelect = StateSelect.always,start = 0) \"Relative angular velocity (= der(phi_rel))\";
    168167 Modelica.SIunits.AngularAcceleration damper.a_rel(start = 0) \"Relative angular acceleration (= der(w_rel))\";
    169168 Modelica.SIunits.Torque damper.tau \"Torque between flanges (= flange_b.tau)\";
     169 parameter Real sine.amplitude \"Amplitude of sine wave\";
    170170 parameter Modelica.SIunits.Angle damper.phi_nominal(displayUnit = \"rad\",min = 0.0) = 1.0E-4 \"Nominal value of phi_rel (used for scaling)\" /* 1.0E-4 */;
    171171 parameter StateSelect damper.stateSelect = StateSelect.prefer \"Priority to use phi_rel and w_rel as states\" /* StateSelect.prefer */;
     
    173173 Modelica.SIunits.Power damper.lossPower \"Loss power leaving component via heatPort (> 0, if heat is flowing out of component)\";
    174174 parameter Modelica.SIunits.Frequency sine.freqHz(start = 1) \"Frequency of sine wave\";
     175 parameter Modelica.SIunits.Angle damper.flange_b.phi \"Absolute rotation angle of flange\";
    175176 parameter Modelica.SIunits.Angle sine.phase = 0 \"Phase of sine wave\" /* 0 */;
    176177 parameter Real sine.offset = 0 \"Offset of output signal\" /* 0 */;
    177178 parameter Modelica.SIunits.Time sine.startTime = 0 \"Output = offset for time < startTime\" /* 0 */;
    178  parameter Modelica.SIunits.Angle damper.flange_b.phi \"Absolute rotation angle of flange\";
    179179 parameter Modelica.SIunits.Angle fixed.flange.phi \"Absolute rotation angle of flange\";
    180180 parameter Modelica.SIunits.Angle idealGear.support.phi \"Absolute rotation angle of the support/housing\";
     
    198198 sine.amplitude = amplitude;
    199199 sine.freqHz = freqHz;
    200  torque.phi_support = fixed.phi0;
    201  damper.flange_b.phi = torque.phi_support;
    202  fixed.flange.phi = torque.phi_support;
    203  idealGear.support.phi = torque.phi_support;
    204  torque.support.phi = torque.phi_support;
    205  idealGear.phi_support = torque.phi_support;
     200 damper.flange_b.phi = fixed.phi0;
     201 fixed.flange.phi = damper.flange_b.phi;
     202 idealGear.support.phi = damper.flange_b.phi;
     203 torque.support.phi = damper.flange_b.phi;
     204 torque.phi_support = damper.flange_b.phi;
     205 idealGear.phi_support = damper.flange_b.phi;
    206206equation
    207207 inertia1.w = inertia1._der_phi;
    208208 inertia1.J * inertia1.a = torque.tau + (- idealGear.flange_a.tau);
    209  idealGear.phi_a = inertia1.phi - torque.phi_support;
    210  - damper.phi_rel = inertia2.phi - torque.phi_support;
     209 idealGear.phi_a = inertia1.phi - damper.flange_b.phi;
     210 - damper.phi_rel = inertia2.phi - damper.flange_b.phi;
    211211 idealGear.phi_a = idealGear.ratio * (- damper.phi_rel);
    212212 0 = idealGear.ratio * idealGear.flange_a.tau + idealGear.flange_b.tau;
  • branches/dev-jk-alias/Compiler/ModelicaMiddleEnd/test/modelica/TransformCanonicalTests.mo

    r12006 r12092  
    14031403")})));
    14041404    end AliasTest36;
     1405
     1406model AliasVisibility1
     1407    Real a;
     1408protected
     1409    Real b(start=1);
     1410equation
     1411    a = b;
     1412    a = time;
     1413
     1414    annotation(__JModelica(UnitTesting(tests={
     1415        TransformCanonicalTestCase(
     1416         name="AliasVisibility1",
     1417         description="",
     1418         flatModel="
     1419fclass TransformCanonicalTests.AliasVisibility1
     1420 Real a(start = 1);
     1421equation
     1422 a = time;
     1423end TransformCanonicalTests.AliasVisibility1;
     1424")})));
     1425end AliasVisibility1;
    14051426
    14061427model AliasFuncTest1
Note: See TracChangeset for help on using the changeset viewer.