Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Goodwin committed Mar 13, 2004
1 parent 08e46a5 commit 27c66a8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 54 deletions.
52 changes: 27 additions & 25 deletions Cantera/matlab/cantera/@Solution/set.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
% Entropy (S)
% MoleFractions (X)
% MassFractions (Y)
% Vapor Fraction (Vapor)
% Liquid Fractio (Liquid)
%
% Either the full property name or the symbol may be
% specified. For the extensive properties (V,H,U,S), the values
Expand All @@ -28,6 +30,7 @@
% set(gas,'H',0.5*enthalpy_mass(gas),'P',pressure(gas));
% set(gas,'S',entropy_mass(gas),'P',0.5*pressure(gas));
% set(gas,'X',ones(nSpecies(gas),1));
% set(gas,'T',500.0,'Vapor',0.8)
%
% Alternatively, individual methods to set properties may be
% called (setTemperature, setMoleFractions, etc.)
Expand Down Expand Up @@ -111,6 +114,12 @@
case 'Sat'
qval = val;
nq = nq + 1;
case 'Vapor'
qval = val;
nq = nq + 1;
case 'Liquid'
qval = 1.0 - val;
nq = nq + 1;
otherwise
error(['unknown property ' char(prop)])
end
Expand Down Expand Up @@ -139,33 +148,26 @@
%
% set property pairs
%
if nt == 1
if nt == 1 & nv == 1
setTemperature(a,tval);
setDensity(a,1.0/vval);
elseif nt == 1 & np == 1
setTemperature(a,tval);
if nv == 1
setDensity(a,1.0/vval); % temperature held fixed
elseif np == 1
setPressure(a, pval); % temperature held fixed
elseif nq == 1
if qval == 'Liquid'
setState_satLiquid(a);
elseif qval == 'Vapor'
setState_satVapor(a);
end
else
error('unimplemented property pair');
end
setPressure(a, pval);
elseif nt == 1 & nq == 1
setState_Tsat(a, [tval,qval]);
elseif np == 1 & nq == 1
setState_Psat(a, [pval,qval]);
elseif np == 1 & nh == 1
setState_HP(a,[hval,pval]);
elseif nu == 1 & nv == 1
setState_UV(a,[uval,vval]);
elseif ns == 1 & np == 1
setState_SP(a,[sval,pval]);
elseif ns == 1 & nv == 1
setState_SV(a,[sval,vval]);
else
if np == 1 & nh == 1
setState_HP(a,[hval,pval]);
elseif nu == 1 & nv == 1
setState_UV(a,[uval,vval]);
elseif ns == 1 & np == 1
setState_SP(a,[sval,pval]);
elseif ns == 1 & nv == 1
setState_SV(a,[sval,vval]);
else
error('unimplemented property pair');
end
error('unimplemented property pair');
end
else
error('too many properties specified');
Expand Down
2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/Hydrogen.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
% For more details, see classes Cantera::PureFluid and tpx::hydrogen in the
% Cantera C++ source code documentation.
%
n = importPhase('purefluids.cti','hydrogen');
n = importPhase('liquidvapor.cti','hydrogen');

2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/Methane.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
% equation of state is taken from W. C. Reynolds, "Thermodynamic
% Properties in SI."
%
n = importPhase('purefluids.cti','methane');
n = importPhase('liquidvapor.cti','methane');

2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/Nitrogen.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
% equation of state is taken from W. C. Reynolds, "Thermodynamic
% Properties in SI."
%
n = importPhase('purefluids.cti','nitrogen');
n = importPhase('liquidvapor.cti','nitrogen');

2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/Oxygen.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
% equation of state is taken from W. C. Reynolds, "Thermodynamic
% Properties in SI."
%
n = importPhase('purefluids.cti','oxygen');
n = importPhase('liquidvapor.cti','oxygen');

2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/Water.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
% For more details, see classes Cantera::PureFluid and tpx::water in the
% Cantera C++ source code documentation.
%
w = importPhase('purefluids.cti','water');
w = importPhase('liquidvapor.cti','water');

60 changes: 40 additions & 20 deletions Cantera/matlab/cantera/examples/rankine.m
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% An ideal Rankine cycle.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [work, efficiency] = rankine(t1, p2, eta_pump, ...
eta_turbine)

% create an object representing water
w = Water;

% start with saturated liquid water at 300 K
set(w,'T',300.0,'Sat','Liquid');
% start with saturated liquid water at t1
set(w,'T',t1,'Liquid',1.0);
h1 = enthalpy_mass(w);
s1 = entropy_mass(w);
p1 = pressure(w);

% pump it isentropically to 10 MPa
set(w,'S',s1,'P',1.0e7);
% pump it to p2
pump_work = pump(w, p2, eta_pump);
h2 = enthalpy_mass(w);
p2 = pressure(w);

pump_work = h2 - h1;


% heat to 1500 K at constant pressure
set(w,'T',1500.0,'P',p2);
% heat to saturated vapor
set(w,'P',p2,'Vapor',1.0);
h3 = enthalpy_mass(w);
s3 = entropy_mass(w);

heat_added = h3 - h2;


% expand isentropically to the initial pressure
set(w,'S',s3,'P',p1);
work = expand(w, p1, eta_turbine);
h4 = enthalpy_mass(w);
x4 = vaporFraction(w);

work_output = h3 - h4;

% compute the efficiency
efficiency = (work_output - pump_work)/heat_added
efficiency = (work - pump_work)/heat_added;



function w = pump(fluid, pfinal, eta)
% Adiabatically pump a fluid to pressure pfinal, using
% a pump with isentropic efficiency eta."""
h0 = enthalpy_mass(fluid);
s0 = entropy_mass(fluid);
set(fluid, 'S', s0, 'P', pfinal);
h1s = enthalpy_mass(fluid);
isentropic_work = h1s - h0;
actual_work = isentropic_work / eta;
h1 = h0 + actual_work;
set(fluid, 'H',h1, 'P',pfinal);
w = actual_work;


function w = expand(fluid, pfinal, eta)
% Adiabatically expand a fluid to pressure pfinal, using
% a turbine with isentropic efficiency eta
h0 = enthalpy_mass(fluid);
s0 = entropy_mass(fluid);
set(fluid, 'S', s0, 'P', pfinal);
h1s = enthalpy_mass(fluid);
isentropic_work = h0 - h1s;
actual_work = isentropic_work * eta;
h1 = h0 - actual_work;
set(fluid, 'H',h1, 'P',pfinal);
w = actual_work;


8 changes: 4 additions & 4 deletions Cantera/matlab/cantera/private/thermomethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ static void thermoset( int nlhs, mxArray *plhs[],
ierr = delThermo(th); break;
case 1:
ierr = th_setPressure(th,*ptr); break;
case 2:
ierr = th_setState_Psat(th,ptr[0],ptr[1]); break;
case 3:
ierr = th_setState_Tsat(th,ptr[0],ptr[1]); break;
default:
mexErrMsgTxt("unknown attribute.");
}
Expand All @@ -49,6 +45,10 @@ static void thermoset( int nlhs, mxArray *plhs[],
ierr = th_set_SV(th,ptr); break;
case 23:
ierr = th_set_SP(th,ptr); break;
case 24:
ierr = th_setState_Psat(th,ptr[0],ptr[1]); break;
case 25:
ierr = th_setState_Tsat(th,ptr[0],ptr[1]); break;
default:
mexErrMsgTxt("unknown pair attribute.");
}
Expand Down

0 comments on commit 27c66a8

Please sign in to comment.