From d7036cead02bc67cc6a896ce04268793a4f315c5 Mon Sep 17 00:00:00 2001 From: Marvin Suen Date: Mon, 5 Aug 2024 17:22:12 +0100 Subject: [PATCH 1/5] Add units to support AGS toolkit Adding mmol/kg and mgCaCO3/L to support AGS toolkit --- Units_Engine/Convert/Density/Density.cs | 1 + .../Convert/Molality/MillimolePerKilogram.cs | 57 +++++++++++++++++++ Units_Engine/Convert/Molality/Molality.cs | 2 + Units_Engine/Units_Engine.csproj | 2 +- Units_oM/Enums/Molality.cs | 3 +- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Units_Engine/Convert/Molality/MillimolePerKilogram.cs diff --git a/Units_Engine/Convert/Density/Density.cs b/Units_Engine/Convert/Density/Density.cs index ca46b9a..f8cfcb2 100644 --- a/Units_Engine/Convert/Density/Density.cs +++ b/Units_Engine/Convert/Density/Density.cs @@ -159,6 +159,7 @@ public static double ToDensity(this double kilogramPerCubicMetres, object unit) return UNU.DensityUnit.MilligramPerCubicMeter; case DensityUnit.MilligramPerDeciliter: return UNU.DensityUnit.MilligramPerDeciliter; + case "mgCaCO3/L": case DensityUnit.MilligramPerLiter: return UNU.DensityUnit.MilligramPerLiter; case DensityUnit.MilligramPerMilliliter: diff --git a/Units_Engine/Convert/Molality/MillimolePerKilogram.cs b/Units_Engine/Convert/Molality/MillimolePerKilogram.cs new file mode 100644 index 0000000..9cb29f6 --- /dev/null +++ b/Units_Engine/Convert/Molality/MillimolePerKilogram.cs @@ -0,0 +1,57 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UN = UnitsNet; //This is to avoid clashes between UnitsNet quantity attributes and BHoM quantity attributes +using UnitsNet.Units; +using System.ComponentModel; +using BH.oM.Base.Attributes; +using BH.oM.Quantities.Attributes; + +namespace BH.Engine.Units +{ + public static partial class Convert + { + [Description("Convert SI units (molePerKilogram) into millimolePerKilogram.")] + [Input("molePerKilograms", "The number of molePerKilogram to convert.", typeof(Molality))] + [Output("millimolePerKilograms", "The number of millimolePerKilogram.")] + public static double ToMillimolePerKilogram(this double molePerKilograms) + { + UN.QuantityValue qv = molePerKilograms; + return UN.UnitConverter.Convert(qv, MolalityUnit.MolePerKilogram, MolalityUnit.MillimolePerKilogram); + } + + /***************************************************/ + + [Description("Convert millimolePerKilogram into SI units (molePerKilogram).")] + [Input("millimolePerKilograms", "The number of millimolePerKilograms to convert.")] + [Output("molePerKilograms", "The number of molePerKilograms.", typeof(Molality))] + public static double FromMillimolePerKiloram(this double millimolePerKilograms) + { + UN.QuantityValue qv = millimolePerKilograms; + return UN.UnitConverter.Convert(qv, MolalityUnit.MillimolePerKilogram, MolalityUnit.MolePerKilogram); + } + } +} diff --git a/Units_Engine/Convert/Molality/Molality.cs b/Units_Engine/Convert/Molality/Molality.cs index a0ccb2f..76aa0f0 100644 --- a/Units_Engine/Convert/Molality/Molality.cs +++ b/Units_Engine/Convert/Molality/Molality.cs @@ -110,6 +110,8 @@ public static double ToMolality(this double molePerKilograms, object unit) return UNU.MolalityUnit.MolePerGram; case MolalityUnit.MolePerKilogram: return UNU.MolalityUnit.MolePerKilogram; + case MolalityUnit.MillimolPerKilogram: + return UNU.MolalityUnit.MillimolePerKilogram; default: return null; } diff --git a/Units_Engine/Units_Engine.csproj b/Units_Engine/Units_Engine.csproj index 196bb8a..f44f978 100644 --- a/Units_Engine/Units_Engine.csproj +++ b/Units_Engine/Units_Engine.csproj @@ -21,7 +21,7 @@ - + diff --git a/Units_oM/Enums/Molality.cs b/Units_oM/Enums/Molality.cs index 091e7a9..244f4bf 100644 --- a/Units_oM/Enums/Molality.cs +++ b/Units_oM/Enums/Molality.cs @@ -32,7 +32,8 @@ public enum MolalityUnit { Undefined = 0, MolePerKilogram = 1, - MolePerGram = 2 + MolePerGram = 2, + MillimolPerKilogram = 3 } } From d15c080cf42b45c94c7a8b143ce782516e6bb661 Mon Sep 17 00:00:00 2001 From: Marvin Suen Date: Mon, 5 Aug 2024 17:44:19 +0100 Subject: [PATCH 2/5] Debug update: case only takes lowercase --- Units_Engine/Convert/Density/Density.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Units_Engine/Convert/Density/Density.cs b/Units_Engine/Convert/Density/Density.cs index f8cfcb2..0137ef5 100644 --- a/Units_Engine/Convert/Density/Density.cs +++ b/Units_Engine/Convert/Density/Density.cs @@ -159,7 +159,7 @@ public static double ToDensity(this double kilogramPerCubicMetres, object unit) return UNU.DensityUnit.MilligramPerCubicMeter; case DensityUnit.MilligramPerDeciliter: return UNU.DensityUnit.MilligramPerDeciliter; - case "mgCaCO3/L": + case "mgcaco3/l": case DensityUnit.MilligramPerLiter: return UNU.DensityUnit.MilligramPerLiter; case DensityUnit.MilligramPerMilliliter: From 79e8fcf432eccff27a9ae178fcd52298d5c5ea61 Mon Sep 17 00:00:00 2001 From: Marvin Suen Date: Mon, 5 Aug 2024 18:05:22 +0100 Subject: [PATCH 3/5] Update Units_Engine/Convert/Molality/MillimolePerKilogram.cs Co-authored-by: Peter Nugent --- Units_Engine/Convert/Molality/MillimolePerKilogram.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Units_Engine/Convert/Molality/MillimolePerKilogram.cs b/Units_Engine/Convert/Molality/MillimolePerKilogram.cs index 9cb29f6..c0a0b40 100644 --- a/Units_Engine/Convert/Molality/MillimolePerKilogram.cs +++ b/Units_Engine/Convert/Molality/MillimolePerKilogram.cs @@ -48,7 +48,7 @@ public static double ToMillimolePerKilogram(this double molePerKilograms) [Description("Convert millimolePerKilogram into SI units (molePerKilogram).")] [Input("millimolePerKilograms", "The number of millimolePerKilograms to convert.")] [Output("molePerKilograms", "The number of molePerKilograms.", typeof(Molality))] - public static double FromMillimolePerKiloram(this double millimolePerKilograms) + public static double FromMillimolePerKilogram(this double millimolePerKilograms) { UN.QuantityValue qv = millimolePerKilograms; return UN.UnitConverter.Convert(qv, MolalityUnit.MillimolePerKilogram, MolalityUnit.MolePerKilogram); From 5fceb9e96b33f96338a864afe5c1cad109460fe6 Mon Sep 17 00:00:00 2001 From: Marvin Suen Date: Mon, 5 Aug 2024 18:42:17 +0100 Subject: [PATCH 4/5] Update Units_oM/Enums/Molality.cs Co-authored-by: Peter Nugent --- Units_oM/Enums/Molality.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Units_oM/Enums/Molality.cs b/Units_oM/Enums/Molality.cs index 244f4bf..d0508c3 100644 --- a/Units_oM/Enums/Molality.cs +++ b/Units_oM/Enums/Molality.cs @@ -33,7 +33,7 @@ public enum MolalityUnit Undefined = 0, MolePerKilogram = 1, MolePerGram = 2, - MillimolPerKilogram = 3 + MillimolePerKilogram = 3 } } From 5cb6464482a53e60af70b4d881cfd532f1da97a7 Mon Sep 17 00:00:00 2001 From: Marvin Suen Date: Mon, 19 Aug 2024 16:55:01 +0100 Subject: [PATCH 5/5] Update Units_Engine/Convert/Molality/Molality.cs Co-authored-by: Peter Nugent --- Units_Engine/Convert/Molality/Molality.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Units_Engine/Convert/Molality/Molality.cs b/Units_Engine/Convert/Molality/Molality.cs index 76aa0f0..fd48ff9 100644 --- a/Units_Engine/Convert/Molality/Molality.cs +++ b/Units_Engine/Convert/Molality/Molality.cs @@ -110,7 +110,7 @@ public static double ToMolality(this double molePerKilograms, object unit) return UNU.MolalityUnit.MolePerGram; case MolalityUnit.MolePerKilogram: return UNU.MolalityUnit.MolePerKilogram; - case MolalityUnit.MillimolPerKilogram: + case MolalityUnit.MillimolePerKilogram: return UNU.MolalityUnit.MillimolePerKilogram; default: return null;