Developing

The GridLABD wrapper assumes a generic setup where there are one or several microgrids connected to a substation. The substation represents the main transport line that distributes the electricity from the power plants. Beneath the substation, there are powerlines connecting several grid nodes. It is up to the developer to consider each grid node a microgrid or to consider the collection of grid nodes as a combined microgrid.

GridLABD provides many and useful configuration facilities that can be used to tune the simulator behavior. However, SGSimulator simplifies the definition to enable an earlier experimentation. The focus is in investing less effort to the grid definition and more to the grid control.

The system can run two different setups:

  • There is a remote simulator acting as the actual grid. Clients connect and disconnect to particular elements to control them.
  • There is a local simulator and clients running inside the same virtual machine. The clients execute orders locally.

Contents

Downloading

The project bases the development on a template which can be downloades from github with

git clone https://github.com/Grasia/sgsim-ingenias.git

Short demo

To try the demo, you have to go to the folder and

mvn compile
sh runSmartGrid.sh 

Wait then sometime for the grid to start. Open another terminal in the same folder and run

sh runSampleClient.sh

The Solar_11 PV will be powered on and off in the simulation.

Inspecting the data

Simulation data is shown in the GUI. Future releases will provide a way to log the data into files. The fundamental data of grid performance can be gathered at the substation node There maybe an excessive generation of current in some nodes. This is detected by the simulator, but remote clients need not to be aware of this unless they probe the grid sensors. Transient states or harmonic issues are not detected by the simulator. However, there are some quality parameters that could be used:

  • the energy loss. These are transport losses, but they may happen too beacause of the transformers energy has to go through.
  • the energy bill. The energy can be bought at the substation too. It will be consumed if the microgrid is not producing enough.
  • the energy injection at the substation. The excess of energy of the microgrid is delivered to the grid. There is an excess if the grid produces more than it can consume.

Grid specification files

The important parts of the development are:

  • src/main/resources/griddef/configuration.glm. It defines basic elements of the grid using GridLABD notation. These elements are then used in the grid.xml. You should not modify this file unless you know what you are doing and have some experience with GridLABD
  • src/main/resources/griddef/grid.xml. It defines the microgrid asuming a bus-like configuration. There is a collection of interconnected first level grid nodes at MV or HV. Those nodes are connected to a single substation. The nodes transform current to LV and put together several buildings, aerogenerators, PV generators, and others.
  • src/main/resources/griddef/scenario.csv. It defines how much wind and sun there will be in the installation at every hour of the day. It uses numbers from 0 to 100 to indicate what percentage of the max expected output will be produced.

Validating the grid spec

There is a XSD describing the network which appears as soon as a “mvn compile” is issued. It will appaer at target/resources/xml/networkSchema.xsd. Developers can take this file and validate the spec.

Despite the XSD, a developer may still add mistakes to the specification document. The SGSimulator will trigger xml errors, then. As an example, readers can invoke this code that will load a wrong specification file.

mvn exec:java -Dexec.mainClass=mired.ucm.examples.server.RunServerFails

It will return an XML syntax error:

org.xml.sax.SAXParseException; systemId: file:/home/sgsimulator/actualizar/sgsim-ingenias/src/main/resources/griddef/wrongGrid.xml; lineNumber: 15; columnNumber: 14; cvc-complex-type.2.4.a: Invalid content was found starting with element 'connection'. One of '{"http://www.example.org/network":substation}' is expected.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.jaxp.validation.StreamValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Validator.java:124)
at mired.ucm.dynamicGLM.XMLUtilities.validateXMLSchema(XMLUtilities.java:169)
at mired.ucm.dynamicGLM.XMLParser.<init>(XMLParser.java:78)
at mired.ucm.simulator.NetworkConfiguration.createNetwork(NetworkConfiguration.java:155)
at mired.ucm.simulator.NetworkConfiguration.<init>(NetworkConfiguration.java:95)
at mired.ucm.simulator.Simulator.<init>(Simulator.java:66)
at mired.ucm.simulator.GridLabDiscreteEventSimulator.<init>(GridLabDiscreteEventSimulator.java:71)
at mired.ucm.simulator.displayer.SimulatorDisplayer.initSimulator(SimulatorDisplayer.java:509)
at mired.ucm.simulator.displayer.SimulatorDisplayer.init(SimulatorDisplayer.java:224)
at mired.ucm.simulator.displayer.SimulatorDisplayer.<init>(SimulatorDisplayer.java:150)
at mired.ucm.remote.server.SGServer.<init>(SGServer.java:104)
at mired.ucm.examples.server.RunServerFails.runServerFails(RunServerFails.java:85)
at mired.ucm.examples.server.RunServerFails.main(RunServerFails.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)

