Skip to content

Commit 824c7f6

Browse files
Add solubilityccs values to Phases
1 parent 616065e commit 824c7f6

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

backend/src/acidwatch_api/models/solubilityccs.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Parameter,
55
RunResult,
66
)
7-
from acidwatch_api.models.datamodel import TextResult
7+
from acidwatch_api.models.datamodel import TextResult, Phase
88

99
from solubilityccs import Fluid, ModelResults # type: ignore
1010
from solubilityccs.neqsim_functions import get_co2_parameters # type: ignore
@@ -68,4 +68,42 @@ async def run(self) -> RunResult:
6868
results_obj = ModelResults(fluid, co2_properties=co2_properties)
6969
table = results_obj.generate_table()
7070

71-
return [], TextResult(data=table, label="Solubility Output")
71+
phases = self._extract_phases(fluid)
72+
73+
return phases, TextResult(data=table, label="Solubility Output")
74+
75+
def _extract_phases(self, fluid: Fluid) -> list[Phase]:
76+
gas_phase = fluid.phases[0]
77+
gas_fraction = fluid.betta
78+
79+
co2_rich_concs: dict[str, float | int] = {}
80+
for component, fraction in zip(gas_phase.components, gas_phase.fractions):
81+
if component != "CO2":
82+
co2_rich_concs[component] = fraction * 1e6
83+
84+
phases = [
85+
Phase(
86+
kind="co2-rich",
87+
fraction=gas_fraction,
88+
concentrations=co2_rich_concs,
89+
)
90+
]
91+
92+
if gas_fraction < 1.0 and len(fluid.phases) > 1:
93+
liquid_phase = fluid.phases[1]
94+
aqueous_concs: dict[str, float | int] = {}
95+
for component, fraction in zip(
96+
liquid_phase.components, liquid_phase.fractions
97+
):
98+
if component != "CO2":
99+
aqueous_concs[component] = fraction * 1e6
100+
101+
phases.append(
102+
Phase(
103+
kind="aqueous",
104+
fraction=1.0 - gas_fraction,
105+
concentrations=aqueous_concs,
106+
)
107+
)
108+
109+
return phases

0 commit comments

Comments
 (0)