Skip to content

Commit

Permalink
Merge branch 'master' into linkconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg committed Aug 28, 2016
2 parents 5e045cc + e005daa commit 639b7b4
Show file tree
Hide file tree
Showing 29 changed files with 1,554 additions and 1,113 deletions.
9 changes: 8 additions & 1 deletion EU2Mod_MB/pom.xml
Expand Up @@ -18,5 +18,12 @@
</parent>

<artifactId>EU2Mod_MB</artifactId>


<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions EU2Mod_MB/src/main/java/itesla/converter/Block.java
Expand Up @@ -12,6 +12,7 @@
/**
* Single block of the Eurostag macroblock
* @author Marc Sabate <sabatem@aia.es>
* @author Raul Viruez <viruezr@aia.es>
*/
public class Block {
public String[] param = new String[8];
Expand Down
38 changes: 6 additions & 32 deletions EU2Mod_MB/src/main/java/itesla/converter/Converter.java
Expand Up @@ -9,8 +9,6 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -21,7 +19,9 @@
import java.util.List;

/**
* Class to convert macroblocks from Eurostag to Modelica
* @author Marc Sabate <sabatem@aia.es>
* @author Raul Viruez <viruezr@aia.es>
*/
public class Converter {
public String pathfrm;
Expand All @@ -33,9 +33,7 @@ public class Converter {
private Boolean init;
private ModelicaModel MO;
private Boolean isEmpty;




public Converter(String pathfrm, String pathOut, Boolean init) {
this.pathfrm = pathfrm;
this.pathOut = pathOut;
Expand All @@ -55,10 +53,7 @@ public Converter(String pathfrm, String pathOut, Boolean init) {
}
}


private ModelicaModel EUparser() throws IOException{


private ModelicaModel EUparser() throws IOException{
String sep = ";";
String line;
Hashtable<Integer,Element> CT = new Hashtable<Integer,Element>(); //correspondance table
Expand Down Expand Up @@ -90,7 +85,6 @@ private ModelicaModel EUparser() throws IOException{
}
Element elt = new Element(CTidEu, nameEu, nameModelica, param, nInputPins);
CT.put(CTidEu, elt);

}
bufferCT.close();

Expand All @@ -110,20 +104,14 @@ private ModelicaModel EUparser() throws IOException{
isEmpty=true;
MO = new ModelicaModel(pathfrm,parData);
} else {

String[][] paramEu = EUfile.getParamEU();
Integer[] GraphicalNumber = EUfile.getGraphicalNumber();
String[][] entries = EUfile.getEntries();
String[] Blocksoutput = EUfile.getBlocksoutput();
Integer[] idEu = EUfile.getIdEu();
Integer[][] link = EUfile.getLink();
Integer nLinks = EUfile.getnLinks();


//.par file lecture
// File parFile = new File(pathPar);
// ParParser parData = new ParParser(parFile);


//creation of the n blocks
//counter of the blocks of the same type
Block[] Macroblock = new Block[nBlocks];
Expand All @@ -146,21 +134,14 @@ private ModelicaModel EUparser() throws IOException{
}
MO = new ModelicaModel(Macroblock, link, pathfrm, CT, parData);
}


return MO;
}


public void convert2MO() throws IOException {
// File parFile = new File(pathPar);
// ParParser parData = new ParParser(parFile);


File frm = new File(pathfrm);
String nameModel = frm.getName().split("\\.")[0];
if (init) nameModel = nameModel+"_init";
File outFile = new File(pathOut, nameModel + ".mo");
File outFile = new File(pathOut, nameModel + ".mo");
BufferedWriter out = new BufferedWriter(new FileWriter(outFile));

if (init) {
Expand All @@ -169,7 +150,6 @@ public void convert2MO() throws IOException {
out.write(MO.outputHeading + "\n");
}


if (!isEmpty) {
List<Integer> setIds = parData.getSetIds();
for (int i=0; i<setIds.size(); i++) {
Expand All @@ -193,7 +173,6 @@ public void convert2MO() throws IOException {
}

out.write("equation\n");
//if (nLinks>0) {
if (MO.outputConnection.size()>0) {
for (int i=0; i<MO.outputConnection.size(); i++){
out.write(MO.outputConnection.get(i) + "\n");
Expand All @@ -217,7 +196,6 @@ public void convert2MO() throws IOException {
out.write(MO.outputParamDeclaration.get(i) + "\n");
}
out.write("equation\n");

}
if (init) {
out.write(MO.outputEnd + "_init" + ";");
Expand All @@ -227,7 +205,6 @@ public void convert2MO() throws IOException {
out.close();
}


public void printLinkNames() throws IOException {

File frm = new File(pathfrm);
Expand Down Expand Up @@ -255,7 +232,4 @@ public List<String> getInit_friParameters() {
public List<String> getInit_InterfaceParameters() {
return MO.init_InterfaceParameters;
}



}
40 changes: 12 additions & 28 deletions EU2Mod_MB/src/main/java/itesla/converter/EU_MBparser.java
Expand Up @@ -14,11 +14,11 @@
import java.util.List;

/**
* Class to parse macroblocks in Eurostag
* @author Marc Sabate <sabatem@aia.es>
* @author Raul Viruez <viruezr@aia.es>
*/
public class EU_MBparser {


private File EUfile;
private String[][] paramEu;
private String[][] entries;
Expand All @@ -29,33 +29,28 @@ public class EU_MBparser {
private Integer nLinks;
private Integer nBlocks;


/*
* Clase que parsea un archivo *.frm o un archivo *.fri guardado en EUfile y lo parsea, con el metodo parser. Los elementos que guarda de un macrobloque son:
* EUfile: la ruta del archivo que se esta parseando.
* nBlocks: numero de bloques del macrobloque
* paramEu: array de 8 filas, i nBlocks columnas. Cada bloque matematico puede tener como maximo 8 parametros: 6 parametros, el offset y el init_value
* entries: array de 5 filas y nBlocks columnas. Cada bloque matematico tiene 5 pins de entrada
* Blocksoutput: array de nBlocks posiciones. Cada bloque tiene un pin de salida
* GraphicalNumber: array de nBlocks posiciones. Cada instancia de un bloque tiene un id gráfico (es el id que vemos en el model Editor de Eurostag)
* idEu: array de nBlocks posiciones. Cada tipo de bloque tiene un id de Eurostag asignado.
* nLinks: numero de links definidos
* link: array de nLinks filas, y 3 columnas. Cada fila es un link: el bloque de salida, el bloque de entrada, y el pin del bloque de entrada.
* Class to parse an *.frm/*.fri files. It saves the following information regarding the macroblocks:
* EUfile: path of the file that will be parsed.
* nBlocks: number of blocks inside the macroblock.
* paramEu: an 8 x nBlocks array. Each mathematic block has a maximum of 8 parameters: 6 parameters, offset and init_value.
* entries: an 5 x nBlocks array. Each mathematic block has 5 input pins.
* Blocksoutput: nBlocks array. Each block has 1 output pin.
* GraphicalNumber: nBLocks array. Each instance of a block has an graphical id
* idEu: nBlocks array. Each type of a block has an Eurostag id.
* nLinks: number of links.
* link: nLinks x 3 array. Each row is a link: the output block and the input block.
*/
public EU_MBparser(File EUfile) {
this.EUfile = EUfile;
try {
parser();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



private void parser() throws IOException {

String sep = "\\s+";
String line;
List<String[]> dataFile = new ArrayList<String[]>();
Expand Down Expand Up @@ -85,8 +80,6 @@ private void parser() throws IOException {
GraphicalNumber = new Integer[nBlocks];
idEu = new Integer[nBlocks];



//parameters
int rowIni = 3;
int nDatosPerBlock = 8;
Expand Down Expand Up @@ -147,14 +140,8 @@ private void parser() throws IOException {
}
}
}



}




public String[][] getParamEU() {
return paramEu;
}
Expand Down Expand Up @@ -203,7 +190,4 @@ static private String[][] Extract(List<String[]> frmFile, Integer ini, Integer r
}
return output;
}



}
18 changes: 9 additions & 9 deletions EU2Mod_MB/src/main/java/itesla/converter/Element.java
Expand Up @@ -9,15 +9,16 @@
import java.util.ArrayList;
import java.util.List;

/**
* Element de la librería PowerSystems. Hace una correspondencia con el elemento de Eurostag.
* idEu: cada bloque del macrobloque tiene un id de Eurostag asignado.
* nameEu: nombre del bloque de Eurostag
* pathModelica: path del correpsondiente bloque dentro de la librería de PowerSystems
* nameModelica: nombre del bloque dentro de la librería de PowerSystems.
* nInputpins: numero de input pins del modelo en Modelica
* param: nombre de los parametros del modelo en Modelica
/*
* Class representing the iPSL model that corresponds to the Eurostag device.
* idEu: each block inside the macroblock has an Eurostag id.
* nameEu: name of the block in Eurostag.
* pathModelica: path of the iPSL model that represents this block.
* nameModelica: name of the iPSL model that represents this block.
* nInputpins: number of the input pins in Modelica.
* param: name of the parameters in the Modelica model.
* @author Marc Sabate <sabatem@aia.es>
* @author Raul Viruez <viruezr@aia.es>
*/
public class Element {
public Integer idEu;
Expand All @@ -37,5 +38,4 @@ public Element(int idEu, String nameEu, String nameModelica, List<String> param,
this.param = param;
this.nInputPins = nInputPins;
}

}

0 comments on commit 639b7b4

Please sign in to comment.