Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
new stuff (Pacal, Bar)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlinka committed Sep 5, 2023
1 parent e0a8e68 commit 7576806
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 18 deletions.
177 changes: 177 additions & 0 deletions NEOSPlus/Quantity/Bar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using QuantityX;

namespace NEOSPlus.Quantity
{
public readonly struct Bar : IQuantitySI<Bar>, IQuantitySI, IQuantity<Bar>, IQuantity, IComparable<Bar>, IEquatable<Bar>
{
public readonly double BaseValue;

// Define pressure units for Bar
public static readonly Unit<Bar> Bar = new UnitSI<Bar>(1, "bar", "bar");
public static readonly Unit<Bar> Millibar = new UnitSI<Bar>(0.001, "mbar", "millibar");
public static readonly Unit<Bar> Microbar = new UnitSI<Bar>(0.000001, "µbar", "microbar");
public static readonly Unit<Bar> Nanobar = new UnitSI<Bar>(0.000000001, "nbar", "nanobar");

double IQuantity.BaseValue => BaseValue;

public double SIPower => 1.0;

// Default unit for Bar
public Unit<Bar> DefaultUnit => Bar;

public Bar(double baseValue = 0.0)
{
this = default(Bar);
BaseValue = baseValue;
}

public bool Equals(Bar other)
{
return BaseValue == other.BaseValue;
}

public int CompareTo(Bar other)
{
return BaseValue.CompareTo(other.BaseValue);
}

public string[] GetShortBaseNames()
{
return new string[] { "bar", "mbar", "µbar", "nbar" };
}

public string[] GetLongBaseNames()
{
return new string[] { "bars", "millibars", "microbars", "nanobars" };
}

public IUnit[] GetCommonSIUnits()
{
return new IUnit[]
{
SI<Bar>.Bar,
SI<Bar>.Millibar,
SI<Bar>.Microbar,
SI<Bar>.Nanobar,
};
}

public IUnit[] GetExcludedSIUnits()
{
return new IUnit[]
{
SI<Data>.MillimetersOfMercury,
SI<Data>.Kilopascals,
SI<Data>.PoundsPerSquareInch,
SI<Data>.CentimetersOfWater
SI<Data>.Lumen
SI<Data>.Deca,
SI<Data>.Hecto,
SI<Data>.Milli,
SI<Data>.Centi,
SI<Data>.Deci,
SI<Data>.Yocto,
SI<Data>.Zepto,
SI<Data>.Atto,
SI<Data>.Femto,
SI<Data>.Pico,
SI<Data>.Nano,
SI<Data>.Micro,
SI<Data>.Yotta,
SI<Data>.Zetta,
SI<Data>.Exa,
SI<Data>.Peta,
SI<Data>.Tera,
SI<Data>.Giga,
SI<Data>.Mega,
SI<Data>.Kilo,
Byte,
};
}

public Bar New(double baseVal)
{
return new Bar(baseVal);
}

public Bar Add(Bar q)
{
return new Bar(BaseValue + q.BaseValue);
}

public Bar Subtract(Bar q)
{
return new Bar(BaseValue - q.BaseValue);
}

public Bar Multiply(double n)
{
return new Bar(BaseValue * n);
}

public Bar Multiply(Bar a, Ratio r)
{
return a * r.BaseValue;
}

public Bar Multiply(Ratio r, Bar a)
{
return a * r.BaseValue;
}

public Bar Divide(double n)
{
return new Bar(BaseValue / n);
}

public Ratio Divide(Bar q)
{
return new Ratio(BaseValue / q.BaseValue);
}

public static Bar Parse(string str, Unit<Bar> defaultUnit = null)
{
return Unit<Bar>.Parse(str, defaultUnit);
}

public static bool TryParse(string str, out Bar q, Unit<Bar> defaultUnit = null)
{
return Unit<Bar>.TryParse(str, out q, defaultUnit);
}

public static Bar operator +(Bar a, Bar b)
{
return a.Add(b);
}

public static Bar operator -(Bar a, Bar b)
{
return a.Subtract(b);
}

public static Bar operator *(Bar a, double n)
{
return a.Multiply(n);
}

public static Bar operator /(Bar a, double n)
{
return a.Divide(n);
}

public static Ratio operator /(Bar a, Bar b)
{
return a.Divide(b);
}

public static Bar operator -(Bar a)
{
return a.Multiply(-1.0);
}

public override string ToString()
{
return this.FormatAuto();
}
}
}
32 changes: 14 additions & 18 deletions NEOSPlus/Quantity/Pressure.cs → NEOSPlus/Quantity/Pascal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ namespace NEOSPlus.Quantity

// Define pressure units
public static readonly Unit<Data> Pascal = new UnitSI<Data>(1, "Pa", "pascal");
public static readonly Unit<Data> Atmosphere = new Unit<Data>(101325, "atm", "atmosphere");
public static readonly Unit<Data> Bar = new UnitSI<Data>(100000, "bar", "bar");
public static readonly Unit<Data> Millibar = new UnitSI<Data>(100, "mbar", "millibar");
public static readonly Unit<Data> Microbar = new UnitSI<Data>(0.1, "µbar", "microbar");
public static readonly Unit<Data> Nanobar = new UnitSI<Data>(0.0001, "nbar", "nanobar");
public static readonly Unit<Data> Hectopascal = new UnitSI<Data>(100, "hPa", "hectopascal");
public static readonly Unit<Data> Kilopascal = new UnitSI<Data>(1000, "kPa", "kilopascal");
public static readonly Unit<Data> Megapascal = new UnitSI<Data>(1000000, "MPa", "megapascal");
public static readonly Unit<Data> Gigapascal = new UnitSI<Data>(1000000000, "GPa", "gigapascal");

double IQuantity.BaseValue => BaseValue;

Expand All @@ -39,24 +38,23 @@ public int CompareTo(Data other)

public string[] GetShortBaseNames()
{
return new string[] { "Pa", "atm", "bar", "mbar", "µbar", "nbar" };
return new string[] { "Pa", "hPa", "kPa", "MPa", "GPa" };
}

public string[] GetLongBaseNames()
{
return new string[] { "pascals", "atmospheres", "bars", "millibars", "microbars", "nanobars" };
return new string[] { "pascals", "hectopascals", "kilopascals", "megapascals", "gigapascals" };
}

public IUnit[] GetCommonSIUnits()
{
return new IUnit[]
{
SI<Data>.Pascal,
SI<Data>.Atmosphere,
SI<Data>.Bar,
SI<Data>.Millibar,
SI<Data>.Microbar,
SI<Data>.Nanobar,
SI<Data>.Hectopascal,
SI<Data>.Kilopascal,
SI<Data>.Megapascal,
SI<Data>.Gigapascal,
};
}

Expand All @@ -65,10 +63,11 @@ public IUnit[] GetExcludedSIUnits()
return new IUnit[]
{
SI<Data>.Lumen,
SI<Bar>.Bar,
SI<Bar>.Millibar,
SI<Bar>.Microbar,
SI<Bar>.Nanobar,
SI<Data>.Deca,
SI<Data>.Hecto,
SI<Data>.Milli,
SI<Data>.Centi,
SI<Data>.Deci,
SI<Data>.Yocto,
SI<Data>.Zepto,
Expand All @@ -82,10 +81,7 @@ public IUnit[] GetExcludedSIUnits()
SI<Data>.Exa,
SI<Data>.Peta,
SI<Data>.Tera,
SI<Data>.Giga,
SI<Data>.Mega,
SI<Data>.Kilo,
Byte,
};
}

Expand Down

0 comments on commit 7576806

Please sign in to comment.