Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PowSyBl parent 9 #612

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent</artifactId>
<version>8</version>
<version>9</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IncrementalTransformerVoltageControlOuterLoop extends AbstractTrans

private static final class ControllerContext {

private final MutableInt directionChangeCount = new MutableInt();
private final MutableInt directionChangeCount = new MutableInt();

private PiModel.AllowedDirection allowedDirection = PiModel.AllowedDirection.BOTH;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void checkPqBus(LfBus controllerCapableBus, List<PqToPvBus> pqToPvBuses)
double q = controllerCapableBus.getGenerationTargetQ();
double distanceToMaxQ = Math.abs(q - maxQ);
double distanceToMinQ = Math.abs(q - minQ);
if (distanceToMaxQ < distanceToMinQ && controllerCapableBus.getV() > getBusTargetV(controllerCapableBus)) { // bus produce too much reactive power
if (distanceToMaxQ < distanceToMinQ && controllerCapableBus.getV() > getBusTargetV(controllerCapableBus)) { // bus produce too much reactive power
pqToPvBuses.add(new PqToPvBus(controllerCapableBus, ReactiveLimitDirection.MAX));
}
if (distanceToMaxQ > distanceToMinQ && controllerCapableBus.getV() < getBusTargetV(controllerCapableBus)) { // bus absorb too much reactive power
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public double der(Variable<AcVariableType> variable) {
} else if (variable.equals(a1Var)) {
return dp2da1(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(r1Var)) {
return dp2dr1(y, v1(), v2(), FastMath.sin(theta));
return dp2dr1(y, v1(), v2(), FastMath.sin(theta));
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public HvdcAcEmulationSide1ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus
}

private static double p1(double p0, double k, double lossFactor1, double lossFactor2, double ph1, double ph2) {
return (isController(ph1, ph2) ? 1 : getLossMultiplier(lossFactor1, lossFactor2)) * (p0 + k * (ph1 - ph2));
return (isController(ph1, ph2) ? 1 : getLossMultiplier(lossFactor1, lossFactor2)) * (p0 + k * (ph1 - ph2));
}

private static boolean isController(double ph1, double ph2) {
return (ph1 - ph2) >= 0;
}

private static double dp1dph1(double k, double lossFactor1, double lossFactor2, double ph1, double ph2) {
return (isController(ph1, ph2) ? 1 : getLossMultiplier(lossFactor1, lossFactor2)) * k;
return (isController(ph1, ph2) ? 1 : getLossMultiplier(lossFactor1, lossFactor2)) * k;
}

private static double dp1dph2(double k, double lossFactor1, double lossFactor2, double ph1, double ph2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public HvdcAcEmulationSide2ActiveFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus
}

private static double p2(double p0, double k, double ph1, double ph2) {
return -(isController(ph1, ph2) ? 1 : getLossMultiplier(ph1, ph2)) * (p0 + k * (ph1 - ph2));
return -(isController(ph1, ph2) ? 1 : getLossMultiplier(ph1, ph2)) * (p0 + k * (ph1 - ph2));
}

private static boolean isController(double ph1, double ph2) {
return (ph1 - ph2) < 0;
}

private static double dp2dph1(double k, double ph1, double ph2) {
return -(isController(ph1, ph2) ? 1 : getLossMultiplier(ph1, ph2)) * k;
return -(isController(ph1, ph2) ? 1 : getLossMultiplier(ph1, ph2)) * k;
}

private static double dp2dph2(double k, double ph1, double ph2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static void initStateVector(LfNetwork network, EquationSystem<AcVariableT
break;

default:
throw new IllegalStateException("Unknown variable type " + v.getType());
throw new IllegalStateException("Unknown variable type " + v.getType());
}
}
equationSystem.getStateVector().set(x);
Expand Down Expand Up @@ -174,7 +174,7 @@ public void updateNetwork() {
break;

default:
throw new IllegalStateException("Unknown variable type " + v.getType());
throw new IllegalStateException("Unknown variable type " + v.getType());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static int checkMaxIteration(int maxIteration) {
}

public NewtonRaphsonParameters setMaxIteration(int maxIteration) {
this.maxIteration = checkMaxIteration(maxIteration);
this.maxIteration = checkMaxIteration(maxIteration);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void init(Equation<AcVariableType, AcEquationType> equation, LfNet
break;

default:
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
}

for (EquationTerm<AcVariableType, AcEquationType> term : equation.getTerms()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void initStateVector(LfNetwork network, EquationSystem<DcVariableT
break;

default:
throw new IllegalStateException("Unknown variable type " + v.getType());
throw new IllegalStateException("Unknown variable type " + v.getType());
}
}
equationSystem.getStateVector().set(x);
Expand All @@ -118,7 +118,7 @@ public static void updateNetwork(LfNetwork network, EquationSystem<DcVariableTyp
break;

default:
throw new IllegalStateException("Unknown variable type " + v.getType());
throw new IllegalStateException("Unknown variable type " + v.getType());
}
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public static void initTarget(Equation<DcVariableType, DcEquationType> equation,
break;

default:
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
}

for (EquationTerm<DcVariableType, DcEquationType> term : equation.getTerms()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected AbstractClosedBranchDcFlowEquationTerm(LfBranch branch, LfBus bus1, Lf
ph1Var = variableSet.getVariable(bus1.getNum(), DcVariableType.BUS_PHI);
ph2Var = variableSet.getVariable(bus2.getNum(), DcVariableType.BUS_PHI);
a1Var = deriveA1 ? variableSet.getVariable(branch.getNum(), DcVariableType.BRANCH_ALPHA1) : null;
power = 1 / piModel.getX() * (useTransformerRatio ? piModel.getR1() * R2 : 1);
power = 1 / piModel.getX() * (useTransformerRatio ? piModel.getR1() * R2 : 1);
if (a1Var != null) {
variables = List.of(ph1Var, ph2Var, a1Var);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ClosedBranchSide1DcFlowEquationTerm create(LfBranch branch, LfBus

@Override
protected double calculateSensi(double ph1, double ph2, double a1) {
double deltaPhase = ph2 - ph1 + A2 - a1;
double deltaPhase = ph2 - ph1 + A2 - a1;
return -power * deltaPhase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static ClosedBranchSide2DcFlowEquationTerm create(LfBranch branch, LfBus

@Override
protected double calculateSensi(double ph1, double ph2, double a1) {
double deltaPhase = ph2 - ph1 + A2 - a1;
double deltaPhase = ph2 - ph1 + A2 - a1;
return power * deltaPhase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public abstract class AbstractEdgeModification<V, E> implements GraphModification<V, E> {
public abstract class AbstractEdgeModification<V, E> implements GraphModification<V, E> {
protected final E e;
protected final V v1;
protected final V v2;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/powsybl/openloadflow/graph/EdgeAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public class EdgeAdd<V, E> extends AbstractEdgeModification<V, E> {
public class EdgeAdd<V, E> extends AbstractEdgeModification<V, E> {
public EdgeAdd(V vertex1, V vertex2, E e) {
super(vertex1, vertex2, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public class EdgeRemove<V, E> extends AbstractEdgeModification<V, E> {
public class EdgeRemove<V, E> extends AbstractEdgeModification<V, E> {

public EdgeRemove(V vertex1, V vertex2, E e) {
super(vertex1, vertex2, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface GraphModification<V, E> {
public interface GraphModification<V, E> {
void apply(Graph<V, E> graph);

void undo(Graph<V, E> graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static boolean isEquivalentToStopAfterSwitch(Switch sw, int nodeAfter) {
if (endNodeAfter) { // check that there isn't another (closed) switch or internal connection at node after
VoltageLevel.NodeBreakerView nbv = sw.getVoltageLevel().getNodeBreakerView();
return noInternalConnectionAtNode(nodeAfter, nbv)
&& nbv.getSwitchStream(nodeAfter).noneMatch(s -> s != sw && !s.isOpen());
&& nbv.getSwitchStream(nodeAfter).noneMatch(s -> s != sw && !s.isOpen());
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static List<PropagatedContingency> createList(Network network, List<Conti
private static PropagatedContingency create(Network network, Contingency contingency, int index, boolean shuntCompensatorVoltageControlOn,
boolean slackDistributionOnConformLoad, boolean hvdcAcEmulation, boolean contingencyPropagation) {
Set<Switch> switchesToOpen = new HashSet<>();
Set<Terminal> terminalsToDisconnect = new HashSet<>();
Set<Terminal> terminalsToDisconnect = new HashSet<>();

// process elements of the contingency
for (ContingencyElement element : contingency.getElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void clear() {
public void addResults(StateMonitor monitor) {
addResults(monitor, branch -> {
var preContingencyBranchResult = preContingencyMonitorInfos.getBranchResult(branch.getId());
double preContingencyBranchP1 = preContingencyBranchResult != null ? preContingencyBranchResult.getP1() : Double.NaN;
double preContingencyBranchP1 = preContingencyBranchResult != null ? preContingencyBranchResult.getP1() : Double.NaN;
double preContingencyBranchOfContingencyP1 = Double.NaN;
if (contingency.getElements().size() == 1) {
ContingencyElement contingencyElement = contingency.getElements().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public static boolean isDistributedSlackOnGenerators(DcLoadFlowParameters lfPara

public static boolean isDistributedSlackOnLoads(DcLoadFlowParameters lfParameters) {
return lfParameters.isDistributedSlack()
&& (lfParameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD
&& (lfParameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD
|| lfParameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void analyse(Network network, List<PropagatedContingency> contingencies,
Map<String, SensitivityVariableSet> variableSetsById = variableSets.stream().collect(Collectors.toMap(SensitivityVariableSet::getId, Function.identity()));
SensitivityFactorHolder<AcVariableType, AcEquationType> allFactorHolder = readAndCheckFactors(network, variableSetsById, factorReader, lfNetwork, breakers);
List<LfSensitivityFactor<AcVariableType, AcEquationType>> allLfFactors = allFactorHolder.getAllFactors();
LOGGER.info("Running AC sensitivity analysis with {} factors and {} contingencies", allLfFactors.size(), contingencies.size());
LOGGER.info("Running AC sensitivity analysis with {} factors and {} contingencies", allLfFactors.size(), contingencies.size());

// next we only work with valid and valid only for function factors
var validFactorHolder = writeInvalidFactors(allFactorHolder, resultWriter);
Expand Down Expand Up @@ -297,15 +297,15 @@ public void analyse(Network network, List<PropagatedContingency> contingencies,
// Sensitivity values 0 and function reference NaN in case of a sensitivity on a disabled branch
contingencyFactors.stream()
.filter(lfFactor -> lfFactor.getFunctionElement() instanceof LfBranch)
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement()))
.forEach(lfFactor -> {
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement()))
.forEach(lfFactor -> {
lfFactor.setSensitivityValuePredefinedResult(0d);
lfFactor.setFunctionPredefinedResult(Double.NaN);
});
// Sensitivity values 0 in case of a sensitivity from the transformer phase of a disabled transformer
contingencyFactors.stream()
.filter(lfFactor -> lfFactor.getVariableType().equals(SensitivityVariableType.TRANSFORMER_PHASE))
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfNetwork.getBranchById(lfFactor.getVariableId())))
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfNetwork.getBranchById(lfFactor.getVariableId())))
.forEach(lfFactor -> lfFactor.setSensitivityValuePredefinedResult(0d));

Map<LfBus, Double> postContingencySlackParticipationByBus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ private static List<ConnectivityAnalysisResult> computeConnectivityData(LfNetwor
*/
public void calculateContingencySensitivityValues(PropagatedContingency contingency, SensitivityFactorGroupList<DcVariableType, DcEquationType> factorGroups, DenseMatrix factorStates, DenseMatrix contingenciesStates,
DenseMatrix flowStates, Collection<ComputedContingencyElement> contingencyElements, SensitivityResultWriter resultWriter,
LfNetwork lfNetwork, DcLoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt, JacobianMatrix<DcVariableType, DcEquationType> j, EquationSystem<DcVariableType, DcEquationType> equationSystem,
LfNetwork lfNetwork, DcLoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt, JacobianMatrix<DcVariableType, DcEquationType> j, EquationSystem<DcVariableType, DcEquationType> equationSystem,
SensitivityFactorHolder<DcVariableType, DcEquationType> factorHolder, List<ParticipatingElement> participatingElements,
Collection<LfBus> disabledBuses, Collection<LfBranch> disabledBranches, Reporter reporter) {
List<LfSensitivityFactor<DcVariableType, DcEquationType>> factors = factorHolder.getFactorsForContingency(contingency.getContingency().getId());
Expand Down Expand Up @@ -873,7 +873,7 @@ public void analyse(Network network, List<PropagatedContingency> contingencies,
throw new PowsyblException("Only variables of type TRANSFORMER_PHASE, INJECTION_ACTIVE_POWER and HVDC_LINE_ACTIVE_POWER, and functions of type BRANCH_ACTIVE_POWER_1 and BRANCH_ACTIVE_POWER_2 are yet supported in DC");
});

LOGGER.info("Running DC sensitivity analysis with {} factors and {} contingencies", allLfFactors.size(), contingencies.size());
LOGGER.info("Running DC sensitivity analysis with {} factors and {} contingencies", allLfFactors.size(), contingencies.size());

var dcLoadFlowParameters = createDcLoadFlowParameters(lfNetworkParameters, matrixFactory, lfParameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void shuntTest() {
var bus = Mockito.mock(LfBus.class, ANSWER);
Mockito.doReturn(0).when(bus).getNum();

VariableSet<AcVariableType> variableSet = new VariableSet<>();
VariableSet<AcVariableType> variableSet = new VariableSet<>();
var vVar = variableSet.getVariable(0, AcVariableType.BUS_V);
var bVar = variableSet.getVariable(0, AcVariableType.SHUNT_B);

Expand Down Expand Up @@ -224,7 +224,7 @@ void hvdcTest() {
Mockito.doReturn(0).when(bus1).getNum();
Mockito.doReturn(1).when(bus2).getNum();

VariableSet<AcVariableType> variableSet = new VariableSet<>();
VariableSet<AcVariableType> variableSet = new VariableSet<>();
var hvdcPh1Var = variableSet.getVariable(0, AcVariableType.BUS_PHI);
var hvdcPh2Var = variableSet.getVariable(1, AcVariableType.BUS_PHI);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class DcLoadFlowMatrixTest {
private final MatrixFactory matrixFactory = new DenseMatrixFactory();

private static void logNetwork(Network network) {
network.getLoads().forEach(l -> LOGGER.info("{} : p = {}.", l.getId(), l.getP0()));
network.getGenerators().forEach(g -> LOGGER.info("{} : p = {}.", g.getId(), g.getTargetP()));
network.getLoads().forEach(l -> LOGGER.info("{} : p = {}.", l.getId(), l.getP0()));
network.getGenerators().forEach(g -> LOGGER.info("{} : p = {}.", g.getId(), g.getTargetP()));
network.getBranchStream().forEach(b -> LOGGER.info("{} : p1 = {}, p2 = {}.",
b.getId(), b.getTerminal1().getP(), b.getTerminal2().getP()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public void onEquationTermChange(EquationTerm<TestVariableType, TestEquationType
var b = equationSystem.getVariableSet().getVariable(0, TestVariableType.B);
var c = equationSystem.getVariableSet().getVariable(0, TestVariableType.C);
EquationTerm<TestVariableType, TestEquationType> aTerm = a.createTerm();
EquationTerm<TestVariableType, TestEquationType> bTerm = b.createTerm();
EquationTerm<TestVariableType, TestEquationType> bTerm = b.createTerm();
var x = equationSystem.createEquation(0, TestEquationType.X)
.addTerm(aTerm)
.addTerm(bTerm);
EquationTerm<TestVariableType, TestEquationType> aTerm2 = a.createTerm();
EquationTerm<TestVariableType, TestEquationType> cTerm = c.createTerm();
EquationTerm<TestVariableType, TestEquationType> cTerm = c.createTerm();
var y = equationSystem.createEquation(0, TestEquationType.Y)
.addTerm(aTerm2)
.addTerm(cTerm);
Expand Down
Loading