Skip to content
Merged
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
21 changes: 17 additions & 4 deletions backend/src/acidwatch_api/models/gibbs_minimization_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

from neqsim import jneqsim
from enum import StrEnum
from acidwatch_api.models.base import (
Expand All @@ -10,10 +12,10 @@
# Model constants
# Damping factor for composition convergence in Gibbs reactor
DAMPING_COMPOSITION = 0.05 # Used for reactor.setDampingComposition()
# Maximum number of iterations for Gibbs reactor convergence
MAX_ITERATIONS = 5000 # Used for reactor.setMaxIterations()
# Convergence tolerance for Gibbs reactor
CONVERGENCE_TOLERANCE = 1e-3 # Used for reactor.setConvergenceTolerance()
CONVERGENCE_TOLERANCE = 1e-2 # Used for reactor.setConvergenceTolerance()
# Timeout for the (blocking) reactor.run() call.
REACTOR_TIMEOUT_SECONDS = 60


NOT_INITIALIZED_BY_DEFAULT = [
Expand Down Expand Up @@ -192,7 +194,18 @@ async def run(self) -> RunResult:
reactor.setEnergyMode(
jneqsim.process.equipment.reactor.GibbsReactor.EnergyMode.ISOTHERMAL
)
reactor.run()

try:
await asyncio.wait_for(
asyncio.to_thread(reactor.run),
timeout=REACTOR_TIMEOUT_SECONDS,
)
except asyncio.TimeoutError:
raise RuntimeError(
f"Gibbs reactor did not converge within "
f"{REACTOR_TIMEOUT_SECONDS}s using the '{eos.value}' "
f"equation of state."
)

assert inlet_stream.getFluid().getNumberOfPhases() == 1, (
"Gibbs model cannot work with two phases as of now"
Expand Down
Loading