Skip to content

Commit

Permalink
fixes case-projector post-processor: the configuration is not read in…
Browse files Browse the repository at this point in the history
… the constructor, anymore (to avoid problems with powsybl-core/ImportersServiceLoader.loadPostProcessors(), when a 'case-projector' section doesn't exist in the configuration)
  • Loading branch information
CBiasuzzi committed Jun 25, 2018
1 parent 15ea987 commit c75896c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
package eu.itesla_project.case_projector;

import com.google.auto.service.AutoService;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.powsybl.commons.config.ComponentDefaultConfig;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.import_.ImportPostProcessor;
import com.powsybl.iidm.network.Network;
Expand All @@ -33,18 +34,11 @@ public class CaseProjectorPostProcessor implements ImportPostProcessor {

public static final String NAME = "case-proj";

private final LoadFlowFactory loadFlowFactory;
private final Supplier<CaseProjectorConfig> caseProjectorConfigSupplier = Suppliers.memoize(CaseProjectorConfig::load);

private final CaseProjectorConfig config;
private final Supplier<ComponentDefaultConfig> defaultConfigSupplier = Suppliers.memoize(ComponentDefaultConfig::load);

public CaseProjectorPostProcessor() {
this(PlatformConfig.defaultConfig());
}

public CaseProjectorPostProcessor(PlatformConfig platformConfig) {
ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load();
loadFlowFactory = defaultConfig.newFactoryImpl(LoadFlowFactory.class);
config = CaseProjectorConfig.load();
}

@Override
Expand All @@ -54,8 +48,9 @@ public String getName() {

@Override
public void process(Network network, ComputationManager computationManager) throws Exception {
LoadFlowFactory loadFlowFactory = defaultConfigSupplier.get().newFactoryImpl(LoadFlowFactory.class);
LoadFlow loadFlow = loadFlowFactory.create(network, computationManager, 0);
CaseProjectorUtils.project(computationManager, network, loadFlow, network.getStateManager().getWorkingStateId(), config).join();
CaseProjectorUtils.project(computationManager, network, loadFlow, network.getStateManager().getWorkingStateId(), caseProjectorConfigSupplier.get()).join();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.config.PlatformConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.nio.file.FileSystem;

public class CaseProjectorPostProcessorTest {

private FileSystem fileSystem;
private PlatformConfig platformConfig;

private PlatformConfig createEmptyPlatformConfig() {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
platformConfig = new InMemoryPlatformConfig(fileSystem);
return platformConfig;
}

@Before
public void setUp() throws Exception {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
platformConfig = createEmptyPlatformConfig();
}

@After
public void tearDown() throws Exception {
fileSystem.close();
}

@Test
public void testInstCaseProjectorPostProcessor() throws Exception {
//when there is no case-projector section, in the configuration, this constructor should not throw any exception
CaseProjectorPostProcessor postProcessor = new CaseProjectorPostProcessor();
}
}

0 comments on commit c75896c

Please sign in to comment.