From 9f8ebe6a3747f839065488a8b04344ca68c7cb1e Mon Sep 17 00:00:00 2001 From: xLinka Date: Sat, 21 Oct 2023 10:49:51 +0100 Subject: [PATCH] Pressure Units Pressure Units: pascals bar atmospheres torrs --- .../Quantities/Basic/Pressure.cs | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Elements.Quantity/Quantities/Basic/Pressure.cs diff --git a/Elements.Quantity/Quantities/Basic/Pressure.cs b/Elements.Quantity/Quantities/Basic/Pressure.cs new file mode 100644 index 0000000..41d08f3 --- /dev/null +++ b/Elements.Quantity/Quantities/Basic/Pressure.cs @@ -0,0 +1,131 @@ +using System; + +namespace Elements.Quantity +{ + public readonly struct Pressure : IQuantitySI + { + #region ESSENTIALS + + public readonly double BaseValue; + + double IQuantity.BaseValue => BaseValue; + + public Pressure(double baseValue = 0) : this() { BaseValue = baseValue; } + + public bool Equals(Pressure other) { return BaseValue == other.BaseValue; } + public int CompareTo(Pressure other) { return BaseValue.CompareTo(other.BaseValue); } + + #endregion + + /* *********************************************** */ + + #region QUANTITY NAME DEFINITIONS + + public string[] GetShortBaseNames() { return new string[] { "Pa" }; } + public string[] GetLongBaseNames() + { return new string[] { "pascals", "pascal" }; } + + #endregion + + /* *********************************************** */ + + #region SI UNIT DEFINITIONS + + public double SIPower { get { return 1; } } + + public IUnit[] GetCommonSIUnits() + { + return new IUnit[] { + SI.Pico, + SI.Nano, + SI.Micro, + SI.Milli, + SI.Centi, + SI.Deci, + SI.Kilo, + SI.Mega, + SI.Giga, + SI.Tera, + SI.Peta, + SI.Exa, + SI.Zetta, + SI.Yotta + }; + } + + public IUnit[] GetExcludedSIUnits() + { + return new IUnit[] { + SI.Quecto, + SI.Ronto, + SI.Yocto, + SI.Zepto, + SI.Atto, + SI.Femto, + SI.Deca, + SI.Hecto, + SI.Ronna, + SI.Quetta + }; + } + + #endregion + + /* *********************************************** */ + + #region UNITS + + public Unit DefaultUnit { get { return Pascal; } } + + public static readonly Unit Pascal = new UnitSI(0, "Pa", "pascal"); + public static readonly Unit Bar = new Unit(1e5, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " bar" }, new string[] { " bars" }); + public static readonly Unit Atmosphere = new Unit(1.01325e5, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " atm" }, new string[] { " atmospheres" }); + public static readonly Unit Torr = new Unit(1.01325e5 / 760, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " Torr" }, new string[] { " torrs" }); + + #endregion + + /* *********************************************** */ + + #region OPERATORS + + public Pressure New(double baseVal) { return new Pressure(baseVal); } + + public Pressure Add(Pressure q) { return new Pressure(BaseValue + q.BaseValue); } + public Pressure Subtract(Pressure q) { return new Pressure(BaseValue - q.BaseValue); } + + public Pressure Multiply(double n) { return new Pressure(BaseValue * n); } + + public Pressure Divide(double n) { return new Pressure(BaseValue / n); } + public Ratio Divide(Pressure q) { return new Ratio(BaseValue / q.BaseValue); } + + public static Pressure Parse(string str, Unit defaultUnit = null) { return Unit.Parse(str, defaultUnit); } + public static bool TryParse(string str, out Pressure q, Unit defaultUnit = null) { return Unit.TryParse(str, out q, defaultUnit); } + + public static Pressure operator +(Pressure a, Pressure b) { return a.Add(b); } + public static Pressure operator -(Pressure a, Pressure b) { return a.Subtract(b); } + public static Pressure operator *(Pressure a, double n) { return a.Multiply(n); } + public static Pressure operator /(Pressure a, double n) { return a.Divide(n); } + public static Ratio operator /(Pressure a, Pressure b) { return a.Divide(b); } + public static Pressure operator -(Pressure a) { return a.Multiply(-1); } + + #endregion + + /* *********************************************** */ + + #region CONVERSIONS + + // ...any necessary conversions + + #endregion + + /* *********************************************** */ + + public override string ToString() => this.FormatAuto(); + } +}