Skip to content

Commit

Permalink
Merge pull request #27 from thermotools/init_with_params
Browse files Browse the repository at this point in the history
Init with params
  • Loading branch information
vegardjervell authored Apr 18, 2024
2 parents 36d2a18 + f3f8865 commit 2aaecaf
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 82 deletions.
64 changes: 58 additions & 6 deletions docs/vCurrent/MieKinGas_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permalink: /vcurrent/MieKinGas_methods.html
---

<!---
Generated at: 2023-11-06T12:02:00.296867
Generated at: 2024-04-18T17:40:59.602391
This is an auto-generated file, generated using the script at KineticGas/pyUtils/markdown_from_docstrings.py
The file is created by parsing the docstrings of the methods in the
MieKinGas class. For instructions on how to use the parser routines, see the
Expand All @@ -17,18 +17,25 @@ RET-Mie Model. This class implements utility methods to access mixing parameters

## Table of contents
* [Constructor](#constructor)
* [\_\_init\_\_](#__init__self-comps-mole_weightsnone-sigmanone-eps_div_knone-lanone-lrnone-lij0-kij0-n4-is_idealgasfalse-use_eosnone-parameter_refdefault)
* [\_\_init\_\_](#__init__self-comps-mole_weightsnone-sigmanone-eps_div_knone-lanone-lrnone-lij0-kij0-n4-is_idealgasfalse-use_eosnone-parameter_refdefault-use_default_eos_paramfalse)
* [Utility methods](#utility-methods)
* [set_eps_div_k](#set_eps_div_kself-eps_div_k-update_eostrue)
* [set_la](#set_laself-la-update_eostrue)
* [set_lr](#set_lrself-lr-update_eostrue)
* [set_sigma](#set_sigmaself-sigma-update_eostrue)
* [Internal methods](#internal-methods)
* [\_\_update_cpp_kingas_param\_\_](#__update_cpp_kingas_param__self)

## Constructor

Methods to initialise RET-Mie model.

### Table of contents
* [Constructor](#constructor)
* [\_\_init\_\_](#__init__self-comps-mole_weightsnone-sigmanone-eps_div_knone-lanone-lrnone-lij0-kij0-n4-is_idealgasfalse-use_eosnone-parameter_refdefault)
* [\_\_init\_\_](#__init__self-comps-mole_weightsnone-sigmanone-eps_div_knone-lanone-lrnone-lij0-kij0-n4-is_idealgasfalse-use_eosnone-parameter_refdefault-use_default_eos_paramfalse)


### `__init__(self, comps, mole_weights=None, sigma=None, eps_div_k=None, la=None, lr=None, lij=0, kij=0, N=4, is_idealgas=False, use_eos=None, parameter_ref='default')`
### `__init__(self, comps, mole_weights=None, sigma=None, eps_div_k=None, la=None, lr=None, lij=0, kij=0, N=4, is_idealgas=False, use_eos=None, parameter_ref='default', use_default_eos_param=False)`
If parameters are explicitly supplied through optional arguments, these will be used instead of those in the database.
To supply specific parameters for only some components, give `None` for the components that should use the database
value
Expand Down Expand Up @@ -64,7 +71,52 @@ value

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Mixing parameter for epsilon (kij > 0 => favours mixing, kij < 0 => favours separation)

&nbsp;&nbsp;&nbsp;&nbsp; **use_eos :**
&nbsp;&nbsp;&nbsp;&nbsp; **use_eos (thermopack eos object, optional) :**

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; (thermopack eos object, optional) EoS to use (initialized), defaults to `saftvrmie`
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; EoS to use (initialized), defaults to `saftvrmie`

&nbsp;&nbsp;&nbsp;&nbsp; **use_default_eos_param (bool) :**

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; If `False` (default), ensure that the EoS and RET-model use the same parameters(if applicable). If `False`, do not forward specified parameters to the EoS.

## Utility methods

Set- and get methods for interaction parameters, mixing parameters ...

### Table of contents
* [Utility methods](#utility-methods)
* [set_eps_div_k](#set_eps_div_kself-eps_div_k-update_eostrue)
* [set_la](#set_laself-la-update_eostrue)
* [set_lr](#set_lrself-lr-update_eostrue)
* [set_sigma](#set_sigmaself-sigma-update_eostrue)


### `set_eps_div_k(self, eps_div_k, update_eos=True)`
See MieType


### `set_la(self, la, update_eos=True)`
See MieType


### `set_lr(self, lr, update_eos=True)`
See MieType


### `set_sigma(self, sigma, update_eos=True)`
See MieType


## Internal methods

Internal methods are not intended for use by end-users.

### Table of contents
* [Internal methods](#internal-methods)
* [\_\_update_cpp_kingas_param\_\_](#__update_cpp_kingas_param__self)


### `__update_cpp_kingas_param__(self)`
See MieType


74 changes: 65 additions & 9 deletions docs/vCurrent/MieType_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permalink: /vcurrent/MieType_methods.html
---

<!---
Generated at: 2023-11-06T12:02:00.296431
Generated at: 2024-04-18T17:31:55.382397
This is an auto-generated file, generated using the script at KineticGas/pyUtils/markdown_from_docstrings.py
The file is created by parsing the docstrings of the methods in the
MieType class. For instructions on how to use the parser routines, see the
Expand All @@ -22,8 +22,13 @@ Mie-Type Model. This class implements utility methods to access mixing parameter
* [get_epsilon_matrix](#get_epsilon_matrixself-eps_div_k-kij)
* [get_lambda_matrix](#get_lambda_matrixself-lambdas-lij)
* [get_sigma_matrix](#get_sigma_matrixself-sigma)
* [Deprecated methods](#deprecated-methods)
* [get_avg_R](#get_avg_rself-t-x)
* [set_eps_div_k](#set_eps_div_kself-eps_div_k-update_eostrue)
* [set_la](#set_laself-la-update_eostrue)
* [set_lr](#set_lrself-lr-update_eostrue)
* [set_sigma](#set_sigmaself-sigma-update_eostrue)
* [Internal methods](#internal-methods)
* [\_\_update_cpp_kingas_param\_\_](#__update_cpp_kingas_param__self)
* [\_\_update_eos_param\_\_](#__update_eos_param__self)

## Constructor

Expand Down Expand Up @@ -78,6 +83,10 @@ Set- and get methods for interaction parameters, mixing parameters ...
* [get_epsilon_matrix](#get_epsilon_matrixself-eps_div_k-kij)
* [get_lambda_matrix](#get_lambda_matrixself-lambdas-lij)
* [get_sigma_matrix](#get_sigma_matrixself-sigma)
* [set_eps_div_k](#set_eps_div_kself-eps_div_k-update_eostrue)
* [set_la](#set_laself-la-update_eostrue)
* [set_lr](#set_lrself-lr-update_eostrue)
* [set_sigma](#set_sigmaself-sigma-update_eostrue)


### `get_epsilon_matrix(self, eps_div_k, kij)`
Expand Down Expand Up @@ -122,7 +131,7 @@ Compute pair-interaction $\lambda_r$ parameters, apply mixing parameter.
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Repulsive exponent for each pair-interaction.

### `get_sigma_matrix(self, sigma)`
Compute interaction parameter $sigma$ for each particle pair, applying mixing parameters given by `self.lij`.
Compute interaction parameter $\sigma$ for each particle pair, applying mixing parameters given by `self.lij`.
Warning: Use of mixing parameters is not thouroughly tested.


Expand All @@ -144,15 +153,62 @@ Warning: Use of mixing parameters is not thouroughly tested.

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Use of mixing parameters is not thouroughly tested.

## Deprecated methods
### `set_eps_div_k(self, eps_div_k, update_eos=True)`
Set the well depth parameter. Note: Running with `update_eos=False` will result in a model using
different parameters for collision integrals and the RDF than for the equation of state.

Deprecated methods are not maintained, and may be removed in the future.
Args:
eps_div_k (list[float or None]) : Well depth parameter for each pure component. Use `None` for default values. Unit (K).
update_eos (bool) : If True (default) also update the eos.


### `set_la(self, la, update_eos=True)`
Set the attractive exponent. Note: Running with `update_eos=False` will result in a model using
different parameters for collision integrals and the RDF than for the equation of state.

Args:
la (list[float or None]) : Attractive exponent for each pure component. Use `None` for default values.
update_eos (bool) : If True (default) also update the eos.


### `set_lr(self, lr, update_eos=True)`
Set the repulsive exponent. Note: Running with `update_eos=False` will result in a model using
different parameters for collision integrals and the RDF than for the equation of state.

Args:
lr (list[float or None]) : Repulsive exponent for each pure component. Use `None` for default values.
update_eos (bool) : If True (default) also update the eos.


### `set_sigma(self, sigma, update_eos=True)`
Set the size parameter. Note: Running with `update_eos=False` will result in a model using
different parameters for collision integrals and the RDF than for the equation of state.

Args:
sigma (list[float or None]) : Size parameter for each pure component. Use `None` for default values. Unit (m).
update_eos (bool) : If True (default) also update the eos.


## Internal methods

Internal methods are not intended for use by end-users.

### Table of contents
* [Deprecated methods](#deprecated-methods)
* [get_avg_R](#get_avg_rself-t-x)
* [Internal methods](#internal-methods)
* [\_\_update_cpp_kingas_param\_\_](#__update_cpp_kingas_param__self)
* [\_\_update_eos_param\_\_](#__update_eos_param__self)


### `__update_cpp_kingas_param__(self)`
Re-Initialize the C++ module with the current parameters in this model. Inheriting classes are responsible
for initializing the correct model.


### `__update_eos_param__(self)`
Update the EoS model to use the same parameters as this model is currently set with.

### `get_avg_R(self, T, x)`
Raises:
AttributeError : If the EoS object does not support setting parameters
Warning : If the EoS object is using segment numbers different from 1.


23 changes: 19 additions & 4 deletions docs/vCurrent/py_KineticGas_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permalink: /vcurrent/py_KineticGas_methods.html
---

<!---
Generated at: 2024-04-16T15:54:30.853573
Generated at: 2024-04-18T17:57:40.002828
This is an auto-generated file, generated using the script at KineticGas/pyUtils/markdown_from_docstrings.py
The file is created by parsing the docstrings of the methods in the
py_KineticGas class. For instructions on how to use the parser routines, see the
Expand All @@ -31,7 +31,7 @@ The `py_KineticGas` class, found in `pykingas/py_KineticGas.py`, is the core of
* [viscosity](#viscosityself-t-vm-x-nnone)
* [Tp-property interfaces](#tp-property-interfaces)
* [interdiffusion_tp](#interdiffusion_tpself-t-p-x-nnone-use_independenttrue-dependent_idxnone-frame_of_referencecon-use_binarytrue-solvent_idxnone)
* [thermal_coductivity_tp](#thermal_coductivity_tpself-t-p-x-nnone)
* [thermal_conductivity_tp](#thermal_conductivity_tpself-t-p-x-nnone)
* [thermal_diffusion_coeff_tp](#thermal_diffusion_coeff_tpself-t-p-x-nnone-use_independentfalse-dependent_idxnone-frame_of_referencecon-solvent_idxnone)
* [thermal_diffusion_factor_tp](#thermal_diffusion_factor_tpself-t-p-x-nnone)
* [viscosity_tp](#viscosity_tpself-t-p-x-nnone)
Expand All @@ -58,6 +58,8 @@ The `py_KineticGas` class, found in `pykingas/py_KineticGas.py`, is the core of
* [get_Eij](#get_eijself-vm-t-x)
* [get_P_factors](#get_p_factorsself-vm-t-x)
* [reshape_diffusion_coeff_vector](#reshape_diffusion_coeff_vectorself-d)
* [Deprecated methods](#deprecated-methods)
* [thermal_coductivity_tp](#thermal_coductivity_tpself-t-p-x-nnone)

## The constructor

Expand Down Expand Up @@ -550,7 +552,7 @@ Computing properties as a function of temperature and pressure. Simply forwards
### Table of contents
* [Tp-property interfaces](#tp-property-interfaces)
* [interdiffusion_tp](#interdiffusion_tpself-t-p-x-nnone-use_independenttrue-dependent_idxnone-frame_of_referencecon-use_binarytrue-solvent_idxnone)
* [thermal_coductivity_tp](#thermal_coductivity_tpself-t-p-x-nnone)
* [thermal_conductivity_tp](#thermal_conductivity_tpself-t-p-x-nnone)
* [thermal_diffusion_coeff_tp](#thermal_diffusion_coeff_tpself-t-p-x-nnone-use_independentfalse-dependent_idxnone-frame_of_referencecon-solvent_idxnone)
* [thermal_diffusion_factor_tp](#thermal_diffusion_factor_tpself-t-p-x-nnone)
* [viscosity_tp](#viscosity_tpself-t-p-x-nnone)
Expand All @@ -561,7 +563,7 @@ Compute molar volume using the internal equation of state (`self.eos`), assuming
`self.interdiffusion`. See `self.interdiffusion` for documentation.


### `thermal_coductivity_tp(self, T, p, x, N=None)`
### `thermal_conductivity_tp(self, T, p, x, N=None)`
Compute molar volume using the internal equation of state (`self.eos`), assuming vapour, and pass the call to
`self.thermal_conductivity`. See `self.thermal_conductivity` for documentation.

Expand Down Expand Up @@ -1161,3 +1163,16 @@ as `d[i][q][j]` where i and j are component indices, and q refferes to the appro

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; The matrix of $d_{i, j}^{(q)}$ coefficients ordered as `d[i][q][j]`

## Deprecated methods

Deprecated methods are not maintained, and may be removed in the future.

### Table of contents
* [Deprecated methods](#deprecated-methods)
* [thermal_coductivity_tp](#thermal_coductivity_tpself-t-p-x-nnone)


### `thermal_coductivity_tp(self, T, p, x, N=None)`
Slightly embarrasing typo in method name... Keeping alive for a while because some code out there uses this one.


10 changes: 9 additions & 1 deletion pyUtils/markdown_from_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def split_methods_by_section(sections, methods):

if 'deprecated' not in [s.lower() for s in sections]:
sections.append('Deprecated')
sections.append('Internal')

method_dict = {}
for name, meth in methods:
Expand Down Expand Up @@ -224,6 +225,14 @@ def get_automatic_sections(sections, section_headers, section_intro, method_dict
if 'Deprecated' not in section_intro.keys():
section_intro['Deprecated'] = 'Deprecated methods are not maintained, and may be removed in the future.'

if 'Internal' in method_dict.keys():
if 'Internal' not in sections:
sections.append('Internal')
if 'Internal' not in section_headers.keys():
section_headers['Internal'] = 'Internal methods'
if 'Internal' not in section_intro.keys():
section_intro['Internal'] = 'Internal methods are not intended for use by end-users.'

return sections, section_headers, section_intro

def get_toc(sections, section_headers, method_dict, is_subsection=False):
Expand Down Expand Up @@ -387,7 +396,6 @@ def miekingas_to_markdown():
class_methods = inspect.getmembers(MieKinGas, predicate=inspect.isfunction)
parent_methods = inspect.getmembers(MieType, predicate=inspect.isfunction)
specific_methods = sorted(list(set(class_methods) - set(parent_methods)))

basic_class_to_markdown(classname, eosname, specific_methods, inherits='MieType')

def hardsphere_to_markdown():
Expand Down
49 changes: 46 additions & 3 deletions pykingas/MieKinGas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
'''
from pykingas import cpp_MieKinGas, MieType
from thermopack.saftvrmie import saftvrmie
from thermopack.saft import saft

class MieKinGas(MieType.MieType):

def __init__(self, comps,
mole_weights=None, sigma=None, eps_div_k=None,
la=None, lr=None, lij=0, kij=0,
N=4, is_idealgas=False, use_eos=None,
parameter_ref='default'):
parameter_ref='default', use_default_eos_param=False):
"""Constructor
If parameters are explicitly supplied through optional arguments, these will be used instead of those in the database.
To supply specific parameters for only some components, give `None` for the components that should use the database
Expand All @@ -25,15 +26,17 @@ def __init__(self, comps,
la, lr (1D array) : attractive and repulsive exponent of the pure components [-]
lij (float) : Mixing parameter for sigma (lij > 0 => smaller sigma_12, lij < 0 => larger sigma_12)
kij (float) : Mixing parameter for epsilon (kij > 0 => favours mixing, kij < 0 => favours separation)
use_eos : (thermopack eos object, optional) EoS to use (initialized), defaults to `saftvrmie`
use_eos (thermopack eos object, optional) : EoS to use (initialized), defaults to `saftvrmie`
use_default_eos_param (bool) : If `False` (default), ensure that the EoS and RET-model use the same parameters
(if applicable). If `False`, do not forward specified parameters to the EoS.
"""
super().__init__(comps, 'Mie',
mole_weights=mole_weights, sigma=sigma,
eps_div_k=eps_div_k, la=la, lr=lr, lij=lij, kij=kij,
N=N, is_idealgas=is_idealgas,
parameter_ref=parameter_ref)

self.cpp_kingas = cpp_MieKinGas(self.mole_weights, self.sigma_ij, self.epsilon_ij, self.la, self.lr, self.is_idealgas)
self.__update_cpp_kingas_param__()
if self.is_idealgas is False:
if use_eos is None:
self.eos = saftvrmie()
Expand All @@ -43,3 +46,43 @@ def __init__(self, comps,
self.eos.init(comps, parameter_reference=parameter_ref)
else:
self.eos = use_eos

if isinstance(self.eos, saft) and (use_default_eos_param is False):
self.__update_eos_param__()

def __update_cpp_kingas_param__(self):
"""Internal
See MieType
"""
self.cpp_kingas = cpp_MieKinGas(self.mole_weights, self.sigma_ij, self.epsilon_ij, self.la, self.lr,
self.is_idealgas)

def set_sigma(self, sigma, update_eos=True):
"""Utility
See MieType
"""
super().set_sigma(sigma, update_eos=update_eos)
self.__update_cpp_kingas_param__()

def set_eps_div_k(self, eps_div_k, update_eos=True):
"""Utility
See MieType
"""
super().set_eps_div_k(eps_div_k, update_eos=update_eos)
self.__update_cpp_kingas_param__()

def set_la(self, la, update_eos=True):
"""Utility
See MieType
"""
super().set_la(la, update_eos=update_eos)
self.__update_cpp_kingas_param__()

def set_lr(self, lr, update_eos=True):
"""Utility
See MieType
"""
super().set_lr(lr, update_eos=update_eos)
self.__update_cpp_kingas_param__()


Loading

0 comments on commit 2aaecaf

Please sign in to comment.