Skip to content

Commit

Permalink
Merge pull request #1000 from CombustionToolbox/oop
Browse files Browse the repository at this point in the history
Update: reduce repository size #988
Former-commit-id: a87a3f9
  • Loading branch information
AlbertoCuadra authored Nov 10, 2024
2 parents 2a80aec + a22d2e7 commit ce495aa
Show file tree
Hide file tree
Showing 165 changed files with 536 additions and 519,916 deletions.
4 changes: 2 additions & 2 deletions +combustiontoolbox/+common/@Constants/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
NA = 6.0221415e23 % Avogadro's number [molecule/mol]
KB = 1.38064852e-23 % Boltzmann constant [J/K]
HBAR = 6.626070041e-34 % Planck constant [J-s]
release = 'v1.1.2' % Release version
date = '04 Nov 2024' % Release date
release = 'v1.1.3' % Release version
date = '10 Nov 2024' % Release date
end

end
16 changes: 8 additions & 8 deletions +combustiontoolbox/+core/@ChemicalSystem/ChemicalSystem.m
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,9 @@
propertiesMatrix(index, obj.ind_ni) = moles; % [mol]

for i = length(moles):-1:1
propertiesMatrix(index(i), obj.ind_hi) = species_h0(species{i}, T, obj.species); % [J/mol]
propertiesMatrix(index(i), obj.ind_cpi) = species_cP(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = species_s0(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_hi) = getEnthalpy(obj.species.(species{i}), T); % [J/mol]
propertiesMatrix(index(i), obj.ind_cpi) = getHeatCapacityPressure(obj.species.(species{i}), T); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = getEntropy(obj.species.(species{i}), T); % [J/mol-K]
end

end
Expand Down Expand Up @@ -705,9 +705,9 @@
% end

for i = length(index):-1:1
propertiesMatrix(index(i), obj.ind_hi) = species_h0(species{i}, T, obj.species); % [J/mol]
propertiesMatrix(index(i), obj.ind_cpi) = species_cP(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = species_s0(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_hi) = getEnthalpy(obj.species.(species{i}), T); % [J/mol]
propertiesMatrix(index(i), obj.ind_cpi) = getHeatCapacityPressure(obj.species.(species{i}), T); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = getEntropy(obj.species.(species{i}), T); % [J/mol-K]
end

end
Expand All @@ -731,8 +731,8 @@
propertiesMatrix(index, obj.ind_hi) = h0(index); % [J/mol]

for i = length(index):-1:1
propertiesMatrix(index(i), obj.ind_cpi) = species_cP(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = species_s0(species{i}, T, obj.species); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_cpi) = getHeatCapacityPressure(obj.species.(species{i}), T); % [J/mol-K]
propertiesMatrix(index(i), obj.ind_si) = getEntropy(obj.species.(species{i}), T); % [J/mol-K]
end

end
Expand Down
10 changes: 10 additions & 0 deletions +combustiontoolbox/+core/@Species/Species.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

methods (Access = public)

cp = getHeatCapacityPressure(obj, T)
cv = getHeatCapacityVolume(obj, T)
e0 = getInternalEnergy(obj, T)
h0 = getEnthalpy(obj, T)
s0 = getEntropy(obj, T)
g0 = getGibbsEnergy(obj, T)
DeT = getThermalInternalEnergy(obj, T)
DhT = getThermalEnthalpy(obj, T)
gamma = getAdiabaticIndex(obj, T)

function elementMatrix = getElementMatrix(obj, elements)
% Compute element matrix of the given species formula
%
Expand Down
19 changes: 19 additions & 0 deletions +combustiontoolbox/+core/@Species/getAdiabaticIndex.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function gamma = getAdiabaticIndex(obj, T)
% Compute adiabatic index of the species [-] at the given temperature
% [K] using piecewise cubic Hermite interpolating polynomials and
% linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% gamma (float): Adiabatic index [-]
%
% Example:
% gamma = getAdiabaticIndex(obj, 300)

gamma = getHeatCapacityPressure(obj, T) ./ getHeatCapacityVolume(obj, T);

assert(any(~isnan(gamma)), 'Adibatic index equal NaN');
end
37 changes: 37 additions & 0 deletions +combustiontoolbox/+core/@Species/getEnthalpy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function h0 = getEnthalpy(obj, T)
% Compute enthalpy [J/mol] of the species at the given temperature [K]
% using piecewise cubic Hermite interpolating polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% h0 (float): Enthalpy in molar basis [J/mol]
%
% Example:
% h0 = getEnthalpy(obj, 300)

persistent cachedSpecies;
persistent cachedH0curves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedH0curves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
h0curve = obj.h0curve;
cachedSpecies{end+1} = obj.name;
cachedH0curves{end+1} = h0curve;
else
% Retrieve cached data
h0curve = cachedH0curves{index};
end

% Compute enthalpy [J/mol]
h0 = h0curve(T);
end
37 changes: 37 additions & 0 deletions +combustiontoolbox/+core/@Species/getEntropy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function s0 = getEntropy(obj, T)
% Compute entropy [J/(mol-K)] of the species at the given temperature [K]
% using piecewise cubic Hermite interpolating polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% s0 (float): Entropy in molar basis [J/(mol-K)]
%
% Example:
% s0 = getEntropy(obj, 300)

persistent cachedSpecies;
persistent cachedS0curves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedS0curves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
s0curve = obj.s0curve;
cachedSpecies{end+1} = obj.name;
cachedS0curves{end+1} = s0curve;
else
% Retrieve cached data
s0curve = cachedS0curves{index};
end

% Compute entropy [J/(mol-K)]
s0 = s0curve(T);
end
38 changes: 38 additions & 0 deletions +combustiontoolbox/+core/@Species/getGibbsEnergy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function g0 = getGibbsEnergy(obj, T)
% Compute Gibbs energy [J/mol] of the species at the given temperature [K]
% using piecewise cubic Hermite interpolating polynomials and linear extrapolation
%
% Args:
% species (char): Chemical species
% T (float): Temperature [K]
% DB (struct): Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits
%
% Returns:
% g0 (float): Gibbs energy in molar basis [J/mol]
%
% Example:
% g0 = getGibbsEnergy('H2O', 298.15, DB)

persistent cachedSpecies;
persistent cachedG0curves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedG0curves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
g0curve = obj.g0curve;
cachedSpecies{end+1} = obj.name;
cachedG0curves{end+1} = g0curve;
else
% Retrieve cached data
g0curve = cachedG0curves{index};
end

% Compute Gibbs energy [J/mol]
g0 = g0curve(T);
end
38 changes: 38 additions & 0 deletions +combustiontoolbox/+core/@Species/getHeatCapacityPressure.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function cp = getHeatCapacityPressure(obj, T)
% Compute specific heat at constant pressure [J/(mol-K)] of the species
% at the given temperature [K] using piecewise cubic Hermite
% interpolating polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% cp (float): Specific heat at constant pressure in molar basis [J/(mol-K)]
%
% Example:
% cp = getHeatCapacityPressure(obj, 300)

persistent cachedSpecies;
persistent cachedCPcurves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedCPcurves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
cpcurve = obj.cpcurve;
cachedSpecies{end+1} = obj.name;
cachedCPcurves{end+1} = cpcurve;
else
% Retrieve cached data
cpcurve = cachedCPcurves{index};
end

% Compute specific heat at constant pressure [J/(mol-K)]
cp = cpcurve(T);
end
21 changes: 21 additions & 0 deletions +combustiontoolbox/+core/@Species/getHeatCapacityVolume.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function cv = getHeatCapacityVolume(obj, T)
% Compute specific heat at constant volume [J/(mol-K)] of the species
% at the given temperature [K] using piecewise cubic Hermite
% interpolating polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% cv (float): Specific heat at constant volume in molar basis [J/(mol-K)]
%
% Example:
% cv = getHeatCapacityVolume(obj, 300)

% Universal gas constant [J/(mol-K)]
R0 = combustiontoolbox.common.Constants.R0;

% Compute specific heat at constant volume [J/(mol-K)]
cv = getHeatCapacityPressure(obj, T) - R0;
end
24 changes: 24 additions & 0 deletions +combustiontoolbox/+core/@Species/getInternalEnergy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function e0 = getInternalEnergy(obj, T)
% Compute internal energy [J/mol] of the species at the given
% temperature [K] using piecewise cubic Hermite interpolating
% polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% e0 (float): Internal energy in molar basis [J/mol]
%
% Example:
% e0 = getInternalEnergy(obj, 300)

% Universal gas constant [J/(K mol)]
R0 = combustiontoolbox.common.Constants.R0;

% Enthalpy [J/mol]
h0 = getEnthalpy(obj, T);

% Internal energy [J/mol]
e0 = h0 - R0 * T;
end
38 changes: 38 additions & 0 deletions +combustiontoolbox/+core/@Species/getThermalEnthalpy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function DhT = getThermalEnthalpy(obj, T)
% Compute thermal enthalpy [J/mol] of the species at the given
% temperature [K] using piecewise cubic Hermite interpolating
% polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% DhT (float): Thermal enthalpy in molar basis [J/mol]
%
% Example:
% DhT = getThermalEnthalpy(obj, 300)

persistent cachedSpecies;
persistent cachedDHTcurves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedDHTcurves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
DhTcurve = obj.DhTcurve;
cachedSpecies{end+1} = obj.name;
cachedDHTcurves{end+1} = DhTcurve;
else
% Retrieve cached data
DhTcurve = cachedDHTcurves{index};
end

% Compute thermal enthalpy [J/mol]
DhT = DhTcurve(T);
end
38 changes: 38 additions & 0 deletions +combustiontoolbox/+core/@Species/getThermalInternalEnergy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function DeT = getThermalInternalEnergy(obj, T)
% Compute thermal internal energy [J/mol] of the species at the given
% temperature [K] using piecewise cubic Hermite interpolating
% polynomials and linear extrapolation
%
% Args:
% obj (Species): Species object
% T (float): Temperature [K]
%
% Returns:
% DeT (float): Thermal internal energy in molar basis [J/mol]
%
% Example:
% DeT = getThermalInternalEnergy(obj, 300)

persistent cachedSpecies;
persistent cachedDETcurves;

if isempty(cachedSpecies)
cachedSpecies = {};
cachedDETcurves = {};
end

% Check if species data is already cached
index = find(strcmp(cachedSpecies, obj.name), 1);
if isempty(index)
% Load species data and cache it
DeTcurve = obj.DeTcurve;
cachedSpecies{end+1} = obj.name;
cachedDETcurves{end+1} = DeTcurve;
else
% Retrieve cached data
DeTcurve = cachedDETcurves{index};
end

% Compute thermal internal energy [J/mol]
DeT = DeTcurve(T);
end
Loading

0 comments on commit ce495aa

Please sign in to comment.