SolutionArray with three dimensions

58 views
Skip to first unread message

Silv Stei

unread,
Nov 23, 2021, 9:51:58 AM11/23/21
to Cantera Users' Group
Hi Everyone

I'm trying to compare different reaction mechanisms for the combustion of ammonia/hydrogen mixtures. This is done for a variety of equivalence ratios, pressures and hydrogen mole fractions in the fuel. There is only one temperature for all initial states. I wanted to set up a SolutionArray with all initial gas states, namely having three dimensions.

I set up the SolutionArray like this:
gasGRI = ct.Solution('gri30.yaml')
phi = np.linspace(0.5,2,20)
P_1 = np.array([101325,3039750,200000])
T_1 = 298
X_H2_fuel = np.array([0,0.3333333,1])
statesGRI = ct.SolutionArray(gasGRI, shape=(phi.size, P_1.size, X_H2_fuel.size))

The dimensions are: elements of phi, elements of P and elements of H2 mole fraction in the fuel, so all possibilites of gas states are defined.

Later on I'm defining the arrays for T, P and X according to this shape and fill them with my values by for loops:
TInit = np.zeros(shape=(phi.size, P_1.size, X_H2_fuel.size))
PInit = np.zeros(shape=(phi.size, P_1.size, X_H2_fuel.size))
XInitGRI = np.zeros(shape=(phi.size, P_1.size, X_H2_fuel.size, gasGRI.n_species))
statesGRI.TPX = TInit, PInit, XInitGRI

In the documentation I only saw an example of a SolutionArray with two dimensions: T and P, and the vectors for defining T and P have to be either column- or row vectors to match the SolutionArray dimensions.
But the results don't seem to be correct (I'm new to Cantera, so probably could be a fault on my side).

Now I'm confused: is it even possible to make SolutionArrays with more than two dimensions?

Thanks in Advance and have a nice day,
Silvan

P.S. Attached you can find my whole code if necessary.
MechComp_NH3_H2_oneStage.py

Ray Speth

unread,
Dec 10, 2021, 6:11:23 PM12/10/21
to Cantera Users' Group
Hi Silvan,

Can you explain better what makes you think something isn't working? I couldn't tell what problem you thought there was in the provided code.

In general, the SolutionArray class supports arrays with an arbitrary number of dimensions (or at least, as many as are supported by Numpy). You can either specify inputs with the same dimensions as the SolutionArray, or with one or more dimensions where the input length is only 1, in which case that value will be "broadcast" to all elements in that dimension. You could use this ability in your code, for instance, to eliminate the loop over setting the pressure.

Regards,
Ray

Silv Stei

unread,
Jan 4, 2022, 1:44:54 PM1/4/22
to Cantera Users' Group

Hi Rey,

Sorry for the late answer.

Thank you very much! You directly answered my question. I probably put in a bad code example to really describe my problem.
In other codes I was trying to define the SolutionArray inputs with two- or higher dimensional arrays. I thought that I have to generate the full start parameter arrays rather than the SolutionArray just doing it for me with broadcasting.

You're right, I'll use broadcasting for making my code simpler (and faster probably).

Thanks again and kind regards,
Silvan
Reply all
Reply to author
Forward
0 new messages