Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions rao/crac/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ def crac(self):
def crac_pprint(self):
return print(json.dumps(self.crac, indent=2))

def perform_cnec_consistency_check(self):

# Find the flowCnec thresholds
flow_cnecs = list(getattr(self._crac, "flowCnecs", []))
kept = []

for cnec in flow_cnecs:
cnec_name = getattr(cnec, "name", None)

thresholds = getattr(cnec, "thresholds", []) or []
if not isinstance(thresholds, list):
thresholds = [thresholds]

# Flag FlowCNEC as removed if limits min=0, max=0
removed = any((getattr(th, "min", None) == 0) and (getattr(th, "max", None) == 0) for th in thresholds)

if removed:
logger.warning(f"CNEC {cnec_name} removed from the CRAC file due to missing limits")
else:
kept.append(cnec)

# Keep only consistent flowCnecs
setattr(self._crac, "flowCnecs", kept)

def get_limits(self):

if self.network is None:
Expand Down Expand Up @@ -385,6 +409,7 @@ def build_crac(self, contingency_ids: list | None = None):
self.process_cnecs()
self.process_remedial_actions()
self.update_limits_from_network()
self.perform_cnec_consistency_check()

return self.crac

Expand Down