Skip to content

Commit 9fde0d9

Browse files
committed
[3618] Refacto newVoltageRegulation() from Generator itself
Signed-off-by: Matthieu SAUR <matthieu.saur@rte-france.com>
1 parent 3401118 commit 9fde0d9

File tree

19 files changed

+241
-125
lines changed

19 files changed

+241
-125
lines changed

cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/RegulatingControlMappingForGenerators.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.powsybl.iidm.network.Terminal;
1818
import com.powsybl.iidm.network.extensions.*;
1919
import com.powsybl.iidm.network.regulation.RegulationMode;
20-
import com.powsybl.iidm.network.regulation.VoltageRegulation;
2120
import com.powsybl.triplestore.api.PropertyBag;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
@@ -98,10 +97,11 @@ private boolean setRegulatingControlVoltage(String controlId, RegulatingControl
9897
.mapForVoltageControl(control.cgmesTerminal, context)
9998
.orElse(gen.getTerminal());
10099

101-
VoltageRegulation voltageRegulation = gen.newAndReplaceVoltageRegulation();
102-
voltageRegulation.setTerminal(regulatingTerminal);
103-
voltageRegulation.setMode(RegulationMode.VOLTAGE);
104-
voltageRegulation.setRegulating(false);
100+
gen.newVoltageRegulation()
101+
.setMode(RegulationMode.VOLTAGE)
102+
.setTerminal(regulatingTerminal)
103+
.setRegulating(false)
104+
.add();
105105

106106
// add qPercent as an extension
107107
if (!Double.isNaN(qPercent)) {
@@ -126,10 +126,11 @@ private boolean setRegulatingControlReactivePower(String controlId, RegulatingCo
126126
return false;
127127
}
128128

129-
VoltageRegulation voltageRegulation = gen.newAndReplaceVoltageRegulation();
130-
voltageRegulation.setTerminal(mappedRegulatingTerminal.getTerminal());
131-
voltageRegulation.setMode(RegulationMode.REACTIVE_POWER);
132-
voltageRegulation.setRegulating(false);
129+
gen.newVoltageRegulation()
130+
.setTerminal(mappedRegulatingTerminal.getTerminal())
131+
.setMode(RegulationMode.REACTIVE_POWER)
132+
.setRegulating(false)
133+
.add();
133134

134135
// add qPercent as an extension
135136
if (!Double.isNaN(qPercent)) {

cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/EquivalentInjectionConversion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static void update(Generator generator, PropertyBag cgmesData, Context co
138138
// .setVoltageRegulatorOn(regulatingOn && regulationCapability && isValidTargetV(targetV));
139139
VoltageRegulation voltageRegulation = generator.getVoltageRegulation();
140140
if (voltageRegulation == null) {
141-
voltageRegulation = generator.newAndReplaceVoltageRegulation();
141+
voltageRegulation = generator.newVoltageRegulation().add();
142142
}
143143
voltageRegulation.setMode(RegulationMode.VOLTAGE);
144144
voltageRegulation.setTargetValue(targetV);

cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/CgmesExportContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.powsybl.commons.report.ReportNode;
2121
import com.powsybl.iidm.network.*;
2222
import com.powsybl.iidm.network.Identifiable;
23-
import com.powsybl.iidm.network.extensions.RemoteReactivePowerControl;
2423
import com.powsybl.triplestore.api.PropertyBag;
2524
import org.apache.commons.lang3.tuple.Pair;
2625

@@ -478,8 +477,9 @@ private void addIidmMappingsGenerators(Network network) {
478477
}
479478

480479
private static boolean hasRegulatingControlCapability(Generator generator) {
481-
return generator.getExtension(RemoteReactivePowerControl.class) != null
482-
|| generator.getVoltageRegulation() != null && generator.getVoltageRegulation().isRegulating() && hasReactiveCapability(generator);
480+
return generator.getVoltageRegulation() != null
481+
&& generator.getVoltageRegulation().isRegulating()
482+
&& hasReactiveCapability(generator);
483483
}
484484

485485
private static boolean hasReactiveCapability(Generator generator) {

cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/EquipmentExportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ private Network prepareNetworkForEQComparison(Network network) {
17731773
shuntCompensator.setSectionCount(0);
17741774
} else if (identifiable instanceof Generator) {
17751775
Generator generator = (Generator) identifiable;
1776-
generator.newAndReplaceVoltageRegulation();
1776+
generator.newVoltageRegulation().add();
17771777
generator.setTargetV(Double.NaN);
17781778
generator.setTargetP(Double.NaN);
17791779
generator.setTargetQ(Double.NaN);

iidm/iidm-api/src/main/java/com/powsybl/iidm/network/regulation/VoltageRegulationHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface VoltageRegulationHolder {
1414

1515
VoltageRegulation getVoltageRegulation();
1616

17-
VoltageRegulation newAndReplaceVoltageRegulation();
17+
VoltageRegulationMsaAdder newVoltageRegulation();
1818

1919
void removeVoltageRegulation();
2020
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.iidm.network.regulation;
9+
10+
import com.powsybl.iidm.network.Terminal;
11+
12+
/**
13+
* @author Matthieu SAUR {@literal <matthieu.saur at rte-france.com>}
14+
*/
15+
public interface VoltageRegulationMsaAdder {
16+
17+
VoltageRegulationMsaAdder setTargetValue(double targetValue);
18+
19+
VoltageRegulationMsaAdder setTargetDeadband(double targetDeadband);
20+
21+
VoltageRegulationMsaAdder setSlope(double slope);
22+
23+
VoltageRegulationMsaAdder setMode(RegulationMode regulationMode);
24+
25+
VoltageRegulationMsaAdder setTerminal(Terminal regulatingTerminal);
26+
27+
VoltageRegulationMsaAdder setRegulating(boolean b);
28+
29+
VoltageRegulation add();
30+
}

iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/BatteryImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import com.powsybl.commons.ref.Ref;
1212
import com.powsybl.iidm.network.impl.regulation.VoltageRegulationImpl;
1313
import com.powsybl.iidm.network.regulation.VoltageRegulation;
14+
import com.powsybl.iidm.network.regulation.VoltageRegulationMsaAdder;
1415
import gnu.trove.list.array.TDoubleArrayList;
1516

1617
/**
1718
* {@inheritDoc}
1819
*
1920
* @author Ghiles Abdellah {@literal <ghiles.abdellah at rte-france.com>}
2021
*/
21-
public class BatteryImpl extends AbstractConnectable<Battery> implements Battery, ReactiveLimitsOwner {
22+
public class BatteryImpl extends AbstractConnectable<Battery> implements Battery, ReactiveLimitsOwner, VoltageRegulationOwner {
2223

2324
private final ReactiveLimitsHolderImpl reactiveLimits;
2425

@@ -30,7 +31,7 @@ public class BatteryImpl extends AbstractConnectable<Battery> implements Battery
3031

3132
private double maxP;
3233

33-
private VoltageRegulation voltageRegulation;
34+
private VoltageRegulationImpl voltageRegulation;
3435

3536
BatteryImpl(Ref<NetworkImpl> ref, String id, String name, boolean fictitious, double targetP, double targetQ, double minP, double maxP) {
3637
super(ref, id, name, fictitious);
@@ -233,11 +234,13 @@ public VoltageRegulation getVoltageRegulation() {
233234
}
234235

235236
@Override
236-
public VoltageRegulation newAndReplaceVoltageRegulation() {
237-
this.voltageRegulation = VoltageRegulationImpl.builder()
238-
.setNetwork(getNetwork().getRef())
239-
.build();
240-
return this.voltageRegulation;
237+
public void setVoltageRegulation(VoltageRegulation voltageRegulation) {
238+
this.voltageRegulation = (VoltageRegulationImpl) voltageRegulation;
239+
}
240+
241+
@Override
242+
public VoltageRegulationMsaAdder newVoltageRegulation() {
243+
return new VoltageRegulationMsaAdderImpl<>(this);
241244
}
242245

243246
@Override

iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/GeneratorImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
import com.powsybl.commons.ref.Ref;
1111
import com.powsybl.iidm.network.*;
12-
import com.powsybl.iidm.network.regulation.RegulationMode;
12+
import com.powsybl.iidm.network.regulation.*;
1313
import com.powsybl.iidm.network.impl.regulation.VoltageRegulationImpl;
14-
import com.powsybl.iidm.network.regulation.VoltageRegulation;
1514
import gnu.trove.list.array.TDoubleArrayList;
1615

1716
/**
1817
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
1918
*/
20-
class GeneratorImpl extends AbstractConnectable<Generator> implements Generator, ReactiveLimitsOwner {
19+
class GeneratorImpl extends AbstractConnectable<Generator> implements Generator, ReactiveLimitsOwner, VoltageRegulationOwner {
2120

2221
private final Ref<? extends VariantManagerHolder> network;
2322

@@ -361,11 +360,13 @@ public VoltageRegulationImpl getVoltageRegulation() {
361360
}
362361

363362
@Override
364-
public VoltageRegulation newAndReplaceVoltageRegulation() {
365-
this.voltageRegulation = (VoltageRegulationImpl) VoltageRegulationImpl.builder()
366-
.setNetwork(getNetwork().getRef())
367-
.build();
368-
return this.voltageRegulation;
363+
public void setVoltageRegulation(VoltageRegulation voltageRegulation) {
364+
this.voltageRegulation = (VoltageRegulationImpl) voltageRegulation;
365+
}
366+
367+
@Override
368+
public VoltageRegulationMsaAdder newVoltageRegulation() {
369+
return new VoltageRegulationMsaAdderImpl<>(this);
369370
}
370371

371372
@Override
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) 2026, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.iidm.network.impl;
9+
10+
import com.powsybl.iidm.network.Terminal;
11+
import com.powsybl.iidm.network.impl.regulation.VoltageRegulationImpl;
12+
import com.powsybl.iidm.network.regulation.RegulationMode;
13+
import com.powsybl.iidm.network.regulation.VoltageRegulation;
14+
import com.powsybl.iidm.network.regulation.VoltageRegulationMsaAdder;
15+
16+
/**
17+
* @author Matthieu SAUR {@literal <matthieu.saur at rte-france.com>}
18+
*/
19+
class VoltageRegulationMsaAdderImpl<O extends VoltageRegulationOwner> implements VoltageRegulationMsaAdder {
20+
21+
private final O owner;
22+
23+
private RegulationMode mode = null;
24+
private double targetValue = Double.NaN;
25+
private double targetDeadband = Double.NaN;
26+
private double slope = Double.NaN;
27+
private Terminal terminal;
28+
private boolean regulating;
29+
30+
VoltageRegulationMsaAdderImpl(O owner) {
31+
this.owner = owner;
32+
}
33+
34+
@Override
35+
public VoltageRegulationMsaAdder setTargetValue(double targetValue) {
36+
this.targetValue = targetValue;
37+
return this;
38+
}
39+
40+
@Override
41+
public VoltageRegulationMsaAdder setTargetDeadband(double targetDeadband) {
42+
this.targetDeadband = targetDeadband;
43+
return this;
44+
}
45+
46+
@Override
47+
public VoltageRegulationMsaAdder setSlope(double slope) {
48+
this.slope = slope;
49+
return this;
50+
}
51+
52+
@Override
53+
public VoltageRegulationMsaAdder setMode(RegulationMode regulationMode) {
54+
this.mode = regulationMode;
55+
return this;
56+
}
57+
58+
@Override
59+
public VoltageRegulationMsaAdder setTerminal(Terminal terminal) {
60+
this.terminal = terminal;
61+
return this;
62+
}
63+
64+
@Override
65+
public VoltageRegulationMsaAdder setRegulating(boolean regulating) {
66+
this.regulating = regulating;
67+
return this;
68+
}
69+
70+
@Override
71+
public VoltageRegulation add() {
72+
// TODO MSA add validation
73+
VoltageRegulation voltageRegulation = new VoltageRegulationImpl(owner.getNetwork().getRef(), targetValue, targetDeadband, slope, terminal, mode, regulating);
74+
owner.setVoltageRegulation(voltageRegulation);
75+
return voltageRegulation;
76+
}
77+
78+
}

iidm/iidm-api/src/main/java/com/powsybl/iidm/network/regulation/VoltageRegulationOwner.java renamed to iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VoltageRegulationOwner.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/**
2-
* Copyright (c) 2025, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2025-2026, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
* SPDX-License-Identifier: MPL-2.0
77
*/
8-
package com.powsybl.iidm.network.regulation;
8+
package com.powsybl.iidm.network.impl;
9+
10+
import com.powsybl.iidm.network.regulation.VoltageRegulation;
911

1012
/**
1113
* @author Matthieu SAUR {@literal <matthieu.saur at rte-france.com>}
1214
*/
13-
public interface VoltageRegulationOwner {
15+
interface VoltageRegulationOwner {
16+
17+
NetworkImpl getNetwork();
1418

1519
VoltageRegulation getVoltageRegulation();
1620

0 commit comments

Comments
 (0)