Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

Here is my translation of the ruby project to c#.

Step 1: Variables Step 2: Create IDF Step 3: Start RunManager Step 4: Found EnergyPlus.exe File Step 5: Simulation Step 6: Read SQL File

       //_path must be your Folder of Saving the Project z.B. C://OpenStudio//Projects//...
        string e _runDirStr =_path + "\\run";
        string _sqlPathStr = _runDirStr + "\\EnergyPlus\\eplusout.sql";
        string _epDirStr = "C:\\EnergyPlusV8-4-0";
        string _epPathStr = _epDirStr + "\\energyplus.exe";
        string idd_pathStr = _epDirStr + "\\Energy+.idd";
        string  outputPathStr = _runDirStr;

        Path _epPath = new Path(_epPathStr);
        Path _sqlPath = new Path(_sqlPathStr);

        System.IO.Directory.CreateDirectory(_path);
        System.IO.Directory.CreateDirectory(_runDirStr);

        SimulationControl control = _model.getSimulationControl();
        control.setDoPlantSizingCalculation(true);
        control.setDoZoneSizingCalculation(true);
        control.setRunSimulationforSizingPeriods(false); //do not use DesignDays
        control.setRunSimulationforWeatherFileRunPeriods(true); //use Weatherfile

        //Export IDF
        string idf_name, osm_name;
        idf_name = "simulation_in.idf";
        osm_name = "simulation_ThesisModel.osm";
        EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator();
        Workspace idf = translator.translateModel(_model);
        //IdfFile idf_file =  _model.toIdfFile();
        _idfPathStr = _runDirStr + "\\" + idf_name;
        osmPathStr = _runDirStr + "\\" + osm_name;
        idf.save(new Path(_idfPathStr),true);
        _model.save(new Path(osmPathStr), true);

        //Runmanager
        Path runManagerPath = new Path(_runDirStr + "\\simulation_runmanager.db");
        RunManager run = new RunManager(runManagerPath, true, false, false, false);
        ToolInfo tool = new ToolInfo(_epPath);
        Job job = JobFactory.createEnergyPlusJob(tool, new Path(idd_pathStr), new Path(_idfPathStr), _weatherFilePath, new Path(outputPathStr));
        run.enqueue(job, true);
        run.setPaused(false);
        run.workPending();

        //start Simulation
        //run.runWorkflow(new Path(job.toJSON()),new Path(_idfPath),new Path(_runDir), new Tools(),"");
        Workflow sim = new Workflow(job);
        sim.create(new Path(outputPathStr), new Path(new Path(_idfPathStr)));

        //read results
        if (System.IO.File.Exists(_sqlPathStr))
        {
            _model.setSqlFile(new SqlFile(_sqlPath));
        }

Here is my translation of the ruby project to c#.

  • Step 1: Variables Variables
  • Step 2: Create IDF IDF
  • Step 3: Start RunManager
  • Step 4: Found EnergyPlus.exe File
  • Step 5: Simulation Simulation
  • Step 6: Read SQL File

        //_path must be your Folder of Saving the Project z.B. C://OpenStudio//Projects//...
         string e _runDirStr =_path + "\\run";
         string _sqlPathStr = _runDirStr + "\\EnergyPlus\\eplusout.sql";
         string _epDirStr = "C:\\EnergyPlusV8-4-0";
         string _epPathStr = _epDirStr + "\\energyplus.exe";
         string idd_pathStr = _epDirStr + "\\Energy+.idd";
         string  outputPathStr = _runDirStr;
    
         Path _epPath = new Path(_epPathStr);
         Path _sqlPath = new Path(_sqlPathStr);
    
         System.IO.Directory.CreateDirectory(_path);
         System.IO.Directory.CreateDirectory(_runDirStr);
    
         SimulationControl control = _model.getSimulationControl();
         control.setDoPlantSizingCalculation(true);
         control.setDoZoneSizingCalculation(true);
         control.setRunSimulationforSizingPeriods(false); //do not use DesignDays
         control.setRunSimulationforWeatherFileRunPeriods(true); //use Weatherfile
    
         //Export IDF
         string idf_name, osm_name;
         idf_name = "simulation_in.idf";
         osm_name = "simulation_ThesisModel.osm";
         EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator();
         Workspace idf = translator.translateModel(_model);
         //IdfFile idf_file =  _model.toIdfFile();
         _idfPathStr = _runDirStr + "\\" + idf_name;
         osmPathStr = _runDirStr + "\\" + osm_name;
         idf.save(new Path(_idfPathStr),true);
         _model.save(new Path(osmPathStr), true);
    
         //Runmanager
         Path runManagerPath = new Path(_runDirStr + "\\simulation_runmanager.db");
         RunManager run = new RunManager(runManagerPath, true, false, false, false);
         ToolInfo tool = new ToolInfo(_epPath);
         Job job = JobFactory.createEnergyPlusJob(tool, new Path(idd_pathStr), new Path(_idfPathStr), _weatherFilePath, new Path(outputPathStr));
         run.enqueue(job, true);
         run.setPaused(false);
         run.workPending();
    
         //start Simulation
         //run.runWorkflow(new Path(job.toJSON()),new Path(_idfPath),new Path(_runDir), new Tools(),"");
         Workflow sim = new Workflow(job);
         sim.create(new Path(outputPathStr), new Path(new Path(_idfPathStr)));
    
         //read results
         if (System.IO.File.Exists(_sqlPathStr))
         {
             _model.setSqlFile(new SqlFile(_sqlPath));
         }