Skip to content

Commit

Permalink
Add InfiniteBus model
Browse files Browse the repository at this point in the history
Add SetPoint model replacing OmegaRef if a InfiniteBus is present in the model

Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte committed May 9, 2023
1 parent f7f7934 commit 39f8046
Show file tree
Hide file tree
Showing 21 changed files with 436 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package com.powsybl.dynawaltz.dsl.models.builders

import com.powsybl.dsl.DslException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.dsl.models.buses

import com.powsybl.dsl.DslException
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.iidm.network.Bus
import com.powsybl.iidm.network.Network

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
abstract class AbstractBusBuilder extends AbstractDynamicModelBuilder {

Bus bus

AbstractBusBuilder(Network network) {
super(network)
}

void checkData() {
super.checkData()
bus = network.getBusBreakerView().getBus(staticId)
if (bus == null) {
throw new DslException("Bus static id unknown: " + staticId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
package com.powsybl.dynawaltz.dsl.models.buses

import com.google.auto.service.AutoService
import com.powsybl.dsl.DslException
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.dynawaltz.models.buses.StandardBus
import com.powsybl.iidm.network.Bus
import com.powsybl.iidm.network.Network

/**
Expand All @@ -34,22 +31,12 @@ class BusGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicModel>
new BusBuilder(network)
}

static class BusBuilder extends AbstractDynamicModelBuilder {

Bus bus
static class BusBuilder extends AbstractBusBuilder {

BusBuilder(Network network) {
super(network)
}

void checkData() {
super.checkData()
bus = network.getBusBreakerView().getBus(staticId)
if (bus == null) {
throw new DslException("Bus static id unknown: " + staticId)
}
}

@Override
StandardBus build() {
checkData()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.dsl.models.buses

import com.google.auto.service.AutoService
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.models.buses.InfiniteBus
import com.powsybl.iidm.network.Network

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class InfiniteBusGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

protected static final String BUSES = "infiniteBuses"

InfiniteBusGroovyExtension() {
ConfigSlurper config = new ConfigSlurper()
modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(BUSES).keySet() as List
}

@Override
protected BusBuilder createBuilder(Network network, String currentTag) {
new BusBuilder(network, currentTag)
}

static class BusBuilder extends AbstractBusBuilder {

String tag

BusBuilder(Network network, String tag) {
super(network)
this.tag = tag
}

@Override
InfiniteBus build() {
checkData()
new InfiniteBus(dynamicModelId, bus, parameterSetId, tag)
}
}
}
6 changes: 6 additions & 0 deletions dynawaltz-dsl/src/main/resources/models.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ hvdc {
HvdcVSCEmulation
}

infiniteBuses {
InfiniteBus
InfiniteBusWithImpedance
InfiniteBusWithVariations
}

loadsAlphaBeta {
LoadAlphaBeta
LoadAlphaBetaRestorative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.powsybl.dynawaltz.models.automatons.UnderVoltageAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton;
import com.powsybl.dynawaltz.models.buses.InfiniteBus;
import com.powsybl.dynawaltz.models.buses.StandardBus;
import com.powsybl.dynawaltz.models.generators.GeneratorFictitious;
import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous;
Expand Down Expand Up @@ -102,6 +103,7 @@ private static Stream<Arguments> provideEquipmentModelData() {
Arguments.of("loadTwoTransformers", LoadTwoTransformers.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LTT", "LoadTwoTransformers"),
Arguments.of("loadTwoTransformersTapChangers", LoadTwoTransformersTapChangers.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LTT", "LoadTwoTransformersTapChangers"),
Arguments.of("hvdc", HvdcModel.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPV"),
Arguments.of("infiniteBus", InfiniteBus.class, HvdcTestNetwork.createVsc(), "B1", "BBM_BUS", "b", "InfiniteBusWithVariations"),
Arguments.of("line", StandardLine.class, EurostagTutorialExample1Factory.create(), "NHV1_NHV2_1", "BBM_NHV1_NHV2_1", "LINE", "Line"),
Arguments.of("genFictitious", GeneratorFictitious.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GF", "GeneratorFictitious"),
Arguments.of("gen", GeneratorSynchronous.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GSFWPR", "GeneratorSynchronousFourWindingsProportionalRegulations"),
Expand Down
15 changes: 15 additions & 0 deletions dynawaltz-dsl/src/test/resources/dynamicModels/infiniteBus.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package dynamicModels

InfiniteBusWithVariations {
staticId "B1"
dynamicModelId "BBM_BUS"
parameterSetId "b"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.powsybl.dynamicsimulation.Curve;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynawaltz.models.*;
import com.powsybl.dynawaltz.models.buses.InfiniteBus;
import com.powsybl.dynawaltz.models.frequencysynchronizers.FrequencySynchronizerModel;
import com.powsybl.dynawaltz.models.frequencysynchronizers.OmegaRef;
import com.powsybl.dynawaltz.models.frequencysynchronizers.SetPoint;
import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel;
import com.powsybl.dynawaltz.xml.MacroStaticReference;
import com.powsybl.iidm.network.Identifiable;
Expand Down Expand Up @@ -40,8 +44,7 @@ public class DynaWaltzContext {
private final List<MacroConnect> macroConnectList = new ArrayList<>();
private final Map<String, MacroConnector> macroConnectorsMap = new LinkedHashMap<>();
private final NetworkModel networkModel = new NetworkModel();

private final OmegaRef omegaRef;
private final FrequencySynchronizerModel frequencySynchronizer;

public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxModel> dynamicModels, List<BlackBoxModel> eventModels,
List<Curve> curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters) {
Expand All @@ -56,10 +59,7 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
this.curves = Objects.requireNonNull(curves);
this.parameters = Objects.requireNonNull(parameters);
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);
this.omegaRef = new OmegaRef(dynamicModels.stream()
.filter(OmegaRefGeneratorModel.class::isInstance)
.map(OmegaRefGeneratorModel.class::cast)
.collect(Collectors.toList()));
this.frequencySynchronizer = setupFrequencySynchronizer(dynamicModels.stream().anyMatch(InfiniteBus.class::isInstance) ? SetPoint::new : OmegaRef::new);

for (BlackBoxModel bbm : getBlackBoxDynamicModelStream().collect(Collectors.toList())) {
macroStaticReferences.computeIfAbsent(bbm.getName(), k -> new MacroStaticReference(k, bbm.getVarsMapping()));
Expand All @@ -71,6 +71,13 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
}
}

private FrequencySynchronizerModel setupFrequencySynchronizer(Function<List<OmegaRefGeneratorModel>, FrequencySynchronizerModel> fsConstructor) {
return fsConstructor.apply(dynamicModels.stream()
.filter(OmegaRefGeneratorModel.class::isInstance)
.map(OmegaRefGeneratorModel.class::cast)
.collect(Collectors.toList()));
}

public Network getNetwork() {
return network;
}
Expand Down Expand Up @@ -194,10 +201,10 @@ private Stream<BlackBoxModel> getInputBlackBoxDynamicModelStream() {
}

public Stream<BlackBoxModel> getBlackBoxDynamicModelStream() {
if (omegaRef.isEmpty()) {
if (frequencySynchronizer.isEmpty()) {
return getInputBlackBoxDynamicModelStream();
}
return Stream.concat(getInputBlackBoxDynamicModelStream(), Stream.of(omegaRef));
return Stream.concat(getInputBlackBoxDynamicModelStream(), Stream.of(frequencySynchronizer));
}

public List<BlackBoxModel> getBlackBoxDynamicModels() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.models.buses;

import com.powsybl.commons.PowsyblException;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel;
import com.powsybl.dynawaltz.models.MacroConnectAttribute;
import com.powsybl.iidm.network.Bus;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public abstract class AbstractBus extends AbstractEquipmentBlackBoxModel<Bus> implements BusModel {

public AbstractBus(String dynamicModelId, Bus bus, String parameterSetId) {
super(dynamicModelId, parameterSetId, bus);
}

@Override
public List<MacroConnectAttribute> getMacroConnectToAttributes() {
List<MacroConnectAttribute> attributesConnectTo = new ArrayList<>(super.getMacroConnectToAttributes());
attributesConnectTo.add(MacroConnectAttribute.of("name2", getStaticId()));
return attributesConnectTo;
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
checkLinkedDynamicModels(equipment, context);
}

private void checkLinkedDynamicModels(Bus bus, DynaWaltzContext context) {
bus.getConnectedTerminalStream()
.map(t -> t.getConnectable().getId())
.filter(context::isWithoutBlackBoxDynamicModel)
.findAny()
.ifPresent(id -> {
throw new PowsyblException(String.format("The equipment %s linked to the %s %s does not possess a dynamic model",
id, this.getClass().getSimpleName(), getStaticId()));
});
}

@Override
public String getName() {
return getLib();
}

@Override
public Optional<String> getSwitchOffSignalVarName() {
return Optional.empty();
}

@Override
public Optional<String> getNumCCVarName() {
return Optional.empty();
}

@Override
public Optional<String> getUImpinVarName() {
return Optional.empty();
}

@Override
public Optional<String> getUpuImpinVarName() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.models.buses;

import com.powsybl.iidm.network.Bus;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public class InfiniteBus extends AbstractBus {

private final String lib;

public InfiniteBus(String dynamicModelId, Bus bus, String parameterSetId, String lib) {
super(dynamicModelId, bus, parameterSetId);
this.lib = lib;
}

@Override
public String getLib() {
return lib;
}

@Override
public String getTerminalVarName() {
return "infiniteBus_terminal";
}
}
Loading

0 comments on commit 39f8046

Please sign in to comment.