Skip to content

Commit

Permalink
Merge pull request #962 from CombustionToolbox/oop
Browse files Browse the repository at this point in the history
Merge: replace procedural version (CT v1.0.5) with the OOP version (CT v1.1.0beta)
  • Loading branch information
AlbertoCuadra authored Aug 3, 2024
2 parents af8d4c4 + ea8ba62 commit 782acf2
Show file tree
Hide file tree
Showing 653 changed files with 188,479 additions and 143,017 deletions.
24 changes: 24 additions & 0 deletions +combustiontoolbox/+common/@Constants/Constants.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
classdef Constants < handle
% Class with constants data
%
% Attributes:
% R0 (float): Universal gas constant [J/(K mol)]
% G (float): Standard gravity [m/s2]
% NA (float): Avogadro's number [molecule/mol]
% release (char): Release of the Combustion Toolbox
% date (char): Date of the release
%
% Examples:
% * R0 = Constants.R0
% * g = Constants.G
% * release = Constants.release

properties (Constant)
R0 = 8.31446261815324 % Universal gas constant [J/(K mol)]
G = 9.80665 % Standard gravity [m/s2]
NA = 6.0221415e23 % Avogadro's number [molecule/mol]
release = 'v1.1.0beta' % Release version
date = '03 Aug 2024' % Release date
end

end
74 changes: 74 additions & 0 deletions +combustiontoolbox/+common/@Units/Units.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
classdef Units < handle
% Class with conversion factors between different units

properties (Constant)
% Pressure
atm2bar = 1.01325 % Conversion factor from atm to bar
bar2atm = 1.01325^-1 % Conversion factor from bar to atm
atm2Pa = 101325 % Conversion factor from atm to Pa
Pa2atm = 101325^-1 % Conversion factor from Pa to atm
bar2Pa = 1e5 % Conversion factor from bar to Pa
Pa2bar = 1e-5 % Conversion factor from Pa to bar
end

methods (Static)

function value_out = convert(value_in, unit_in, unit_out)
% Convert a value from one unit to another
%
% Args:
% value_in (double): Value to convert
% unit_in (char): Unit of the input value
% unit_out (char): Unit of the output value
%
% Returns:
% value_out: Value converted to the output unit
%
% Example:
% Units.convert(1, 'atm', 'bar')

% Import packages
import combustiontoolbox.common.Units

% Get the conversion factor property name
conversion_factor_name = [unit_in,'2',unit_out];

% Check conversion factor exist
assert(isprop(Units, conversion_factor_name), 'Conversion from %s to %s is not defined.', unit_in, unit_out);

% Get the conversion factor
conversion_factor = Units.(conversion_factor_name);

% Convert the value
value_out = value_in * conversion_factor;
end

function moles = convertWeightPercentage2moles(listSpecies, weightPercentage, database)
% Convert weight percentage (wt%) to moles
%
% Args:
% listSpecies (cell): List of species
% weightPercentage (float): Weight percentage of the species [%]
% database (Database): Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits
%
% Returns:
% moles (float): Number of moles [mol]
%
% Example:
% moles = Units.WeightPercentage2moles({'H2O', 'CO2'}, [50, 50], database)

% Check if value is a cell
if ~iscell(listSpecies)
listSpecies = {listSpecies};
end

% Get molecular weight [g] of the species
W = getProperty(database, listSpecies, 'W') * 1e3;

% Convert weight percentage (wt%) to moles
moles = weightPercentage ./ W;
end

end

end
Loading

0 comments on commit 782acf2

Please sign in to comment.