Skip to content
Snippets Groups Projects
Commit 06a99aad authored by Ian Bell's avatar Ian Bell
Browse files

Some docs for estimation of parameters

parent 92f39f6c
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Multi-fluid EOS # Multi-fluid EOS
Peering into the innards of teqp Peering into the innards of teqp
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import timeit, json import timeit, json
import pandas import pandas
import numpy as np import numpy as np
import teqp import teqp
teqp.__version__ teqp.__version__
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Ancillary Equations ## Ancillary Equations
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Ancillary equations are provided along with multiparameter equations of state. The give a good *approximation* to the phase equilibrium densities. There are routines in teqp to use the ancillary equations provided with the EOS. First a class containing the ancillary equations is obtained, then methods on that class are called Ancillary equations are provided along with multiparameter equations of state. The give a good *approximation* to the phase equilibrium densities. There are routines in teqp to use the ancillary equations provided with the EOS. First a class containing the ancillary equations is obtained, then methods on that class are called
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
model = teqp.build_multifluid_model(["Methane"], teqp.get_datapath()) model = teqp.build_multifluid_model(["Methane"], teqp.get_datapath())
anc = model.build_ancillaries() anc = model.build_ancillaries()
T = 100.0 # [K] T = 100.0 # [K]
rhoL, rhoV = anc.rhoL(T), anc.rhoV(T) rhoL, rhoV = anc.rhoL(T), anc.rhoV(T)
print('Densities are:', rhoL, rhoV, 'mol/m^3') print('Densities are:', rhoL, rhoV, 'mol/m^3')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
But those densities do not correspond to the *true* phase equilibrium solution, so we need to polish the solution: But those densities do not correspond to the *true* phase equilibrium solution, so we need to polish the solution:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Niter = 10 Niter = 10
rhoLtrue, rhoVtrue = model.pure_VLE_T(T, rhoL, rhoV, Niter) rhoLtrue, rhoVtrue = model.pure_VLE_T(T, rhoL, rhoV, Niter)
print('VLE densities are:', rhoLtrue, rhoVtrue, 'mol/m^3') print('VLE densities are:', rhoLtrue, rhoVtrue, 'mol/m^3')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
And looking the densities, they are slightly different after the phase equilibrium calculation And looking the densities, they are slightly different after the phase equilibrium calculation
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Pure fluid loading ## Pure fluid loading
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# By default teqp looks for fluids relative to the set of fluids in ROOT/dev/fluids # By default teqp looks for fluids relative to the set of fluids in ROOT/dev/fluids
# The name (case-sensitive) should match the .json file, without the json extension. # The name (case-sensitive) should match the .json file, without the json extension.
%timeit model = teqp.build_multifluid_model(["Methane", "Ethane"], teqp.get_datapath()) %timeit model = teqp.build_multifluid_model(["Methane"], teqp.get_datapath())
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# And if you provide valid aliases, alias lookup will be used to resolve the name # And if you provide valid aliases, alias lookup will be used to resolve the name
# But beware, this is rather a lot slower than the above because all fluid files need to be read # But beware, this is rather a lot slower than the above because all fluid files need to be read
# in to build the alias map # in to build the alias map
%timeit model = teqp.build_multifluid_model(["n-C1H4", "n-C3H8"], teqp.get_datapath()) %timeit model = teqp.build_multifluid_model(["n-C1H4"], teqp.get_datapath())
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
So, how to make it faster? Only do it once and cache So, how to make it faster? Only do it once and cache
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Here is the set of possible aliases to absolute paths of files # Here is the set of possible aliases to absolute paths of files
# Building this map takes a little while (somewhat faster in C++) due to all the file reads # Building this map takes a little while (somewhat faster in C++) due to all the file reads
# If you know your files will not change, good idea to build this alias map yourself. # If you know your files will not change, good idea to build this alias map yourself.
%timeit aliasmap = teqp.build_alias_map(teqp.get_datapath()) %timeit aliasmap = teqp.build_alias_map(teqp.get_datapath())
aliasmap = teqp.build_alias_map(teqp.get_datapath()) aliasmap = teqp.build_alias_map(teqp.get_datapath())
aliasmap
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Then load the absolute paths from the alias map, # Then load the absolute paths from the alias map,
# which will guarantee that you hit exactly what you were looking for, # which will guarantee that you hit exactly what you were looking for,
# resolving aliases as needed # resolving aliases as needed
identifiers = [aliasmap[n] for n in ["Neon", "Hydrogen"]] identifiers = [aliasmap[n] for n in ["n-C1H4"]]
%timeit model = teqp.build_multifluid_model(identifiers, teqp.get_datapath()) %timeit model = teqp.build_multifluid_model(identifiers, teqp.get_datapath())
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
At some point soon teqp will support in-memory loading of JSON data for the pure components, without requiring reads from the operating system At some point soon teqp will support in-memory loading of JSON data for the pure components, without requiring reads from the operating system
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# And you can also load the JSON that teqp is loading for the pure fluids # And you can also load the JSON that teqp is loading for the pure fluids
pureJSON = teqp.collect_component_json(['Neon','Hydrogen'], teqp.get_datapath()) pureJSON = teqp.collect_component_json(['Neon','Hydrogen'], teqp.get_datapath())
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Mixture model loading ## Mixture model loading
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Load the default JSON for the binary interaction parameters # Load the default JSON for the binary interaction parameters
BIP = json.load(open(teqp.get_datapath()+'/dev/mixtures/mixture_binary_pairs.json')) BIP = json.load(open(teqp.get_datapath()+'/dev/mixtures/mixture_binary_pairs.json'))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# You can obtain interaction parameters either by pairs of names, where name is the name that teqp uses, the ["INFO"]["NAME"] field # You can obtain interaction parameters either by pairs of names, where name is the name that teqp uses, the ["INFO"]["NAME"] field
params, swap_needed = teqp.get_BIPdep(BIP, ['Methane','Ethane']) params, swap_needed = teqp.get_BIPdep(BIP, ['Methane','Ethane'])
params params
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Or also by CAS# # Or also by CAS#
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0']) params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'])
params params
``` ```
%% Cell type:code id: tags:raises-exception %% Cell type:code id: tags:raises-exception
``` python ``` python
# But mixing is not allowed # But mixing is not allowed
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane']) params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane'])
params params
``` ```
%% Cell type:markdown id: tags:
## Estimation of interaction parameters
Estimation of interaction parameters can be used when no mixture model is present. The ``flags`` keyword argument allows the user to control how estimation is applied. The ``flags`` keyword argument should be a dictionary, with keys of ``"estimate"`` to provide the desired estimation scheme as-needed. For now, the only allowed estimation scheme is ``Lorentz-Berthelot``.
If it is desired to force the estimation, the ``"force-estimate"`` to force the use of the provided esimation scheme for all binaries, even when one is available. The value associated with ``"force-estimate"`` is ignored.
%% Cell type:code id: tags:
``` python
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'], flags={'force-estimate':'yes', 'estimate': 'Lorentz-Berthelot'})
params
```
%% Cell type:code id: tags:
``` python
# And without the force, the forcing is ignored
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'], flags={'estimate': 'Lorentz-Berthelot'})
params
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment