Changeset 13843


Ignore:
Timestamp:
Oct 24, 2019 4:01:08 PM (3 weeks ago)
Author:
molsson
Message:

AUTO catchup merge from trunk to branches/dev-mo-2278

Location:
branches/dev-mo-2278
Files:
55 edited
12 copied

Legend:

Unmodified
Added
Removed
  • branches/dev-mo-2278

  • branches/dev-mo-2278/.project

    r5080 r13843  
    77    <buildSpec>
    88        <buildCommand>
    9             <name>org.python.pydev.PyDevBuilder</name>
    10             <arguments>
    11             </arguments>
    12         </buildCommand>
    13         <buildCommand>
    149            <name>org.eclipse.jdt.core.javabuilder</name>
    1510            <arguments>
     
    1914    <natures>
    2015        <nature>org.eclipse.jdt.core.javanature</nature>
    21         <nature>org.python.pydev.pythonNature</nature>
    2216    </natures>
    2317</projectDescription>
  • branches/dev-mo-2278/CHANGELOG.txt

    r13703 r13843  
    11================= Unreleased ==================
     2# Feature ; Minor ; Compiler; #5837
     3Added a pre-compiled evaluator used for evaluating external functions
     4during the compilation (for performance). Activated by the option
     5"external_constant_evaluation_dynamic"
     6
    27# Fixed ; Minor ; Compiler ; #5855
    38Nominal are now always positive in the FMI model description.
  • branches/dev-mo-2278/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenExpressions.jrag

    r13431 r13843  
    13531353    }
    13541354   
    1355     /**
    1356      * Generate the initialization of delay blocks.
    1357      */
    1358     public void FDelayExp.genInit_C(CodePrinter p, CodeStream str, String indent) {
    1359         FExp maxDelayExp = myMaxDelayExp();
     1355    private void FClass.genDelayInitVarDecls_C(CodePrinter p, CodeStream str, String indent) { // Hook to facilitate extensions
     1356        for (FDelayExp d : myDelayExps()) {
     1357            d.genInitVarDecls_C(p, str, indent);
     1358        }
     1359        for (FSpatialDistExp d : mySpatialDistExps()) {
     1360            d.genInitVarDecls_C(p, str, indent);
     1361        }
     1362    }
     1363
     1364    private void FClass.genDelayInitAssignments_C(CodePrinter p, CodeStream str, String indent) { // Hook to facilitate extensions
     1365        for (FDelayExp d : myDelayExps()) {
     1366            d.genInit_C(p, str, indent);
     1367        }
     1368        for (FSpatialDistExp d : mySpatialDistExps()) {
     1369            d.genInit_C(p, str, indent);
     1370        }
     1371    }
     1372   
     1373    public void FClass.genDelayInit_C(CodeStream genPrinter) {
     1374        CodePrinter p = ASTNode.printer_C;
     1375        String indent = p.indent("");
     1376        genDelayInitVarDecls_C(p, genPrinter, indent);
     1377        genDelayInitAssignments_C(p, genPrinter, indent);
     1378    }
     1379
     1380    private void FDelayExp.prepareInit_C(CodePrinter p, CodeStream str, String indent, int delayIndex) {
     1381        FExp maxDelayExp = myMaxDelayExp();
    13601382        boolean fixed = isTimeEventGenerating();
    1361         p.printPreSteps(getFExp(), str, indent);
     1383        p.printPreSteps(getFExp(), str, indent);
    13621384        p.printPreSteps(maxDelayExp, str, indent);
    1363        
    1364         str.format("%sjmi_delay_init(jmi, %d, ", indent, myDelayIndex());
     1385        str.format("%sjmi_delay_init(jmi, %d, ", indent, delayIndex);
    13651386        str.print(boolValue_C(fixed)); // jmi_boolean fixed
    13661387        str.print(", ");
     
    13681389        str.print(", ");
    13691390        p.print(fixed ? getDelay() : maxDelayExp, str, indent); // jmi_real_t max_delay
    1370         str.print(", ");
    1371         p.print(getFExp(), str, indent); // jmi_real_t y0
    1372         str.println(");");
    1373        
     1391        str.print(", ");
     1392
     1393    }
     1394
     1395    private void FDelayExp.finalizeInit_C(CodePrinter p, CodeStream str, String indent) {
     1396        str.println(");");
    13741397        p.printPostSteps(getFExp(), str, indent);
    1375         p.printPostSteps(maxDelayExp, str, indent);
     1398        p.printPostSteps(myMaxDelayExp(), str, indent);
     1399    }
     1400   
     1401    /**
     1402     * Generate the initialization of delay blocks.
     1403     */
     1404    public void FDelayExp.genInit_C(CodePrinter p, CodeStream str, String indent) {
     1405        prepareInit_C(p, str, indent, myDelayIndex());
     1406        p.print(getFExp(), str, indent); // jmi_real_t y0
     1407        finalizeInit_C(p, str, indent);
    13761408    }
    13771409    syn FExp FDelayExp.myMaxDelayExp() = hasMax() ? getMax() : getDelay();
  • branches/dev-mo-2278/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenExternalCeval.jrag

    r13703 r13843  
    248248        Collection<ExternalArgument> res = new LinkedHashSet<>();
    249249        if (hasReturnVar()) {
    250             res.add(getReturnVar().externalArgument());
    251         }
     250            res.add(returnVarToSerialize());
     251        }
     252        res.addAll(argVarsToSerialize());
     253        return res;
     254    }
     255   
     256    syn ExternalArgument FExternalStmt.returnVarToSerialize() = getReturnVar().externalArgument();
     257    syn Collection<ExternalArgument> FExternalStmt.argVarsToSerialize() {
     258        Collection<ExternalArgument> res = new LinkedHashSet<>();
    252259        for (FExp e : getArgs()) {
    253260            res.add(e.externalArgument());
     
    288295        }
    289296        return functionArgs;
     297    }
     298   
     299
     300    syn String FType.cMappedTypeString() = cMappedTypeStringScalar() + (isArray() ? "v" : "");
     301
     302    syn String FType.cMappedTypeStringScalar() {
     303        throw new InternalCompilerError("cMappedTypeStringScalar() is not supported for class type " + getClass().getSimpleName());
     304    }
     305    eq FArrayType.cMappedTypeStringScalar() = getFPrimitiveType().cMappedTypeStringScalar();
     306    eq FIntegerType.cMappedTypeStringScalar() = "i";
     307    eq FEnumType.cMappedTypeStringScalar() = "i";
     308    eq FBooleanType.cMappedTypeStringScalar() = "i";
     309    eq FRealType.cMappedTypeStringScalar() = "d";
     310    eq FStringType.cMappedTypeStringScalar() = "s";
     311    eq FRecordType.cMappedTypeStringScalar() {
     312        String o = "R[";
     313        for (FRecordComponentType rType: getComponents()) {
     314                o = o.concat(rType.getFType().cMappedTypeStringScalar());
     315                o = o.concat(",");
     316        }
     317        return o.concat("]");
     318    }
     319   
     320    syn String FExternalStmt.functionReturnArgSerialized() {
     321        if (hasReturnVar()) {
     322            return returnVarToSerialize().type().cMappedTypeString();
     323        } else {
     324            return "void";
     325        }
     326    }
     327   
     328    syn String FExternalStmt.functionArgsSerialized() {
     329        String input = "";
     330        for (ExternalArgument var : argVarsToSerialize()) {
     331            if (var.isOutput()) {
     332               input = input.concat("*");
     333            }
     334            input += var.type().cMappedTypeString() + ",";
     335        }
     336        return input;
    290337    }
    291338   
     
    347394            }
    348395        }
     396    }
     397   
     398    public String FClass.externalCTypes() {
     399        StringBuilder sb = new StringBuilder();
     400        for (FExternalStmt stmt : myExternals()) {
     401            if (stmt.dynamicEvaluatorEnabled()) {
     402                sb.append(stmt.getName());
     403                sb.append("\n");
     404                sb.append(stmt.functionReturnArgSerialized());
     405                sb.append("\n");
     406                sb.append(stmt.functionArgsSerialized());
     407                sb.append("\n");
     408            }
     409        }
     410        return sb.toString();
    349411    }
    350412
  • branches/dev-mo-2278/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CGenerator.jrag

    r12423 r13843  
    2121
    2222import java.io.*;
     23
     24aspect CGenerator {
    2325
    2426public class CGenerator extends GenericGenerator {
     
    12461248       
    12471249        public void generate(CodeStream genPrinter) {
    1248             genPrinter.print(fclass.myDelayExps().size());
     1250            genPrinter.print(fclass.numberOfDelaysInCCode());
    12491251        }
    12501252    }
     
    13041306       
    13051307        public void generate(CodeStream genPrinter) {
    1306             CodePrinter p = ASTNode.printer_C;
    1307             String indent = p.indent("");
    1308             for (FDelayExp d : fclass.myDelayExps()) {
    1309                 d.genInitVarDecls_C(p, genPrinter, indent);
    1310             }
    1311             for (FSpatialDistExp d : fclass.mySpatialDistExps()) {
    1312                 d.genInitVarDecls_C(p, genPrinter, indent);
    1313             }
    1314             for (FDelayExp d : fclass.myDelayExps()) {
    1315                 d.genInit_C(p, genPrinter, indent);
    1316             }
    1317             for (FSpatialDistExp d : fclass.mySpatialDistExps()) {
    1318                 d.genInit_C(p, genPrinter, indent);
    1319             }
     1308            fclass.genDelayInit_C(genPrinter);
    13201309        }
    13211310    }
     
    15781567    }
    15791568}
     1569
     1570    syn int FClass.numberOfDelaysInCCode() = myDelayExps().size(); // Hook to facilitate extensions
     1571}
  • branches/dev-mo-2278/Compiler/ModelicaCBackEnd/templates/ceval_external_template.c

    r13703 r13843  
    1414*/
    1515
    16 #include <stdio.h>
    17 #include <stdlib.h>
    18 #include <string.h>
    19 #include "jmi.h"
    20 #include "jmi_dyn_mem.h"
    21 #include "ModelicaUtilities.h"
    22 #include <fcntl.h>
     16#include "jmi_evaluator_util.h"
     17
     18/* Must be defined here in order to override the methods from jmi_global.c */
     19void jmi_global_log(int warning, const char* name, const char* fmt, const char* value) {
     20    _jmi_global_log(warning, name, fmt, value);
     21}
     22void jmi_throw() {
     23    _jmi_throw();
     24}
     25void* jmi_global_calloc(size_t n, size_t s) {
     26    return _jmi_global_calloc(n,s);
     27}
    2328
    2429$ECE_external_includes$
    2530 
    26 /* Manual debugging */
    27 #define JMCEVAL_DEBUG 0
    28 #define JMCEVAL_DBGP(x) if (JMCEVAL_DEBUG) { printf(x); fflush(stdout);}
    29 
    30 /* Format specifier when printing jmi_real_t */
    31 #define JMCEVAL_realFormat "%.16f"
    32 
    3331/* Used record definitions */
    3432$ECE_record_definitions$
    35 
    36 /* Parses ND dimensions into dimension buffer d*/
    37 #define JMCEVAL_parseArrayDims(ND) \
    38     for (di = 0; di < ND; di++) { scanf("%d",&d[di]); }
    39 
    40 /* Parse/print basic types */
    41 double JMCEVAL_parseReal() {
    42     /* Char buffer when reading jmi_real_t. This is necessary
    43        since "%lf" is not allowed in c89. */
    44     char buff[32];
    45     JMCEVAL_DBGP("Parse number: ");
    46     scanf("%s",buff);
    47     return strtod(buff, 0);
    48 }
    49 
    50 void JMCEVAL_printReal(double x) {
    51     printf(JMCEVAL_realFormat, x); \
    52     printf("\n"); \
    53     fflush(stdout); \
    54 }
    55 
    56 char* JMCEVAL_parseString() {
    57     int d[1];
    58     char* str;
    59     size_t si,di;
    60     JMCEVAL_parseArrayDims(1);
    61     getchar();
    62     str = ModelicaAllocateString(d[0]);
    63     JMCEVAL_DBGP("Parse string: ");
    64     for (si = 0; si < d[0]; si++) str[si] = getchar();
    65     str[d[0]] = '\0';
    66     return str;
    67 }
    68 
    69 void JMCEVAL_printString(const char* str) {
    70     printf("%u\n%s\n", (unsigned)strlen(str), str);
    71     fflush(stdout);
    72 }
    73 
    74 #define JMCEVAL_parseInteger()  JMCEVAL_parseReal()
    75 #define JMCEVAL_parseBoolean()  JMCEVAL_parseInteger()
    76 #define JMCEVAL_parseEnum()     JMCEVAL_parseInteger()
    77 #define JMCEVAL_printInteger(X) JMCEVAL_printReal(X)
    78 #define JMCEVAL_printBoolean(X) JMCEVAL_printInteger(X)
    79 #define JMCEVAL_printEnum(X)    JMCEVAL_printInteger(X)
    80 #define JMCEVAL_parse(TYPE, X)  X = JMCEVAL_parse##TYPE()
    81 #define JMCEVAL_print(TYPE, X)  JMCEVAL_print##TYPE(X)
    82 
    83 /* Parse/print arrays */
    84 #define JMCEVAL_parseArray(TYPE,ARR) for (vi = 1; vi <= ARR->num_elems; vi++) { JMCEVAL_parse(TYPE, jmi_array_ref_1(ARR,vi)); }
    85 #define JMCEVAL_printArray(TYPE,ARR) for (vi = 1; vi <= ARR->num_elems; vi++) { JMCEVAL_print(TYPE, jmi_array_val_1(ARR,vi)); }
    86 
    87 /* Used by ModelicaUtilities */
    88 void jmi_global_log(int warning, const char* name, const char* fmt, const char* value)
    89 {
    90     printf("LOG\n");
    91     JMCEVAL_printInteger((double)warning);
    92     JMCEVAL_printString(name);
    93     JMCEVAL_printString(fmt);
    94     JMCEVAL_printString(value);
    95 }
    96 
    97 jmp_buf jmceval_try_location;
    98 
    99 #define JMCEVAL_try() (setjmp(jmceval_try_location) == 0)
    100 
    101 void jmi_throw()
    102 {
    103     longjmp(jmceval_try_location, 1);
    104 }
    105 
    106 jmi_dynamic_function_memory_t* dyn_fcn_mem = NULL;
    107 
    108 jmi_dynamic_function_memory_t* jmi_dynamic_function_memory() {
    109     if (dyn_fcn_mem == NULL) { dyn_fcn_mem = jmi_dynamic_function_pool_create(1024*1024); }
    110     return dyn_fcn_mem;
    111 }
    112 
    113 void* jmi_global_calloc(size_t n, size_t s)
    114 {
    115     return jmi_dynamic_function_pool_direct_alloc(dyn_fcn_mem, n*s, 1);
    116 }
    117 
    118 void JMCEVAL_setup() {
    119 #ifdef _WIN32
    120     /* Prevent win from translating \n to \r\n */
    121     _setmode(fileno(stdout), _O_BINARY);
    122 #endif
    123 }
    124 
    125 int JMCEVAL_cont(const char* word) {
    126     char l[10];
    127     char* s = fgets(l, 10, stdin);
    128     if (strlen(s) == 1) {
    129         s = fgets(l, 10, stdin); /* Extra call to fix stray newline */
    130     }
    131     if (s == NULL) {
    132         exit(2);
    133     }
    134     if (strlen(s) == strlen(word)) {
    135         return strncmp(l, word, strlen(word)) == 0;
    136     }
    137     return 0;
    138 }
    139 
    140 void JMCEVAL_check(const char* str) {
    141     printf("%s\n",str);
    142     fflush(stdout);
    143 }
    144 
    145 void JMCEVAL_failed() {
    146     JMCEVAL_check("ABORT");
    147 }
    14833
    14934/* Main */
     
    19580        JMCEVAL_failed();
    19681    }
    197     jmi_dynamic_function_pool_destroy(dyn_fcn_mem);
     82    _jmi_dynamic_function_pool_destroy();
    19883    JMCEVAL_check("END");
    19984    return 0;
  • branches/dev-mo-2278/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenExternalCevalTests.mo

    r13703 r13843  
    1717
    1818package CCodeGenExternalCevalTests
     19
     20model ExtDynFcn1
     21        type E = enumeration(A,B);
     22    function f
     23        input Real a1;
     24        input Integer a2;
     25        input Boolean a3;
     26        input String a4;
     27        input E a5;
     28        output Real b1;
     29        output Integer b2;
     30        output Boolean b3;
     31        output String b4;
     32        output E b5;
     33        external;
     34    end f;
     35   
     36    Real x1;
     37    Integer x2;
     38    Boolean x3;
     39    String x4;
     40    E x5;
     41equation
     42    (x1,x2,x3,x4,x5) = f(1,2,true,"s",E.A);
     43
     44    annotation(__JModelica(UnitTesting(tests={
     45        FClassMethodTestCase(
     46            name="ExtDynFcn1",
     47            methodName="externalCTypes",
     48            description="Test that the different primitive types generates the correct C mapping",
     49            external_constant_evaluation_dynamic=true,
     50            methodResult="
     51f
     52void
     53d,i,i,s,i,*d,*i,*i,*s,*i,
     54")})));
     55end ExtDynFcn1;
     56
     57model ExtDynFcn2
     58type E = enumeration(A,B);
     59function f
     60    input Real[:] a1;
     61    input Integer[:] a2;
     62    input Boolean[:] a3;
     63    input String[:] a4;
     64    input E[:] a5;
     65    output Real[size(a1,1)] b1;
     66    output Integer[size(a2,1)] b2;
     67    output Boolean[size(a3,1)] b3;
     68    output String[size(a4,1)] b4;
     69    output E[size(a5,1)] b5;
     70    external;
     71end f;
     72    Real[1] x1;
     73    Integer[1] x2;
     74    Boolean[1] x3;
     75    String[1] x4;
     76    E[1] x5;
     77equation
     78    (x1,x2,x3,x4,x5) = f({1},{2},{true},{"s"},{E.A});
     79
     80    annotation(__JModelica(UnitTesting(tests={
     81        FClassMethodTestCase(
     82            name="ExtDynFcn2",
     83            methodName="externalCTypes",
     84            description="Test that the different primitive types (arrays of) generates the correct C mapping",
     85            external_constant_evaluation_dynamic=true,
     86            methodResult="
     87f
     88void
     89dv,i,iv,i,iv,i,sv,i,iv,i,*dv,i,*iv,i,*iv,i,*sv,i,*iv,i,
     90")})));
     91end ExtDynFcn2;
     92
     93model ExtDynFcn3
     94    type E = enumeration(A,B);
     95    record R
     96        Real a1;
     97        Integer a2;
     98        Boolean a3;
     99        String a4;
     100        E a5;
     101        R2 r2;
     102    end R;
     103    record R2
     104        Real x;
     105    end R2;
     106   
     107    function f
     108        input R a;
     109        output R b;
     110        external f(a,b);
     111    end f;
     112   
     113    R r = f(R(1,2,true,"s",E.A, R2(3)));
     114
     115    annotation(__JModelica(UnitTesting(tests={
     116        FClassMethodTestCase(
     117            name="ExtDynFcn3",
     118            methodName="externalCTypes",
     119            description="Test that records generates the correct C mapping",
     120            external_constant_evaluation_dynamic=true,
     121            methodResult="
     122f
     123void
     124R[d,i,i,s,i,R[d,],],*R[d,i,i,s,i,R[d,],],
     125")})));
     126end ExtDynFcn3;
     127
    19128
    20129model Scalar
     
    789898end ExtObj5;
    790899
     900model ExtDynObj1
     901    function use1
     902        input  Os.Obj1 o1;
     903        output Real x;
     904        external annotation(Library="extObjectsUse", Include="#include \"extObjectsUse.h\"",
     905            LibraryDirectory="modelica://Library2", IncludeDirectory="Include2");
     906    end use1;
     907
     908    Os.Obj1 o1 = Os.Obj1(3.13, 3, true, "A message");
     909    Real x = use1(o1);
     910
     911    annotation(__JModelica(UnitTesting(tests={
     912        FClassMethodTestCase(
     913            name="ExtDynObj1",
     914            methodName="externalCTypes",
     915            description="Verifies that external objects are not handled by the dynamic evaluator",
     916            methodResult="
     917")})));
     918end ExtDynObj1;
     919
     920
    791921model Dgelsx
    792922    function dgelsx
  • branches/dev-mo-2278/Compiler/ModelicaCompiler/module.options

    r13703 r13843  
    136136external objects during compilation.If less than 1, no processes will be kept
    137137alive, i.e. this feature is turned off."
     138
     139********************************************************************************
     140BOOLEAN external_constant_evaluation_dynamic compiler experimental false
     141
     142"If enabled, calls to external functions will be evaluated during compilation
     143using a pre-compiled program (instead of generating and compiling one), if
     144possible."
    138145
    139146********************************************************************************
     
    458465
    459466********************************************************************************
    460 
  • branches/dev-mo-2278/Compiler/ModelicaCompiler/runtime.options

    r11347 r13843  
    221221"Compares the analytic block jacobians with the finite difference block
    222222jacobians during block evaluation. An error is given if the relative error is
    223 to big."
     223too big."
    224224
    225225********************************************************************************
  • branches/dev-mo-2278/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13715 r13843  
    12581258        /* Temporary fix to problems with long compilation times due to later evaluations */
    12591259        getExternalFunctionCache().tearDown();
    1260         options.setIntegerOption("external_constant_evaluation", 0);
     1260        options.external_constant_evaluation.setValue(0);
    12611261       
    12621262        hookModelTransformed(fc);
     
    20452045            InstClassDecl icl = instantiateModel(name, cl, target);
    20462046            UtilInterface util = icl.root().getUtilInterface();
     2047            String flatName = null;
    20472048            if (compileTo != null) {
    20482049                Path unitFile = makePackagingDirs(cl, compileTo, target);
    20492050                util.setCompilationOutputPath(unitFile);
     2051                flatName = computeFlatName(compileTo, util);
    20502052            }
    2051            
    2052             String flatName = computeFlatName(compileTo, util);
    20532053           
    20542054            // flattening
     
    22802280    private String ModelicaCompiler.computeFlatName(Path compileTo, UtilInterface util) {
    22812281        String flatName = null;
    2282         if (compileTo != null && !Files.isDirectory(compileTo)) {
     2282        if (!Files.isDirectory(compileTo)) {
    22832283            flatName = compileTo.getFileName().toString();
    22842284            int i = flatName.lastIndexOf('.');
  • branches/dev-mo-2278/Compiler/ModelicaCompiler/src/java/org/jmodelica/util/ccompiler/CCompilerDelegator.java

    r13703 r13843  
    351351        };
    352352    }
     353
     354    public abstract Set<String> expandCompilerSpecificLibraryPaths(ModelicaLogger log, AbstractOptionRegistry options,
     355            Set<String> extLibDirs, String platform);
    353356}
    354357
  • branches/dev-mo-2278/Compiler/ModelicaCompiler/src/java/org/jmodelica/util/ccompiler/GccCompilerDelegator.java

    r13703 r13843  
    2626import java.util.Set;
    2727
     28import org.jmodelica.common.options.AbstractOptionRegistry;
    2829import org.jmodelica.util.EnvironmentUtils;
    2930import org.jmodelica.util.exceptions.CcodeCompilationException;
     
    106107            vars.put("AR", new File(mingw_bin, "ar").getPath());
    107108        }
     109    }
     110   
     111    @Override
     112    public Set<String> expandCompilerSpecificLibraryPaths(ModelicaLogger log, AbstractOptionRegistry options, Set<String> extLibDirs, String platform) {
     113        Set<String> expandedLibDirs = expandLibraries(extLibDirs, platform, "gcc" + compilerVersionNumber());
     114        return expandedLibDirs;
    108115    }
    109116   
  • branches/dev-mo-2278/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ConstantEvaluation.jrag

    r13703 r13843  
    50795079        }
    50805080       
    5081         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5081        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    50825082            return new AlgorithmEvaluator(externalEvaluationEnabled, options, values);
    50835083        }
    50845084       
    5085         public AlgorithmEvaluator createEmptyAlgorithmEvaluator(AbstractOptionRegistry options) {
     5085        public AlgorithmEvaluator createEmptyAlgorithmEvaluator(OptionRegistry options) {
    50865086            return new AlgorithmEvaluator(true, options, Collections.<CommonVariableDecl, CValue>emptyMap());
    50875087        }
     
    51495149       
    51505150        @Override
    5151         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5151        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    51525152            return new PartialAlgorithmEvaluator(externalEvaluationEnabled(), options, values, this);
    51535153        }
     
    51835183       
    51845184        @Override
    5185         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5185        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    51865186            if (this.values == null) {
    51875187                this.values = values;
     
    52775277    public class AlgorithmEvaluator extends VariableEvaluator {
    52785278       
    5279         protected Map<CommonVariableDecl, CValue> values;
    5280         private AbstractOptionRegistry options;
    5281        
    5282         public AlgorithmEvaluator(boolean evaluateExternalEnabled, AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5279        protected final Map<CommonVariableDecl, CValue> values;
     5280        private final OptionRegistry options;
     5281       
     5282        public AlgorithmEvaluator(boolean evaluateExternalEnabled, OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    52835283            super(evaluateExternalEnabled);
    52845284            this.values  = values;
     
    52875287       
    52885288        public int externalEvaluation() {
    5289             return externalEvaluationEnabled() ? options.getIntegerOption("external_constant_evaluation") : 0;
     5289            return externalEvaluationEnabled() ? options.external_constant_evaluation.getValue() : 0;
    52905290        }
    52915291       
     
    53515351        protected ArrayList<IfEvaluation> ifStack;
    53525352       
    5353         public PartialAlgorithmEvaluator(boolean evaluateExternalEnabled, AbstractOptionRegistry options,
     5353        public PartialAlgorithmEvaluator(boolean evaluateExternalEnabled, OptionRegistry options,
    53545354                Map<CommonVariableDecl, CValue> values, PartialVariableEvaluator variableEvaluator) {
    53555355            super(evaluateExternalEnabled, options, values);
     
    53685368       
    53695369        @Override
    5370         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5370        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    53715371            return variableEvaluator.createAlgorithmEvaluator(options, values);
    53725372        }
  • branches/dev-mo-2278/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ExternalConstantEvaluation.jrag

    r13703 r13843  
    2626import java.util.TimerTask;
    2727
     28import org.jmodelica.common.evaluation.ExternalFunctionCompiler;
    2829import org.jmodelica.common.evaluation.ExternalFunction;
    2930import org.jmodelica.common.evaluation.ExternalProcessCache;
    3031import org.jmodelica.common.evaluation.ExternalProcessCacheImpl;
    3132import org.jmodelica.common.evaluation.ExternalProcessMultiCache;
     33import org.jmodelica.common.evaluation.FailedExternalFunction;
    3234import org.jmodelica.common.evaluation.ProcessCommunicator;
    3335
     
    4951    class ModelicaCompiler {}
    5052   
    51     ModelicaCompiler   implements ExternalProcessMultiCache.Compiler<ExternalArgument, FExternalStmt>;
     53    ModelicaCompiler   implements ExternalFunctionCompiler<ExternalArgument, FExternalStmt>;
    5254    FExternalStmt      implements ExternalProcessMultiCache.External<ExternalArgument>;
    5355    ExternalArgument   extends    ExternalProcessMultiCache.Variable<CValue,FType>;
     
    8991     * Check if this external function should be cached as a live process.
    9092     */
    91     syn boolean FExternalStmt.shouldCacheProcess() {
    92         return myOptions().getIntegerOption("external_constant_evaluation_max_proc") > 0;
    93     }
     93    syn int FExternalStmt.processLimit() =
     94            myOptions().external_constant_evaluation_max_proc.getValue();
     95   
     96    syn boolean FExternalStmt.dynamicEvaluatorEnabled() =
     97            myOptions().external_constant_evaluation_dynamic.getValue()
     98            && !externalObjectsToSerialize().iterator().hasNext();
    9499   
    95100    /**
     
    169174        ExternalFunctionCache efc = root().getUtilInterface().getExternalFunctionCache();
    170175        if (efc == null) {
    171             return new ExternalProcessCacheImpl<>(root().getUtilInterface().getModelicaCompiler())
    172                 .failedEval(this, "external function cache unavailable", false);
     176            return FailedExternalFunction.<ExternalArgument, CValue, FType, FExternalStmt>failedEval(
     177                    root().getUtilInterface().getModelicaCompiler(),
     178                    this, "external function cache unavailable", false);
    173179        }
    174180        return efc.getExternalProcessCache(getLibTopPackagePath()).getExternalFunction(this);
     
    205211       
    206212        if (error != null) {
    207             throw new ConstantEvaluationException(null, ExternalProcessCacheImpl.failedEvalMsg(getName(), error));
     213            throw new ConstantEvaluationException(null, FailedExternalFunction.failedEvalMsg(getName(), error));
    208214        }
    209215       
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/jastadd/util/Util.jrag

    r13476 r13843  
    15841584
    15851585    syn boolean SrcBaseNode.isLibNode() = false;
    1586     eq SrcLibNode.isLibNode()            = true;
     1586    eq SrcLibNode.isLibNode()           = true;
     1587    syn SrcLibNode SrcBaseNode.asSrcLibNode() {
     1588        throw new UnsupportedOperationException();
     1589    }
     1590    syn SrcLibNode SrcLibNode.asSrcLibNode() = this;
    15871591}
    15881592
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalFunctionExecutableGenerated.java

    r13720 r13843  
    1717    @Override
    1818    public void remove() {
    19         new File(executable).delete();
     19        File file = new File(executable);
     20        boolean success = file.delete();
     21        // The first attempt to delete may fail if the process has not terminated yet.
     22        // Possibly not necessary since LiveExternalFunction.destroyProcess() now calls ProcessCommunicator.teardown().
     23        if (!success) {
     24            try {
     25                Thread.sleep(10); // Sleep some arbitrary duration to give the process time to die.
     26            } catch (InterruptedException e) {
     27                // Ignore
     28            }
     29            success = file.delete();
     30        }
    2031    }
    2132}
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalFunctionImpl.java

    r13720 r13843  
    4545            setup(ext, values, timeout, com);
    4646            evaluate(ext, values, timeout, com);
    47             return teardown(timeout, com);
     47            return com.teardown(timeout);
    4848        } finally {
    4949            if (com != null) {
     
    7979        com.accept("READY");
    8080        com.cancelTimer();
    81     }
    82 
    83     public int teardown(int timeout, ProcessCommunicator<V, T> com) throws IOException {
    84         com.startTimer(timeout);
    85         com.check("EXIT");
    86         com.accept("END");
    87         int result = com.end();
    88         com.cancelTimer();
    89         // log().debug("SUCCESS TEARDOWN");
    90         return result;
    9181    }
    9282
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessCache.java

    r13703 r13843  
    2424
    2525    protected abstract void tearDown();
    26 
    27     public abstract ExternalFunction<K, V> failedEval(External<?> ext, String msg, boolean log);
    2826   
    2927
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessCacheImpl.java

    r13703 r13843  
    33import java.io.File;
    44import java.io.FileNotFoundException;
    5 import java.io.IOException;
    65import java.io.PrintStream;
    76import java.util.ArrayList;
     7import java.util.Arrays;
     8import java.util.Collection;
    89import java.util.HashMap;
     10import java.util.HashSet;
    911import java.util.LinkedHashSet;
    1012import java.util.Map;
    11 
    12 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Compiler;
     13import java.util.Set;
     14
    1315import org.jmodelica.common.evaluation.ExternalProcessMultiCache.External;
    1416import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Type;
     
    1618import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Variable;
    1719import org.jmodelica.util.EnvironmentUtils;
     20import org.jmodelica.util.SystemUtil;
    1821import org.jmodelica.util.ccompiler.CCompilerDelegator;
    1922import org.jmodelica.util.exceptions.CcodeCompilationException;
    2023import org.jmodelica.util.logging.ModelicaLogger;
    21 import org.jmodelica.util.values.ConstantEvaluationException;
    2224
    2325public class ExternalProcessCacheImpl<K extends Variable<V, T>, V extends Value, T extends Type<V>, E extends External<K>> extends ExternalProcessCache<K, V, T, E> {
     
    2628     * Maps external functions names to compiled executables.
    2729     */
    28     private Map<String, ExternalFunction<K, V>> cachedExternals = new HashMap<String, ExternalFunction<K, V>>();
     30    private final Map<String, ExternalFunction<K, V>> cachedExternals = new HashMap<String, ExternalFunction<K, V>>();
    2931
    3032    /**
    3133     * Keeps track of all living processes, least recently used first.
    3234     */
    33     private LinkedHashSet<ExternalFunction<K, V>> livingCachedExternals = new LinkedHashSet<ExternalFunction<K, V>>();
    34 
    35     private Compiler<K, E> mc;
    36 
    37     public ExternalProcessCacheImpl(Compiler<K, E> mc) {
     35    private final LinkedHashSet<ExternalFunction<K, V>> livingCachedExternals = new LinkedHashSet<ExternalFunction<K, V>>();
     36
     37    private final ExternalFunctionCompiler<K, E> mc;
     38
     39    public ExternalProcessCacheImpl(ExternalFunctionCompiler<K, E> mc) {
    3840        this.mc = mc;
    3941    }
     
    4244        return mc.log();
    4345    }
    44 
     46   
     47    private String getPlatform() {
     48        return CCompilerDelegator.reduceBits(EnvironmentUtils.getJavaPlatform(),
     49                mc.getCCompiler().getTargetPlatforms());
     50    }
     51   
     52    private String getSharedLibrary(External<K> ext) {
     53        String sharedLib = "";
     54        String extLibrary = "";
     55       
     56        if (ext.library() != null && ext.library().length == 1) {
     57            extLibrary = ext.library()[0];
     58        } else {
     59            return sharedLib;
     60        }
     61       
     62        HashSet<String> externalLibraryDirectories = new HashSet<String>();
     63        externalLibraryDirectories.add(ext.libraryDirectory());
     64        Set<String> expandedLibDirs = mc.getCCompiler().expandCompilerSpecificLibraryPaths(mc.log(), ext.myOptions(),
     65                                                   externalLibraryDirectories, getPlatform());
     66       
     67        for (String dir : expandedLibDirs) {
     68            File testlib1 = new File(dir, extLibrary + SystemUtil.sharedLibraryExtension());
     69            File testlib2 = new File(dir, "lib" + extLibrary + SystemUtil.sharedLibraryExtension());
     70           
     71            if (testlib1.exists() && !testlib1.isDirectory()) {
     72                sharedLib = testlib1.toString();
     73                break;
     74            }
     75            if (testlib2.exists() && !testlib2.isDirectory()) {
     76                sharedLib = testlib2.toString();
     77                break;
     78            }
     79        }
     80       
     81        return sharedLib;
     82    }
     83   
     84    private static Collection<String> builtinExternalFunctions = Arrays.asList(
     85        "ModelicaStrings_substring",
     86        "ModelicaStrings_length",
     87        "ModelicaStrings_skipWhiteSpace",
     88        "ModelicaStrings_compare"
     89    );
     90   
     91    private static Collection<String> supportedSignatures = Arrays.asList(
     92        "d+d,d,",
     93        "d+i,",
     94        "d+i,d,d,",
     95        "s+s,i,i,",
     96        "i+s,",
     97        "i+s,i,",
     98        "i+s,s,i,",
     99        "i+i,i,",
     100        "void+i,d,d,*R[d,d,d,d,d,d,d,d,d,d,d,],",
     101        "void+d,d,*d,"
     102    );
     103   
     104    public boolean canUseEvaluator(E ext, ArrayList<String> arguments) {
     105        if (!ext.dynamicEvaluatorEnabled()) {
     106            return false;
     107        }
     108       
     109        String sharedLibrary = getSharedLibrary(ext);
     110        String functionName  = ext.getName();
     111        String outputArguments = ext.functionReturnArgSerialized();
     112        String inputArguments  = ext.functionArgsSerialized();
     113       
     114        if (sharedLibrary.equals("")) {
     115            if (builtinExternalFunctions.contains(functionName)) {
     116                sharedLibrary = "NoSharedLibrary";
     117            } else {
     118                mc.log().debug("Could not find a shared library containing '" + functionName + "'. Disabling use of the evaluator...");
     119                return false;
     120            }
     121        }
     122       
     123        if (!supportedSignatures.contains(outputArguments+"+"+inputArguments)) {
     124            mc.log().debug("The function signature, outputs '" + outputArguments + "', inputs '" + inputArguments + "', is not supported. Disabling use of the evaluator...");
     125            return false;
     126        }
     127       
     128        arguments.add(sharedLibrary);
     129        arguments.add(functionName);
     130        arguments.add(outputArguments);
     131        arguments.add(inputArguments);
     132
     133        return true;
     134    }
     135   
    45136    @Override
    46137    public ExternalFunction<K, V> getExternalFunction(E ext) {
     
    48139        if (ef == null) {
    49140            if (mc == null) {
    50                 return failedEval(ext, "Missing ModelicaCompiler", false);
     141                return FailedExternalFunction.<K,V,T,E>failedEval(mc, ext, "Missing ModelicaCompiler", false);
    51142            }
    52143            try {
    53144                long time = System.currentTimeMillis();
    54                 String executable = mc.compileExternal(ext);
    55                 if (ext.shouldCacheProcess()) {
    56                     ef = new MappedExternalFunction(ext, executable);
     145                String executable = null;
     146                ArrayList<String> arguments = new ArrayList<String>();
     147                String debugMsg = "";
     148                ExternalFunctionExecutable extFunctionExecutable;
     149                if (canUseEvaluator(ext, arguments)) {
     150                    String jmHome = System.getenv("JMODELICA_HOME");
     151                    String bits = getPlatform().contains("64") && SystemUtil.isWindows() ? "64" : "";
     152                    executable = jmHome + File.separator + "bin" + bits + File.separator + "jmi_evaluator" + SystemUtil.executableExtension();
     153                   
     154                    arguments.add(0, executable); /* Needs to be first */
     155                   
     156                    extFunctionExecutable = new ExternalFunctionExecutableDynamic(arguments);
     157                   
     158                    debugMsg = "Succesfully connected external function '" + ext.getName() + "' to the evaluator '"
     159                            + executable + "' with outputs: '" + ext.functionReturnArgSerialized() + "' and inputs: '" + ext.functionArgsSerialized() + "'";
    57160                } else {
    58                     ef = new CompiledExternalFunction(ext, executable);
     161                    executable = mc.compileExternal(ext);
     162                   
     163                    extFunctionExecutable = new ExternalFunctionExecutableGenerated(executable);
     164                   
     165                    debugMsg = "Succesfully compiled external function '" + ext.getName() + "' to executable '"
     166                            + executable + "' code for evaluation";
     167                }
     168               
     169                if (ext.processLimit() > 0) {
     170                    ef = new MappedExternalFunction<K,V,T,E>(mc, ext, extFunctionExecutable, livingCachedExternals);
     171                } else {
     172                    ef = new ExternalFunctionImpl<K,V,T,E>(mc, ext, extFunctionExecutable);
    59173                }
    60174                time = System.currentTimeMillis() - time;
    61                 mc.log().debug("Succesfully compiled external function '" + ext.getName() + "' to executable '"
    62                         + executable + "' code for evaluation, time: " + time + "ms");
     175                mc.log().debug(debugMsg +", time: " + time + "ms");
    63176            } catch (FileNotFoundException e) {
    64                 ef = failedEval(ext, "c-code generation failed '" + e.getMessage() + "'", true);
     177                ef = FailedExternalFunction.<K,V,T,E>failedEval(mc, ext, "c-code generation failed '" + e.getMessage() + "'", true);
    65178                mc.log().debug(ef.getMessage());
    66179            } catch (CcodeCompilationException e) {
    67                 ef = failedEval(ext, "c-code compilation failed '" + e.getMessage() + "'", true);
     180                ef = FailedExternalFunction.<K,V,T,E>failedEval(mc, ext, "c-code compilation failed '" + e.getMessage() + "'", true);
    68181                mc.log().debug(ef.getMessage());
    69182                e.printStackTrace(new PrintStream(mc.log().debugStream()));
     
    95208    }
    96209
    97     @Override
    98     public ExternalFunction<K, V> failedEval(External<?> ext, String msg, boolean log) {
    99         return new FailedExternalFunction(failedEvalMsg(ext.getName(), msg), log);
    100     }
    101 
    102     public static String failedEvalMsg(String name, String msg) {
    103         return "Failed to evaluate external function '" + name + "', " + msg;
    104     }
    105 
    106     private class FailedExternalFunction implements ExternalFunction<K, V> {
    107         private String msg;
    108         private boolean log;
    109 
    110         public FailedExternalFunction(String msg, boolean log) {
    111             this.msg = msg;
    112             this.log = log;
    113         }
    114 
    115         @Override
    116         public String getMessage() {
    117             return msg;
    118         }
    119 
    120         @Override
    121         public int evaluate(External<K> ext, Map<K, V> values, int timeout) throws IOException {
    122             if (log) {
    123                 log().debug("Evaluating failed external function: " + ext.getName());
    124             }
    125             throw new ConstantEvaluationException(null, getMessage());
    126         }
    127 
    128         @Override
    129         public void destroyProcess() {
    130             // Do nothing
    131         }
    132 
    133         @Override
    134         public void remove() {
    135             // Do nothing
    136         }
    137     }
    138 
    139     /**
    140      * Represents an external function that has been compiled successfully.
    141      */
    142     private class CompiledExternalFunction implements ExternalFunction<K, V> {
    143         protected String executable;
    144         protected ProcessBuilder processBuilder;
    145         private String msg;
    146 
    147         public CompiledExternalFunction(External<K> ext, String executable) {
    148             this.executable = executable;
    149             this.processBuilder = createProcessBuilder(ext);
    150             this.msg = "Succesfully compiled external function '" + ext.getName() + "'";
    151         }
    152 
    153         @Override
    154         public String getMessage() {
    155             return msg;
    156         }
    157 
    158         protected ProcessCommunicator<V, T> createProcessCommunicator() throws IOException {
    159             return new ProcessCommunicator<V, T>(mc, processBuilder.start());
    160         }
    161 
    162         @Override
    163         public int evaluate(External<K> ext, Map<K, V> values, int timeout) throws IOException {
    164             log().debug("Evaluating compiled external function: " + ext.getName());
    165             ProcessCommunicator<V, T> com = null;
    166             try {
    167                 com = createProcessCommunicator();
    168                 setup(ext, values, timeout, com);
    169                 evaluate(ext, values, timeout, com);
    170                 return teardown(timeout, com);
    171             } finally {
    172                 if (com != null) {
    173                     com.destroy();
    174                 }
    175             }
    176         }
    177 
    178         public void setup(External<K> ext, Map<K, V> values, int timeout, ProcessCommunicator<V, T> com)
    179                 throws IOException {
    180             com.startTimer(timeout);
    181             com.accept("START");
    182             for (K eo : ext.externalObjectsToSerialize()) {
    183                 com.put(values.containsKey(eo) ? values.get(eo) : eo.ceval(), eo.type());
    184             }
    185             com.accept("READY");
    186             com.cancelTimer();
    187         }
    188 
    189         public void evaluate(External<K> ext, Map<K, V> values, int timeout, ProcessCommunicator<V, T> com)
    190                 throws IOException {
    191             com.startTimer(timeout);
    192             com.check("EVAL");
    193 
    194             for (K arg : ext.functionArgsToSerialize()) {
    195                 com.put(values.containsKey(arg) ? values.get(arg) : arg.ceval(), arg.type());
    196             }
    197             com.accept("CALC");
    198             com.accept("DONE");
    199             for (K cvd : ext.varsToDeserialize())
    200                 values.put(cvd, com.get(cvd.type()));
    201             com.accept("READY");
    202             com.cancelTimer();
    203         }
    204 
    205         public int teardown(int timeout, ProcessCommunicator<V, T> com) throws IOException {
    206             com.startTimer(timeout);
    207             com.check("EXIT");
    208             com.accept("END");
    209             int result = com.end();
    210             com.cancelTimer();
    211             // log().debug("SUCCESS TEARDOWN");
    212             return result;
    213         }
    214 
    215         @Override
    216         public void destroyProcess() {
    217             // Do nothing
    218         }
    219 
    220         @Override
    221         public void remove() {
    222             new File(executable).delete();
    223         }
    224 
    225         private ProcessBuilder createProcessBuilder(External<K> ext) {
    226             ProcessBuilder pb = new ProcessBuilder(executable);
    227             Map<String, String> env = pb.environment();
    228             if (env.keySet().contains("Path")) {
    229                 env.put("PATH", env.get("Path"));
    230                 env.remove("Path");
    231             }
    232             pb.redirectErrorStream(true);
    233             if (ext.libraryDirectory() != null) {
    234                 // Update environment in case of shared library
    235                 String platform = CCompilerDelegator.reduceBits(EnvironmentUtils.getJavaPlatform(),
    236                         mc.getCCompiler().getTargetPlatforms());
    237                 File f = new File(ext.libraryDirectory(), platform);
    238                 String libLoc = f.isDirectory() ? f.getPath() : ext.libraryDirectory();
    239                 appendPath(env, libLoc, platform);
    240             }
    241             return pb;
    242         }
    243 
    244         /**
    245          * Append a library location <code>libLoc</code> to the path variable in
    246          * environment <code>env</code>.
    247          */
    248         private void appendPath(Map<String, String> env, String libLoc, String platform) {
    249             String sep = platform.startsWith("win") ? ";" : ":";
    250             String var = platform.startsWith("win") ? "PATH" : "LD_LIBRARY_PATH";
    251             String res = env.get(var);
    252             if (res == null)
    253                 res = libLoc;
    254             else
    255                 res = res + sep + libLoc;
    256             env.put(var, res);
    257         }
    258     }
    259 
    260     /**
    261      * A CompiledExternalFunction which can cache several processes with external
    262      * object constructor only called once.
    263      */
    264     private class MappedExternalFunction extends CompiledExternalFunction {
    265 
    266         private Map<String, ExternalFunction<K, V>> lives = new HashMap<>();
    267 
    268         private final int externalConstantEvaluationMaxProc;
    269 
    270         public MappedExternalFunction(External<K> ext, String executable) {
    271             super(ext, executable);
    272             externalConstantEvaluationMaxProc = ext.myOptions()
    273                     .getIntegerOption("external_constant_evaluation_max_proc");
    274         }
    275 
    276         /**
    277          * Find a LiveExternalFunction based on the external object of this external
    278          * function. Start a new process if not up already. Failure to set up (call
    279          * constructor) will cache and return a Failed external function.
    280          */
    281         private ExternalFunction<K, V> getActual(External<K> ext, Map<K, V> values, int timeout) {
    282             Variable<V, T> cvd = ext.cachedExternalObject();
    283             String name = cvd == null ? "" : cvd.ceval().getMarkedExternalObject();
    284             ExternalFunction<K, V> ef = lives.get(name);
    285             if (ef == null) {
    286                 LiveExternalFunction lef = new LiveExternalFunction();
    287                 try {
    288                     lef.ready(ext, values, timeout);
    289                     ef = lef;
    290                 } catch (IOException e) {
    291                     lef.destroyProcess();
    292                     ef = failedEval(ext, " error starting process '" + e.getMessage() + "'", true);
    293                 } catch (ConstantEvaluationException e) {
    294                     lef.destroyProcess();
    295                     ef = failedEval(ext, " error starting process '" + e.getMessage() + "'", true);
    296                 }
    297                 lives.put(name, ef);
    298             }
    299             return ef;
    300         }
    301 
    302         @Override
    303         public int evaluate(External<K> ext, Map<K, V> values, int timeout) throws IOException {
    304             return getActual(ext, values, timeout).evaluate(ext, values, timeout);
    305         }
    306 
    307         @Override
    308         public void destroyProcess() {
    309             for (ExternalFunction<K, V> ef : lives.values()) {
    310                 ef.destroyProcess();
    311             }
    312             lives.clear();
    313         }
    314 
    315         /**
    316          * Represents a (possible) living external function process.
    317          */
    318         private class LiveExternalFunction implements ExternalFunction<K, V> {
    319 
    320             protected ProcessCommunicator<V, T> com;
    321 
    322             public LiveExternalFunction() {
    323                 super();
    324             }
    325 
    326             @Override
    327             public String getMessage() {
    328                 return MappedExternalFunction.this.getMessage();
    329             }
    330 
    331             @Override
    332             public int evaluate(External<K> ext, Map<K, V> values, int timeout) throws IOException {
    333                 log().debug("Evaluating live external function: " + ext.getName());
    334                 try {
    335                     ready(ext, values, timeout);
    336                     long time = System.currentTimeMillis();
    337                     MappedExternalFunction.this.evaluate(ext, values, timeout, com);
    338                     time = System.currentTimeMillis() - time;
    339                     log().debug("Finished evaluating live external function, time: " + time + "ms");
    340                 } catch (ProcessCommunicator.AbortConstantEvaluationException e) {
    341 
    342                 } catch (ConstantEvaluationException e) {
    343                     destroyProcess();
    344                     throw e;
    345                 } catch (IOException e) {
    346                     destroyProcess();
    347                     throw e;
    348                 }
    349                 return 0;
    350             }
    351 
    352             /**
    353              * Make sure process is ready for evaluation call.
    354              */
    355             protected void ready(External<K> ext, Map<K, V> values, int timeout) throws IOException {
    356                 if (com == null) {
    357                     long time1 = System.currentTimeMillis();
    358                     // Start process if not live.
    359                     com = createProcessCommunicator();
    360                     long time2 = System.currentTimeMillis();
    361                     // Send external object constructor inputs
    362                     MappedExternalFunction.this.setup(ext, values, timeout, com);
    363                     long time3 = System.currentTimeMillis();
    364                     log().debug("Setup live external function: " + ext.getName()
    365                               + ", createProcessCommunicator() time: " + (time2 - time1)
    366                               + "ms, setup time: " + (time3 - time2) + "ms");
    367                 }
    368 
    369                 // Mark as most recently used
    370                 livingCachedExternals.remove(this);
    371                 livingCachedExternals.add(this);
    372 
    373                 // If we are over the allowed number of cached processes
    374                 // we kill the least recently used.
    375                 if (livingCachedExternals.size() > externalConstantEvaluationMaxProc) {
    376                     livingCachedExternals.iterator().next().destroyProcess();
    377                 }
    378             }
    379 
    380             @Override
    381             public void destroyProcess() {
    382                 if (com != null) {
    383                     livingCachedExternals.remove(this);
    384                     com.destroy();
    385                     com = null;
    386                 }
    387             }
    388 
    389             @Override
    390             public void remove() {
    391                 // Removing this executable is handled by surrounding MappedExternalFunction
    392                 throw new UnsupportedOperationException();
    393             }
    394         }
    395     }
    396210}
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessMultiCache.java

    r13703 r13843  
    22
    33import java.io.BufferedWriter;
    4 import java.io.FileNotFoundException;
    54import java.io.IOException;
    65import java.util.LinkedHashMap;
    76import java.util.Map;
    87
    9 import org.jmodelica.common.LogContainer;
    108import org.jmodelica.common.options.AbstractOptionRegistry;
    11 import org.jmodelica.util.ccompiler.CCompilerDelegator;
    12 import org.jmodelica.util.exceptions.CcodeCompilationException;
    139
    1410public class ExternalProcessMultiCache<K extends ExternalProcessMultiCache.Variable<V, T>, V extends ExternalProcessMultiCache.Value, T extends ExternalProcessMultiCache.Type<V>, E extends ExternalProcessMultiCache.External<K>> {
    15 
    16     public interface Compiler<K, E extends External<K>> extends LogContainer {
    17         public String compileExternal(E ext) throws FileNotFoundException, CcodeCompilationException;
    18 
    19         public CCompilerDelegator getCCompiler();
    20     }
    2111
    2212    public interface External<K> {
    2313        public String getName();
    2414
    25         public boolean shouldCacheProcess();
     15        public int processLimit();
     16
     17        public boolean dynamicEvaluatorEnabled();
    2618
    2719        public AbstractOptionRegistry myOptions();
     
    3527        public Iterable<K> functionArgsToSerialize();
    3628
     29        public String functionArgsSerialized();
     30
     31        public String functionReturnArgSerialized();
     32
    3733        public Iterable<K> varsToDeserialize();
     34
     35        public String[] library();
    3836    }
    3937
     
    5654    private Map<String, ExternalProcessCache<K, V, T, E>> map = new LinkedHashMap<>();
    5755
    58     private Compiler<K, E> mc;
     56    private ExternalFunctionCompiler<K, E> mc;
    5957
    60     public ExternalProcessMultiCache(Compiler<K, E> mc) {
     58    public ExternalProcessMultiCache(ExternalFunctionCompiler<K, E> mc) {
    6159        this.mc = mc;
    6260    }
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/LiveExternalFunction.java

    r13720 r13843  
    4646            compiler.log().debug("Finished evaluating live external function, time: " + time + "ms");
    4747        } catch (ProcessCommunicator.AbortConstantEvaluationException e) {
    48 
     48            // TODO What does this mean?
    4949        } catch (ConstantEvaluationException e) {
    5050            destroyProcess();
     
    8989        if (com != null) {
    9090            livingCachedExternals.remove(this);
    91             com.destroy();
     91            try {
     92                com.teardown(100); // TODO Should we check the return value?
     93            } catch (IOException e) {
     94                // TODO Do we need to do anything here?
     95            }
     96            com.destroy(); // TODO Do we still need to call destroy() if teardown is successful?
    9297            com = null;
    9398        }
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ProcessCommunicator.java

    r12940 r13843  
    4949    private String getLine() throws IOException {
    5050        String line = buffLine;
    51         if (line == null)
     51        if (line == null) {
    5252            line = in.readLine();
     53        }
    5354        if (line == null) {
    5455            if (timeOutHappened) {
     
    110111            String format = deserializeString();
    111112            String value = deserializeString();
    112             if (warning != 0)
     113            if (warning != 0) {
    113114                mc.log().warning("%s: " + format, name, value);
    114             else
     115            } else {
    115116                mc.log().verbose("%s: " + format, name, value);
     117            }
    116118            line = getLine();
    117119        }
     
    133135            super(null, string);
    134136        }
     137    }
     138
     139    public int teardown(int timeout) throws IOException {
     140        startTimer(timeout);
     141        check("EXIT");
     142        accept("END");
     143        int result = end();
     144        cancelTimer();
     145        return result;
    135146    }
    136147
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/options/AbstractOptionRegistry.java

    r13252 r13843  
    4040 * to get an option registry populated with all available options.
    4141 */
     42@SuppressWarnings("javadoc")
    4243public abstract class AbstractOptionRegistry {
    4344
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/separateProcess/CompilerInstance.java

    r13396 r13843  
    274274         * {@link org.jmodelica.modelica.compiler.ModelicaCompiler ModelicaCompiler}.
    275275         */
     276        @SuppressWarnings("javadoc")
    276277        MODELICA("org.jmodelica.modelica.compiler.ModelicaCompiler"),
    277278
     
    279280         * {@link org.jmodelica.optimica.compiler.OptimicaCompiler OptimicaCompiler}.
    280281         */
     282        @SuppressWarnings("javadoc")
    281283        OPTIMICA("org.jmodelica.optimica.compiler.OptimicaCompiler");
    282284
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/MemorySpider.java

    r12940 r13843  
    145145        private Field field;
    146146       
    147         public Object perform(Field f, Object o) {
     147        @SuppressWarnings("deprecation")
     148        public Object perform(Field f, Object o) {
    148149            field = f;
    149150            if (!f.isAccessible())
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/SystemUtil.java

    r13703 r13843  
    7272        return isLinux() ? "" : ".exe";
    7373    }
     74   
     75    public static String sharedLibraryExtension() {
     76        if (isWindows()) {
     77            return ".dll";
     78        } else if (isLinux()) {
     79            return ".so";
     80        } else {
     81            return ".dylib";
     82        }
     83    }
    7484
    7585    /**
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/logging/PipeLogger.java

    r12984 r13843  
    7272    }
    7373
     74    @SuppressWarnings("deprecation")
    7475    @Override
    7576    protected void finalize() throws Throwable {
  • branches/dev-mo-2278/Compiler/ModelicaFrontEnd/test/junit/org/jmodelica/test/common/ExternalProcessCacheTest.java

    r13703 r13843  
    99import java.io.IOException;
    1010
     11import org.jmodelica.common.evaluation.ExternalFunctionCompiler;
     12import org.jmodelica.common.evaluation.ExternalFunction;
    1113import org.jmodelica.common.evaluation.ExternalProcessCache;
    12 import org.jmodelica.common.evaluation.ExternalFunction;
    1314import org.jmodelica.common.evaluation.ExternalProcessMultiCache;
     15import org.jmodelica.common.evaluation.ExternalProcessMultiCache.External;
     16import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Type;
     17import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Value;
    1418import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Variable;
     19import org.jmodelica.common.evaluation.ProcessCommunicator;
    1520import org.jmodelica.common.options.AbstractOptionRegistry;
    16 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Value;
    17 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Type;
    18 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.External;
    19 import org.jmodelica.common.evaluation.ProcessCommunicator;
    2021import org.jmodelica.util.ccompiler.CCompilerDelegator;
    2122import org.jmodelica.util.exceptions.CcodeCompilationException;
     
    7475    class ExternalProcessCacheMock<K extends Variable<V,T>, V extends Value, T extends Type<V>, E extends External<K>> extends ExternalProcessMultiCache<K,V,T,E> {
    7576
    76         public ExternalProcessCacheMock(Compiler<K,E> mc) {
     77        public ExternalProcessCacheMock(ExternalFunctionCompiler<K,E> mc) {
    7778            super(mc);
    7879        }
     
    108109        }
    109110
    110         @Override
    111         public ExternalFunction<K,V> failedEval(External<?> ext, String msg, boolean log) {
    112             // TODO Auto-generated method stub
    113             return null;
    114         }
    115        
    116     }
    117 
    118     class CompilerMock implements ExternalProcessMultiCache.Compiler<VariableMock, ExternalMock> {
     111    }
     112
     113    class CompilerMock implements ExternalFunctionCompiler<VariableMock, ExternalMock> {
    119114
    120115        @Override
     
    189184
    190185        @Override
    191         public boolean shouldCacheProcess() {
    192             // TODO Auto-generated method stub
     186        public int processLimit() {
     187            // TODO Auto-generated method stub
     188            return 0;
     189        }
     190
     191        @Override
     192        public boolean dynamicEvaluatorEnabled() {
    193193            return false;
    194194        }
     
    223223            return null;
    224224        }
     225       
     226        @Override
     227        public String functionArgsSerialized() {
     228            // TODO Auto-generated method stub
     229            return null;
     230        }
     231       
     232        @Override
     233        public String functionReturnArgSerialized() {
     234            // TODO Auto-generated method stub
     235            return null;
     236        }
    225237
    226238        @Override
     
    229241            return null;
    230242        }
     243       
     244        @Override
     245        public String[] library() {
     246            // TODO Auto-generated method stub
     247            return null;
     248        }
    231249
    232250    }
  • branches/dev-mo-2278/Compiler/ModelicaMiddleEnd/src/jastadd/structural/Symbolic.jrag

    r13636 r13843  
    217217    private static Boolean FEquation.nominalAllowsDivision(FExp factor, FVariable var, double tol) {
    218218        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;
     219            FExp varNominalExp = factor.dynamicFExp(var.nominal());
     220            if (varNominalExp.variability().constantVariability()) {
     221                double factorNominal = Math.abs(factor.ceval().realValue());
     222                double varNominal    = varNominalExp.ceval().realValue();
     223                double totalNominal  = factorNominal * varNominal;
     224                if (totalNominal < tol) {
     225                    return false;
     226                }
    224227            }
    225228        }
  • branches/dev-mo-2278/Compiler/ModelicaMiddleEnd/test/modelica/EquationSolvingTests.mo

    r13636 r13843  
    3434        FClassMethodTestCase(
    3535            name="ParametricNominal1",
    36             description="",
     36            description="Test that parametric nominal that cannot be evaluated does not lead to exception during equation solving. Instead we handle it as if there was no nominal set.",
    3737            methodName="printDAEBLT",
    3838            methodResult="
  • branches/dev-mo-2278/Makefile.am

    r13636 r13843  
    4545bindistdir=JModelica.org-$(VERSION)-bin
    4646
    47 casadi:
    48 if COMPILE_WITH_IPOPT
    49     cd $(abs_builddir)/ThirdParty/CasADi; \
    50     make -f Makefile  "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR)" "IPOPT_HOME=$(IPOPT_HOME)" "CASADI_PYTHON_INST_DIR=${CASADI_PYTHON_INST_DIR}" "CASADI_INST_DIR=${CASADI_INST_DIR}" "CASADI_PLUGIN_INST_DIR=${CASADI_PLUGIN_INST_DIR}" "CMAKE_CASADI_ARGS=${CMAKE_CASADI_ARGS}" "CMAKE_CASADI_COMPILER_ARGS=${CMAKE_CASADI_COMPILER_ARGS}" "CMAKE_CASADI_CXX_FLAG=${CMAKE_CASADI_CXX_FLAG}" "CMAKE_PYTHON_LIB=${CMAKE_PYTHON_LIB}"
    51 endif
    52 if COMPILE_WITH_IPOPT64
    53     export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}"; \
    54     export PYTHONHOME=$(PYTHON64_HOME); \
    55     cd $(abs_builddir)/ThirdParty/CasADi; \
    56     make -f Makefile  "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR64)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR64)" "IPOPT_HOME=$(IPOPT64_HOME)" "CASADI_PYTHON_INST_DIR=${CASADI_PYTHON_INST_DIR64}" "CASADI_INST_DIR=${CASADI_INST_DIR64}" "CASADI_PLUGIN_INST_DIR=${CASADI_PLUGIN_INST_DIR64}" "CMAKE_CASADI_ARGS=${CMAKE_CASADI_ARGS64}" "CMAKE_CASADI_COMPILER_ARGS=${CMAKE_CASADI_COMPILER_ARGS64}" "CMAKE_CASADI_CXX_FLAG=${CMAKE_CASADI_CXX_FLAG64}" "CMAKE_PYTHON_LIB=${CMAKE_PYTHON64_LIB}" "CMAKE_PYTHON_INCLUDE=${CMAKE_PYTHON64_INCLUDE}"
    57     export PYTHONHOME=$(ORIG_PYTHON_HOME); \
    58     export PATH="$(ORIG_PATH)";
    59 endif
    60 
    61 install_casadi: casadi
    62 if COMPILE_WITH_IPOPT
    63     cd $(abs_builddir)/ThirdParty/CasADi; \
    64     make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR)" "IPOPT_HOME=$(IPOPT_HOME)"
    65     mkdir -p $(DESTDIR)$(prefix)/Python/
    66     cp -r $(CASADI_PYTHON_INST_DIR)/casadi $(DESTDIR)$(prefix)/Python/
    67     ## temp fix
    68     cp $(CASADI_BUILD_DIR)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python/casadi
    69 endif
    70 if COMPILE_WITH_IPOPT64 
    71     export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}"; \
    72     export PYTHONHOME=$(PYTHON64_HOME); 
    73     cd $(abs_builddir)/ThirdParty/CasADi; \
    74     make -f Makefile install "SWIGCHECK_BUILD_DIR=$(SWIGCHECK_BUILD_DIR)" "CASADI_BUILD_DIR=$(CASADI_BUILD_DIR64)" "IPOPT_HOME=$(IPOPT64_HOME)"
    75     mkdir -p $(DESTDIR)$(prefix)/Python/
    76     cp -r $(CASADI_PYTHON_INST_DIR64)/casadi $(DESTDIR)$(prefix)/Python_64/
    77     ## temp fix
    78     cp $(CASADI_BUILD_DIR64)/swig/casadi_core.py $(DESTDIR)$(prefix)/Python_64/casadi
    79     export PYTHONHOME=$(ORIG_PYTHON_HOME); \
    80     export PATH="$(ORIG_PATH)";
    81 endif
    82 ## Install for CasADiInterface, Variables and targets.
    83 ## MC_interface installs the system with Python.
    84 ## If C++ compilation/tests are wanted there is the target MC_interface_cplusplus
    85 
    86 MC_INTERFACE=$(abs_top_srcdir)/ModelicaCasADiInterface
    87 
    88 CASADI_HOME=$(abs_top_srcdir)/ThirdParty/CasADi/CasADi
    89 MC_SRC=$(JAVA_CASADI_BASE_DIR)/ModelicaCompilerCasADi
    90 OC_SRC=$(JAVA_CASADI_BASE_DIR)/OptimicaCompilerCasADi
    91 MC_SRC_SWIG=$(abs_top_srcdir)/Compiler/ModelicaCompilerCasADi/src/swig
    92 
    93 MC_CASADI_BUILD=$(abs_builddir)/ModelicaCompilerCasADi
    94 OC_CASADI_BUILD=$(abs_builddir)/OptimicaCompilerCasADi
    95 
    96 # The modelica casadi interface is built into a build folder
    97 MC_BUILD=$(abs_builddir)/ModelicaCasADiInterfaceBuild
    98 MC_BUILD64=$(abs_builddir)/ModelicaCasADiInterfaceBuild64
    99 # Jars from the modified modelica and optimica compilers are put into the JModelica folder
    100 MC_COMPILERS_DIR=$(MC_BUILD)/JModelica.org
    101 MC_LIB=$(DESTDIR)$(prefix)/lib/casadi_interface
    102 MC_LIB64=$(DESTDIR)$(prefix)/lib/casadi_interface64
    103 
    104 CASADI_BUILD_DIR=$(abs_builddir)/casadi_build
    105 CASADI_BUILD_DIR64=$(abs_builddir)/casadi_build64
    106 SWIGCHECK_BUILD_DIR=$(abs_builddir)/swig_check
    107 SWIGCHECK_BUILD_DIR64=$(abs_builddir)/swig_check64
    108 CASADI_PYTHON_INST_DIR=$(abs_builddir)/casadi_install
    109 CASADI_INST_DIR=$(prefix)/ThirdParty/CasADi
    110 CASADI_PLUGIN_INST_DIR=$(CASADI_INST_DIR)/lib
    111 CASADI_PYTHON_INST_DIR64=$(abs_builddir)/casadi_install64
    112 CASADI_INST_DIR64=$(prefix)/ThirdParty/CasADi64
    113 CASADI_PLUGIN_INST_DIR64=$(CASADI_INST_DIR64)/lib
    114 CMAKE_CASADI_CXX_FLAG=-m32
    115 CMAKE_CASADI_COMPILER_ARGS=-m32 -mincoming-stack-boundary=2
    116 CMAKE_CASADI_CXX_FLAG64=-m64
    117 CMAKE_CASADI_COMPILER_ARGS64=-m64 -fpermissive
    118 
    119 casadi_interface: install_casadi_interface
    120 build_casadi_interface: casadi modelicacasadi_wrapper
    121 install_casadi_interface: install_casadi $(MC_LIB) $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/__init__.py $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper/__init__.py $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/modelica_casadi_transfer_wrapper.py
    122     if [ "$(INSTALL_EXTRA_CASADI)" ]; then exec "$(INSTALL_EXTRA_CASADI)" "$(abs_top_srcdir)" "$(DESTDIR)$(prefix)"; fi
    123 
    124 ifcasadi: casadi
    125 if COMPILE_WITH_IPOPT
    126     mkdir -p $(MC_BUILD)/ifcasadi; \
    127     cd $(MC_BUILD)/ifcasadi; \
    128     case $(build) in \
    129     *-cygwin*|*-mingw*) \
    130     cmake $(MC_SRC_SWIG) -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER_ARG1="-m32" -DCMAKE_CXX_FLAGS="-m32" \
    131         -DIFCASADI_OUTDIR="$(MC_CASADI_BUILD)" -DCASADI_HOME="$(CASADI_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR)";; \
    132     *) \
    133     cmake $(MC_SRC_SWIG) \
    134         -DIFCASADI_OUTDIR="$(MC_CASADI_BUILD)" -DCASADI_HOME="$(CASADI_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR)";; \
    135     esac
    136     cd $(MC_BUILD)/ifcasadi;  make
    137 endif
    138 if COMPILE_WITH_IPOPT64
    139     export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}";
    140     export PYTHONHOME=$(PYTHON64_HOME);
    141     mkdir -p $(MC_BUILD64)/ifcasadi; \
    142     cd $(MC_BUILD64)/ifcasadi; \
    143     cmake $(MC_SRC_SWIG) -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER_ARG1="-m64" -DCMAKE_CXX_FLAGS="-m64" \
    144         -DIFCASADI_OUTDIR="$(MC_CASADI_BUILD)" -DCASADI_HOME="$(CASADI_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR64)"; \
    145     cd $(MC_BUILD64)/ifcasadi;  make
    146     export PYTHONHOME=$(ORIG_PYTHON_HOME); \
    147     export PATH="$(ORIG_PATH)";
    148 endif
    149 
    150 $(MC_LIB): $(MC_CASADI_BUILD)/bin/ModelicaCompiler.jar $(OC_CASADI_BUILD)/bin/OptimicaCompiler.jar $(MC_CASADI_BUILD)/bin/util.jar ifcasadi
    151 if COMPILE_WITH_IPOPT
    152     rm -rf $(MC_LIB)
    153     mkdir -p $(MC_LIB)
    154     cp $(MC_CASADI_BUILD)/bin/ModelicaCompiler.jar $(MC_LIB)
    155     cp $(OC_CASADI_BUILD)/bin/OptimicaCompiler.jar $(MC_LIB)
    156     cp $(MC_CASADI_BUILD)/bin/util.jar $(MC_LIB)
    157     case $(build) in \
    158     *-cygwin*) \
    159     cp $(MC_BUILD)/ifcasadi/ifcasadi.dll $(MC_LIB) ;; \
    160     *-mingw*) \
    161     cp $(MC_BUILD)/ifcasadi/ifcasadi.dll $(MC_LIB) ;; \
    162     *) \
    163     cp $(MC_BUILD)/ifcasadi/libifcasadi.so $(MC_LIB) ;; \
    164     esac
    165 endif
    166 if COMPILE_WITH_IPOPT64
    167     rm -rf $(MC_LIB64)
    168     mkdir -p $(MC_LIB64)
    169     cp $(MC_CASADI_BUILD)/bin/ModelicaCompiler.jar $(MC_LIB64)
    170     cp $(OC_CASADI_BUILD)/bin/OptimicaCompiler.jar $(MC_LIB64)
    171     cp $(MC_CASADI_BUILD)/bin/util.jar $(MC_LIB64)
    172     cp $(MC_BUILD64)/ifcasadi/ifcasadi.dll $(MC_LIB64)
    173 endif
    174 
    175 mc_modelica: ifcasadi
    176     cd $(MC_CASADI_BUILD); $(ANT_OPTS) $(ANT) -f "$(JAVA_MC_CASADI_ANT_FILE)" "-Dcompiler=$(COMPILER_DIR)" "-Dtarget=$(MC_CASADI_BUILD)"
    177 
    178 mc_optimica: ifcasadi
    179     mkdir -p $(OC_CASADI_BUILD)/src/generated/optimica/java
    180     cp -pr $(MC_CASADI_BUILD)/src/generated/modelica/java/ifcasadi $(OC_CASADI_BUILD)/src/generated/optimica/java
    181     cd $(OC_CASADI_BUILD); $(ANT_OPTS) $(ANT) -f "$(JAVA_OC_CASADI_ANT_FILE)" "-Dcompiler=$(COMPILER_DIR)" "-Dtarget=$(OC_CASADI_BUILD)"
    182 
    183 $(MC_CASADI_BUILD)/bin/ModelicaCompiler.jar: mc_modelica
    184 $(MC_CASADI_BUILD)/bin/util.jar:             mc_modelica
    185 $(MC_CASADI_BUILD)/bin/separateProcess.jar:  mc_modelica
    186 
    187 $(OC_CASADI_BUILD)/bin/OptimicaCompiler.jar: mc_optimica
    188 $(OC_CASADI_BUILD)/bin/util.jar:             mc_optimica
    189 $(OC_CASADI_BUILD)/bin/separateProcess.jar:  mc_optimica
    190 
    191 $(MC_BUILD)/modelicacasadi_wrapper/swig/modelicacasadi_wrapper.py: modelicacasadi_wrapper
    192 
    193 
    194 modelicacasadi_wrapper: $(MC_CASADI_BUILD)/bin/ModelicaCompiler.jar $(OC_CASADI_BUILD)/bin/OptimicaCompiler.jar $(MC_CASADI_BUILD)/bin/util.jar ifcasadi # $(MC_LIB)
    195 if COMPILE_WITH_IPOPT
    196     mkdir -p $(MC_BUILD)/modelicacasadi_wrapper; \
    197     cd $(MC_BUILD)/modelicacasadi_wrapper; \
    198     case $(build) in \
    199     *-cygwin*|*-mingw*) \
    200     cmake $(MC_INTERFACE) -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER_ARG1="-m32" -DCMAKE_CXX_FLAGS="-m32" \
    201         -DMC_BUILD="$(MC_BUILD)" -DIPOPT_HOME="$(IPOPT_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR)" \
    202         -DIFCASADI_JAR_BASE="$(JAVA_CASADI_BUILD_DIR)" -DCASADI_HOME="$(CASADI_HOME)" \
    203         "$(CMAKE_PYTHON_LIB)" "$(CMAKE_PYTHON_INCLUDE)" ;; \
    204     *) \
    205     cmake $(MC_INTERFACE) \
    206         -DMC_BUILD="$(MC_BUILD)" -DIPOPT_HOME="$(IPOPT_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR)" \
    207         -DIFCASADI_JAR_BASE="$(JAVA_CASADI_BUILD_DIR)" -DCASADI_HOME="$(CASADI_HOME)" \
    208         "$(CMAKE_PYTHON_LIB)" "$(CMAKE_PYTHON_INCLUDE)" ;; \
    209     esac
    210     cd $(MC_BUILD)/modelicacasadi_wrapper;  make modelicacasadi_wrapper
    211 endif
    212 if COMPILE_WITH_IPOPT64
    213     export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}"; \
    214     export PYTHONHOME=$(PYTHON64_HOME); \
    215     mkdir -p $(MC_BUILD64)/modelicacasadi_wrapper; \
    216     cd $(MC_BUILD64)/modelicacasadi_wrapper; \
    217     cmake $(MC_INTERFACE) -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER_ARG1="-m64" -DCMAKE_CXX_FLAGS="-m64" \
    218         -DMC_BUILD="$(MC_BUILD64)" -DIPOPT_HOME="$(IPOPT64_HOME)" -DCASADI_BUILD_DIR="$(CASADI_BUILD_DIR64)" \
    219         -DIFCASADI_JAR_BASE="$(JAVA_CASADI_BUILD_DIR)" -DCASADI_HOME="$(CASADI_HOME)" \
    220         "$(CMAKE_PYTHON64_LIB)" "$(CMAKE_PYTHON64_INCLUDE)"; \
    221     cd $(MC_BUILD64)/modelicacasadi_wrapper;  make modelicacasadi_wrapper
    222     export PYTHONHOME=$(ORIG_PYTHON_HOME);
    223     export PATH="$(ORIG_PATH)";
    224 endif
    225 
    226  $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/__init__.py: install_modelicacasadi_transfer
    227  $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/modelica_casadi_transfer_wrapper.py: install_modelicacasadi_transfer
    228  
    229  $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper/__init__.py: install_modelicacasadi_wrapper
    230  
    231  install_modelicacasadi_wrapper: $(MC_BUILD)/modelicacasadi_wrapper/swig/modelicacasadi_wrapper.py
    232 if COMPILE_WITH_IPOPT
    233     mkdir -p $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper
    234     cp $(MC_BUILD)/modelicacasadi_wrapper/swig/*modelicacasadi_wrapper* $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper
    235     rm -f $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper/__init__.py
    236     touch $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper/__init__.py
    237     echo "from modelicacasadi_wrapper import *" >> $(DESTDIR)$(prefix)/Python/modelicacasadi_wrapper/__init__.py
    238 endif
    239 if COMPILE_WITH_IPOPT64
    240     export PATH=$(PYTHON64_HOME):$(PYTHON64_HOME)/Scripts:$(PYTHON64_HOME)/Lib:"${PATH}"; \
    241     export PYTHONHOME=$(PYTHON64_HOME);
    242     mkdir -p $(DESTDIR)$(prefix)/Python_64/modelicacasadi_wrapper
    243     cp $(MC_BUILD64)/modelicacasadi_wrapper/swig/*modelicacasadi_wrapper* $(DESTDIR)$(prefix)/Python_64/modelicacasadi_wrapper
    244     rm -f $(DESTDIR)$(prefix)/Python_64/modelicacasadi_wrapper/__init__.py
    245     touch $(DESTDIR)$(prefix)/Python_64/modelicacasadi_wrapper/__init__.py
    246     echo "from modelicacasadi_wrapper import *" >> $(DESTDIR)$(prefix)/Python_64/modelicacasadi_wrapper/__init__.py
    247     export PYTHONHOME=$(ORIG_PYTHON_HOME)
    248     export PATH="$(ORIG_PATH)"
    249 endif
    250 
    251  install_modelicacasadi_transfer: $(MC_INTERFACE)/python/modelica_casadi_transfer_wrapper.py
    252 if COMPILE_WITH_IPOPT
    253     mkdir -p $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer
    254     rm -f $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/__init__.py
    255     touch $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/__init__.py
    256     echo "from modelica_casadi_transfer_wrapper import *" >> $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer/__init__.py
    257     cp $(MC_INTERFACE)/python/modelica_casadi_transfer_wrapper.py $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer
    258 endif
    259 if COMPILE_WITH_IPOPT64   
    260     mkdir -p $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer
    261     rm -f $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer/__init__.py
    262     touch $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer/__init__.py
    263     echo "from modelica_casadi_transfer_wrapper import *" >> $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer/__init__.py
    264     cp $(MC_INTERFACE)/python/modelica_casadi_transfer_wrapper.py $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer
    265 endif
    266        
     47include MakefileCasadi.am
     48
    26749if NUMPY_NO_MSVCR
    26850NUMPY_NO_MSVCR_ARG=--no-msvcr="true"
     
    654436
    655437clean-local: clean-frontends clean-python-packages clean-casadi-interface
    656 
    657 clean-casadi-interface:
    658     rm -rf $(MC_BUILD)
    659     rm -rf $(MC_BUILD64)
    660 #   rm -rf $(DESTDIR)$(prefix)/Python/casadi
    661 #   rm -rf $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer
    662 if HAVE_ANT
    663     cd $(JAVA_CASADI_BUILD_DIR)/ModelicaCompilerCasADi; \
    664     $(ANT_OPTS) $(ANT) clean ; rm -rf $(MC_CASADI_BUILD)/src/cpp-generated $(MC_CASADI_BUILD)/src/generated/modelica/java/ifcasadi
    665     cd $(JAVA_CASADI_BUILD_DIR)/OptimicaCompilerCasADi; \
    666     $(ANT_OPTS) $(ANT) clean ; rm -rf $(OC_CASADI_BUILD)/src/cpp-generated $(OC_CASADI_BUILD)/src/generated/optimica/java/ifcasadi
    667 endif
    668438   
    669439clean-python-packages:
     
    701471    make -C $(abs_top_srcdir)/doc/PyJMI html
    702472
    703 
    704 .PHONY: modelicacasadi_wrapper ifcasadi install_modelicacasadi_transfer install_modelicacasadi_wrapper
  • branches/dev-mo-2278/Makefile.in

    r13636 r13843  
    1515
    1616@SET_MAKE@
     17
     18#
     19#    Copyright (C) 2009 Modelon AB
     20#
     21#    This program is free software: you can redistribute it and/or modify
     22#    it under the terms of the Common Public License as published by
     23#    IBM, version 1.0 of the License.
     24#
     25#    This program is distributed in the hope that it will be useful,
     26#    but WITHOUT ANY WARRANTY. See the Common Public License for more details.
     27#
     28#    You should have received a copy of the Common Public License
     29#    along with this program.  If not, see
     30#     <http://www.ibm.com/developerworks/library/os-cpl.html/>.
    1731
    1832#
     
    4963host_triplet = @host@
    5064@PYTHON_ENABLED_TRUE@am__append_1 = Python
    51 subdir = .
    5265DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
    53     $(srcdir)/Makefile.in $(srcdir)/config.h.in \
    54     $(srcdir)/jm_tests.in \
     66    $(srcdir)/Makefile.in $(srcdir)/MakefileCasadi.am \
     67    $(srcdir)/config.h.in $(srcdir)/jm_tests.in \
    5568    $(top_srcdir)/Python/src/required_defaults.py.in \
    5669    $(top_srcdir)/configure INSTALL config.guess config.sub \
    5770    depcomp install-sh ltmain.sh missing
     71subdir = .
    5872ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    5973am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
     
    371385am--refresh:
    372386    @:
    373 $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(am__configure_deps)
     387$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/MakefileCasadi.am $(am__configure_deps)
    374388    @for dep in $?; do \
    375389      case '$(am__configure_deps)' in \
     
    865879
    866880
     881.PHONY: modelicacasadi_wrapper ifcasadi install_modelicacasadi_transfer install_modelicacasadi_wrapper
     882
    867883casadi:
    868884@COMPILE_WITH_IPOPT_TRUE@   cd $(abs_builddir)/ThirdParty/CasADi; \
     
    10171033@COMPILE_WITH_IPOPT64_TRUE@ echo "from modelica_casadi_transfer_wrapper import *" >> $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer/__init__.py
    10181034@COMPILE_WITH_IPOPT64_TRUE@ cp $(MC_INTERFACE)/python/modelica_casadi_transfer_wrapper.py $(DESTDIR)$(prefix)/Python_64/modelicacasadi_transfer
     1035
     1036clean-casadi-interface:
     1037    rm -rf $(MC_BUILD)
     1038    rm -rf $(MC_BUILD64)
     1039#   rm -rf $(DESTDIR)$(prefix)/Python/casadi
     1040#   rm -rf $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer
     1041@HAVE_ANT_TRUE@ cd $(JAVA_CASADI_BUILD_DIR)/ModelicaCompilerCasADi; \
     1042@HAVE_ANT_TRUE@ $(ANT_OPTS) $(ANT) clean ; rm -rf $(MC_CASADI_BUILD)/src/cpp-generated $(MC_CASADI_BUILD)/src/generated/modelica/java/ifcasadi
     1043@HAVE_ANT_TRUE@ cd $(JAVA_CASADI_BUILD_DIR)/OptimicaCompilerCasADi; \
     1044@HAVE_ANT_TRUE@ $(ANT_OPTS) $(ANT) clean ; rm -rf $(OC_CASADI_BUILD)/src/cpp-generated $(OC_CASADI_BUILD)/src/generated/optimica/java/ifcasadi
    10191045
    10201046build-python-packages:
     
    13231349clean-local: clean-frontends clean-python-packages clean-casadi-interface
    13241350
    1325 clean-casadi-interface:
    1326     rm -rf $(MC_BUILD)
    1327     rm -rf $(MC_BUILD64)
    1328 #   rm -rf $(DESTDIR)$(prefix)/Python/casadi
    1329 #   rm -rf $(DESTDIR)$(prefix)/Python/modelicacasadi_transfer
    1330 @HAVE_ANT_TRUE@ cd $(JAVA_CASADI_BUILD_DIR)/ModelicaCompilerCasADi; \
    1331 @HAVE_ANT_TRUE@ $(ANT_OPTS) $(ANT) clean ; rm -rf $(MC_CASADI_BUILD)/src/cpp-generated $(MC_CASADI_BUILD)/src/generated/modelica/java/ifcasadi
    1332 @HAVE_ANT_TRUE@ cd $(JAVA_CASADI_BUILD_DIR)/OptimicaCompilerCasADi; \
    1333 @HAVE_ANT_TRUE@ $(ANT_OPTS) $(ANT) clean ; rm -rf $(OC_CASADI_BUILD)/src/cpp-generated $(OC_CASADI_BUILD)/src/generated/optimica/java/ifcasadi
    1334 
    13351351clean-python-packages:
    13361352@PYTHON_ENABLED_TRUE@   if [ -d $(assimulo_build_dir)/Assimulo ]; then \
     
    13631379    make -C $(abs_top_srcdir)/doc/PyJMI html
    13641380
    1365 .PHONY: modelicacasadi_wrapper ifcasadi install_modelicacasadi_transfer install_modelicacasadi_wrapper
    1366 
    13671381# Tell versions [3.59,3.63) of GNU make to not export all variables.
    13681382# Otherwise a system limit (for SysV at least) may be exceeded.
  • branches/dev-mo-2278/Python/src/pyjmi/examples/cstr_mpc_casadi.py

    r8187 r13843  
    8686    sim_model.set('_start_T', T_0_A)
    8787    sim_model.set('Tc', 280)
    88     init_res = sim_model.simulate(start_time=0., final_time=150)
     88   
     89    opts = sim_model.simulate_options()
     90    opts["CVode_options"]["maxh"] = 0.0
     91    opts["ncp"] = 0
     92   
     93    init_res = sim_model.simulate(start_time=0., final_time=150, options=opts)
    8994
    9095    ### 2. Define the optimal control problem and solve it using the MPC class
     
    159164        sim_res = sim_model.simulate(start_time=k*sample_period,
    160165                                     final_time=(k+1)*sample_period,
    161                                      input=u_k)
     166                                     input=u_k, options=opts)
    162167
    163168        # Extract state at end of sample_period from sim_res and add Gaussian
  • branches/dev-mo-2278/Python/src/pyjmi/examples/if_example_2.py

    r4648 r13843  
    4949    t = res['time']
    5050   
    51     assert N.abs(res.final('x') - 3.5297217)    < 1e-3
    52     assert N.abs(res.final('u') - (-0.2836621)) < 1e-3
     51    assert N.abs(res.final('x') - 3.5297217)    < 1e-2, N.abs(res.final('x') - 3.5297217)
     52    assert N.abs(res.final('u') - (-0.2836621)) < 1e-2, N.abs(res.final('u') - (-0.2836621))
    5353
    5454    if with_plots:
  • branches/dev-mo-2278/Python/src/pyjmi/ukf.py

    r10171 r13843  
    368368                opt['CVode_options']['atol'] = 1e-8
    369369                opt['CVode_options']['rtol'] = 1e-6
     370                opt['CVode_options']['maxh'] = 0.0
     371                opt['ncp'] = 0
    370372                print 'Simulating sigma-point '+str(i+1)+' out of '+str(sigma.shape[1])+' :'
    371373                try:
  • branches/dev-mo-2278/Python/src/tests_jmodelica/files/Modelica/ExtFunctionTests.mo

    r13703 r13843  
    11package ExtFunctionTests
     2
     3model Evaluator_Double
     4    function d_i
     5     input Integer a;
     6     output Real b;
     7
     8     external "C" b=f_d_i(a) annotation(Library="evaluatorTestsShared",
     9                             Include="#include \"evaluatorTests.h\"");
     10    end d_i;
     11   
     12    function d_idd
     13     input Integer a;
     14     input Real b;
     15     input Real c;
     16     output Real d;
     17
     18     external "C" d=f_d_idd(a,b,c) annotation(Library="evaluatorTestsShared",
     19                             Include="#include \"evaluatorTests.h\"");
     20    end d_idd;
     21   
     22   
     23    Real c = d_i(1);
     24    Real d = d_idd(1, 2.0, 3.0);
     25end Evaluator_Double;
     26
     27model Evaluator_Integer
     28    function i_ii
     29     input Integer a;
     30     input Integer b;
     31     output Integer c;
     32
     33     external "C" c=f_i_ii(a,b) annotation(Library="evaluatorTestsShared",
     34                             Include="#include \"evaluatorTests.h\"");
     35    end i_ii;
     36   
     37    constant Integer c = i_ii(1,2);
     38end Evaluator_Integer;
     39
     40model Evaluator_Record
     41    record R
     42        Real x0;
     43        Real x1;
     44        Real x2;
     45        Real x3;
     46        Real x4;
     47        Real x5;
     48        Real x6;
     49        Real x7;
     50        Real x8;
     51        Real x9;
     52        Real x10;
     53    end R;
     54    function iddpR_ddddddddddd_
     55     input Integer a;
     56     input Real b;
     57     input Real c;
     58     output R d;
     59
     60     external "C" f___iddpR_ddddddddddd_(a,b,c,d) annotation(Library="evaluatorTestsShared",
     61                             Include="#include \"evaluatorTests.h\"");
     62    end iddpR_ddddddddddd_;
     63   
     64    constant R c = iddpR_ddddddddddd_(1,2.0,3.0);
     65end Evaluator_Record;
     66
     67
     68model Evaluator_Substring
     69    constant String full="Yy00";
     70    constant String sub=Modelica.Utilities.Strings.substring(full,1,1);
     71    constant String string1 = "This is line 111";
     72    constant String string2 = Modelica.Utilities.Strings.substring(string1,9,12); // string2 = \"line\"
     73    constant Integer len = Modelica.Utilities.Strings.length(string1);
     74    constant Integer start = Modelica.Utilities.Strings.Advanced.skipWhiteSpace("   Hello", 1);
     75    constant Boolean not_equal = Modelica.Utilities.Strings.isEqual("Temp", "test", true);
     76    constant Boolean equal = Modelica.Utilities.Strings.isEqual("Temp", "Temp", true);
     77end Evaluator_Substring;
     78
     79model Evaluator_Add
     80 function add1
     81     input Real a;
     82     input Real b;
     83     output Real c;
     84
     85     external "C" c=add(a,b) annotation(Library="addNumbersShared",
     86                             Include="#include \"addNumbers.h\"");
     87 end add1;
     88 
     89 function add2
     90     input Real a;
     91     input Real b;
     92     output Real c;
     93
     94     external "C" add_output(a,b,c) annotation(Library="addNumbersShared",
     95                             Include="#include \"addNumbers.h\"");
     96 end add2;
     97
     98 constant Real a = 1;
     99 constant Real b = 2;
     100 Real c = add1(a,b);
     101 Real d = add2(a,b);
     102end Evaluator_Add;
     103
     104model Evaluator_Multiple_Add
     105 function add
     106     input Real a;
     107     input Real b;
     108     input Real c;
     109     input Real d;
     110     input Real e;
     111     input Real f;
     112     input Real g;
     113     input Real h;
     114     input Real i;
     115     output Real o;
     116
     117     external "C" o=multiple_add(a,b,c,d,e,f,g,h,i) annotation(Library="addNumbersShared",
     118                             Include="#include \"addNumbers.h\"");
     119 end add;
     120 
     121 constant Real a = 1;
     122 constant Real b = 2;
     123 Real c = add(a,b,a,b,a,b,a,b,a);
     124end Evaluator_Multiple_Add;
     125
     126model Evaluator_Unknown_Shared
     127    function unknown_function
     128        input Real a;
     129        output Real b;
     130        external "C" b = unknown(a) annotation(Library="unknown");
     131    end unknown_function;
     132   
     133    constant Real a = unknown_function(1.0);
     134end Evaluator_Unknown_Shared;
    2135
    3136model ExtFunctionTest1
  • branches/dev-mo-2278/Python/src/tests_jmodelica/files/Modelica/Resources/CMakeLists.txt

    r13703 r13843  
    3838include_directories(${TOP_SRC}/RuntimeLibrary/src/jmi)
    3939
     40set(EVALUATORTESTS_Sources
     41    src/evaluatorTests.c
     42    Include/evaluatorTests.h
     43)
     44
    4045set(ADDNUMBERS_Sources
    4146    src/addNumbers.c
     
    7075endif()
    7176
     77#Build evaluatorTests library
     78add_library(evaluatorTestsShared SHARED ${EVALUATORTESTS_Sources})
     79if(NOT MSVC)
     80    set_target_properties(evaluatorTestsShared PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
     81endif()
     82
    7283#Build addNumbers library
    7384add_library(addNumbers STATIC ${ADDNUMBERS_Sources})
     85add_library(addNumbersShared SHARED ${ADDNUMBERS_Sources})
    7486if(NOT MSVC)
    7587    set_target_properties(addNumbers PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
     88    set_target_properties(addNumbersShared PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -Werror -O2")
    7689endif()
    7790
     
    106119
    107120#Install the libraries
     121install(TARGETS evaluatorTestsShared DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    108122install(TARGETS addNumbers DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
     123install(TARGETS addNumbersShared DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    109124install(TARGETS arrayFunctions DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
    110125install(TARGETS externalFunctionsC DESTINATION "${TEST_LIBRARY_INSTALL_DIR}")
  • branches/dev-mo-2278/Python/src/tests_jmodelica/files/Modelica/Resources/Include/addNumbers.h

    r13703 r13843  
    22#define ADDNUMBERS_H
    33
    4 double add(double a, double b);
     4#if defined _WIN32
     5    #define DllExport __declspec(dllexport)
     6#else
     7    #define DllExport
     8#endif
     9
     10DllExport double add(double a, double b);
     11DllExport void add_output(double a, double b, double *c);
     12DllExport double multiple_add(double a, double b, double c, double d, double e, double f, double g, double h, double i);
    513void multiplyAnArray(int* inputs, int* outputs, int size, int m);
    614
  • branches/dev-mo-2278/Python/src/tests_jmodelica/files/Modelica/Resources/src/addNumbers.c

    r13703 r13843  
    11#include "addNumbers.h"
    22
    3 double add(double a, double b)
     3DllExport double add(double a, double b)
    44{
    5   return a+b;
     5  return a + b;
     6}
     7
     8DllExport void add_output(double a, double b, double *c)
     9{
     10  *c = a + b;
     11}
     12
     13DllExport double multiple_add(double a, double b, double c, double d, double e, double f, double g, double h, double i)
     14{
     15  return a+b+c+d+e+f+g+h+i;
    616}
    717
  • branches/dev-mo-2278/Python/src/tests_jmodelica/general/base_simul.py

    r10446 r13843  
    286286       
    287287        if not cvode_options:
    288             cvode_options = {'atol':self.abs_tol,'rtol':self.rel_tol}
     288            cvode_options = {'atol':self.abs_tol,'rtol':self.rel_tol, 'maxh':0.0}
     289        else:
     290            if not 'maxh' in cvode_options:
     291                cvode_options['maxh'] = 0.0
    289292       
    290293        if isinstance(self.model, FMUModelME1) or isinstance(self.model, FMUModelME2):
  • branches/dev-mo-2278/Python/src/tests_jmodelica/general/test_extfunctions.py

    r13703 r13843  
    2222
    2323import nose
     24import fnmatch
    2425
    2526from pymodelica import compile_fmu
    2627from pymodelica.common.core import get_platform_dir, create_temp_dir
    27 from pyfmi import load_fmu
     28from pyfmi import load_fmu, FMUModelME2
    2829from pyfmi.fmi import FMUException
    2930from tests_jmodelica import testattr, get_files_path
     
    3334path_to_mofiles = os.path.join(get_files_path(), 'Modelica')
    3435
     36class TestEvaluator:
     37    @classmethod
     38    def setUpClass(cls):
     39        """
     40        Sets up the test class.
     41        """
     42        cls.fpath = path(path_to_mofiles, "ExtFunctionTests.mo")
     43   
     44    @testattr(stddist_base = True)
     45    def test_builtin_substring(self):
     46        cpath = "ExtFunctionTests.Evaluator_Substring"
     47        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, compiler_log_level="d:log.txt")
     48       
     49        nbr_of_evaluator_calls = 0
     50        with open("log.txt") as f:
     51            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     52            nbr_of_evaluator_calls = len(res)
     53       
     54        assert nbr_of_evaluator_calls == 4, "Wrong number of external function calls, check log."
     55       
     56        model = load_fmu(fmu_name)
     57       
     58        assert model.get("sub")[0] == "Y", model.get("sub")
     59        assert model.get("string2")[0] == "line", model.get("string2")
     60        assert model.get("len") == 16, model.get("len")
     61        assert model.get("start") == 4, model.get("start")
     62        assert not model.get("not_equal"), model.get("not_equal")
     63        assert model.get("equal"), model.get("equal")
     64   
     65    @testattr(stddist_base = True)
     66    def test_add(self):
     67        cpath = "ExtFunctionTests.Evaluator_Add"
     68        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, version=2.0, compiler_log_level="d:log.txt")
     69       
     70        nbr_of_evaluator_calls = 0
     71        with open("log.txt") as f:
     72            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     73            nbr_of_evaluator_calls = len(res)
     74       
     75        assert nbr_of_evaluator_calls == 2, "Wrong number of external function calls, check log."
     76       
     77        model = FMUModelME2(fmu_name, _connect_dll=False)
     78       
     79        assert model.get_variable_start("c") == 3, model.get_variable_start("c")
     80        assert model.get_variable_start("d") == 3, model.get_variable_start("d")
     81   
     82    @testattr(stddist_base = True)
     83    def test_unsupported_signature(self):
     84        cpath = "ExtFunctionTests.Evaluator_Multiple_Add"
     85        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, compiler_log_level="d:log.txt")
     86       
     87        matches = 0
     88        with open("log.txt") as f:
     89            res = fnmatch.filter(f, "*is not supported. Disabling use of the evaluator*")
     90            matches = len(res)
     91       
     92        assert matches == 1, "Does not seem to disabling the evaluator"
     93
     94    @testattr(stddist_base = True)
     95    def test_unknown_shared_library(self):
     96        cpath = "ExtFunctionTests.Evaluator_Unknown_Shared"
     97        try:
     98            fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, compiler_log_level="d:log_unknown_shared.txt")
     99        except: #The compilation will fail, the interesting parts will though still be contained in the log file
     100            pass
     101       
     102        matches = 0
     103        with open("log_unknown_shared.txt") as f:
     104            res = fnmatch.filter(f, "Could not find a shared library containing*")
     105            matches = len(res)
     106       
     107        assert matches == 1, "Seems to have found an unknown shared library"
     108   
     109    @testattr(stddist_base = True)
     110    def test_double_return(self):
     111        cpath = "ExtFunctionTests.Evaluator_Double"
     112        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, version=2.0, compiler_log_level="d:log.txt")
     113       
     114        nbr_of_evaluator_calls = 0
     115        with open("log.txt") as f:
     116            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     117            nbr_of_evaluator_calls = len(res)
     118       
     119        assert nbr_of_evaluator_calls == 2, "Wrong number of external function calls, check log."
     120       
     121        model = FMUModelME2(fmu_name, _connect_dll=False)
     122       
     123        assert model.get_variable_start("c") == 3.0, model.get_variable_start("c")
     124        assert model.get_variable_start("d") == 9.0, model.get_variable_start("d")
     125   
     126    @testattr(stddist_base = True)
     127    def test_integer_return(self):
     128        cpath = "ExtFunctionTests.Evaluator_Integer"
     129        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, version=2.0, compiler_log_level="d:log.txt")
     130       
     131        nbr_of_evaluator_calls = 0
     132        with open("log.txt") as f:
     133            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     134            nbr_of_evaluator_calls = len(res)
     135       
     136        assert nbr_of_evaluator_calls == 1, "Wrong number of external function calls, check log."
     137       
     138        model = FMUModelME2(fmu_name, _connect_dll=False)
     139       
     140        assert model.get_variable_start("c") == 3.0, model.get_variable_start("c")
     141   
     142    @testattr(stddist_base = True)
     143    def test_record(self):
     144        cpath = "ExtFunctionTests.Evaluator_Record"
     145        fmu_name = compile_fmu(cpath, self.fpath, compiler_options={"external_constant_evaluation_dynamic":True}, version=2.0, compiler_log_level="d:log.txt")
     146       
     147        nbr_of_evaluator_calls = 0
     148        with open("log.txt") as f:
     149            res = fnmatch.filter(f, "Succesfully connected external function '*' to the evaluator*")
     150            nbr_of_evaluator_calls = len(res)
     151       
     152        assert nbr_of_evaluator_calls == 1, "Wrong number of external function calls, check log."
     153       
     154        model = FMUModelME2(fmu_name, _connect_dll=False)
     155       
     156        assert model.get_variable_start("c.x0") == 1.0, model.get_variable_start("c.x0")
     157        assert model.get_variable_start("c.x1") == 2.0, model.get_variable_start("c.x1")
     158        assert model.get_variable_start("c.x2") == 3.0, model.get_variable_start("c.x2")
     159        assert model.get_variable_start("c.x3") == 3.0, model.get_variable_start("c.x3")
     160        assert model.get_variable_start("c.x4") == 4.0, model.get_variable_start("c.x4")
     161        assert model.get_variable_start("c.x5") == 5.0, model.get_variable_start("c.x5")
     162        assert model.get_variable_start("c.x6") == 6.0, model.get_variable_start("c.x6")
     163        assert model.get_variable_start("c.x7") == 7.0, model.get_variable_start("c.x7")
     164        assert model.get_variable_start("c.x8") == 8.0, model.get_variable_start("c.x8")
     165        assert model.get_variable_start("c.x9") == 9.0, model.get_variable_start("c.x9")
     166        assert model.get_variable_start("c.x10") == 10.0, model.get_variable_start("c.x10")
     167   
    35168class TestExternalStatic:
    36169
  • branches/dev-mo-2278/Python/src/tests_jmodelica/optimization/test_casadi_collocation.py

    r13401 r13843  
    366366        opts["CVode_options"]["rtol"] = 1e-6
    367367        opts["CVode_options"]["atol"] = 1e-8 * model.nominal_continuous_states
     368        opts["CVode_options"]["maxh"] = 0.0
     369        opts["ncp"] = 0
    368370        init_res = model.simulate(final_time=300, input=('Tc', u_traj),
    369371                                  options=opts)
     
    21252127        opts["CVode_options"]["rtol"] = 1e-6
    21262128        opts["CVode_options"]["atol"] = 1e-8 * model.nominal_continuous_states
     2129        opts["CVode_options"]["maxh"] = 0.0
     2130        opts["ncp"] = 0
    21272131        res = model.simulate(start_time=0., final_time=150., input=opt_input,
    21282132                             options=opts)
  • branches/dev-mo-2278/Python/src/tests_jmodelica/optimization/test_realtime_mpc.py

    r13492 r13843  
    3535def check_result(results, ref):
    3636    for key in ref:
    37         assert abs(ref[key] - results[key][-1]) < 1e-3, abs(ref[key] - results[key][-1])
     37        assert abs(ref[key] - results[key][-1]) < 1e-2, abs(ref[key] - results[key][-1])
    3838       
    3939
  • branches/dev-mo-2278/Python/src/tests_jmodelica/simulation/test_assimulo_interface_fmi.py

    r13366 r13843  
    20022002        opts["CVode_options"]["rtol"] = 1e-4
    20032003        opts["CVode_options"]["atol"] = 1e-6
     2004        opts["CVode_options"]["maxh"] = 0.0
     2005        opts["ncp"] = 0
    20042006        res = bounce.simulate(start_time=2.,final_time=5.,options=opts)
    20052007
     
    20202022        opts["CVode_options"]["rtol"] = 1e-4
    20212023        opts["CVode_options"]["atol"] = 1e-6
     2024        opts["CVode_options"]["maxh"] = 0.0
     2025        opts["ncp"] = 0
    20222026        res = bounce.simulate(final_time=3., options=opts)
    20232027       
     
    20332037        opt["CVode_options"]["rtol"] = 1e-4
    20342038        opt["CVode_options"]["atol"] = 1e-6
     2039        opt["CVode_options"]["maxh"] = 0.0
     2040        opt["ncp"] = 0
    20352041        res = bounce.simulate(final_time=3., options=opt)
    20362042       
     
    20592065        opts["CVode_options"]["rtol"] = 1e-4
    20602066        opts["CVode_options"]["atol"] = 1e-6
     2067        opts["CVode_options"]["maxh"] = 0.0
     2068        opts["ncp"] = 0
    20612069        res = bounce.simulate(final_time=3., options=opts)
    20622070
     
    20702078        #Writing continuous
    20712079        bounce = load_fmu('bouncingBall.fmu', path_to_fmus_me1)
    2072         #bounce.initialize(options={'initialize':False})
    20732080        res = bounce.simulate(final_time=3.,
    2074             options={'initialize':True,'CVode_options':{'iter':'FixedPoint','rtol':1e-6,'atol':1e-6}})
     2081            options={'initialize':True,'ncp':0, 'CVode_options':{'maxh':0.0, 'iter':'FixedPoint','rtol':1e-6,'atol':1e-6}})
    20752082   
    20762083        nose.tools.assert_almost_equal(res.solver.rtol, 0.00000100, 7)
     
    20922099        opts["CVode_options"]["rtol"] = 1e-4
    20932100        opts["CVode_options"]["atol"] = 1e-6
    2094         #bounce.initialize()
     2101        opts["CVode_options"]["maxh"] = 0.0
     2102        opts["ncp"] = 0
    20952103        res = bounce.simulate(final_time=3., options=opts)
    20962104       
     
    20992107       
    21002108        bounce.reset()
    2101         #bounce.initialize()
    2102        
     2109
    21032110        nose.tools.assert_almost_equal(bounce.get('h'), 1.00000,5)
    21042111       
  • branches/dev-mo-2278/Python/src/tests_jmodelica/test_delay.py

    r10318 r13843  
    3838def simulate(fmu, final_time, maxh = None):
    3939    opts = fmu.simulate_options()     
    40     opts['solver'] = 'CVode'           
     40    opts['solver'] = 'CVode'
     41    opts['ncp'] = 0
     42    opts['CVode_options']['maxh'] = 0.0
    4143    if maxh is not None:
    4244        opts['CVode_options']['maxh'] = maxh
  • branches/dev-mo-2278/Python/src/tests_jmodelica/test_fmi_2.py

    r13338 r13843  
    988988        assert opts['initialize']
    989989        assert opts['with_jacobian'] == "Default"
    990         assert opts['ncp'] == 0
    991990
    992991        #Test the result file
  • branches/dev-mo-2278/Python/src/tests_jmodelica/test_fmi_coupled.py

    r13338 r13843  
    8282        nose.tools.assert_almost_equal(res.final("time"),1.5)
    8383        nose.tools.assert_almost_equal(res.final("First.J1.w"),res.final("Second.J1.w"))
    84         nose.tools.assert_almost_equal(res.final("First.J1.w"), 3.2501079, places=3)
     84        nose.tools.assert_almost_equal(res.final("First.J1.w"), 3.2501079, places=2)
    8585       
    8686        coupled.reset()
     
    9090        nose.tools.assert_almost_equal(res.final("time"),1.5)
    9191        nose.tools.assert_almost_equal(res.final("First.J1.w"),res.final("Second.J1.w"))
    92         nose.tools.assert_almost_equal(res.final("First.J1.w"), 3.2501079, places=3)
     92        nose.tools.assert_almost_equal(res.final("First.J1.w"), 3.2501079, places=2)
    9393
    9494    @testattr(stddist_full = True)
  • branches/dev-mo-2278/RuntimeLibrary/CMakeLists.txt

    r13703 r13843  
    5555if(" ${CMAKE_C_FLAGS} " MATCHES " -m64 ")
    5656    set(RTLIB_LIB_DIR ${JMODELICA_INSTALL_DIR}/lib/RuntimeLibrary64)
     57    set(RTLIB_BIN_DIR ${JMODELICA_INSTALL_DIR}/bin64)
    5758else()
    5859    set(RTLIB_LIB_DIR ${JMODELICA_INSTALL_DIR}/lib/RuntimeLibrary)
     60    set(RTLIB_BIN_DIR ${JMODELICA_INSTALL_DIR}/bin)
    5961endif()
    6062install(CODE "file(MAKE_DIRECTORY $ENV{DESTDIR}${RTLIB_LIB_DIR})")
     
    9193add_subdirectory(src/modules)
    9294
     95#Add evaluator
     96include_directories(src/evaluator)
     97add_subdirectory(src/evaluator)
    9398
    9499if(EXTRA_RUNTIME_MODULES)
  • branches/dev-mo-2278/RuntimeLibrary/Makefiles/Makefile.linux

    r13703 r13843  
    126126LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a
    127127LIBS_FMU20   = -lfmi2 $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a
    128 LIBS_CEVAL   = $(LIBS_FMU_STD)
     128LIBS_CEVAL   = -ljmi_evaluator_util $(LIBS_FMU_STD)
    129129
    130130# Include paths for compilation
  • branches/dev-mo-2278/RuntimeLibrary/Makefiles/Makefile.macosx

    r13703 r13843  
    125125LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) $(SUNDIALS_HOME)/lib/libsundials_cvode.a
    126126LIBS_FMU20   = -lfmi2 $(LIBS_FMU_STD) $(LIB_COMMON) $(SUNDIALS_HOME)/lib/libsundials_cvode.a
    127 LIBS_CEVAL   = $(LIBS_FMU_STD)
     127LIBS_CEVAL   = -ljmi_evaluator_util $(LIBS_FMU_STD)
    128128
    129129# Include paths for compilation
  • branches/dev-mo-2278/RuntimeLibrary/Makefiles/Makefile.windows

    r13703 r13843  
    160160LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_ALL)
    161161LIBS_FMU20   = -lfmi2              $(LIBS_FMU_ALL)
    162 LIBS_CEVAL = $(LIBS_FMU_STD)
     162LIBS_CEVAL = -ljmi_evaluator_util $(LIBS_FMU_STD)
    163163
    164164# Include paths for compilation
  • branches/dev-mo-2278/RuntimeLibrary/src

  • branches/dev-mo-2278/RuntimeLibrary/src/fmi1_cs/CMakeLists.txt

    r13703 r13843  
    3737
    3838#Install the libraries
    39 install(TARGETS fmi1_cs DESTINATION "${RTLIB_LIB_DIR}")
     39if (NOT MSVC)
     40    install(TARGETS fmi1_cs DESTINATION "${RTLIB_LIB_DIR}")
     41endif()
    4042
    4143#Install header files
  • branches/dev-mo-2278/RuntimeLibrary/src/fmi1_me/CMakeLists.txt

    r13703 r13843  
    3939
    4040#Install the libraries
    41 install(TARGETS fmi1_me DESTINATION "${RTLIB_LIB_DIR}")
     41if (NOT MSVC)
     42    install(TARGETS fmi1_me DESTINATION "${RTLIB_LIB_DIR}")
     43endif()
    4244
    4345#Install header files
  • branches/dev-mo-2278/RuntimeLibrary/src/fmi2/CMakeLists.txt

    r13703 r13843  
    4949
    5050#Install the libraries
    51 install(TARGETS fmi2 DESTINATION "${RTLIB_LIB_DIR}")
     51if (NOT MSVC)
     52    install(TARGETS fmi2 DESTINATION "${RTLIB_LIB_DIR}")
     53endif()
    5254
    5355#Install header files
  • branches/dev-mo-2278/RuntimeLibrary/src/jmi/CMakeLists.txt

    r13703 r13843  
    202202
    203203    #Install the libraries
    204     install(TARGETS jmi
    205         DESTINATION "${RTLIB_LIB_DIR}")
     204    if (NOT MSVC)
     205        install(TARGETS jmi
     206            DESTINATION "${RTLIB_LIB_DIR}")
     207    endif()
    206208
    207209    #Install header files
     
    247249
    248250    #Install the libraries
    249     install(TARGETS ModelicaExternalC ModelicaStandardTables ModelicaIO ModelicaMatIO zlib
    250         DESTINATION "${RTLIB_LIB_DIR}")
     251    if (NOT MSVC)
     252        install(TARGETS ModelicaExternalC ModelicaStandardTables ModelicaIO ModelicaMatIO zlib
     253            DESTINATION "${RTLIB_LIB_DIR}")
     254    endif()
    251255
    252256    install(DIRECTORY "${MSLCSOURCES}/"
  • branches/dev-mo-2278/ThirdParty/build_thirdparties/build/sundials/makefile

    r12138 r13843  
    2828    mkdir -p $(SUNDIALS_BUILD_DIR); \
    2929    cd $(SUNDIALS_BUILD_DIR); \
    30     cmake $(GENERATOR) -DEXAMPLES_ENABLE=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=$(SUNDIALS_C_FLAGS) -DCMAKE_INSTALL_PREFIX:PATH=$(SUNDIALS_INSTALL_DIR) $(SUNDIALS_SRC_DIR)
     30    cmake $(GENERATOR) $(SUPERLU_ADDON) -DEXAMPLES_ENABLE=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=$(SUNDIALS_C_FLAGS) -DCMAKE_INSTALL_PREFIX:PATH=$(SUNDIALS_INSTALL_DIR) $(SUNDIALS_SRC_DIR)
    3131
    3232clean:
Note: See TracChangeset for help on using the changeset viewer.