public SecurityAnalyzer(LimitViolationFilter filter, ComputationManager computationManager, int priority, Set<SecurityAnalysisInterceptor> interceptors) { this.filter = Objects.requireNonNull(filter); this.computationManager = Objects.requireNonNull(computationManager); this.priority = priority; this.interceptors = Objects.requireNonNull(interceptors); ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load(); securityAnalysisFactory = defaultConfig.newFactoryImpl(SecurityAnalysisFactory.class); contingenciesProviderFactory = defaultConfig.newFactoryImpl(ContingenciesProviderFactory.class); }
/** * Returns a factory as defined in the {@link ComponentDefaultConfig}. */ public static SecurityAnalysisFactory newDefaultFactory() { return ComponentDefaultConfig.load().newFactoryImpl(SecurityAnalysisFactory.class); }
public static ContingenciesProviderFactory getContingenciesProviderFactory() { if (contingenciesProviderFactory == null) { if (componentDefaultConfig == null) { componentDefaultConfig = ComponentDefaultConfig.load(); } contingenciesProviderFactory = componentDefaultConfig.newFactoryImpl(ContingenciesProviderFactory.class); } return contingenciesProviderFactory; }
public LocalSecurityAnalysisRunningServiceExtension() { this(() -> ComponentDefaultConfig.load().newFactoryImpl(SecurityAnalysisFactory.class, SecurityAnalysisFactoryImpl.class)); }
public static ComputationManager createMpiComputationManager(CommandLine line, FileSystem fileSystem) { Path tmpDir = fileSystem.getPath(line.hasOption(TMP_DIR) ? line.getOptionValue(TMP_DIR) : System.getProperty("java.io.tmpdir")); Path statisticsDbDir = line.hasOption(STATISTICS_DB_DIR) ? fileSystem.getPath(line.getOptionValue(STATISTICS_DB_DIR)) : null; String statisticsDbName = line.hasOption(STATISTICS_DB_NAME) ? line.getOptionValue(STATISTICS_DB_NAME) : null; int coresPerRank = Integer.parseInt(line.getOptionValue(CORES)); boolean verbose = line.hasOption(VERBOSE); Path stdOutArchive = line.hasOption(STDOUT_ARCHIVE) ? fileSystem.getPath(line.getOptionValue(STDOUT_ARCHIVE)) : null; ComponentDefaultConfig config = ComponentDefaultConfig.load(); MpiStatisticsFactory statisticsFactory = config.newFactoryImpl(MpiStatisticsFactory.class, NoMpiStatisticsFactory.class); try { return new MpiComputationManager(tmpDir, statisticsFactory, statisticsDbDir, statisticsDbName, new MpiExecutorContext(), coresPerRank, verbose, stdOutArchive); } catch (IOException e) { throw new UncheckedIOException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new UncheckedInterruptedException(e); } } }
@Override public SecurityAnalysis create(Network network, LimitViolationDetector detector, LimitViolationFilter filter, ComputationManager computationManager, int priority) { ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load(); LoadFlowFactory loadFlowFactory = defaultConfig.newFactoryImpl(LoadFlowFactory.class); return new SecurityAnalysisImpl(network, detector, filter, computationManager, loadFlowFactory); } }
@Override public void run(CommandLine line, ToolRunningContext context) throws Exception { ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load(); Path caseFile = context.getFileSystem().getPath(line.getOptionValue(CASE_FILE)); final Set<String> contingencyIds = line.hasOption(CONTINGENCIES) ? Sets.newHashSet(line.getOptionValue(CONTINGENCIES).split(",")) : null; Path outputCsvFile = null; if (line.hasOption(OUTPUT_CSV_FILE)) { outputCsvFile = context.getFileSystem().getPath(line.getOptionValue(OUTPUT_CSV_FILE)); } ContingenciesProvider contingenciesProvider = defaultConfig.newFactoryImpl(ContingenciesProviderFactory.class).create(); SimulatorFactory simulatorFactory = defaultConfig.newFactoryImpl(SimulatorFactory.class); if (Files.isRegularFile(caseFile)) { runSingleAnalysis(context, caseFile, outputCsvFile, contingencyIds, contingenciesProvider, simulatorFactory); } else if (Files.isDirectory(caseFile)) { runMultipleAnalyses(context, caseFile, outputCsvFile, contingencyIds, contingenciesProvider, simulatorFactory); } }
@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(), caseProjectorConfigSupplier.get()).join(); }
@Override public void run(CommandLine line, ToolRunningContext context) throws Exception { ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load(); CaseRepository caseRepository = defaultConfig.newFactoryImpl(CaseRepositoryFactory.class).create(LocalComputationManager.getDefault()); LoadFlowFactory loadFlowFactory = defaultConfig.newFactoryImpl(LoadFlowFactory.class); MergeOptimizerFactory mergeOptimizerFactory = defaultConfig.newFactoryImpl(MergeOptimizerFactory.class); Set<Country> countries = Arrays.stream(line.getOptionValue("countries").split(",")).map(Country::valueOf).collect(Collectors.toSet()); DateTime date = DateTime.parse(line.getOptionValue("date")); Path outputDir = Paths.get(line.getOptionValue("output-dir")); String outputFormat = line.getOptionValue("output-format"); Exporter exporter = Exporters.getExporter(outputFormat); if (exporter == null) { throw new RuntimeException("Format " + outputFormat + " not supported"); } boolean optimize = line.hasOption("optimize"); context.getOutputStream().println("merging..."); Network merge = MergeUtil.merge(caseRepository, date, CaseType.SN, countries, loadFlowFactory, 0, mergeOptimizerFactory, LocalComputationManager.getDefault(), optimize); context.getOutputStream().println("exporting..."); String baseName = merge.getId().replace(" ", "_"); exporter.export(merge, null, new FileDataSource(outputDir, baseName)); } }
@Override public void run(CommandLine line, ToolRunningContext context) throws Exception { Path caseFile = Paths.get(line.getOptionValue("case-file")); Network network = Importers.loadNetwork(caseFile); if (network == null) { throw new RuntimeException("Case " + caseFile + " not found"); } ComponentDefaultConfig config = ComponentDefaultConfig.load(); LoadFlowFactory loadFlowFactory = config.newFactoryImpl(LoadFlowFactory.class); SimulatorFactory simulatorFactory = config.newFactoryImpl(SimulatorFactory.class); CaseProjectorConfig caseProjectorConfig = CaseProjectorConfig.load(); if (line.hasOption("generators-domains-file")) { caseProjectorConfig = new CaseProjectorConfig(caseProjectorConfig.getAmplHomeDir(), Paths.get(line.getOptionValue("generators-domains-file")), caseProjectorConfig.isDebug()); } new CaseProjector(network, LocalComputationManager.getDefault(), loadFlowFactory, simulatorFactory, caseProjectorConfig) .project(StateManagerConstants.INITIAL_STATE_ID).join(); } }
public static void init() { componentDefaultConfig = ComponentDefaultConfig.load(); actionSimulatorConfig = LoadFlowActionSimulatorConfig.load(); contingenciesProviderFactory = componentDefaultConfig.newFactoryImpl(ContingenciesProviderFactory.class); try { localComputationManager = new LocalComputationManager(); } catch (IOException e) { throw new PowsyblException(e); } }
@Test public void newFactoryImplDefaultTest() throws IOException { assertTrue(config.newFactoryImpl(A.class, B.class) instanceof B); } }
@Test public void newFactoryImplTest() throws IOException { moduleConfig.setClassProperty(A.class.getSimpleName(), B.class); assertTrue(config.newFactoryImpl(A.class) instanceof B); }
throw new PowsyblException("Case '" + caseFile + "' not found"); LoadFlow loadFlow = defaultConfig.newFactoryImpl(LoadFlowFactory.class).create(network, context.getShortTimeExecutionComputationManager(), 0);
throw new PowsyblException("Case '" + caseFile + "' not found"); SensitivityComputation sensitivityComputation = defaultConfig.newFactoryImpl(SensitivityComputationFactory.class).create(network, context.getShortTimeExecutionComputationManager(), 0); SensitivityFactorsProviderFactory factorsProviderFactory = defaultConfig.newFactoryImpl(SensitivityFactorsProviderFactory.class); SensitivityFactorsProvider factorsProvider = factorsProviderFactory.create(sensitivityFactorsFile); SensitivityComputationResults result = sensitivityComputation.run(factorsProvider, workingStateId, params).join();
throw new RuntimeException(outputDir + " is not a directory"); DynamicDatabaseClient ddbClient = defaultConfig.newFactoryImpl(DynamicDatabaseClientFactory.class).create(eurostagConfig.isDdbCaching()); EurostagEchExporterFactory echExportFactory = defaultConfig.newFactoryImpl(EurostagEchExporterFactory.class, EurostagEchExporterFactoryImpl.class); EsgNetwork networkEch = echExportFactory.createEchExporter(network, exportConfig, parallelIndexes, dictionary, fakeNodes).createNetwork(parameters); new EurostagNetworkModifier().hvLoadModelling(networkEch); scenario.writePreFaultSeq(writer, PRE_FAULT_SAC_FILE_NAME); ContingenciesProvider contingenciesProvider = new FilterValidContingenciesProvider(defaultConfig.newFactoryImpl(ContingenciesProviderFactory.class).create());
this.priority = priority; ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load(); this.ddbClient = defaultConfig.newFactoryImpl(DynamicDatabaseClientFactory.class).create(config.isDdbCaching()); this.eurostagEchExporterFactory = defaultConfig.newFactoryImpl(EurostagEchExporterFactory.class, EurostagEchExporterFactoryImpl.class); this.config = config;