Skip to content

Commit ceeb381

Browse files
Erik Ovegardangularsen
authored andcommitted
Added missing overloads for viscosity
1 parent da59246 commit ceeb381

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

UnitsNet.Tests/CustomCode/DensityTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,12 @@ public static void VolumeTimesDensityEqualsMass()
5858
Mass mass = Volume.FromCubicMeters(3)*Density.FromKilogramsPerCubicMeter(2);
5959
Assert.AreEqual(mass, Mass.FromKilograms(6));
6060
}
61+
62+
[Test]
63+
public static void DensityTimesKinematicViscosityEqualsDynamicViscosity()
64+
{
65+
DynamicViscosity dynamicViscosity = Density.FromKilogramsPerCubicMeter(2) * KinematicViscosity.FromSquareMetersPerSecond(10);
66+
Assert.AreEqual(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20));
67+
}
6168
}
6269
}

UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ public class DynamicViscosityTests : DynamicViscosityTestsBase
3333
protected override double PascalSecondsInOneNewtonSecondPerMeterSquared => 1;
3434
protected override double PoiseInOneNewtonSecondPerMeterSquared => 10;
3535

36+
[Test]
37+
public static void DynamicViscosityDividedByDensityEqualsKinematicViscosity()
38+
{
39+
KinematicViscosity kinematicViscosity = DynamicViscosity.FromNewtonSecondsPerMeterSquared(10) / Density.FromKilogramsPerCubicMeter(2);
40+
Assert.AreEqual(kinematicViscosity, KinematicViscosity.FromSquareMetersPerSecond(5));
41+
}
3642
}
3743
}

UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ public static void TimeSpanTimesKinematicViscosityEqualsArea()
7676
Area area = TimeSpan.FromSeconds(2)*KinematicViscosity.FromSquareMetersPerSecond(4);
7777
Assert.AreEqual(area, Area.FromSquareMeters(8));
7878
}
79+
80+
[Test]
81+
public static void KinematicViscosityTimesDensityEqualsDynamicViscosity()
82+
{
83+
DynamicViscosity dynamicViscosity = KinematicViscosity.FromSquareMetersPerSecond(10) * Density.FromKilogramsPerCubicMeter(2);
84+
Assert.AreEqual(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20));
85+
}
7986
}
8087
}

UnitsNet/CustomCode/UnitClasses/Density.extra.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public partial struct Density
3232
{
3333
return Mass.FromKilograms(density.KilogramsPerCubicMeter*volume.CubicMeters);
3434
}
35+
36+
public static DynamicViscosity operator *(Density density, KinematicViscosity kinematicViscosity)
37+
{
38+
return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter);
39+
}
3540
}
3641
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright(c) 2007 Andreas Gullberg Larsen
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
using System;
23+
24+
namespace UnitsNet
25+
{
26+
public partial struct DynamicViscosity
27+
{
28+
public static KinematicViscosity operator /(DynamicViscosity dynamicViscosity, Density density)
29+
{
30+
return KinematicViscosity.FromSquareMetersPerSecond(dynamicViscosity.NewtonSecondsPerMeterSquared / density.KilogramsPerCubicMeter);
31+
}
32+
}
33+
}

UnitsNet/CustomCode/UnitClasses/KinematicViscosity.extra.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@ public partial struct KinematicViscosity
4949
{
5050
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond*duration.Seconds);
5151
}
52+
53+
public static DynamicViscosity operator *(KinematicViscosity kinematicViscosity, Density density)
54+
{
55+
return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter);
56+
}
5257
}
5358
}

0 commit comments

Comments
 (0)