Skip to content

Commit

Permalink
resolved bugs to start multiple simulations and services within multi…
Browse files Browse the repository at this point in the history
…ple simulations
  • Loading branch information
poorva1209 committed Jan 5, 2024
1 parent caf817d commit faa2d4e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,6 @@ public List<ServiceInstance> listRunningServices(String serviceId, String simula
if(instance.getService_info().getId().equals(serviceId)){
if(simulationId!=null && instance.getSimulation_id().equals(simulationId))
result.add(instance);
else
result.add(instance);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void resumeSimulation(String simulationId){
}
@Override
public void endSimulation(String simulationId){
client.publish(GridAppsDConstants.topic_COSIM_input, "{\"command\": \"stop\"}");
client.publish(GridAppsDConstants.topic_COSIM_input+"."+simulationId, "{\"command\": \"stop\"}");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ else if(simulationConfig.getSimulator().equals(gridlabdConstant)){

//Subscribe to fncs-goss-bridge output topic
GossFncsResponseEvent gossFncsResponseEvent = new GossFncsResponseEvent(logManager, isInitialized, isFinished, simulationId);
client.subscribe("/topic/"+GridAppsDConstants.topic_COSIM_output, gossFncsResponseEvent);
client.subscribe("/topic/"+GridAppsDConstants.topic_COSIM_output+"."+simulationId, gossFncsResponseEvent);

logManager.info(ProcessStatus.RUNNING, simulationId, "Checking if co-simulation is initialized, currently "+isInitialized.isInited);

Expand All @@ -196,7 +196,7 @@ else if(simulationConfig.getSimulator().equals(gridlabdConstant)){
//TODO add limiting how long it checks for initialized, or cancel if the fncs process exits
//This call would return true/false for initialization and simulation output of time step 0.

client.publish(GridAppsDConstants.topic_COSIM_input, "{\"command\": \"isInitialized\"}");
client.publish(GridAppsDConstants.topic_COSIM_input+"."+simulationId, "{\"command\": \"isInitialized\"}");
initAttempts++;
Thread.sleep(1000);

Expand All @@ -217,7 +217,7 @@ else if(simulationConfig.getSimulator().equals(gridlabdConstant)){
}

//call to stop the simulation
client.publish(GridAppsDConstants.topic_COSIM_input, "{\"command\": \"stop\"}");
client.publish(GridAppsDConstants.topic_COSIM_input+"."+simulationId, "{\"command\": \"stop\"}");
logManager.info(ProcessStatus.COMPLETE, simulationId, "Simulation "+simulationId+" complete");
}
catch(Exception e){
Expand Down Expand Up @@ -251,7 +251,7 @@ private void startSimulation(GossFncsResponseEvent gossEvent, SimulationConfig s
// Send the start simulation command to the fncsgossbridge so that it runs it's time loop to move the fncs simulation forward
logManager.debug(ProcessStatus.RUNNING, simulationId, "Sending start simulation to bridge.");
String message = "{\"command\": \"StartSimulation\"}";
client.publish(GridAppsDConstants.topic_COSIM_input, message);
client.publish(GridAppsDConstants.topic_COSIM_input+"."+simulationId, message);
}

private void watch(final Process process, String processName) {
Expand Down
6 changes: 3 additions & 3 deletions services/helicsgossbridge/service/helics_goss_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def on_message(self, headers, msg):
message['response'] = str(self._is_initialized)
t_now = datetime.utcnow()
message['timestamp'] = int(time.mktime(t_now.timetuple()))
self._gad_connection.send(self._simulation_manager_input_topic , json.dumps(message))
self._gad_connection.send(self._simulation_manager_input_topic+"."+self._simulation_id , json.dumps(message))
elif json_msg.get('command', '') == 'update':
json_msg['input']["time_received"] = time.perf_counter()
message['command'] = 'update'
Expand Down Expand Up @@ -606,7 +606,7 @@ def run_simulation(self):
log.debug(f"Simulation finished in {time.perf_counter() - simulation_run_time_start} seconds.")
message['command'] = 'simulationFinished'
del message['output']
self._gad_connection.send(self._simulation_manager_input_topic, json.dumps(message))
self._gad_connection.send(self._simulation_manager_input_topic+"."+self._simulation_id, json.dumps(message))
log.info(f'Simulation {self._simulation_id} has finished.')
self._gad_connection.send_simulation_status('COMPLETE', f'Simulation {self._simulation_id} has finished.', 'INFO')
except Exception as e:
Expand All @@ -630,7 +630,7 @@ def _register_with_goss(self):
self._gad_connection = GridAPPSD(self._simulation_id)
log.debug("Successfully registered with the GridAPPS-D platform.")
self._gad_connection.subscribe(topics.simulation_input_topic(self._simulation_id), self.on_message)
self._gad_connection.subscribe("/topic/goss.gridappsd.cosim.input", self.on_message)
self._gad_connection.subscribe("/topic/goss.gridappsd.cosim.input."+self._simulation_id, self.on_message)
except Exception as e:
log.error("An error occurred when trying to register with the GridAPPS-D platform!", exc_info=True)

Expand Down

0 comments on commit faa2d4e

Please sign in to comment.