Skip to content

Commit

Permalink
Merge pull request #1668 from poorva1209/develop
Browse files Browse the repository at this point in the history
passing load file to ochre and number of load federated to helics
  • Loading branch information
poorva1209 authored Aug 22, 2022
2 parents d18dc42 + bb0d972 commit 4ba4eaf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
throw new Exception("Missing parameter "+MODEL_ID);
}

String separated_loads_file = GridAppsDConstants.getStringProperty(parameters, GLDAllConfigurationHandler.SEPARATED_LOADS_FILE, null);
if(separated_loads_file==null || separated_loads_file.trim().length()==0){
logManager.error(ProcessStatus.ERROR,processId,"No "+GLDAllConfigurationHandler.SEPARATED_LOADS_FILE+" parameter provided");
throw new Exception("Missing parameter "+GLDAllConfigurationHandler.SEPARATED_LOADS_FILE);
}



try{
File tmpDir = new File(tempDataPath);
RunCommandLine.runCommand("cp -r /gridappsd/services/gridappsd-ochre/inputs/ "+tempDataPath);
Expand All @@ -160,14 +168,16 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
CONFIG_FILENAME+" "+
simulationBrokerPort+" "+
processId+" "+
model_id);
model_id+ " "+
separated_loads_file);
logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+
simulationBrokerHost+" "+
tempDataPath+" "+
CONFIG_FILENAME+" "+
simulationBrokerPort+" "+
processId+" "+
model_id);
model_id+" "+
separated_loads_file);

}catch(Exception e){
log.warn("Could not create OCHRE HELICS config file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ public void onMessage(Serializable message) {
JsonElement data = parser.parse(event.getData().toString());
if (data.isJsonObject()) {
JsonObject dataObj = data.getAsJsonObject();
String datatype = dataObj.get("datatype").getAsString();
if(datatype!=null)
provenWriteProducer.sendBulkMessage(event.getData().toString(), datatype, instanceId, simulationId, new Date().getTime());
if(dataObj.get("datatype")!=null){
String datatype = dataObj.get("datatype").getAsString();
if(datatype!=null)
provenWriteProducer.sendBulkMessage(event.getData().toString(), datatype, instanceId, simulationId, new Date().getTime());
}
}
}
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,24 @@
package gov.pnnl.goss.gridappsd.process;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.google.gson.Gson;

import gov.pnnl.goss.gridappsd.api.AppManager;
Expand Down Expand Up @@ -138,6 +146,14 @@ public void process(ConfigurationManager configurationManager,
if(!tempDataPathDir.exists()){
tempDataPathDir.mkdirs();
}


Map<String,Object> simulationContext = new HashMap<String,Object>();
simulationContext.put("request",simRequest);
simulationContext.put("simulationId",simulationId);
simulationContext.put("simulationHost","127.0.0.1");
simulationContext.put("simulationPort",simulationPort);
simulationContext.put("simulationDir",simulationConfigDir);


SimulationContext simContext = new SimulationContext();
Expand Down Expand Up @@ -183,10 +199,21 @@ else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE"))
configurationManager.generateConfiguration(DSSAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username);
}
else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){
numFederates = 42;
Properties simulationParams = generateSimulationParameters(simRequest);
simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId);
simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath());

if(simRequest.simulation_config.model_creation_config.separated_loads_file!=null){
numFederates = getSeparatedLoadNames(simRequest.simulation_config.model_creation_config.separated_loads_file).size()+2;
simulationParams.put(GLDAllConfigurationHandler.SEPARATED_LOADS_FILE, simRequest.simulation_config.model_creation_config.separated_loads_file);
}
else{
logManager.error(ProcessStatus.ERROR,simulationId,"No "+GLDAllConfigurationHandler.SEPARATED_LOADS_FILE+" parameter provided");
throw new Exception("Missing parameter "+GLDAllConfigurationHandler.SEPARATED_LOADS_FILE);
}



if(gldInterface!=null){
simulationParams.put(GridAppsDConstants.GRIDLABD_INTERFACE, gldInterface);
}
Expand All @@ -208,14 +235,9 @@ else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){

// Start Apps and Services

Map<String,Object> simulationContext = new HashMap<String,Object>();
simulationContext.put("request",simRequest);
simulationContext.put("simulationId",simulationId);
simulationContext.put("simulationHost","127.0.0.1");
simulationContext.put("simulationPort",simulationPort);
simulationContext.put("simulationDir",simulationConfigDir);
simulationContext.put("numFederates",numFederates);

simContext.numFederates = numFederates;

if(simRequest.getSimulation_config().getSimulator().equals("GridLAB-D"))
simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm");
else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE"))
Expand Down Expand Up @@ -374,6 +396,41 @@ Properties generateSimulationParameters(RequestSimulation requestSimulation){
}
return params;
}

private List<String> getSeparatedLoadNames(String fileName) {

List<String> loadNames = new ArrayList<String>();
boolean isHeader = true;

try {
FileInputStream fis = new FileInputStream(fileName);
Workbook workbook = null;
if(fileName.toLowerCase().endsWith("xlsx")){
workbook = new XSSFWorkbook(fis);
}else if(fileName.toLowerCase().endsWith("xls")){
workbook = new HSSFWorkbook(fis);
}

Sheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{

Row row = rowIterator.next();
if(!isHeader){
loadNames.add(row.getCell(5).getStringCellValue());
System.out.println(row.getCell(5).getStringCellValue());
}
isHeader=false;
}
fis.close();

} catch (IOException e) {
e.printStackTrace();
}

return loadNames;
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ public void run() {
List<String> commands = new ArrayList<String>();

if(simulationConfig.getSimulator().equals(OchreAllConfigurationHandler.TYPENAME)){
simContext.setNumFederates(42);
logManager.info(ProcessStatus.RUNNING, simulationId, "Setting num federates ");



//Start gridlabd
// simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm");
//File gldStartupFile = new File(simContext.simulationDir+File.separator+"inputs"+File.separator+"gridlabd"+File.separator+"IEEE-13"+File.separator+"IEEE-13_Houses.glm");
Expand Down

0 comments on commit 4ba4eaf

Please sign in to comment.