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

Models integration tests #392

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
/**
* Copyright (c) 2024, 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.dynawo.it;

import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynamicsimulation.*;
import com.powsybl.dynawo.DynawoSimulationConfig;
import com.powsybl.dynawo.DynawoSimulationParameters;
import com.powsybl.dynawo.DynawoSimulationProvider;
import com.powsybl.dynawo.builders.ModelInfo;
import com.powsybl.dynawo.builders.VersionBound;
import com.powsybl.dynawo.models.buses.InfiniteBusBuilder;
import com.powsybl.dynawo.models.buses.StandardBusBuilder;
import com.powsybl.dynawo.models.generators.*;
import com.powsybl.dynawo.models.hvdc.HvdcPBuilder;
import com.powsybl.dynawo.models.hvdc.HvdcVscBuilder;
import com.powsybl.dynawo.models.lines.LineBuilder;
import com.powsybl.dynawo.models.loads.*;
import com.powsybl.dynawo.models.shunts.BaseShuntBuilder;
import com.powsybl.dynawo.models.svarcs.BaseStaticVarCompensatorBuilder;
import com.powsybl.dynawo.models.transformers.TransformerFixedRatioBuilder;
import com.powsybl.dynawo.parameters.ParametersSet;
import com.powsybl.dynawo.xml.ParametersXml;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.ShuntTestCaseFactory;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Stream;

import static com.powsybl.dynawo.builders.VersionBound.MODEL_DEFAULT_MIN_VERSION;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
@Disabled
public class ModelsTest extends AbstractDynawoTest {

private static final Network SMIB = Network.read(new ResourceDataSource("SMIB", new ResourceSet("/smib", "SMIB.iidm")));
private static final Network EUROSTAG = EurostagTutorialExample1Factory.create();
private static final Network HVDC = Network.read(new ResourceDataSource("HvdcPowerTransfer", new ResourceSet("/hvdc", "HvdcPowerTransfer.iidm")));
//TODO remove skipped model list when fixed (see issue #400)
private static final List<String> SKIPPED_MODELS = List.of(
"GeneratorPQPropSignalN",
"GeneratorPQPropDiagramPQSignalN",
"GeneratorPVRemoteSignalN",
"GeneratorPVRemoteDiagramPQSignalN",
"StaticVarCompensatorPVRemote",
"StaticVarCompensatorPVPropRemote",
"StaticVarCompensatorPVRemoteModeHandling",
"StaticVarCompensatorPVPropRemoteModeHandling",
"HvdcPQProp",
"HvdcPQPropDangling",
"HvdcPQPropDanglingDiagramPQ",
"HvdcPQPropDiagramPQ",
"HvdcPQPropDiagramPQEmulation",
"HvdcPQPropDiagramPQEmulationSet",
"HvdcPQPropDiagramPQEmulationVariableK",
"HvdcPQPropEmulation",
"HvdcPQPropEmulationSet",
"HvdcPQPropEmulationVariableK"
);

private DynamicSimulationProvider provider;
private DynamicSimulationParameters parameters;

@BeforeEach
void setup() {
provider = new DynawoSimulationProvider(new DynawoSimulationConfig(Path.of("/dynawo"), false));
parameters = new DynamicSimulationParameters()
.setStartTime(0)
.setStopTime(1);
DynawoSimulationParameters dynawoSimulationParameters = new DynawoSimulationParameters();
parameters.addExtension(DynawoSimulationParameters.class, dynawoSimulationParameters);
List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/models/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/smib/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/smib/solvers.par"), "3");
dynawoSimulationParameters.setModelsParameters(modelsParameters)
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
.setSolverType(DynawoSimulationParameters.SolverType.SIM);
}

@MethodSource("dynamicModelBuilderProvider")
@ParameterizedTest
void testDynamicModel(Network network, Collection<ModelInfo> models, BiFunction<Network, String, List<DynamicModel>> dynamicModelSupplier) {
SoftAssertions assertions = new SoftAssertions();
StringBuilder sb = new StringBuilder();
for(ModelInfo modelInfo : models.stream().filter(m -> !SKIPPED_MODELS.contains(m.name())).toList()) {
ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate("modelTest", "Model test").build();
provider.run(network, (n, r) -> dynamicModelSupplier.apply(n, modelInfo.name()), EventModelsSupplier.empty(),
CurvesSupplier.empty(), VariantManagerConstants.INITIAL_VARIANT_ID, computationManager,
parameters, reportNode)
.join();
Optional<ReportNode> modelLog = reportNode.getChildren().stream()
.filter(r -> r.getMessageKey().equalsIgnoreCase("dynawoLog"))
.flatMap(o -> o.getChildren().stream())
.filter(m -> m.getMessage().equalsIgnoreCase("model was built successfully"))
.findFirst();
assertions.assertThat(modelLog)
.withFailMessage(() -> "Model %s was not built successfully".formatted(modelInfo.name()))
.isNotEmpty();
if (modelLog.isEmpty()) {
sb.append(modelInfo.name()).append("\n");
StringWriter swReporterAs = new StringWriter();
reportNode.getChildren().stream()
.filter(r -> r.getMessageKey().equalsIgnoreCase("dynawoLog"))
.findFirst().ifPresent(rr -> {
try {
rr.print(swReporterAs);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
sb.append(swReporterAs);
}

}
System.out.println(sb);
assertions.assertAll();
}

private static Stream<Arguments> dynamicModelBuilderProvider() {
return Stream.of(
Arguments.of(
SMIB,
GeneratorFictitiousBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(GeneratorFictitiousBuilder.of(n, m)
.staticId("SM")
.parameterSetId("BaseGenerator")
.build())
),
Arguments.of(
SMIB,
SynchronizedGeneratorBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(SynchronizedGeneratorBuilder.of(n, m)
.staticId("SM")
.parameterSetId("SynchronizedGenerator")
.build())
),
Arguments.of(
SMIB,
SynchronousGeneratorBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(SynchronousGeneratorBuilder.of(n, m)
.staticId("SM")
.parameterSetId("SynchronousGenerator")
.build())
),
Arguments.of(
SMIB,
WeccBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(WeccBuilder.of(n, m)
.staticId("SM")
.parameterSetId("GridForming")
.build())
),
Arguments.of(
SMIB,
GridFormingConverterBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(GridFormingConverterBuilder.of(n, m)
.staticId("SM")
.parameterSetId("GridForming")
.build())
),
Arguments.of(
SMIB,
SignalNGeneratorBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(SignalNGeneratorBuilder.of(n, m)
.staticId("SM")
.parameterSetId("GeneratorPVSignalN")
.build())
),
Arguments.of(
SMIB,
StandardBusBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(
StandardBusBuilder.of(n, m)
.staticId("VL1_BUS1")
.parameterSetId("Bus")
.build(),
StandardBusBuilder.of(n)
.staticId("VL2_BUS1")
.parameterSetId("Bus")
.build(),
StandardBusBuilder.of(n)
.staticId("VL3_BUS1")
.parameterSetId("Bus")
.build(),
LineBuilder.of(n)
.staticId("line1")
.parameterSetId("Line")
.build(),
LineBuilder.of(n)
.staticId("line2")
.parameterSetId("Line")
.build(),
TransformerFixedRatioBuilder.of(n)
.staticId("TR")
.parameterSetId("Transformer")
.build(),
GeneratorFictitiousBuilder.of(n)
.staticId("SM")
.parameterSetId("BaseGenerator")
.build())
),
Arguments.of(
SMIB,
InfiniteBusBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(
InfiniteBusBuilder.of(n, m)
.staticId("VL1_BUS1")
.parameterSetId("Bus")
.build(),
StandardBusBuilder.of(n)
.staticId("VL2_BUS1")
.parameterSetId("Bus")
.build(),
StandardBusBuilder.of(n)
.staticId("VL3_BUS1")
.parameterSetId("Bus")
.build(),
LineBuilder.of(n)
.staticId("line1")
.parameterSetId("Line")
.build(),
LineBuilder.of(n)
.staticId("line2")
.parameterSetId("Line")
.build(),
TransformerFixedRatioBuilder.of(n)
.staticId("TR")
.parameterSetId("Transformer")
.build(),
GeneratorFictitiousBuilder.of(n)
.staticId("SM")
.parameterSetId("BaseGenerator")
.build())
),
Arguments.of(
EUROSTAG,
BaseLoadBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(BaseLoadBuilder.of(n, m)
.staticId("LOAD")
.parameterSetId("LAB")
.build())
),
Arguments.of(
EUROSTAG,
LoadOneTransformerBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(LoadOneTransformerBuilder.of(n, m)
.staticId("LOAD")
.parameterSetId("LAB")
.build())
),
Arguments.of(
EUROSTAG,
LoadOneTransformerTapChangerBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(LoadOneTransformerTapChangerBuilder.of(n, m)
.staticId("LOAD")
.parameterSetId("LAB")
.build())
),
Arguments.of(
EUROSTAG,
LoadTwoTransformersBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(LoadTwoTransformersBuilder.of(n, m)
.staticId("LOAD")
.parameterSetId("LAB")
.build())
),
Arguments.of(
EUROSTAG,
LoadTwoTransformersTapChangersBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(LoadTwoTransformersTapChangersBuilder.of(n, m)
.staticId("LOAD")
.parameterSetId("LAB")
.build())
),
Arguments.of(
SMIB,
LineBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(
LineBuilder.of(n,m)
.staticId("line1")
.parameterSetId("Line")
.build())
),
Arguments.of(
EUROSTAG,
TransformerFixedRatioBuilder.getSupportedModelInfos(MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(
TransformerFixedRatioBuilder.of(n,m)
.staticId("NGEN_NHV1")
.parameterSetId("Transformer")
.build())
),
Arguments.of(
ShuntTestCaseFactory.create(),
BaseShuntBuilder.getSupportedModelInfos(VersionBound.MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(BaseShuntBuilder.of(n, m)
.staticId("SHUNT")
.parameterSetId("Shunt")
.build())
),
Arguments.of(
SvcTestCaseFactory.create(),
BaseStaticVarCompensatorBuilder.getSupportedModelInfos(VersionBound.MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(BaseStaticVarCompensatorBuilder.of(n, m)
.staticId("SVC2")
.parameterSetId("SvarC")
.build())
),
Arguments.of(
HVDC,
HvdcPBuilder.getSupportedModelInfos(VersionBound.MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(HvdcPBuilder.of(n, m)
.staticId("HVDC1")
.parameterSetId("Hvdc")
.build())
),
Arguments.of(
HVDC,
HvdcVscBuilder.getSupportedModelInfos(VersionBound.MODEL_DEFAULT_MIN_VERSION),
(BiFunction<Network, String, List<DynamicModel>>) (n, m) -> List.of(HvdcVscBuilder.of(n, m)
.staticId("HVDC1")
.parameterSetId("Hvdc")
.build())
)
);
}
}
Loading
Loading