File tree Expand file tree Collapse file tree
backend/src/acidwatch_api/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import asyncio
2+
13from neqsim import jneqsim
24from enum import StrEnum
35from acidwatch_api .models .base import (
1012# Model constants
1113# Damping factor for composition convergence in Gibbs reactor
1214DAMPING_COMPOSITION = 0.05 # Used for reactor.setDampingComposition()
13- # Maximum number of iterations for Gibbs reactor convergence
1415MAX_ITERATIONS = 5000 # Used for reactor.setMaxIterations()
15- # Convergence tolerance for Gibbs reactor
16- CONVERGENCE_TOLERANCE = 1e-3 # Used for reactor.setConvergenceTolerance()
16+ CONVERGENCE_TOLERANCE = 1e-2 # Used for reactor.setConvergenceTolerance()
17+ # Timeout for the (blocking) reactor.run() call.
18+ REACTOR_TIMEOUT_SECONDS = 60
1719
1820
1921NOT_INITIALIZED_BY_DEFAULT = [
@@ -192,7 +194,18 @@ async def run(self) -> RunResult:
192194 reactor .setEnergyMode (
193195 jneqsim .process .equipment .reactor .GibbsReactor .EnergyMode .ISOTHERMAL
194196 )
195- reactor .run ()
197+
198+ try :
199+ await asyncio .wait_for (
200+ asyncio .to_thread (reactor .run ),
201+ timeout = REACTOR_TIMEOUT_SECONDS ,
202+ )
203+ except asyncio .TimeoutError :
204+ raise RuntimeError (
205+ f"Gibbs reactor did not converge within "
206+ f"{ REACTOR_TIMEOUT_SECONDS } s using the '{ eos .value } ' "
207+ f"equation of state."
208+ )
196209
197210 assert inlet_stream .getFluid ().getNumberOfPhases () == 1 , (
198211 "Gibbs model cannot work with two phases as of now"
You can’t perform that action at this time.
0 commit comments