Skip to content

Commit

Permalink
Replace TwoTerminalConnectable by Branch and SingleTerminalConnectab…
Browse files Browse the repository at this point in the history
…l by Injection
  • Loading branch information
yichen88 committed Aug 30, 2017
1 parent a967e45 commit 9c8ceb7
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
Expand Up @@ -23,13 +23,13 @@ public class BranchParallelIndexes {

public static BranchParallelIndexes build(Network network, EurostagEchExportConfig config, EurostagFakeNodes fakeNodes) {
Multimap<String, Identifiable> map = HashMultimap.create();
for (TwoTerminalsConnectable ttc : Iterables.concat(network.getLines(), network.getTwoWindingsTransformers())) {
ConnectionBus bus1 = ConnectionBus.fromTerminal(ttc.getTerminal1(), config, fakeNodes);
ConnectionBus bus2 = ConnectionBus.fromTerminal(ttc.getTerminal2(), config, fakeNodes);
for (Branch branch : Iterables.concat(network.getLines(), network.getTwoWindingsTransformers())) {
ConnectionBus bus1 = ConnectionBus.fromTerminal(branch.getTerminal1(), config, fakeNodes);
ConnectionBus bus2 = ConnectionBus.fromTerminal(branch.getTerminal2(), config, fakeNodes);
if (bus1.getId().compareTo(bus2.getId()) < 0) {
map.put(bus1.getId() + bus2.getId(), ttc);
map.put(bus1.getId() + bus2.getId(), branch);
} else {
map.put(bus2.getId() + bus1.getId(), ttc);
map.put(bus2.getId() + bus1.getId(), branch);
}
}
for (VoltageLevel vl : network.getVoltageLevels()) {
Expand Down
Expand Up @@ -227,7 +227,7 @@ private static void dumpBusesDictionary(Network network, EurostagDictionary dict
}
}

private static void dumpLimits(EurostagDictionary dictionary, BufferedWriter writer, TwoTerminalsConnectable branch) throws IOException {
private static void dumpLimits(EurostagDictionary dictionary, BufferedWriter writer, Branch branch) throws IOException {
dumpLimits(dictionary, writer, branch.getId(),
branch.getCurrentLimits1(),
branch.getCurrentLimits2(),
Expand Down
Expand Up @@ -139,7 +139,7 @@ public static Connect2RegulatorsRecord getModelicaRecord(Internal reg1, Internal
* @param modContext
* @return
*/
public static ConnectGlobalVarRecord getModelicaRecord(SingleTerminalConnectable ident, GlobalVariable globalVar, ModExportContext modContext, DDBManager ddbManager, SimulatorInst simulator) {
public static ConnectGlobalVarRecord getModelicaRecord(Injection ident, GlobalVariable globalVar, ModExportContext modContext, DDBManager ddbManager, SimulatorInst simulator) {
ConnectGlobalVarRecord connectGlobalVarRecord = new ConnectGlobalVarRecord(ident, globalVar);
connectGlobalVarRecord.createModelicaName(modContext, ddbManager, simulator);
return connectGlobalVarRecord;
Expand Down Expand Up @@ -398,7 +398,7 @@ public static RegulatorRecord getModelicaRecord(GeneratorRecord genRecord, Inter
}


public static float getNominalVoltage(TwoTerminalsConnectable twoTermCon, TwoTerminalsConnectable.Side side) {
public static float getNominalVoltage(Branch branch, Branch.Side side) {

return 0;
}
Expand Down
Expand Up @@ -276,7 +276,7 @@ private void DoConvertion(Writer writerMo, String modelicaVersion) throws IOExce
if (OMEGAREF_Var.getValue() != null)
{
// Export Connect between Generators and OmegaRef
exportConnectGlobalVar(writerMo, modContext, new ArrayList<SingleTerminalConnectable>(generators), OMEGAREF_Var, modelicaSim);
exportConnectGlobalVar(writerMo, modContext, new ArrayList<Injection>(generators), OMEGAREF_Var, modelicaSim);
}
}

Expand Down Expand Up @@ -1079,16 +1079,16 @@ private List<RegulatorRecord> searchSpecialRegs(List<RegulatorRecord> regulators
/**
* Export IIDM Generators to Modelica Generators-OmegaRef connect
*/
private void exportConnectGlobalVar(Writer writerMo, ModExportContext modContext, List<SingleTerminalConnectable> identList, GlobalVariable globalVar, SimulatorInst modelicaSim) throws IOException {
private void exportConnectGlobalVar(Writer writerMo, ModExportContext modContext, List<Injection> identList, GlobalVariable globalVar, SimulatorInst modelicaSim) throws IOException {
if ((identList.size() != 0) && (!identList.isEmpty()))
{
this.addRecord(writerMo, null);
for (SingleTerminalConnectable singleTerCon : identList)
for (Injection injection : identList)
{
ConnectBusInfo busInfo = findBus(singleTerCon.getTerminal(), singleTerCon.getId());
ConnectBusInfo busInfo = findBus(injection.getTerminal(), injection.getId());
if (!Float.isNaN(busInfo.getBus().getV()) && busInfo.isConnected())
{
ConnectGlobalVarRecord record = ModelConverter.getModelicaRecord(singleTerCon, globalVar, modContext, _ddbManager, modelicaSim);
ConnectGlobalVarRecord record = ModelConverter.getModelicaRecord(injection, globalVar, modContext, _ddbManager, modelicaSim);
if (record != null)
{
this.addRecord(record, writerMo, modContext, _ddbManager, modelicaSim);
Expand Down
Expand Up @@ -361,7 +361,7 @@ private static void writeNetworkData(Network network, boolean isOld) {
_log.info("# ------------------------------- ------------------------------- ");
_log.info("# Name From To From To ");
_log.info("#------------------------ --------------- --------------- --------------- --------------- ");
for(TwoTerminalsConnectable trafo : network.getTwoWindingsTransformers())
for(Branch trafo : network.getTwoWindingsTransformers())
{
_log.info(String.format("%s %15.8f %15.8f %15.8f %15.8f", trafo.getId(), trafo.getTerminal1().getQ(), trafo.getTerminal2().getQ(), trafo.getTerminal1().getP(), trafo.getTerminal2().getP()));
}
Expand Down
Expand Up @@ -11,9 +11,9 @@
import eu.itesla_project.iidm.ddb.model.Parameter;
import eu.itesla_project.iidm.ddb.model.SimulatorInst;
import eu.itesla_project.iidm.ddb.service.DDBManager;
import eu.itesla_project.iidm.network.Branch;
import eu.itesla_project.iidm.network.Bus;
import eu.itesla_project.iidm.network.Equipments;
import eu.itesla_project.iidm.network.TwoTerminalsConnectable;
import eu.itesla_project.modelica_export.ModExportContext;
import eu.itesla_project.modelica_export.ModelicaRecord;
import eu.itesla_project.modelica_export.util.IIDMParameter;
Expand All @@ -31,29 +31,29 @@
*/
public abstract class BranchRecord extends ModelicaRecord {

BranchRecord(TwoTerminalsConnectable twoTerminalsConnectable) {
this.twoTerminalsConnectable = twoTerminalsConnectable;
BranchRecord(Branch branch) {
this.branch = branch;
}

@Override
public void createModelicaName(ModExportContext modContext, DDBManager ddbManager, SimulatorInst modelicaSim) {
Equipments.ConnectionInfo terminal1Info = Equipments.getConnectionInfoInBusBreakerView(twoTerminalsConnectable.getTerminal1());
Equipments.ConnectionInfo terminal2Info = Equipments.getConnectionInfoInBusBreakerView(twoTerminalsConnectable.getTerminal2());
Equipments.ConnectionInfo terminal1Info = Equipments.getConnectionInfoInBusBreakerView(branch.getTerminal1());
Equipments.ConnectionInfo terminal2Info = Equipments.getConnectionInfoInBusBreakerView(branch.getTerminal2());

bus1 = terminal1Info.getConnectionBus();
bus2 = terminal2Info.getConnectionBus();

//System.out.println("Trafo: " + this.twoTerminalsConnectable.getId() + ". Terminal 1: " + bus1.getId() + ". Terminal 2: " + bus2.getId());
//System.out.println("Trafo: " + this.branch.getId() + ". Terminal 1: " + bus1.getId() + ". Terminal 2: " + bus2.getId());

nodeName1 = parseName(bus1.getId());
nodeName2 = parseName(bus2.getId());

String branchName = parseName(twoTerminalsConnectable.getId()); //CIM ID
String branchName = parseName(branch.getId()); //CIM ID
String modelicaName = DEFAULT_BRANCH_PREFIX + branchName; //CIM ID
modelicaName = WordUtils.uncapitalize(modelicaName.substring(0,1)) + modelicaName.substring(1);

// modelicaName = parseName(modelicaName); //Añadido de cara al conversor de PSSE
modContext.dictionary.add(twoTerminalsConnectable, modelicaName);
modContext.dictionary.add(branch, modelicaName);
super.setModelicaName(modelicaName);

ModelTemplate model = null;
Expand Down Expand Up @@ -123,7 +123,7 @@ public String parseName(String name) {

// abstract void addParameter(String name, Object value);

private TwoTerminalsConnectable twoTerminalsConnectable;
private Branch branch;
protected String nodeName1;
protected String nodeName2;
protected Bus bus1 = null;
Expand Down
Expand Up @@ -8,7 +8,7 @@

import eu.itesla_project.iidm.ddb.model.SimulatorInst;
import eu.itesla_project.iidm.ddb.service.DDBManager;
import eu.itesla_project.iidm.network.SingleTerminalConnectable;
import eu.itesla_project.iidm.network.Injection;
import eu.itesla_project.modelica_export.ModExportContext;
import eu.itesla_project.modelica_export.ModelicaRecord;
import eu.itesla_project.modelica_export.util.eurostag.EurostagFixedData;
Expand All @@ -19,8 +19,8 @@
*/
public class ConnectGlobalVarRecord extends ModelicaRecord {

public ConnectGlobalVarRecord(SingleTerminalConnectable singleTerCon, GlobalVariable globalVar) {
this.node1 = singleTerCon;
public ConnectGlobalVarRecord(Injection injection, GlobalVariable globalVar) {
this.node1 = injection;
this.globalVar = globalVar;
}

Expand Down Expand Up @@ -49,6 +49,6 @@ public ConnectGlobalVarRecord getClassName() {
return this;
}

private SingleTerminalConnectable node1;
private Injection node1;
private GlobalVariable globalVar;
}
Expand Up @@ -12,9 +12,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eu.itesla_project.iidm.network.Branch;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.iidm.network.StateManager;
import eu.itesla_project.iidm.network.TwoTerminalsConnectable;
import eu.itesla_project.iidm.network.VoltageLevel;
import eu.itesla_project.security.LimitViolation;
import eu.itesla_project.security.LimitViolationFilter;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void looseConstraints(String stateId, List<LimitViolation> violations, fl
}

private void setNewCurrentLimit(String stateId, LimitViolation violation, float margin, boolean applyToBaseCase) {
TwoTerminalsConnectable branch = network.getBranch(violation.getSubjectId());
Branch branch = network.getBranch(violation.getSubjectId());
if ( branch != null ) {
float newLimit = getNewUpperLimit(violation, margin);
if ( branch.getTerminal1().getI() == violation.getValue() ) {
Expand Down
Expand Up @@ -230,11 +230,11 @@ public static CimValuesMap extractCimValues(Network n, Config config) {

vl.visitEquipments(new AbstractTopologyVisitor() {

private void visitInjection(SingleTerminalConnectable inj) {
private void visitInjection(Injection inj) {
visitInjection(inj, new TerminalContext());
}

private void visitInjection(SingleTerminalConnectable inj, TerminalContext context) {
private void visitInjection(Injection inj, TerminalContext context) {
Terminal t = inj.getTerminal();
context.update(t);

Expand Down Expand Up @@ -262,8 +262,8 @@ private void visitInjection(SingleTerminalConnectable inj, TerminalContext conte
valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.I), context.i);
}

private void visitBranch(TwoTerminalsConnectable branch, TwoTerminalsConnectable.Side side, float r, float x, float g1, float b1, float g2, float b2, float ratio) {
Terminal t = side == TwoTerminalsConnectable.Side.ONE ? branch.getTerminal1() : branch.getTerminal2();
private void visitBranch(Branch branch, Branch.Side side, float r, float x, float g1, float b1, float g2, float b2, float ratio) {
Terminal t = side == Branch.Side.ONE ? branch.getTerminal1() : branch.getTerminal2();

TerminalContext context = TerminalContext.create(t);

Expand Down
Expand Up @@ -325,7 +325,7 @@ private boolean fixBranchesAlwaysDisconnectAtOneSide(int iteration, Network netw
String branchId = entry.getKey();
if (entry.getValue().size() == 1) {
String substationId = entry.getValue().iterator().next();
TwoTerminalsConnectable branch = network.getBranch(branchId);
Branch branch = network.getBranch(branchId);
if (branch == null) {
throw new RuntimeException();
}
Expand Down
Expand Up @@ -250,14 +250,14 @@ public static void cleanNetwork(Network network, Map<String, UniqueTopology> uni
List<String> equipmentsRemoved = new ArrayList<>();
List<String> fictiveEquipmentsRemoved = new ArrayList<>();
// branches
List<TwoTerminalsConnectable> branches = new ArrayList<>();
List<Branch> branches = new ArrayList<>();
for (Line l : network.getLines()) {
branches.add(l);
}
for (TwoWindingsTransformer twt : network.getTwoWindingsTransformers()) {
branches.add(twt);
}
for (TwoTerminalsConnectable branch : branches) {
for (Branch branch : branches) {
UniqueTopology topo1 = uniqueTopos.get(branch.getTerminal1().getVoltageLevel().getId());
UniqueTopology topo2 = uniqueTopos.get(branch.getTerminal2().getVoltageLevel().getId());
if (!topo1.containsEquipment(branch.getId()) && !topo2.containsEquipment(branch.getId())) {
Expand All @@ -275,7 +275,7 @@ public static void cleanNetwork(Network network, Map<String, UniqueTopology> uni
}

// injections
List<SingleTerminalConnectable> injections = new ArrayList<>();
List<Injection> injections = new ArrayList<>();
for (Generator g : network.getGenerators()) {
injections.add(g);
}
Expand All @@ -288,7 +288,7 @@ public static void cleanNetwork(Network network, Map<String, UniqueTopology> uni
for (DanglingLine dl : network.getDanglingLines()) {
injections.add(dl);
}
for (SingleTerminalConnectable injection : injections) {
for (Injection injection : injections) {
UniqueTopology topo = uniqueTopos.get(injection.getTerminal().getVoltageLevel().getId());
if (!topo.containsEquipment(injection.getId())) {
if (injection.getId().contains(TopologyHistory.FICTIVE_PATTERN)) {
Expand Down
Expand Up @@ -80,7 +80,7 @@ private static WCAEntity toEntity(HistoDbNetworkAttributeId attrId, Network netw
int entityNum;
int sideNum = 0;
float nomV;
TwoTerminalsConnectable branch = network.getBranch(attrId.getEquipmentId());
Branch branch = network.getBranch(attrId.getEquipmentId());
if (branch != null) {
entityType = 1;
entityNum = mapper.getInt(AmplSubset.BRANCH, attrId.getEquipmentId());
Expand Down

0 comments on commit 9c8ceb7

Please sign in to comment.