Skip to content

Commit

Permalink
Use targetP/targetQ instead of p0/q0 for IIDM Battery (#2153)
Browse files Browse the repository at this point in the history
Signed-off-by: VEDELAGO MIORA <[email protected]>
  • Loading branch information
miovd authored Jun 3, 2022
1 parent dd0653f commit f27a89a
Show file tree
Hide file tree
Showing 29 changed files with 301 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public AmplNetworkReader readBatteries() throws IOException {
private Void readBattery(String[] tokens) {
int num = Integer.parseInt(tokens[1]);
int busNum = Integer.parseInt(tokens[2]);
double p0 = readDouble(tokens[3]);
double q0 = readDouble(tokens[4]);
double targetP = readDouble(tokens[3]);
double targetQ = readDouble(tokens[4]);
double p = readDouble(tokens[5]);
double q = readDouble(tokens[6]);

Expand All @@ -158,8 +158,8 @@ private Void readBattery(String[] tokens) {
if (b == null) {
throw new AmplException("Invalid battery id '" + id + "'");
}
b.setP0(p0);
b.setQ0(q0);
b.setTargetP(targetP);
b.setTargetQ(targetQ);

Terminal t = b.getTerminal();
t.setP(p).setQ(q);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1603,8 +1603,8 @@ private void writeBatteries(AmplExportContext context) throws IOException {
context.batteryIdsToExport.add(id);
int num = mapper.getInt(AmplSubset.BATTERY, id);
int vlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, t.getVoltageLevel().getId());
double p0 = b.getP0();
double q0 = b.getQ0();
double targetP = b.getTargetP();
double targetQ = b.getTargetQ();
double minP = b.getMinP();
double maxP = b.getMaxP();

Expand All @@ -1613,8 +1613,8 @@ private void writeBatteries(AmplExportContext context) throws IOException {
.writeCell(busNum)
.writeCell(conBusNum != -1 ? conBusNum : busNum)
.writeCell(vlNum)
.writeCell(p0)
.writeCell(q0)
.writeCell(targetP)
.writeCell(targetQ)
.writeCell(minP)
.writeCell(maxP)
.writeCell(b.getReactiveLimits().getMinQ(maxP))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,17 @@ private void testGenerators(Network network, AmplNetworkReader reader) throws IO
private void testBatteries(Network network, AmplNetworkReader reader) throws IOException {
Battery battery = network.getBattery("BAT");

assertEquals(9999.99, battery.getP0(), 0.0);
assertEquals(9999.99, battery.getQ0(), 0.0);
assertEquals(9999.99, battery.getTargetP(), 0.0);
assertEquals(9999.99, battery.getTargetQ(), 0.0);
assertEquals(-9999.99, battery.getMinP(), 0.0);
assertEquals(9999.99, battery.getMaxP(), 0.0);
assertEquals(-605.0, battery.getTerminal().getP(), 0.0);
assertEquals(-225.0, battery.getTerminal().getQ(), 0.0);

reader.readBatteries();

assertEquals(12.0, battery.getP0(), 0.0);
assertEquals(13.0, battery.getQ0(), 0.0);
assertEquals(12.0, battery.getTargetP(), 0.0);
assertEquals(13.0, battery.getTargetQ(), 0.0);
assertEquals(300.0, battery.getTerminal().getP(), 0.0);
assertEquals(150.0, battery.getTerminal().getQ(), 0.0);
}
Expand Down
48 changes: 40 additions & 8 deletions iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Battery.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,64 @@
public interface Battery extends Injection<Battery>, ReactiveLimitsHolder {

/**
* Get the constant active power in MW.
* @deprecated Use {@link #getTargetP()} instead.
*/
@Deprecated(since = "4.9.0")
default double getP0() {
return getTargetP();
}

/**
* Get the target active power in MW.
* <p>Depends on the working variant.
* @see VariantManager
*/
double getP0();
double getTargetP();

/**
* @deprecated Use {@link #setTargetP(double)} instead.
*/
@Deprecated(since = "4.9.0")
default Battery setP0(double p0) {
return setTargetP(p0);
}

/**
* Set the constant active power in MW.
* Set the target active power in MW.
* <p>Depends on the working variant.
* @see VariantManager
*/
Battery setP0(double p0);
Battery setTargetP(double targetP);

/**
* Get the constant reactive power in MVar.
* @deprecated Use {@link #getTargetQ()} instead.
*/
@Deprecated(since = "4.9.0")
default double getQ0() {
return getTargetQ();
}

/**
* Get the target reactive power in MVar.
* <p>Depends on the working variant.
* @see VariantManager
*/
double getQ0();
double getTargetQ();

/**
* @deprecated Use {@link #setTargetP(double)} instead.
*/
@Deprecated(since = "4.9.0")
default Battery setQ0(double q0) {
return setTargetQ(q0);
}

/**
* Set the constant reactive power in MVar.
* Set the target reactive power in MVar.
* <p>Depends on the working variant.
* @see VariantManager
*/
Battery setQ0(double q0);
Battery setTargetQ(double targetQ);

/**
* Get the minimal active power in MW.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,34 @@
public interface BatteryAdder extends InjectionAdder<BatteryAdder> {

/**
* Set the constant active power in MW.
* @deprecated Use {@link #setTargetP(double)} instead.
*/
@Deprecated(since = "4.9.0")
default BatteryAdder setP0(double p0) {
return setTargetP(p0);
}

/**
* Set the target active power in MW.
* <p>Depends on the working variant.
* @see VariantManager
*/
BatteryAdder setP0(double p0);
BatteryAdder setTargetP(double targetP);

/**
* @deprecated Use {@link #setTargetQ(double)} instead.
*/
@Deprecated(since = "4.9.0")
default BatteryAdder setQ0(double q0) {
return setTargetQ(q0);
}

/**
* Set the constant reactive power in MVar.
* Set the target reactive power in MVar.
* <p>Depends on the working variant.
* @see VariantManager
*/
BatteryAdder setQ0(double q0);
BatteryAdder setTargetQ(double targetQ);

/**
* Set the minimal active power in MW.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ private static ValidationLevel checkIdentifiable(Identifiable<?> identifiable, V
Validable validable = (Validable) identifiable;
if (identifiable instanceof Battery) {
Battery battery = (Battery) identifiable;
validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, battery.getP0(), throwException, reporter));
validationLevel = ValidationLevel.min(validationLevel, checkQ0(validable, battery.getQ0(), throwException, reporter));
validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, battery.getTargetP(), throwException, reporter));
validationLevel = ValidationLevel.min(validationLevel, checkQ0(validable, battery.getTargetQ(), throwException, reporter));
} else if (identifiable instanceof DanglingLine) {
DanglingLine danglingLine = (DanglingLine) identifiable;
validationLevel = ValidationLevel.min(validationLevel, checkP0(validable, danglingLine.getP0(), throwException, reporter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class BatteryAdderImpl extends AbstractInjectionAdder<BatteryAdderImpl> i

private final VoltageLevelExt voltageLevel;

private double p0 = Double.NaN;
private double targetP = Double.NaN;

private double q0 = Double.NaN;
private double targetQ = Double.NaN;

private double minP = Double.NaN;

Expand Down Expand Up @@ -52,17 +52,17 @@ protected String getTypeDescription() {
* {@inheritDoc}
*/
@Override
public BatteryAdderImpl setP0(double p0) {
this.p0 = p0;
public BatteryAdderImpl setTargetP(double targetP) {
this.targetP = targetP;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public BatteryAdderImpl setQ0(double q0) {
this.q0 = q0;
public BatteryAdderImpl setTargetQ(double targetQ) {
this.targetQ = targetQ;
return this;
}

Expand Down Expand Up @@ -92,13 +92,13 @@ public BatteryImpl add() {
NetworkImpl network = getNetwork();
String id = checkAndGetUniqueId();
TerminalExt terminal = checkAndGetTerminal();
network.setValidationLevelIfGreaterThan(ValidationUtil.checkP0(this, p0, network.getMinValidationLevel()));
network.setValidationLevelIfGreaterThan(ValidationUtil.checkQ0(this, q0, network.getMinValidationLevel()));
network.setValidationLevelIfGreaterThan(ValidationUtil.checkP0(this, targetP, network.getMinValidationLevel()));
network.setValidationLevelIfGreaterThan(ValidationUtil.checkQ0(this, targetQ, network.getMinValidationLevel()));
ValidationUtil.checkMinP(this, minP);
ValidationUtil.checkMaxP(this, maxP);
ValidationUtil.checkActivePowerLimits(this, minP, maxP);

BatteryImpl battery = new BatteryImpl(network.getRef(), id, getName(), isFictitious(), p0, q0, minP, maxP);
BatteryImpl battery = new BatteryImpl(network.getRef(), id, getName(), isFictitious(), targetP, targetQ, minP, maxP);

battery.addTerminal(terminal);
voltageLevel.attach(terminal, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ public class BatteryImpl extends AbstractConnectable<Battery> implements Battery

private final ReactiveLimitsHolderImpl reactiveLimits;

private TDoubleArrayList p0;
private final TDoubleArrayList targetP;

private TDoubleArrayList q0;
private final TDoubleArrayList targetQ;

private double minP;

private double maxP;

BatteryImpl(Ref<NetworkImpl> ref, String id, String name, boolean fictitious, double p0, double q0, double minP, double maxP) {
BatteryImpl(Ref<NetworkImpl> ref, String id, String name, boolean fictitious, double targetP, double targetQ, double minP, double maxP) {
super(ref, id, name, fictitious);
this.minP = minP;
this.maxP = maxP;
this.reactiveLimits = new ReactiveLimitsHolderImpl(this, new MinMaxReactiveLimitsImpl(-Double.MAX_VALUE, Double.MAX_VALUE));

int variantArraySize = ref.get().getVariantManager().getVariantArraySize();
this.p0 = new TDoubleArrayList(variantArraySize);
this.q0 = new TDoubleArrayList(variantArraySize);
this.targetP = new TDoubleArrayList(variantArraySize);
this.targetQ = new TDoubleArrayList(variantArraySize);
for (int i = 0; i < variantArraySize; i++) {
this.p0.add(p0);
this.q0.add(q0);
this.targetP.add(targetP);
this.targetQ.add(targetQ);
}
}

Expand All @@ -54,45 +54,45 @@ protected String getTypeDescription() {
* {@inheritDoc}
*/
@Override
public double getP0() {
return p0.get(getNetwork().getVariantIndex());
public double getTargetP() {
return targetP.get(getNetwork().getVariantIndex());
}

/**
* {@inheritDoc}
*/
@Override
public Battery setP0(double p0) {
public Battery setTargetP(double targetP) {
NetworkImpl network = getNetwork();
ValidationUtil.checkP0(this, p0, network.getMinValidationLevel());
ValidationUtil.checkP0(this, targetP, network.getMinValidationLevel());
int variantIndex = network.getVariantIndex();
double oldValue = this.p0.set(variantIndex, p0);
double oldValue = this.targetP.set(variantIndex, targetP);
String variantId = network.getVariantManager().getVariantId(variantIndex);
network.invalidateValidationLevel();
notifyUpdate("p0", variantId, oldValue, p0);
notifyUpdate("targetP", variantId, oldValue, targetP);
return this;
}

/**
* {@inheritDoc}
*/
@Override
public double getQ0() {
return q0.get(getNetwork().getVariantIndex());
public double getTargetQ() {
return targetQ.get(getNetwork().getVariantIndex());
}

/**
* {@inheritDoc}
*/
@Override
public Battery setQ0(double q0) {
public Battery setTargetQ(double targetQ) {
NetworkImpl network = getNetwork();
ValidationUtil.checkQ0(this, q0, network.getMinValidationLevel());
ValidationUtil.checkQ0(this, targetQ, network.getMinValidationLevel());
int variantIndex = network.getVariantIndex();
double oldValue = this.q0.set(variantIndex, q0);
double oldValue = this.targetQ.set(variantIndex, targetQ);
String variantId = network.getVariantManager().getVariantId(variantIndex);
network.invalidateValidationLevel();
notifyUpdate("q0", variantId, oldValue, q0);
notifyUpdate("targetQ", variantId, oldValue, targetQ);
return this;
}

Expand Down Expand Up @@ -192,11 +192,11 @@ public MinMaxReactiveLimitsAdder newMinMaxReactiveLimits() {
@Override
public void extendVariantArraySize(int initVariantArraySize, int number, int sourceIndex) {
super.extendVariantArraySize(initVariantArraySize, number, sourceIndex);
p0.ensureCapacity(p0.size() + number);
q0.ensureCapacity(q0.size() + number);
targetP.ensureCapacity(targetP.size() + number);
targetQ.ensureCapacity(targetQ.size() + number);
for (int i = 0; i < number; i++) {
p0.add(p0.get(sourceIndex));
q0.add(q0.get(sourceIndex));
targetP.add(targetP.get(sourceIndex));
targetQ.add(targetQ.get(sourceIndex));
}
}

Expand All @@ -206,8 +206,8 @@ public void extendVariantArraySize(int initVariantArraySize, int number, int sou
@Override
public void reduceVariantArraySize(int number) {
super.reduceVariantArraySize(number);
p0.remove(p0.size() - number, number);
q0.remove(q0.size() - number, number);
targetP.remove(targetP.size() - number, number);
targetQ.remove(targetQ.size() - number, number);
}

/**
Expand All @@ -217,8 +217,8 @@ public void reduceVariantArraySize(int number) {
public void allocateVariantArrayElement(int[] indexes, int sourceIndex) {
super.allocateVariantArrayElement(indexes, sourceIndex);
for (int index : indexes) {
p0.set(index, p0.get(sourceIndex));
q0.set(index, q0.get(sourceIndex));
targetP.set(index, targetP.get(sourceIndex));
targetQ.set(index, targetQ.get(sourceIndex));
}
}
}
Loading

0 comments on commit f27a89a

Please sign in to comment.