Packages for thermodynamic calculations using equations of state, using scipy and numpy
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Tools for thermodynamic calculations using equations of state, using scipy and numpy

Tested with Python 3.5, Numpy 1.11.2, Scipy 0.18.1

There are a myriad of different thermodynamic models that can be used to model the behaviour of fluids, each with its own idiosyncracies, strengths, and weaknesses. The aim here is to abstract away the flash calculations and data handling from the particulars of the model as much as possible, dropping the barrier to rolling out new models. Deploying a new model only requires determining the departure functions and fugacity coefficient for a given `Mixture` object.


`clausius` can be installed checking out the git repository and running the setup script. Installation requires `setuptools`

  git co
  python install

Once installed, try running the test scripts

  import clausius


### Mixtures
A `Mixture` is a convenience class for working with numpy structured arrays under the hood. The `Mixture` acts like a list and can be iterated and sliced like a list.


    from clausius import Mixture
    mix = Mixture([ { 'name': 'hexane',
                      'molarmass': None, # All keys must be present,
                                         # may be set to None or numpy.nan
                      # The Critical Point
                      'critical': { 'acentric': 0.305,
                                    'temperature': 507.4, # Kelvin
                                    'pressure': 3012000,  # Pascals
                                    'volume': 0.000369764,# m3/mol,
                                    'compressibility':  0.264},
                      'composition': { 'overall': 0.5,
                                       'vapor': 0.5,
                                       'liquid': 0.5 },
                    { 'name': 'heptane',
                      'molarmass': None,
                      'critical': { 'acentric': 0.349,
                                    'temperature': 540.3,
                                    'pressure': 2736000,
                                    'volume': 0.000431818,
                                    'compressibility':  0.263},
                      'composition': { 'overall': 0.5,
                                       'vapor': 0.5,
                                       'liquid': 0.5 }

     hexane = mix[0] # Returns the original dictionary
     hexane = mix['hexane'] # Does the same thing

     mix['hexane']['composition']['overall'] = 0.25 # changes mole fraction
     mix.composition['overall'][0] = 0.5 # Changes it back

`mix` is an equimolar mixture of n-hexane and n-heptane. At this point has no temperature, pressure, and all thermodynamic variables are numpy.nan.

### Models
Models are functions that accept `Mixture` objects and return the `Mixture` with the departure functions completed. They may require a mixing rule for set up, and models are designed to be relatively agnostic when it comes to mixing rules.

For example, I can calculate the departure functions for this mixture, using the Peng Robinson cubic equation of state and a van Der Waals mixing rule:

    from clausius.eos import PengRobinson
    from clausius.eos import vanDerWaalsMixing

    mixingrule = vanDerWaalsMixing(kij=0) # Using a van Der Waals mixing rule
                                          # binary interaction parameters = 0
    model = PengRobinson(mixingrule)

    mix.temperature = 298 # Kelvin
    mix.pressure = 101325 # Pascals
    mix = model(mix)

    mix.departure['gibbs'] # returns a structured array with (G*-G)/RT
                           # {'vapor': 0.07039007916301798,
                           #  'liquid': 2.20259298687189)

Departure functions are all in unitless form, e.g. Gibbs' departure is returned as (G* - G)/RT.
In addition to the basic departure functions, models must calculate the natural log of the fugacity coefficients for the mixture. This is required for flash calculations.

### Flash Calculations
The basic flash calculation algorithms take a model and mixture and attempt to find the stable mixture using K values from the fugacity coefficient. The function returns a `Mixture` at the relevant state (e.g. bubble point, dew point, etc). They are model agnostic and will work with any model that implements the `Model` interface.

To continue the example, the mixture can be set to the bubble point at 298K like so:

    from clausius.flash import bubblepoint

    mix = bubblepoint(model, mix, temperature=298)
    mix.pressure # 13.133 kPa

### Additional odds and ends

Some models require additional parameters, beyond the basic critical point data. These additional parameters must be provided in the `mix.modelparams` dictionary, see the model docstrings for more details.

Generally mixing rules accept parameters in unitless form, for example instead of the `b` parameter from the Soave Redlich Kwong equation of state one would pass B = (P/RT)*b.