cantera/interfaces/matlab/toolbox/@ThermoPhase/setMoleFractions.m
Ray Speth 2528df0f75 Reorganized source tree structure
These changes make it unnecessary to copy header files around during
the build process, which tends to confuse IDEs and debuggers. The
headers which comprise Cantera's external C++ interface are now in
the 'include' directory.

All of the samples and demos are now in the 'samples' subdirectory.
2012-02-12 02:27:14 +00:00

47 lines
1.6 KiB
Matlab

function a = setMoleFractions(a,x,norm)
% SETMOLEFRACTIONS Set the species mole fractions.
%
% setMoleFractions(a,x)
%
% If x is a vector of doubles, this call sets the species mole
% fractions to the values in x and then scales them so that they
% sum to 1.0. The length of x must equal the number of species.
%
% If x is a string, then the mole fractions of the listed
% species are set to the specified values, and all others are
% set to zero. The syntax for the string is as shown in these
% examples:
% 'CH4:4, O2:2, AR:3'
% 'SIH2:0.9,H2:0.1'
%
% setMoleFractions(a, x, 'nonorm')
%
% As above, but the normalization step is skipped. This only
% works if x is an array, not a string. Since unnormalized mole
% fractions can lead to unphysical results, 'nonorm' should be
% used only in rare cases, such as computing partial
% derivatives with respect to a species mole fraction.
%
% Note that calling setMoleFractions leaves the temperature and
% density unchanged, and therefore the pressure changes if the new
% composition has a molar mass that is different than the old
% composition. If it is desired to change the composition and hold
% the pressure fixed, use method 'set' (defined in class Solution)
% instead, or call setPressure after calling setMoleFractions.
if isa(x,'double')
if nargin == 3
if strcmp(norm,'nonorm')
phase_set(a.tp_id,22,x);
else
phase_set(a.tp_id,20,x);
end
else
phase_set(a.tp_id,20,x);
end
%
% string input
%
elseif isa(x,'char')
phase_set(a.tp_id,30,x);
end