com.powsybl.glsk.cse.CseGlskPoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-glsk-document-cse Show documentation
Show all versions of powsybl-glsk-document-cse Show documentation
Model of GLSK according to CSE format with its importer.
The newest version!
/*
* Copyright (c) 2020, 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 com.powsybl.glsk.cse;
import com.powsybl.glsk.api.AbstractGlskPoint;
import com.powsybl.glsk.commons.GlskException;
import org.threeten.extra.Interval;
import xsd.etso_code_lists.BusinessTypeList;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
/**
* @author Sebastien Murgey {@literal }
* @author Vincent BOCHET {@literal }
*/
public class CseGlskPoint extends AbstractGlskPoint {
private static final List> STANDARD_BLOCK_CLASSES = List.of(ManualGSKBlockType.class, PropGSKBlockType.class, PropLSKBlockType.class, ReserveGSKBlockType.class);
public CseGlskPoint(TimeSeriesType timeSeries) {
Objects.requireNonNull(timeSeries);
this.position = 1;
this.pointInterval = Interval.parse(timeSeries.getTimeInterval().getV());
this.subjectDomainmRID = timeSeries.getArea().getV();
this.curveType = "A03";
this.glskShiftKeys = new ArrayList<>();
BusinessTypeList businessType = timeSeries.getBusinessType().getV();
try {
BigDecimal sumBlockFactors = getSumBlockFactors(timeSeries);
Stream.concat(Stream.ofNullable(timeSeries.getManualLSKBlockOrPropLSKBlock()),
Stream.ofNullable(timeSeries.getPropGSKBlockOrReserveGSKBlockOrMeritOrderGSKBlock()))
.flatMap(List::stream)
.filter(block -> STANDARD_BLOCK_CLASSES.stream().anyMatch(acceptedClass -> acceptedClass.isInstance(block)))
.map(BlockWrapper::new)
.forEach(block -> importStandardBlock(block, businessType, sumBlockFactors));
Stream.ofNullable(timeSeries.getPropGSKBlockOrReserveGSKBlockOrMeritOrderGSKBlock())
.flatMap(List::stream)
.filter(MeritOrderGSKBlockType.class::isInstance)
.map(BlockWrapper::new)
.forEach(block -> importMeritOrderBlock(block, businessType, sumBlockFactors));
} catch (GlskException e) {
throw new GlskException(String.format("Impossible to import GLSK on area %s", subjectDomainmRID), e);
}
}
private BigDecimal getSumBlockFactors(TimeSeriesType timeSeries) {
return Stream.concat(Stream.ofNullable(timeSeries.getManualLSKBlockOrPropLSKBlock()),
Stream.ofNullable(timeSeries.getPropGSKBlockOrReserveGSKBlockOrMeritOrderGSKBlock()))
.flatMap(List::stream)
.map(BlockWrapper::new)
.filter(blockWrapper -> blockWrapper.getFactor().isPresent())
.map(blockWrapper -> blockWrapper.getFactor().get())
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);
}
private void importMeritOrderBlock(BlockWrapper blockWrapper, BusinessTypeList businessType, BigDecimal sumBlockFactors) {
MeritOrderGSKBlockType block = (MeritOrderGSKBlockType) blockWrapper.getBlock();
List upNodes = block.getUp().getNode();
for (int j = 0; j < upNodes.size(); j++) {
// Up nodes have positive merit order position
// First is 1 last is N to be easily recognized in GLSK point conversion.
glskShiftKeys.add(new CseGlskShiftKey(blockWrapper, new NodeWrapper(upNodes.get(j)), businessType, pointInterval, subjectDomainmRID, j + 1, sumBlockFactors));
}
List downNodes = block.getDown().getNode();
for (int j = 0; j < downNodes.size(); j++) {
// Down nodes have negative merit order position
// First is -1 last is -N to be easily recognized in GLSK point conversion.
glskShiftKeys.add(new CseGlskShiftKey(blockWrapper, new NodeWrapper(downNodes.get(j)), businessType, pointInterval, subjectDomainmRID, -j - 1, sumBlockFactors));
}
}
private void importStandardBlock(BlockWrapper blockWrapper, BusinessTypeList businessType, BigDecimal sumBlockFactors) {
this.glskShiftKeys.add(new CseGlskShiftKey(blockWrapper, businessType, pointInterval, subjectDomainmRID, sumBlockFactors));
}
}