Skip to content

Commit ea1da4f

Browse files
tmilnthorpangularsen
authored andcommitted
Add imperial units for thermal conductivity (#432)
1 parent 9d644a9 commit ea1da4f

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

UnitsNet.Tests/CustomCode/ThermalConductivityTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ namespace UnitsNet.Tests.CustomCode
4747
public class ThermalConductivityTests : ThermalConductivityTestsBase
4848
{
4949
protected override double WattsPerMeterKelvinInOneWattPerMeterKelvin => 1;
50+
protected override double BtusPerHourFootFahrenheitInOneWattPerMeterKelvin => 5.77789317e-1;
5051
}
5152
}

UnitsNet.Tests/GeneratedCode/ThermalConductivityTestsBase.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,42 @@ namespace UnitsNet.Tests
5252
// ReSharper disable once PartialTypeWithSinglePart
5353
public abstract partial class ThermalConductivityTestsBase
5454
{
55+
protected abstract double BtusPerHourFootFahrenheitInOneWattPerMeterKelvin { get; }
5556
protected abstract double WattsPerMeterKelvinInOneWattPerMeterKelvin { get; }
5657

5758
// ReSharper disable VirtualMemberNeverOverriden.Global
59+
protected virtual double BtusPerHourFootFahrenheitTolerance { get { return 1e-5; } }
5860
protected virtual double WattsPerMeterKelvinTolerance { get { return 1e-5; } }
5961
// ReSharper restore VirtualMemberNeverOverriden.Global
6062

6163
[Fact]
6264
public void WattPerMeterKelvinToThermalConductivityUnits()
6365
{
6466
ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1);
67+
AssertEx.EqualTolerance(BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, wattpermeterkelvin.BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance);
6568
AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, wattpermeterkelvin.WattsPerMeterKelvin, WattsPerMeterKelvinTolerance);
6669
}
6770

6871
[Fact]
6972
public void FromValueAndUnit()
7073
{
74+
AssertEx.EqualTolerance(1, ThermalConductivity.From(1, ThermalConductivityUnit.BtuPerHourFootFahrenheit).BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance);
7175
AssertEx.EqualTolerance(1, ThermalConductivity.From(1, ThermalConductivityUnit.WattPerMeterKelvin).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance);
7276
}
7377

7478
[Fact]
7579
public void As()
7680
{
7781
var wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1);
82+
AssertEx.EqualTolerance(BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, wattpermeterkelvin.As(ThermalConductivityUnit.BtuPerHourFootFahrenheit), BtusPerHourFootFahrenheitTolerance);
7883
AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, wattpermeterkelvin.As(ThermalConductivityUnit.WattPerMeterKelvin), WattsPerMeterKelvinTolerance);
7984
}
8085

8186
[Fact]
8287
public void ConversionRoundTrip()
8388
{
8489
ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1);
90+
AssertEx.EqualTolerance(1, ThermalConductivity.FromBtusPerHourFootFahrenheit(wattpermeterkelvin.BtusPerHourFootFahrenheit).WattsPerMeterKelvin, BtusPerHourFootFahrenheitTolerance);
8591
AssertEx.EqualTolerance(1, ThermalConductivity.FromWattsPerMeterKelvin(wattpermeterkelvin.WattsPerMeterKelvin).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance);
8692
}
8793

UnitsNet/GeneratedCode/Extensions/Number/NumberToThermalConductivityExtensions.g.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,40 @@ namespace UnitsNet.Extensions.NumberToThermalConductivity
4444
{
4545
public static class NumberToThermalConductivityExtensions
4646
{
47+
#region BtuPerHourFootFahrenheit
48+
49+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double)"/>
50+
public static ThermalConductivity BtusPerHourFootFahrenheit(this int value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
51+
52+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double?)"/>
53+
public static ThermalConductivity? BtusPerHourFootFahrenheit(this int? value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
54+
55+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double)"/>
56+
public static ThermalConductivity BtusPerHourFootFahrenheit(this long value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
57+
58+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double?)"/>
59+
public static ThermalConductivity? BtusPerHourFootFahrenheit(this long? value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
60+
61+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double)"/>
62+
public static ThermalConductivity BtusPerHourFootFahrenheit(this double value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
63+
64+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double?)"/>
65+
public static ThermalConductivity? BtusPerHourFootFahrenheit(this double? value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
66+
67+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double)"/>
68+
public static ThermalConductivity BtusPerHourFootFahrenheit(this float value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
69+
70+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double?)"/>
71+
public static ThermalConductivity? BtusPerHourFootFahrenheit(this float? value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value);
72+
73+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double)"/>
74+
public static ThermalConductivity BtusPerHourFootFahrenheit(this decimal value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(Convert.ToDouble(value));
75+
76+
/// <inheritdoc cref="ThermalConductivity.FromBtusPerHourFootFahrenheit(double?)"/>
77+
public static ThermalConductivity? BtusPerHourFootFahrenheit(this decimal? value) => ThermalConductivity.FromBtusPerHourFootFahrenheit(value == null ? (double?)null : Convert.ToDouble(value.Value));
78+
79+
#endregion
80+
4781
#region WattPerMeterKelvin
4882

4983
/// <inheritdoc cref="ThermalConductivity.FromWattsPerMeterKelvin(double)"/>

UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public ThermalConductivity(double wattspermeterkelvin)
163163
/// </summary>
164164
public static ThermalConductivityUnit[] Units { get; } = Enum.GetValues(typeof(ThermalConductivityUnit)).Cast<ThermalConductivityUnit>().ToArray();
165165
/// <summary>
166+
/// Get ThermalConductivity in BtusPerHourFootFahrenheit.
167+
/// </summary>
168+
public double BtusPerHourFootFahrenheit => As(ThermalConductivityUnit.BtuPerHourFootFahrenheit);
169+
/// <summary>
166170
/// Get ThermalConductivity in WattsPerMeterKelvin.
167171
/// </summary>
168172
public double WattsPerMeterKelvin => As(ThermalConductivityUnit.WattPerMeterKelvin);
@@ -173,6 +177,20 @@ public ThermalConductivity(double wattspermeterkelvin)
173177

174178
public static ThermalConductivity Zero => new ThermalConductivity(0, BaseUnit);
175179

180+
/// <summary>
181+
/// Get ThermalConductivity from BtusPerHourFootFahrenheit.
182+
/// </summary>
183+
#if WINDOWS_UWP
184+
[Windows.Foundation.Metadata.DefaultOverload]
185+
public static ThermalConductivity FromBtusPerHourFootFahrenheit(double btusperhourfootfahrenheit)
186+
#else
187+
public static ThermalConductivity FromBtusPerHourFootFahrenheit(QuantityValue btusperhourfootfahrenheit)
188+
#endif
189+
{
190+
double value = (double) btusperhourfootfahrenheit;
191+
return new ThermalConductivity(value, ThermalConductivityUnit.BtuPerHourFootFahrenheit);
192+
}
193+
176194
/// <summary>
177195
/// Get ThermalConductivity from WattsPerMeterKelvin.
178196
/// </summary>
@@ -189,6 +207,21 @@ public static ThermalConductivity FromWattsPerMeterKelvin(QuantityValue wattsper
189207

190208
// Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
191209
#if !WINDOWS_UWP
210+
/// <summary>
211+
/// Get nullable ThermalConductivity from nullable BtusPerHourFootFahrenheit.
212+
/// </summary>
213+
public static ThermalConductivity? FromBtusPerHourFootFahrenheit(QuantityValue? btusperhourfootfahrenheit)
214+
{
215+
if (btusperhourfootfahrenheit.HasValue)
216+
{
217+
return FromBtusPerHourFootFahrenheit(btusperhourfootfahrenheit.Value);
218+
}
219+
else
220+
{
221+
return null;
222+
}
223+
}
224+
192225
/// <summary>
193226
/// Get nullable ThermalConductivity from nullable WattsPerMeterKelvin.
194227
/// </summary>
@@ -431,6 +464,7 @@ public double As(ThermalConductivityUnit unit)
431464

432465
switch (unit)
433466
{
467+
case ThermalConductivityUnit.BtuPerHourFootFahrenheit: return baseUnitValue/1.73073467;
434468
case ThermalConductivityUnit.WattPerMeterKelvin: return baseUnitValue;
435469

436470
default:
@@ -795,6 +829,7 @@ private double AsBaseUnitWattsPerMeterKelvin()
795829

796830
switch (Unit)
797831
{
832+
case ThermalConductivityUnit.BtuPerHourFootFahrenheit: return _value*1.73073467;
798833
case ThermalConductivityUnit.WattPerMeterKelvin: return _value;
799834
default:
800835
throw new NotImplementedException("Unit not implemented: " + Unit);

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
39433943
new UnitLocalization(typeof (ThermalConductivityUnit),
39443944
new[]
39453945
{
3946+
new CulturesForEnumValue((int) ThermalConductivityUnit.BtuPerHourFootFahrenheit,
3947+
new[]
3948+
{
3949+
new AbbreviationsForCulture("en-US", "BTU/h·ft·°F"),
3950+
}),
39463951
new CulturesForEnumValue((int) ThermalConductivityUnit.WattPerMeterKelvin,
39473952
new[]
39483953
{

UnitsNet/GeneratedCode/Units/ThermalConductivityUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace UnitsNet.Units
4242
public enum ThermalConductivityUnit
4343
{
4444
Undefined = 0,
45+
BtuPerHourFootFahrenheit,
4546
WattPerMeterKelvin,
4647
}
4748
}

UnitsNet/UnitDefinitions/ThermalConductivity.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
"Abbreviations": [ "W/m·K" ]
1616
}
1717
]
18+
},
19+
{
20+
"SingularName": "BtuPerHourFootFahrenheit",
21+
"PluralName": "BtusPerHourFootFahrenheit",
22+
"FromUnitToBaseFunc": "x*1.73073467",
23+
"FromBaseToUnitFunc": "x/1.73073467",
24+
"Localization": [
25+
{
26+
"Culture": "en-US",
27+
"Abbreviations": [ "BTU/h·ft·°F" ]
28+
}
29+
]
1830
}
1931
]
2032
}

0 commit comments

Comments
 (0)