Skip to content

Commit

Permalink
Merge pull request #343 from itesla/projector_load_flow
Browse files Browse the repository at this point in the history
Ampl based load flow implementation
  • Loading branch information
sylvlecl committed Jun 6, 2018
2 parents 7de88b4 + 088bbe5 commit e6b6fc4
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2018, 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/.
*/
package eu.itesla_project.case_projector;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.loadflow.LoadFlowResultImpl;

/**
* @author Giovanni Ferrari <giovanni.ferrari at techrain.eu>
*/
public class CaseProjectorLoadFlow implements LoadFlow {

private final Network network;
private final ComputationManager computationManager;

public CaseProjectorLoadFlow(Network network, ComputationManager computationManager, int priority) {
this.network = Objects.requireNonNull(network);
this.computationManager = Objects.requireNonNull(computationManager);
}

@Override
public String getName() {
return "case-projector-load-flow";
}

@Override
public String getVersion() {
return "1.0.0";
}

@Override
public LoadFlowResult run(LoadFlowParameters params) throws Exception {
CaseProjectorLoadFlowParameters amplParams = params.getExtension(CaseProjectorLoadFlowParameters.class);
Path generatorsDomains = amplParams.getGeneratorsDomainsFile();
Map<String, String> metrics = new HashMap<>();
CompletableFuture<Boolean> result = CaseProjectorUtils.createAmplTask(computationManager, network, network.getStateManager().getWorkingStateId(), new CaseProjectorConfig(amplParams.getAmplHomeDir(), generatorsDomains, amplParams.isDebug()));
Boolean wres = result.join();
return new LoadFlowResultImpl(wres, metrics, null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2018, 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/.
*/
package eu.itesla_project.case_projector;

import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowFactory;

/**
* @author Giovanni Ferrari <giovanni.ferrari at techrain.eu>
*/
public class CaseProjectorLoadFlowFactory implements LoadFlowFactory {

@Override
public LoadFlow create(Network network, ComputationManager computationManager, int priority) {

return new CaseProjectorLoadFlow(network, computationManager, priority);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2018, 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/.
*/
package eu.itesla_project.case_projector;

import java.nio.file.Path;
import java.util.Objects;

import com.google.auto.service.AutoService;
import com.powsybl.commons.config.ModuleConfig;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.loadflow.LoadFlowParameters;

/**
* @author Giovanni Ferrari <giovanni.ferrari at techrain.eu>
*/
public class CaseProjectorLoadFlowParameters extends AbstractExtension<LoadFlowParameters> {

private Path amplHomeDir;
private Path generatorsDomainsFile;
private boolean debug;

public CaseProjectorLoadFlowParameters(PlatformConfig config) {
Objects.requireNonNull(config);

if (config.moduleExists("caseProjector")) {
ModuleConfig amplConfig = config.getModuleConfig("caseProjector");
this.amplHomeDir = amplConfig.getPathProperty("amplHomeDir");
this.generatorsDomainsFile = amplConfig.getPathProperty("generatorsDomainsFile");
this.debug = amplConfig.getBooleanProperty("debug");
}
}

public CaseProjectorLoadFlowParameters(Path amplHomeDir, Path generatorsDomainsFile, boolean debug) {
this.amplHomeDir = Objects.requireNonNull(amplHomeDir);
this.generatorsDomainsFile = Objects.requireNonNull(generatorsDomainsFile);
this.debug = debug;
}

@AutoService(LoadFlowParameters.ConfigLoader.class)
public static class AmplLoadFlowConfigLoader implements LoadFlowParameters.ConfigLoader<CaseProjectorLoadFlowParameters> {

@Override
public CaseProjectorLoadFlowParameters load(PlatformConfig config) {
return new CaseProjectorLoadFlowParameters(config);
}

@Override
public String getCategoryName() {
return "loadflow-parameters";
}

@Override
public Class<? super CaseProjectorLoadFlowParameters> getExtensionClass() {
return CaseProjectorLoadFlowParameters.class;
}

@Override
public String getExtensionName() {
return "ampl";
}
}

@Override
public String getName() {
return "ampl";
}

public Path getAmplHomeDir() {
return amplHomeDir;
}

public boolean isDebug() {
return debug;
}

public Path getGeneratorsDomainsFile() {
return generatorsDomainsFile;
}

}

0 comments on commit e6b6fc4

Please sign in to comment.