Changeset 13670


Ignore:
Timestamp:
Oct 4, 2019 1:54:21 PM (2 months ago)
Author:
molsson
Message:

#5855 Use the absolute value of nominals when generating modelDescription.xml.

Location:
trunk/Compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/FmiXMLCodeGen/test/modelica/FmiXMLTests.mo

    r13636 r13670  
    25432543end ParametricAttributes1;
    25442544
     2545
     2546model NegativeNominal1
     2547    Real x1(nominal=-1);   // Negative integer nominal
     2548    Real x2(nominal=-1.0); // Negative real nominal
     2549equation
     2550    x1 = time;
     2551    x2 = time;
     2552annotation(__JModelica(UnitTesting(tests={
     2553    FmiXMLCodeGenTestCase(
     2554        description="Nominals are always non-negative in FMI",
     2555        fmi_version="2.0",
     2556        template="
     2557$modelVariables$
     2558",      generatedCode="
     2559<ModelVariables>
     2560    <!-- Variable with index #1 -->
     2561    <ScalarVariable name=\"x1\" valueReference=\"0\" causality=\"local\" variability=\"continuous\" initial=\"calculated\">
     2562        <Real relativeQuantity=\"false\" nominal=\"1\" />
     2563    </ScalarVariable>
     2564    <!-- Variable with index #2 -->
     2565    <ScalarVariable name=\"x2\" valueReference=\"0\" causality=\"local\" variability=\"continuous\" initial=\"calculated\">
     2566        <Real relativeQuantity=\"false\" nominal=\"1.0\" />
     2567    </ScalarVariable>
     2568</ModelVariables>
     2569")})));
     2570end NegativeNominal1;
     2571
    25452572end FmiXMLTests;
  • trunk/Compiler/GenericCodeGen/src/jastadd/GenericXMLGenerator.jrag

    r13636 r13670  
    217217                    variable.isInput() || variable.isDifferentiatedVariable()) {
    218218                try {
    219                     String value = attributeExp.ceval().xmlValue();
     219                    CValue cvalue = attributeExp.ceval();
     220                    if (name.equals("nominal")) {
     221                        cvalue = cvalue.absoluteValue();
     222                    }
     223                    String value = cvalue.xmlValue();
    220224                    generateAttribute(name, value, printer);
    221225                } catch (ConstantEvaluationException e) {
  • trunk/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ConstantEvaluation.jrag

    r13605 r13670  
    46334633    eq CValueUnknown.lt(CValue v1, CValue v2) = CValue.UNKNOWN;
    46344634
     4635   
     4636    public CValue CValue.absoluteValue() {
     4637        return this;
     4638    }
     4639    @Override
     4640    public CValue CValueReal.absoluteValue() {
     4641        return new CValueReal(Math.abs(realValue()));
     4642    }
     4643    @Override
     4644    public CValue CValueInteger.absoluteValue() {
     4645        return new CValueInteger(Math.abs(intValue()));
     4646    }
     4647   
    46354648}
    46364649
Note: See TracChangeset for help on using the changeset viewer.