Also, when launching the simulator, a GUI will show the representation of the grid in a more friendly way. It is useful to validate the connections. The viewer is visible as soon as the server is started.

Gridviewer showing the interconnected elements

Launching the simulation

A remote simulation and remote clients

Each smartgrid simualtion is launched in paralell, so it is possible to run different grids at the same time. Class mired.ucm.examples.server.RunServer1 shows how to define and launch a smartgrid simulation with its RMI server. The core of the configuration of this grid follows:

public static SGServer runServer() throws IOException,
	java.rmi.AlreadyBoundException, GridlabException,
	ParserConfigurationException, SAXException, InterruptedException,
	RemoteException, NotBoundException {

	SGServer server = null;
	Tariff tarrif = new TariffExample();
	Calendar calendar = Calendar.getInstance();
	calendar.set(2014, 4, 15, 6, 0, 0); // Set the start time of the simulation
	// simulation configuration files
	String configFile = "src/main/resources/griddef/configuration.glm"; // tech params of grid elements
	String gridFile = "src/main/resources/griddef/grid.xml"; // grid definition		
	String scenarioFile = "src/main/resources/griddef/scenario.csv"; // weather and load per hour
	try {
		server = new SGServer("My simulation", 
				calendar.getTime(),
				gridFile, configFile, scenarioFile,
				ManageServer.hoursOfSimulation,
				ManageServer.cycleTimeInMinutes,
				ManageServer.momentsToShow, tarrif, 
				true); // The last parameter indicates clients will not be binded to the simulation cycle
		server.runServer();
	} catch (Throwable t) {
		t.printStackTrace();
	}
	return server;
}

The xml and glm files can be anywhere, but their paths need to be provided. Each server instance runs a separated instance of the GridLABD simulator run in a different temporal folder..

Once launched, the clients can find the server through the RMI. A simple client implementation is included. It should be launched afterwerds the grid is started. The client connects itself as the controller of the node transformerCT1. From there, it issues an order to Solar_11 to switch on, waits 2 seconds, and then switches it off. It also probes the sensors available in the transformation center.

public class SampleRunClientImp {
	public static void main(String args[]) throws Exception {
		RunClient.launch(new SGClient() {
		
			boolean finished=false;
		
			@Override
			public String getName() throws RemoteException {
				return "transformerCT1";
			}

			@Override
			public void serverStopped() throws RemoteException {
			  // invoked when the server has stopped
			}

			@Override
			public void serverStarted(RemoteSGServer server)
					throws RemoteException {
					System.out.println(server.getSubstationSensors());
				try {
					System.out.println(server.getTransformerSensors(this
						.getName()));
					System.out.println(server.getControllableDevices(this
						.getName()));
					server.executeOrder(this.getName(), new
					 RemoteSwitchOn("Solar_11"));					
					try {
						Thread.currentThread().sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}					
					server.executeOrder(this.getName(), new
							 RemoteSwitchOff("Solar_11"));
					finished=true;					
				} catch (SensorContainerNotFound e) {
					e.printStackTrace();
				}
			}
		
			@Override
			public boolean isFinished() {				
				return finished;
			}
		});
	}
}

There are four basic orders to be issued:

  • RemoteSwitchOn. It switches on a device.
  • RemoteSwitchOff. It switches off a device.
  • RemoteSet. Sets the device to produce a certain amount of P active power. If the device is a battery, a negative value means “charge to” and a positive value “discharge to” the value indicated as parameter (in watts). If the device is a generator, it tells the device to produce the indicated amount of power in the parameter (in watts)

To get the name of controlled devices, use the method getControllableDevices, as in the example. Each client connects itself to the entity with the same name in the grid. To get all accepted entities names, you can go to the microgrid definition file. In the example, it is src/main/resources/griddef/grid.xml Look for name tags in the transformer or in any of the tags nested under compoments tag.

Launching a local simulation with local clients

Local simulation implies the clients are binded to the simulation cycle. In this variant, the clients will issue and expect orders to be processed only when the time comes. The coding implies defining method to deliver orders when requested. All orders will be executed within the simulation cycle.