-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #962 from CombustionToolbox/oop
Merge: replace procedural version (CT v1.0.5) with the OOP version (CT v1.1.0beta)
- Loading branch information
Showing
653 changed files
with
188,479 additions
and
143,017 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.