Skip to content

Commit

Permalink
update replacement to subassembly id to avoid killing every process o…
Browse files Browse the repository at this point in the history
…n a system
  • Loading branch information
RHammond2 committed Apr 1, 2024
1 parent dacff87 commit 04b0ec4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
8 changes: 4 additions & 4 deletions wombat/core/repair_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def invalidate_system(
)

def interrupt_system(
self, system: System | Cable, replacement: bool = False
self, system: System | Cable, replacement: str | None = None
) -> None:
"""Sets the turbine status to be in servicing, and interrupts all the processes
to turn off operations.
Expand All @@ -542,9 +542,9 @@ def interrupt_system(
----------
system_id : str
The system to disable repairs.
replacement: bool, optional
Indicates if the interruption is caused a result of a replacement event.
Defaults to False.
replacement: str | None, optional
If a subassebly `id` is provided, this indicates the interruption is caused
by its replacement event. Defaults to None.
"""
if system.servicing.triggered and system.id in self.invalid_systems:
system.servicing = self.env.event()
Expand Down
8 changes: 5 additions & 3 deletions wombat/core/service_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,9 +1471,10 @@ def in_situ_repair(
raise RuntimeError(f"{self.settings.name} is lost!")

if initial:
self.manager.interrupt_system(
system, replacement=request.details.replacement
replacement = (
request.subassembly_id if request.details.replacement else None
)
self.manager.interrupt_system(system, replacement=replacement)
yield self.env.process(
self.crew_transfer(system, subassembly, request, to_system=True)
)
Expand Down Expand Up @@ -1891,7 +1892,8 @@ def run_tow_to_port(self, request: RepairRequest) -> Generator[Process, None, No
)

# Turn off the turbine
self.manager.interrupt_system(system, replacement=request.details.replacement)
replacement = request.subassembly_id if request.details.replacement else None
self.manager.interrupt_system(system, replacement=replacement)

Check warning on line 1896 in wombat/core/service_equipment.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/service_equipment.py#L1895-L1896

Added lines #L1895 - L1896 were not covered by tests

# Unmoor the turbine and tow it back to port
yield self.env.process(self.mooring_connection(system, request, which="unmoor"))
Expand Down
19 changes: 12 additions & 7 deletions wombat/windfarm/system/cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def recreate_processes(self) -> None:
"""
self.processes = dict(self._create_processes())

def interrupt_processes(self, replacement: bool = False) -> None:
def interrupt_processes(self, replacement: str | None = None) -> None:
"""Interrupts all of the running processes within the subassembly except for the
process associated with failure that triggers the catastrophic failure.
Expand All @@ -178,25 +178,30 @@ def interrupt_processes(self, replacement: bool = False) -> None:
subassembly : Subassembly
The subassembly that should have all processes interrupted.
replacement: bool, optional
Indicates if the interruption is caused a result of a replacement event.
Defaults to False.
If a subassebly `id` is provided, this indicates the interruption is caused
by its replacement event. Defaults to None.
"""
cause = "replacement" if replacement else "failure"
cause = "failure"
if self.id == replacement:
cause = "replacement"

Check warning on line 186 in wombat/windfarm/system/cable.py

View check run for this annotation

Codecov / codecov/patch

wombat/windfarm/system/cable.py#L186

Added line #L186 was not covered by tests

for _, process in self.processes.items():
try:
process.interrupt(cause=cause)
except RuntimeError:
# This error occurs for the process halting all other processes.
pass

def interrupt_all_subassembly_processes(self, replacement: bool = False) -> None:
def interrupt_all_subassembly_processes(
self, replacement: str | None = None
) -> None:
"""Thin wrapper for ``interrupt_processes`` for consistent usage with system.
Parameters
----------
replacement: bool, optional
Indicates if the interruption is caused a result of a replacement event.
Defaults to False.
If a subassebly `id` is provided, this indicates the interruption is caused
by its replacement event. Defaults to None.
"""
self.interrupt_processes(replacement=replacement)

Expand Down
10 changes: 6 additions & 4 deletions wombat/windfarm/system/subassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def recreate_processes(self) -> None:
self.processes = dict(self._create_processes())

def interrupt_processes(
self, origin: Subassembly | None = None, replacement: bool = False
self, origin: Subassembly | None = None, replacement: str | None = None
) -> None:
"""Interrupts all of the running processes within the subassembly except for the
process associated with failure that triggers the catastrophic failure.
Expand All @@ -97,10 +97,12 @@ def interrupt_processes(
current subassembly, then a try/except flow is used to ensure the process
that initiated the shutdown is not interrupting itself.
replacement: bool, optional
Indicates if the interruption is caused a result of a replacement event.
Defaults to False.
If a subassebly `id` is provided, this indicates the interruption is caused
by its replacement event. Defaults to None.
"""
cause = "replacement" if replacement else "failure"
cause = "failure"
if self.id == replacement:
cause = "replacement"

Check warning on line 105 in wombat/windfarm/system/subassembly.py

View check run for this annotation

Codecov / codecov/patch

wombat/windfarm/system/subassembly.py#L105

Added line #L105 was not covered by tests
if origin is not None and id(origin) == id(self):
for _, process in self.processes.items():
try:
Expand Down
6 changes: 3 additions & 3 deletions wombat/windfarm/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _initialize_power_curve(self, power_curve_dict: dict | None) -> None:
)

def interrupt_all_subassembly_processes(
self, origin: Subassembly | None = None, replacement: bool = False
self, origin: Subassembly | None = None, replacement: str | None = None
) -> None:
"""Interrupts the running processes in all of the system's subassemblies.
Expand All @@ -172,8 +172,8 @@ def interrupt_all_subassembly_processes(
The subassembly that triggered the request, if the method call is coming
from a subassembly shutdown event.
replacement: bool, optional
Indicates if the interruption is caused a result of a replacement event.
Defaults to False.
If a subassebly `id` is provided, this indicates the interruption is caused
by its replacement event. Defaults to None.
"""
[
subassembly.interrupt_processes(origin=origin, replacement=replacement) # type: ignore
Expand Down

0 comments on commit 04b0ec4

Please sign in to comment.