Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

Set mixture fraction for SolutionArray #147

Closed wigging closed 2 years ago

wigging commented 2 years ago

Abstract

Set the mixture fraction for a SolutionArray. This can be accomplished with the equivalence ratio so a similar approach could be used for the mixture fraction.

Motivation

The equivalence ratio can be set for a SolutionArray using something like the following:

import cantera as ct

yfuel = {'C': 43.41, 'H': 5.82, 'O': 44.32, 'N': 0.25}
yair = {'O2': 23, 'N2': 76, 'Ar': 1}
phi = np.linspace(0.1, 0.9, 20)

gas = ct.Solution('gri30.yaml')
states = ct.SolutionArray(gas, shape=len(phi))
states.TP = 900, ct.one_atm
states.set_equivalence_ratio(phi, yfuel, yair, basis='mass')
states.equilibrate('TP')

However, the above example cannot be done with the mixture fraction.

Possible Solutions

A possible implementation for the mixture fraction could be:

import cantera as ct

yfuel = {'C': 43.41, 'H': 5.82, 'O': 44.32, 'N': 0.25}
yair = {'O2': 23, 'N2': 76, 'Ar': 1}
mixfrac = np.linspace(0.1, 0.9, 20)

gas = ct.Solution('gri30.yaml')
states = ct.SolutionArray(gas, shape=len(mixfrac))
states.TP = 900, ct.one_atm
states.set_mixture_fraction(mixfrac, yfuel, yair, basis='mass')
states.equilibrate('TP')
decaluwe commented 2 years ago

Two bits of follow up:

  1. The mwe above does require a numpy import: import numpy as np in order to work.
  2. The error message is as follows:

    Traceback (most recent call last): File "", line 1, in File "/Users/decaluwe/opt/anaconda3/envs/cantera/lib/python3.6/site-packages/cantera/composite.py", line 598, in getattr self.class.name, name)) AttributeError: 'SolutionArray' object has no attribute 'set_mixture_fraction'

decaluwe commented 2 years ago

Thanks, @wigging -- this seems like it should be pretty straightforward. Working on an implementation, atm.

decaluwe commented 2 years ago

Okay, @wigging this is now incorporated, via https://github.com/Cantera/cantera/pull/1242