Skip to content

Commit

Permalink
chore: duplication and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <[email protected]>
  • Loading branch information
TheMaskedTurtle committed Feb 6, 2024
1 parent 6c95545 commit c559efa
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions open-reac/src/main/java/com/powsybl/openreac/OpenReacRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ private OpenReacRunner() {

/**
* Run OpenReac on the given network. It will NOT modify the network.
* @param variantId the network variant to use. It will set the variant on the network.
*
* @param variantId the network variant to use. It will set the variant on the network.
* @param parameters Parameters to customize the OpenReac run.
* @return All information about the run and possible modifications to apply.
*/
Expand All @@ -41,9 +42,10 @@ public static OpenReacResult run(Network network, String variantId, OpenReacPara

/**
* Run OpenReac on the given network. It will NOT modify the network.
* @param variantId the network variant to use. It will set the variant on the network.
*
* @param variantId the network variant to use. It will set the variant on the network.
* @param parameters Parameters to customize the OpenReac run.
* @param config allows debugging
* @param config allows debugging
* @return All information about the run and possible modifications to apply.
*/
public static OpenReacResult run(Network network, String variantId, OpenReacParameters parameters, OpenReacConfig config, ComputationManager manager) {
Expand All @@ -52,33 +54,28 @@ public static OpenReacResult run(Network network, String variantId, OpenReacPara

/**
* Run OpenReac on the given network. It will NOT modify the network.
* @param variantId the network variant to use. It will set the variant on the network.
*
* @param variantId the network variant to use. It will set the variant on the network.
* @param parameters Parameters to customize the OpenReac run.
* @param config allows debugging
* @param reporter aggregates functional logging
* @param config allows debugging
* @param reporter aggregates functional logging
* @return All information about the run and possible modifications to apply.
*/
public static OpenReacResult run(Network network, String variantId, OpenReacParameters parameters, OpenReacConfig config, ComputationManager manager, Reporter reporter) {
Objects.requireNonNull(network);
Objects.requireNonNull(variantId);
Objects.requireNonNull(parameters);
Objects.requireNonNull(config);
Objects.requireNonNull(manager);
Objects.requireNonNull(reporter);
parameters.checkIntegrity(network);
checkParameters(network, variantId, parameters, config, manager, reporter);
AmplModel reactiveOpf = OpenReacModel.buildModel();
Reporter voltageInitReporter = Reports.createVoltageInitReporter(reporter, network.getId());
OpenReacAmplIOFiles amplIoInterface = new OpenReacAmplIOFiles(parameters, network, config.isDebug(), voltageInitReporter);
OpenReacAmplIOFiles amplIoInterface = new OpenReacAmplIOFiles(parameters, network, config.isDebug(), Reports.createVoltageInitReporter(reporter, network.getId()));
AmplResults run = AmplModelRunner.run(network, variantId, reactiveOpf, manager, amplIoInterface);
return new OpenReacResult(run.isSuccess() && amplIoInterface.checkErrors() ? OpenReacStatus.OK : OpenReacStatus.NOT_OK,
amplIoInterface, run.getIndicators());
}

/**
* Run OpenReac on the given network. It will NOT modify the network.
* @param variantId the network variant to use. It will set the variant on the network.
*
* @param variantId the network variant to use. It will set the variant on the network.
* @param parameters Parameters to customize the OpenReac run.
* @param config allows debugging
* @param config allows debugging
* @return All information about the run and possible modifications to apply.
*/
public static CompletableFuture<OpenReacResult> runAsync(Network network, String variantId, OpenReacParameters parameters, OpenReacConfig config, ComputationManager manager) {
Expand All @@ -87,25 +84,29 @@ public static CompletableFuture<OpenReacResult> runAsync(Network network, String

/**
* Run OpenReac on the given network. It will NOT modify the network.
* @param variantId the network variant to use. It will set the variant on the network.
*
* @param variantId the network variant to use. It will set the variant on the network.
* @param parameters Parameters to customize the OpenReac run.
* @param config allows debugging
* @param reporter aggregates functional logging
* @param config allows debugging
* @param reporter aggregates functional logging
* @return All information about the run and possible modifications to apply.
*/
public static CompletableFuture<OpenReacResult> runAsync(Network network, String variantId, OpenReacParameters parameters, OpenReacConfig config, ComputationManager manager, Reporter reporter) {
checkParameters(network, variantId, parameters, config, manager, reporter);
AmplModel reactiveOpf = OpenReacModel.buildModel();
OpenReacAmplIOFiles amplIoInterface = new OpenReacAmplIOFiles(parameters, network, config.isDebug(), Reports.createVoltageInitReporter(reporter, network.getId()));
CompletableFuture<AmplResults> runAsync = AmplModelRunner.runAsync(network, variantId, reactiveOpf, manager, amplIoInterface);
return runAsync.thenApply(run -> new OpenReacResult(run.isSuccess() && amplIoInterface.checkErrors() ? OpenReacStatus.OK : OpenReacStatus.NOT_OK,
amplIoInterface, run.getIndicators()));
}

private static void checkParameters(Network network, String variantId, OpenReacParameters parameters, OpenReacConfig config, ComputationManager manager, Reporter reporter) {
Objects.requireNonNull(network);
Objects.requireNonNull(variantId);
Objects.requireNonNull(parameters);
Objects.requireNonNull(config);
Objects.requireNonNull(manager);
Objects.requireNonNull(reporter);
parameters.checkIntegrity(network);
AmplModel reactiveOpf = OpenReacModel.buildModel();
Reporter voltageInitReporter = Reports.createVoltageInitReporter(reporter, network.getId());
OpenReacAmplIOFiles amplIoInterface = new OpenReacAmplIOFiles(parameters, network, config.isDebug(), voltageInitReporter);
CompletableFuture<AmplResults> runAsync = AmplModelRunner.runAsync(network, variantId, reactiveOpf, manager, amplIoInterface);
return runAsync.thenApply(run -> new OpenReacResult(run.isSuccess() && amplIoInterface.checkErrors() ? OpenReacStatus.OK : OpenReacStatus.NOT_OK,
amplIoInterface, run.getIndicators()));
}
}

0 comments on commit c559efa

Please sign in to comment.