Skip to content

Commit

Permalink
Merge pull request #203 from newcleo-dev-team/188_contamination_tests…
Browse files Browse the repository at this point in the history
…_in_common

188 contamination tests in common
  • Loading branch information
lelaus authored Aug 30, 2024
2 parents a8323da + f09ae5c commit c942772
Show file tree
Hide file tree
Showing 15 changed files with 1,420 additions and 506 deletions.
13 changes: 12 additions & 1 deletion lbh15/_lbh15.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import List
from typing import Tuple
from typing import Union
import numpy as np
from scipy.constants import atm
from scipy.optimize import fsolve
from .properties.interface import PropertyInterface
Expand Down Expand Up @@ -232,6 +233,8 @@ def check_temperature(self, T: float) -> Tuple[bool, str]:
to the temperature check
"""
# Manage acceptable value
if np.isnan(T):
return True, ""
if self.T_m0 < T < self.T_b0:
return True, ""
# Manage value outside the acceptable range
Expand Down Expand Up @@ -423,6 +426,12 @@ def __compute_T(self, input_value: float, input_property: str) -> float:
f"{input_property}! The temperature "
"value can not be computed!")

# Check if the correlation is constant
if self.__properties[input_property].is_constant():
raise ValueError(f"The property {input_property} is "
"constant. The temperature value "
"can not be computed !")

def function_to_solve(T: float, target: float) -> float:
return function_of_T(T, self.__p) - target

Expand All @@ -442,7 +451,9 @@ def function_to_solve(T: float, target: float) -> float:
index = (self._roots_to_use[input_property]
if input_property in self._roots_to_use else 0)
res, _, ier, msg = fsolve(function_to_solve,
x0=[self._guess, 3*self._guess],
x0=[k*self._guess for k in
self.__properties[input_property]
.guess_helper(input_value)],
args=(input_value), xtol=1e-10,
full_output=True)
# Raise an exception in case the solver did not converge
Expand Down
3 changes: 2 additions & 1 deletion lbh15/lbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class LBE(LiquidMetalInterface):
'gamma_Po': 'ohno2006', 'P_PbI2': 'knacke1991',
'K_PbI2': 'knacke1991', 'gamma_Cs': 'lbh15'}
_correlations_to_use: Dict[str, str] = copy.deepcopy(_default_corr_to_use)
_roots_to_use: Dict[str, int] = {'cp': 0}
_roots_to_use: Dict[str, int] = {'cp': 0, 'P_PbI2': 0, 'K_PbI2': 0,
'K_Cs': 0}
_custom_properties_path: Dict[str, List[str]] = {}
_available_properties_dict: Dict[str, PropertyInterface] = {}
_available_correlations_dict: Dict[str, List[str]] = {}
Expand Down
3 changes: 2 additions & 1 deletion lbh15/lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class Lead(LiquidMetalInterface):
'lim_cr': "gosse2014", 'P_PbI2': 'knacke1991',
'K_PbI2': 'knacke1991'}
_correlations_to_use: Dict[str, str] = copy.deepcopy(_default_corr_to_use)
_roots_to_use: Dict[str, int] = {'cp': 0}
_roots_to_use: Dict[str, int] = {'cp': 0, 'P_PbI2': 0, 'K_PbI2': 0,
'K_PbCs': 1, 'P_PbCs': 1}
_custom_properties_path: Dict[str, List[str]] = {}
_available_properties_dict: Dict[str, PropertyInterface] = {}
_available_correlations_dict: Dict[str, List[str]] = {}
Expand Down
19 changes: 19 additions & 0 deletions lbh15/properties/bismuth_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ def correlation(self, T: float, p: float = atm,
"""
return 118.2 + 5.934e-3*T + 7.183e6/T/T

def guess_helper(self, property_value: float) -> List[float]:
"""
Returns the coefficient values applied to the temperature initial
guess if the correlation is non injective. The return type is `None`
if the correlation is injective.
Parameters
----------
property_value : float
value of the specific heat capacity in :math:`[J/(kg \\cdot K)]`
Returns
-------
List[float]:
Temperature initial guess' coefficients
"""
return [1, 3]

@property
def correlation_name(self) -> str:
"""
Expand Down Expand Up @@ -607,3 +625,4 @@ def description(self) -> str:
str : Thermal conductivity description
"""
return f"Liquid bismuth {self.long_name}"

Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def range(self) -> List[float]:
List[float] : Temperature validity range of the BiI3 Iodide
vapour pressure correlation function
"""
return [682.0, T_b0]
return [T_m0, T_b0]


class BismuthCaesiumActivityCoefficientGverdtsiteli1984(PropertyInterface):
Expand Down Expand Up @@ -234,6 +234,17 @@ def correlation(self, T: float, p: float = atm,
"""
return np.power(10, -2.5)

def is_constant(self) -> bool:
"""
Returns True if the correlation returns a constant value,
False otherwise.
Returns
-------
bool
"""
return True

@property
def name(self) -> str:
"""
Expand Down
29 changes: 29 additions & 0 deletions lbh15/properties/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ def initialization_helper(self,
"""
return None

def guess_helper(self,
property_value: float) -> Union[List[float], None]:
"""
Returns the coefficient values applied to the temperature initial
guess if the correlation is non injective. The return type is `None`
if the correlation is injective.
Parameters
----------
property_value : float
value of the property
Returns
-------
None
"""
return None

def is_constant(self) -> bool:
"""
Returns True if the correlation returns a constant value,
False otherwise.
Returns
-------
bool
"""
return False

def info(self, T: float, p: float = atm,
print_info: bool = True, n_tab: int = 0) -> Union[None, str]:
"""
Expand Down
18 changes: 18 additions & 0 deletions lbh15/properties/lbe_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,24 @@ def correlation(self, T: float, p: float = atm,
"""
return 164.8 - T * (3.94e-2 - 1.25e-5 * T) - 4.56e5 / T / T

def guess_helper(self, property_value: float) -> List[float]:
"""
Returns the coefficient values applied to the temperature initial
guess if the correlation is non injective. The return type is `None`
if the correlation is injective.
Parameters
----------
property_value : float
value of the specific heat capacity in :math:`[J/(kg \\cdot K)]`
Returns
-------
List[float]:
Temperature initial guess' coefficients
"""
return [1, 3]

@property
def correlation_name(self) -> str:
"""
Expand Down
Loading

0 comments on commit c942772

Please sign in to comment.