![JAR search and dependency download from the Maven repository](/logo.png)
com.powsybl.openrao.data.cracimpl.OnContingencyStateAdderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of open-rao-crac-impl Show documentation
Show all versions of open-rao-crac-impl Show documentation
Object model for CRAC implementation
/*
* 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.powsybl.openrao.data.cracimpl;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.contingency.Contingency;
import com.powsybl.openrao.data.cracapi.Instant;
import com.powsybl.openrao.data.cracapi.State;
import com.powsybl.openrao.data.cracapi.usagerule.*;
import static com.powsybl.openrao.data.cracimpl.AdderUtils.assertAttributeNotNull;
/**
* Adds an OnContingencyState usage rule to a RemedialActionAdder
* Needs the CRAC to look up the contingency and add the new state if needed
*
* @author Peter Mitri {@literal }
* @author Baptiste Seguinot {@literal }
*/
public class OnContingencyStateAdderImpl> implements OnContingencyStateAdder {
private T owner;
private String instantId;
private String contingencyId;
private UsageMethod usageMethod;
private static final String CLASS_NAME = "OnContingencyState";
OnContingencyStateAdderImpl(AbstractRemedialActionAdder owner) {
this.owner = (T) owner;
}
@Override
public OnContingencyStateAdder withContingency(String contingencyId) {
this.contingencyId = contingencyId;
return this;
}
@Override
public OnContingencyStateAdder withInstant(String instantId) {
this.instantId = instantId;
return this;
}
@Override
public OnContingencyStateAdder withUsageMethod(UsageMethod usageMethod) {
this.usageMethod = usageMethod;
return this;
}
@Override
public T add() {
assertAttributeNotNull(instantId, CLASS_NAME, "instant", "withInstant()");
assertAttributeNotNull(usageMethod, CLASS_NAME, "usage method", "withUsageMethod()");
State state;
Instant instant = owner.getCrac().getInstant(instantId);
if (instant.isPreventive()) {
if (usageMethod != UsageMethod.FORCED) {
throw new OpenRaoException("OnContingencyState usage rules are not allowed for PREVENTIVE instant, except when FORCED. Please use newOnInstantUsageRule() instead.");
}
state = owner.getCrac().addPreventiveState();
} else if (instant.isOutage()) {
throw new OpenRaoException("OnContingencyState usage rules are not allowed for OUTAGE instant.");
} else {
assertAttributeNotNull(contingencyId, CLASS_NAME, "contingency", "withContingency()");
Contingency contingency = owner.getCrac().getContingency(contingencyId);
if (contingency == null) {
throw new OpenRaoException(String.format("Contingency %s of OnContingencyState usage rule does not exist in the crac. Use crac.newContingency() first.", contingencyId));
}
state = owner.getCrac().addState(contingency, instant);
}
owner.addUsageRule(new OnContingencyStateImpl(usageMethod, state));
return owner;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy