Ignore:
Timestamp:
09/24/11 22:52:30 (13 years ago)
Author:
vasaie_p
Message:

simulation execution with omc

Location:
trunk/modelicaml/org.openmodelica.modelicaml.simulation/src/org/openmodelica/modelicaml/simulation/execution
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.simulation/src/org/openmodelica/modelicaml/simulation/execution/ExecuteSimulation.java

    r996 r1004  
    1 package org.openmodelica.modelicaml.simulation.simulationexecution;
     1package org.openmodelica.modelicaml.simulation.execution;
    22import java.io.File;
    33
     4import org.openmodelica.modelicaml.simulation.filehandling.cp;
    45import org.openmodelica.modelicaml.simulation.omc.OpenModelicaCompilerCommunication;
    56import org.openmodelica.modelicaml.simulation.xml.TestSession;
     
    1011
    1112    /**
    12      * Compiling the model code using OMC
     13     * Compiling and simulating the model code using OMC
    1314     * Error Handling : Syntax, Semantic check by OMC.
    1415     *
    15      * @return the string
     16     * @return the omc return string, if the string is empty there was no error otherwise the error string is included
    1617     */
    17     private static String compileModel(File sessionFolder, File tempSimulationFolder, TestSession testSessionObj){
     18    public static String executeAllModels(File sessionFolder, String omcTempWorkingFolder, TestSession testSessionObj){
    1819        OpenModelicaCompilerCommunication omcc = new OpenModelicaCompilerCommunication();
    1920        String omcReturnString = "";
    20         String pathForOMC = tempSimulationFolder.getAbsolutePath();
    2121       
    22         while(pathForOMC.contains("\\")){
    23             pathForOMC = pathForOMC.replace('\\', '/');
     22        while(omcTempWorkingFolder.contains("\\")){
     23            omcTempWorkingFolder = omcTempWorkingFolder.replace('\\', '/');
    2424        }
    2525       
     
    2727        omcc.clear();
    2828       
    29         //Change directory
    30         omcReturnString = omcc.cd();
     29        //OMC is working in the eclipse project folder, therefore the folder must been changed to the OM installation folder where a tmp folder can be created.
     30        omcReturnString = omcc.cd(omcTempWorkingFolder);       
    3131        if(omcReturnString.contains("Error")){
    3232            String errorString = omcc.getErrorString();
     
    3434            return "cd: " + omcReturnString + "\nErrorString: " + errorString;
    3535        }
    36         else{
    37             File omcWorkingDirectory = new File(omcReturnString);
    38 //          omcReturnString = ""; //TODO cd muss hier raus und nach oben gepackt werden!
    39         }
     36        else
     37            omcReturnString = "";
    4038       
    4139        //Load package.mo
     
    4644                packageMO = packageMO.replace('\\', '/');
    4745            }
    48             //TODO [20110224] Check for true or false
     46           
    4947            if(new File(packageMO).isDirectory()){
    5048                omcReturnString = omcc.loadFile(packageMO.replaceAll("%20", " ") + "/package.mo"); //If the file is a directory the whole contained model will be loaded
     
    8583        //Simulate model
    8684        for(TestModel model : testSessionObj.testModels){
    87             omcReturnString = omcc.buildModel(model.qualifiedName, model.start, model.stop, model.numberOfIntervals, model.tolerance, model.solver, model.outputFormat);
     85            omcReturnString = omcc.simulate(model.qualifiedName, model.start, model.stop, model.numberOfIntervals, model.tolerance, model.solver, model.outputFormat);
    8886           
    8987            if(omcReturnString.contains("{\"\",\"\"}") || omcReturnString.contains("Error")){
     
    107105     */
    108106    public static void main(String[] args) {
    109         String sessionFolderPath = "C:\\Projects\\ModelicaML\\runtime-New_configuration\\modelicaml.example.potableWaterSystem_v25\\test-gen\\test-session_20110922235427\\";
     107        String sessionFolderPath = "C:\\Projects\\ModelicaML\\runtime-New_configuration\\modelicaml.example.potableWaterSystem_v26\\test-gen\\test-session_20110924175101\\";
    110108       
    111109        TestSession testSessionObj = TestSessionXML_Reader.readFromXML(sessionFolderPath + "test_session.xml");
    112        
     110        String omcTempWorkingFolder = System.getenv().get("OPENMODELICAHOME") + "/tmp";
    113111        File sessionFolder = new File(sessionFolderPath);
    114112        File tempSimulationFolder = new File(sessionFolderPath + "tmp");
    115             tempSimulationFolder.mkdir();
    116             tempSimulationFolder.canWrite();
    117         String omcMessage = compileModel(sessionFolder, tempSimulationFolder, testSessionObj);
     113        tempSimulationFolder.mkdir();
     114        tempSimulationFolder.canWrite();
     115        String omcMessage = executeAllModels(sessionFolder, omcTempWorkingFolder, testSessionObj);
    118116        if(omcMessage.isEmpty()){
    119117           
     
    121119        else
    122120            System.out.println("OMC Message: /n" + omcMessage);
     121       
     122        for(TestModel model : testSessionObj.testModels){
     123            cp.copyFile(omcTempWorkingFolder + "/" + model.qualifiedName + ".exe", tempSimulationFolder + "/" + model.qualifiedName + ".exe");
     124            cp.copyFile(omcTempWorkingFolder + "/" + model.qualifiedName + "_init.xml", tempSimulationFolder + "/" + model.qualifiedName + "_init.xml");
     125            cp.copyFile(omcTempWorkingFolder + "/" + model.qualifiedName + "_res.plt", tempSimulationFolder + "/" + model.qualifiedName + "_res.plt");
     126        }
    123127    }
    124128
Note: See TracChangeset for help on using the changeset viewer.