Changeset 13636


Ignore:
Timestamp:
Oct 2, 2019 9:54:32 AM (2 months ago)
Author:
Jonathan Kämpe
Message:

#5844 Merging to trunk. Fixes related to attribute evaluation robustness.

Location:
trunk
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/CHANGELOG.txt

    r13512 r13636  
    11================= Unreleased ==================
     2# Fixed ; Minor ; Compiler; #5844
     3Improved attribute evaluation robustness for some cases. Parametric
     4attributes are now only generated in model description for inputs
     5and states.
     6
    27# Fixed ; Minor ; Compiler; #5835
    38Format string argument to the String function is now useable.
  • trunk/Compiler/FmiXMLCodeGen/test/modelica/FmiXMLTests.mo

    r12934 r13636  
    25002500end Start5;
    25012501
     2502model ParametricAttributes1
     2503    parameter Real p = 1;
     2504    input Real x1(min=p, max=p, nominal=p);
     2505    Real x2(min=p, max=p, nominal=p);
     2506    output Real x3(min=p, max=p, nominal=p);
     2507equation
     2508    der(x2) = x1;
     2509    x3 = x2;
     2510
     2511    annotation(__JModelica(UnitTesting(tests={
     2512        FmiXMLCodeGenTestCase(
     2513            name="ParametricAttributes1",
     2514            description="",
     2515            fmi_version="2.0",
     2516            template="
     2517$modelVariables$
     2518",
     2519            generatedCode="
     2520<ModelVariables>
     2521    <!-- Variable with index #1 -->
     2522    <ScalarVariable name=\"p\" valueReference=\"0\" causality=\"parameter\" variability=\"fixed\" initial=\"exact\">
     2523        <Real relativeQuantity=\"false\" start=\"1.0\" />
     2524    </ScalarVariable>
     2525    <!-- Variable with index #2 -->
     2526    <ScalarVariable name=\"x1\" valueReference=\"3\" causality=\"input\" variability=\"continuous\">
     2527        <Real relativeQuantity=\"false\" min=\"1.0\" max=\"1.0\" nominal=\"1.0\" start=\"0.0\" />
     2528    </ScalarVariable>
     2529    <!-- Variable with index #3 -->
     2530    <ScalarVariable name=\"x2\" valueReference=\"2\" causality=\"local\" variability=\"continuous\" initial=\"calculated\">
     2531        <Real relativeQuantity=\"false\" min=\"1.0\" max=\"1.0\" nominal=\"1.0\" />
     2532    </ScalarVariable>
     2533    <!-- Variable with index #4 -->
     2534    <ScalarVariable name=\"der(x2)\" valueReference=\"1\" causality=\"local\" variability=\"continuous\" initial=\"calculated\">
     2535        <Real relativeQuantity=\"false\" derivative=\"3\" />
     2536    </ScalarVariable>
     2537    <!-- Variable with index #5 -->
     2538    <ScalarVariable name=\"x3\" valueReference=\"4\" causality=\"output\" variability=\"continuous\" initial=\"calculated\">
     2539        <Real relativeQuantity=\"false\" />
     2540    </ScalarVariable>
     2541</ModelVariables>
     2542")})));
     2543end ParametricAttributes1;
     2544
    25022545end FmiXMLTests;
  • trunk/Compiler/GenericCodeGen/src/jastadd/GenericXMLGenerator.jrag

    r11966 r13636  
    213213    protected void generateAttributeIfSet(String name, FVariable variable, CodeStream printer) {
    214214        if (variable.attributeSet(name)) {
    215             String value = variable.attributeCValue(name).xmlValue();
    216             generateAttribute(name, value, printer);
     215            FExp attributeExp = variable.attributeExp(name);
     216            if (attributeExp.variability().constantVariability() ||
     217                    variable.isInput() || variable.isDifferentiatedVariable()) {
     218                try {
     219                    String value = attributeExp.ceval().xmlValue();
     220                    generateAttribute(name, value, printer);
     221                } catch (ConstantEvaluationException e) {
     222                    throw new InternalCompilerError("Exception when generating xml attribute '" +
     223                        name + "' for variable '" + variable.name() + "'.", e);
     224                }
     225            }
    217226        }
    218227    }
  • trunk/Compiler/ModelicaMiddleEnd/src/jastadd/structural/Symbolic.jrag

    r13529 r13636  
    187187                    negatedFactor = true;
    188188                } else if (ee.nbrUses(var.name())==0) {
    189                     if (ee.variability().constantVariability() &&
    190                             Math.abs(ee.ceval().realValue()) *
    191                             ee.dynamicFExp(var.nominal()).ceval().realValue() < tol) {
     189                    if (!nominalAllowsDivision(ee, var, tol)) {
    192190                        return new FNoExp();
    193191                    }
     
    212210        }
    213211        return FExp.createBalancedBinaryTree(new FAddExp(), parts);
     212    }
     213   
     214    /**
     215     * Check if nominal values allow the variable to be divided by the factor.
     216     */
     217    private static Boolean FEquation.nominalAllowsDivision(FExp factor, FVariable var, double tol) {
     218        if (factor.variability().constantVariability()) {
     219            FExp nominal = factor.dynamicFExp(var.nominal());
     220            if (nominal.variability().constantVariability() &&
     221                    Math.abs(factor.ceval().realValue()) *
     222                    nominal.ceval().realValue() < tol) {
     223                return false;
     224            }
     225        }
     226        return true;
    214227    }
    215228   
  • trunk/Makefile.am

    r13396 r13636  
    6464    make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR)" "IPOPT_HOME=$(IPOPT_HOME)"
    6565    mkdir -p $(DESTDIR)$(prefix)/Python/
    66     cp -r $(abs_builddir)/casadi_install/casadi $(DESTDIR)$(prefix)/Python/
     66    cp -r $(CASADI_PYTHON_INST_DIR)/casadi $(DESTDIR)$(prefix)/Python/
    6767    ## temp fix
    68     cp $(abs_builddir)/casadi_build/swig/casadi_core.py $(DESTDIR)$(prefix)/Python/casadi
     68    cp $(CASADI_BUILD_DIR)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python/casadi
    6969endif
    7070if COMPILE_WITH_IPOPT64 
     
    7474    make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR64)" "IPOPT_HOME=$(IPOPT64_HOME)"
    7575    mkdir -p $(DESTDIR)$(prefix)/Python/
    76     cp -r $(abs_builddir)/casadi_install64/casadi $(DESTDIR)$(prefix)/Python_64/
     76    cp -r $(CASADI_PYTHON_INST_DIR64)/casadi $(DESTDIR)$(prefix)/Python_64/
    7777    ## temp fix
    78     cp $(abs_builddir)/casadi_build64/swig/casadi_core.py $(DESTDIR)$(prefix)/Python_64/casadi
     78    cp $(CASADI_BUILD_DIR64)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python_64/casadi
    7979    export PYTHONHOME=$(ORIG_PYTHON_HOME); \
    8080    export PATH="$(ORIG_PATH)";
     
    504504JAVA_OC_CASADI_ANT_FILE=$(COMPILER_DIR)/OptimicaCompilerCasADi/build.xml
    505505
    506 all-local: build-python-packages build-compiler
    507     $(abs_top_srcdir)/get_version.sh $(abs_top_srcdir) https://svn.jmodelica.org > $(abs_builddir)/version.txt
     506all-local: build-python-packages build-compiler $(abs_builddir)/version.txt build-extra
     507
     508$(abs_builddir)/version.txt: TODO-always-trigger
     509    $(abs_top_srcdir)/get_version.sh $(abs_top_srcdir) https://svn.jmodelica.org > $(@)
     510
     511build-extra: TODO-always-trigger
    508512    if [ "$(BUILD_EXTRA)" ]; then exec "$(BUILD_EXTRA)" "$(abs_top_srcdir)" "$(DESTDIR)$(prefix)"; fi
    509513
     
    578582ant_output_options=$(JAVA_BUILD_DIR)/src/build/DefaultOptions.xml
    579583
    580 install-compiler: $(ant_output_jars) $(ant_output_options) TODO-always-trigger
     584install-compiler: $(ant_output_jars) $(ant_output_options)
    581585if HAVE_ANT
    582586    mkdir -p $(DESTDIR)$(prefix)/lib/
     
    585589endif
    586590
    587 # Dummy target used to always trigger rebuilds. Used to enable references to
    588 # outputs from phony targets as real targets. For example ant output.
    589 TODO-always-trigger: ;
    590 
    591591$(ant_output_jars) $(ant_output_options): build-compiler
    592592
    593 build-compiler:
     593build-compiler: TODO-always-trigger
    594594if HAVE_ANT
    595595    mkdir -p $(JAVA_BUILD_DIR)
     
    599599    $(ANT_OPTS) $(ANT) -f "$(JAVA_OC_ANT_FILE)" "-Dcompiler=$(COMPILER_DIR)" "-Dtarget=$(JAVA_BUILD_DIR)"
    600600endif
     601
     602# Dummy target used to always trigger rebuilds. Used to enable references to
     603# outputs from phony targets as real targets. For example ant output.
     604TODO-always-trigger: ;
    601605
    602606install-modules: install-modules-ModelicaFrontEnd
  • trunk/Makefile.in

    r13396 r13636  
    879879@COMPILE_WITH_IPOPT_TRUE@   make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR)" "IPOPT_HOME=$(IPOPT_HOME)"
    880880@COMPILE_WITH_IPOPT_TRUE@   mkdir -p $(DESTDIR)$(prefix)/Python/
    881 @COMPILE_WITH_IPOPT_TRUE@   cp -r $(abs_builddir)/casadi_install/casadi $(DESTDIR)$(prefix)/Python/
    882 @COMPILE_WITH_IPOPT_TRUE@   cp $(abs_builddir)/casadi_build/swig/casadi_core.py $(DESTDIR)$(prefix)/Python/casadi
     881@COMPILE_WITH_IPOPT_TRUE@   cp -r $(CASADI_PYTHON_INST_DIR)/casadi $(DESTDIR)$(prefix)/Python/
     882@COMPILE_WITH_IPOPT_TRUE@   cp $(CASADI_BUILD_DIR)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python/casadi
    883883@COMPILE_WITH_IPOPT64_TRUE@ export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}"; \
    884884@COMPILE_WITH_IPOPT64_TRUE@ export PYTHONHOME=$(PYTHON64_HOME); 
     
    886886@COMPILE_WITH_IPOPT64_TRUE@ make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR64)" "IPOPT_HOME=$(IPOPT64_HOME)"
    887887@COMPILE_WITH_IPOPT64_TRUE@ mkdir -p $(DESTDIR)$(prefix)/Python/
    888 @COMPILE_WITH_IPOPT64_TRUE@ cp -r $(abs_builddir)/casadi_install64/casadi $(DESTDIR)$(prefix)/Python_64/
    889 @COMPILE_WITH_IPOPT64_TRUE@ cp $(abs_builddir)/casadi_build64/swig/casadi_core.py $(DESTDIR)$(prefix)/Python_64/casadi
     888@COMPILE_WITH_IPOPT64_TRUE@ cp -r $(CASADI_PYTHON_INST_DIR64)/casadi $(DESTDIR)$(prefix)/Python_64/
     889@COMPILE_WITH_IPOPT64_TRUE@ cp $(CASADI_BUILD_DIR64)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python_64/casadi
    890890@COMPILE_WITH_IPOPT64_TRUE@ export PYTHONHOME=$(ORIG_PYTHON_HOME); \
    891891@COMPILE_WITH_IPOPT64_TRUE@ export PATH="$(ORIG_PATH)";
     
    11931193@PYTHON_ENABLED_TRUE@   chmod ugo+x $(DESTDIR)$(prefix)/bin/jm_*.sh
    11941194
    1195 all-local: build-python-packages build-compiler
    1196     $(abs_top_srcdir)/get_version.sh $(abs_top_srcdir) https://svn.jmodelica.org > $(abs_builddir)/version.txt
     1195all-local: build-python-packages build-compiler $(abs_builddir)/version.txt build-extra
     1196
     1197$(abs_builddir)/version.txt: TODO-always-trigger
     1198    $(abs_top_srcdir)/get_version.sh $(abs_top_srcdir) https://svn.jmodelica.org > $(@)
     1199
     1200build-extra: TODO-always-trigger
    11971201    if [ "$(BUILD_EXTRA)" ]; then exec "$(BUILD_EXTRA)" "$(abs_top_srcdir)" "$(DESTDIR)$(prefix)"; fi
    11981202
     
    12571261    if [ "$(INSTALL_EXTRA)" ]; then exec "$(INSTALL_EXTRA)" "$(abs_top_srcdir)" "$(DESTDIR)$(prefix)"; fi
    12581262
    1259 install-compiler: $(ant_output_jars) $(ant_output_options) TODO-always-trigger
     1263install-compiler: $(ant_output_jars) $(ant_output_options)
    12601264@HAVE_ANT_TRUE@ mkdir -p $(DESTDIR)$(prefix)/lib/
    12611265@HAVE_ANT_TRUE@ install -t $(DESTDIR)$(prefix)/lib/ $(ant_output_jars)
    12621266@HAVE_ANT_TRUE@ install -t $(DESTDIR)$(prefix)/ $(ant_output_options)
    12631267
    1264 # Dummy target used to always trigger rebuilds. Used to enable references to
    1265 # outputs from phony targets as real targets. For example ant output.
    1266 TODO-always-trigger: ;
    1267 
    12681268$(ant_output_jars) $(ant_output_options): build-compiler
    12691269
    1270 build-compiler:
     1270build-compiler: TODO-always-trigger
    12711271@HAVE_ANT_TRUE@ mkdir -p $(JAVA_BUILD_DIR)
    12721272@HAVE_ANT_TRUE@ cd $(JAVA_BUILD_DIR); \
     
    12741274@HAVE_ANT_TRUE@ cd $(JAVA_BUILD_DIR); \
    12751275@HAVE_ANT_TRUE@ $(ANT_OPTS) $(ANT) -f "$(JAVA_OC_ANT_FILE)" "-Dcompiler=$(COMPILER_DIR)" "-Dtarget=$(JAVA_BUILD_DIR)"
     1276
     1277# Dummy target used to always trigger rebuilds. Used to enable references to
     1278# outputs from phony targets as real targets. For example ant output.
     1279TODO-always-trigger: ;
    12761280
    12771281install-modules: install-modules-ModelicaFrontEnd
Note: See TracChangeset for help on using the changeset viewer.