From 6cd78c023335b67584ac85f4deda50a835ec5d54 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Fri, 18 Jul 2014 14:35:15 +0000 Subject: [PATCH] [Matlab] Move @Solution/soundspeed.m and set.m to @ThermoPhase. Delete duplicated 1D/nComponents.m method --- interfaces/matlab/toolbox/1D/nComponents.m | 2 - interfaces/matlab/toolbox/@Solution/set.m | 177 ------------------ interfaces/matlab/toolbox/@ThermoPhase/set.m | 171 ++++++++++++++++- .../{@Solution => @ThermoPhase}/soundspeed.m | 0 4 files changed, 166 insertions(+), 184 deletions(-) delete mode 100644 interfaces/matlab/toolbox/1D/nComponents.m delete mode 100644 interfaces/matlab/toolbox/@Solution/set.m rename interfaces/matlab/toolbox/{@Solution => @ThermoPhase}/soundspeed.m (100%) diff --git a/interfaces/matlab/toolbox/1D/nComponents.m b/interfaces/matlab/toolbox/1D/nComponents.m deleted file mode 100644 index 0baa8aefb..000000000 --- a/interfaces/matlab/toolbox/1D/nComponents.m +++ /dev/null @@ -1,2 +0,0 @@ -function n = nComponents(d) -n = domain_methods(d.dom_id, 11); diff --git a/interfaces/matlab/toolbox/@Solution/set.m b/interfaces/matlab/toolbox/@Solution/set.m deleted file mode 100644 index 1bc324004..000000000 --- a/interfaces/matlab/toolbox/@Solution/set.m +++ /dev/null @@ -1,177 +0,0 @@ -function a = set(a,varargin) -% SET - Set properties. -% -% The properties that may be set are -% -% Temperature (T) -% Density (Rho) -% Volume (V) -% Pressure (P) -% Enthalpy (H) -% 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 -% must be given per unit mass. H, U, and S must be set in -% conjunction with pressure (for H,S) or volume (for U,S). Either -% (specific) volume or density may be specified. Mole and mass -% fractions must be input as vectors (either row or column) with -% length equal to the number of species. -% -% Examples: -% -% set(gas,'Temperature',600.0); -% set(gas,'T',600.0); -% set(gas,'T',600.0,'P',2*oneatm,'Y',massfracs); -% 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.) -% - -property_argin = varargin; -tval = -999; -pval = -999; -hval = -999; -uval = -999; -sval = -999; -vval = -999; -qval = -999; - -np = 0; -nt = 0; -nv = 0; -nx = 0; -ny = 0; -ns = 0; -nh = 0; -nu = 0; -nq = 0; - -while length(property_argin) >= 2, - prop = property_argin{1}; - val = property_argin{2}; - if issparse(val) - val = full(val); - end - property_argin = property_argin(3:end); - switch prop - case 'Temperature' - nt = nt + 1; - tval = val; - case 'T' - nt = nt + 1; - tval = val; - case 'Density' - nv = nv + 1; - vval = 1.0/val; - case 'Rho' - nv = nv + 1; - vval = 1.0/val; - case 'V' - nv = nv + 1; - vval = val; - case 'MoleFractions' - nx = nx + 1; - setMoleFractions(a,val); - case 'X' - nx = nx + 1; - setMoleFractions(a,val); - case 'MassFractions' - ny = ny + 1; - setMassFractions(a,val); - case 'Y' - ny = ny + 1; - setMassFractions(a,val); - case 'Pressure' - pval = val; - np = np + 1; - case 'P' - pval = val; - np = np + 1; - case 'Enthalpy' - hval = val; - nh = nh + 1; - case 'H' - hval = val; - nh = nh + 1; - case 'IntEnergy' - uval = val; - nu = nu + 1; - case 'U' - uval = val; - nu = nu + 1; - case 'Entropy' - sval = val; - ns = ns + 1; - case 'S' - sval = val; - ns = ns + 1; - 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 -end - -if nx + ny > 1 - error('composition specified multiple times'); -end - -ntot = nt + np + nv + ns + nh + nu + nq; - -if ntot == 1 - % - % set T, v, or P individually - % - if nt == 1 - setTemperature(a,tval); % density held fixed - elseif nv == 1 - setDensity(a,1.0/vval); % temperature held fixed - elseif np == 1 - setPressure(a, pval); % temperature held fixed - else - error('pressure, volume, or density must also be specified'); - end -elseif ntot == 2 - % - % set property pairs - % - if nt == 1 && nv == 1 - setTemperature(a,tval); - setDensity(a,1.0/vval); - elseif nt == 1 && np == 1 - setTemperature(a,tval); - 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 - error('unimplemented property pair'); - end -elseif ntot > 2 - error('too many properties specified'); -end diff --git a/interfaces/matlab/toolbox/@ThermoPhase/set.m b/interfaces/matlab/toolbox/@ThermoPhase/set.m index a007f4cc3..8692f851b 100644 --- a/interfaces/matlab/toolbox/@ThermoPhase/set.m +++ b/interfaces/matlab/toolbox/@ThermoPhase/set.m @@ -1,16 +1,177 @@ -function a = set(a, varargin) -% SET Set phase properties and return the updated object +function set(tp, varargin) +% SET - Set properties. +% +% The properties that may be set are +% +% Temperature (T) +% Density (Rho) +% Volume (V) +% Pressure (P) +% Enthalpy (H) +% 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 +% must be given per unit mass. H, U, and S must be set in +% conjunction with pressure (for H,S) or volume (for U,S). Either +% (specific) volume or density may be specified. Mole and mass +% fractions must be input as vectors (either row or column) with +% length equal to the number of species. +% +% Examples: +% +% set(gas,'Temperature',600.0); +% set(gas,'T',600.0); +% set(gas,'T',600.0,'P',2*oneatm,'Y',massfracs); +% 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.) +% + property_argin = varargin; +tval = -999; +pval = -999; +hval = -999; +uval = -999; +sval = -999; +vval = -999; +qval = -999; + +np = 0; +nt = 0; +nv = 0; +nx = 0; +ny = 0; +ns = 0; +nh = 0; +nu = 0; +nq = 0; + while length(property_argin) >= 2, prop = property_argin{1}; val = property_argin{2}; + if issparse(val) + val = full(val); + end property_argin = property_argin(3:end); switch prop case 'Temperature' - phase_set(a.tp_id, 1, val); + nt = nt + 1; + tval = val; + case 'T' + nt = nt + 1; + tval = val; case 'Density' - phase_set(a.tp_id, 2, val); + nv = nv + 1; + vval = 1.0/val; + case 'Rho' + nv = nv + 1; + vval = 1.0/val; + case 'V' + nv = nv + 1; + vval = val; + case 'MoleFractions' + nx = nx + 1; + setMoleFractions(tp, val); + case 'X' + nx = nx + 1; + setMoleFractions(tp, val); + case 'MassFractions' + ny = ny + 1; + setMassFractions(tp, val); + case 'Y' + ny = ny + 1; + setMassFractions(tp, val); + case 'Pressure' + pval = val; + np = np + 1; + case 'P' + pval = val; + np = np + 1; + case 'Enthalpy' + hval = val; + nh = nh + 1; + case 'H' + hval = val; + nh = nh + 1; + case 'IntEnergy' + uval = val; + nu = nu + 1; + case 'U' + uval = val; + nu = nu + 1; + case 'Entropy' + sval = val; + ns = ns + 1; + case 'S' + sval = val; + ns = ns + 1; + 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('Phase properties: Temperature, Density') + error(['Unknown property ' char(prop)]) end end + +if nx + ny > 1 + error('Composition specified multiple times.'); +end + +ntot = nt + np + nv + ns + nh + nu + nq; + +if ntot == 1 + % + % set T, v, or P individually + % + if nt == 1 + setTemperature(tp, tval); % density held fixed + elseif nv == 1 + setDensity(tp, 1.0/vval); % temperature held fixed + elseif np == 1 + setPressure(tp, pval); % temperature held fixed + else + error('Pressure, Volume, or Density must also be specified.'); + end +elseif ntot == 2 + % + % set property pairs + % + if nt == 1 && nv == 1 + setTemperature(tp, tval); + setDensity(tp, 1.0/vval); + elseif nt == 1 && np == 1 + setTemperature(tp, tval); + setPressure(tp, pval); + elseif nt == 1 && nq == 1 + setState_Tsat(tp, [tval,qval]); + elseif np == 1 && nq == 1 + setState_Psat(tp, [pval,qval]); + elseif np == 1 && nh == 1 + setState_HP(tp, [hval,pval]); + elseif nu == 1 && nv == 1 + setState_UV(tp, [uval,vval]); + elseif ns == 1 && np == 1 + setState_SP(tp, [sval,pval]); + elseif ns == 1 && nv == 1 + setState_SV(tp, [sval,vval]); + else + error('Unimplemented property pair.'); + end +elseif ntot > 2 + error('Too many properties specified.'); +end diff --git a/interfaces/matlab/toolbox/@Solution/soundspeed.m b/interfaces/matlab/toolbox/@ThermoPhase/soundspeed.m similarity index 100% rename from interfaces/matlab/toolbox/@Solution/soundspeed.m rename to interfaces/matlab/toolbox/@ThermoPhase/soundspeed.m