All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.farao_community.farao.data.crac_impl.AbstractRemedialActionAdder Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
/*
 * Copyright (c) 2021, 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.farao_community.farao.data.crac_impl;

import com.farao_community.farao.commons.FaraoException;
import com.farao_community.farao.data.crac_api.Instant;
import com.farao_community.farao.data.crac_api.RemedialActionAdder;
import com.farao_community.farao.data.crac_api.cnec.Cnec;
import com.farao_community.farao.data.crac_api.usage_rule.*;

import java.util.*;

/**
 * @author Peter Mitri {@literal }
 * @author Baptiste Seguinot {@literal }
 */
public abstract class AbstractRemedialActionAdder> extends AbstractIdentifiableAdder implements RemedialActionAdder {

    protected String operator;
    protected Integer speed;
    protected List usageRules = new ArrayList<>();
    private final CracImpl crac;

    AbstractRemedialActionAdder(CracImpl crac) {
        Objects.requireNonNull(crac);
        this.crac = crac;
    }

    @Override
    public T withOperator(String operator) {
        this.operator = operator;
        return (T) this;
    }

    @Override
    public T withSpeed(Integer speed) {
        this.speed = speed;
        return (T) this;
    }

    @Override
    public OnInstantAdder newOnInstantUsageRule() {
        return new OnInstantAdderImpl(this);
    }

    @Override
    public OnContingencyStateAdder newOnContingencyStateUsageRule() {
        return new OnContingencyStateAdderImpl(this);
    }

    @Override
    public OnFlowConstraintAdder newOnFlowConstraintUsageRule() {
        return new OnFlowConstraintAdderImpl(this);
    }

    @Override
    public OnAngleConstraintAdder newOnAngleConstraintUsageRule() {
        return new OnAngleConstraintAdderImpl(this);
    }

    @Override
    public OnVoltageConstraintAdder newOnVoltageConstraintUsageRule() {
        return new OnVoltageConstraintAdderImpl(this);
    }

    @Override
    public OnFlowConstraintInCountryAdder newOnFlowConstraintInCountryUsageRule() {
        return new OnFlowConstraintInCountryAdderImpl(this);
    }

    void addUsageRule(UsageRule usageRule) {
        this.usageRules.add(usageRule);
    }

    CracImpl getCrac() {
        return this.crac;
    }

    static void checkOnConstraintUsageRules(Instant instant, Cnec cnec) {
        // Only allow PRAs with usage method OnFlowConstraint/OnAngleConstraint/OnVoltageConstraint, for CNECs of instants PREVENTIVE & OUTAGE & CURATIVE
        // Only allow ARAs with usage method OnFlowConstraint/OnAngleConstraint/OnVoltageConstraint, for CNECs of instant AUTO
        // Only allow CRAs with usage method OnFlowConstraint/OnAngleConstraint/OnVoltageConstraint, for CNECs of instant CURATIVE

        Map> allowedCnecInstantPerRaInstant = Map.of(
            Instant.PREVENTIVE, Set.of(Instant.PREVENTIVE, Instant.OUTAGE, Instant.CURATIVE),
            Instant.AUTO, Set.of(Instant.AUTO),
            Instant.CURATIVE, Set.of(Instant.CURATIVE)
        );

        if (!allowedCnecInstantPerRaInstant.get(instant).contains(cnec.getState().getInstant())) {
            throw new FaraoException(String.format("Remedial actions available at instant %s on a CNEC constraint at instant %s are not allowed.", instant, cnec.getState().getInstant()));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy