Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
NeqModPlus
de.hft-stuttgart.cityunits
Commits
527b8c29
Commit
527b8c29
authored
3 years ago
by
Kai-Holger Brassel
Browse files
Options
Download
Email Patches
Plain Diff
Dimension for VolumetricFlowRate added plus some tests
parent
2d962f5e
Pipeline
#4361
failed with stage
in 3 minutes and 11 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+5
-5
README.md
de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
+3
-1
...de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
+20
-6
...sts/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
with
28 additions
and
12 deletions
+28
-12
README.md
+
5
-
5
View file @
527b8c29
...
...
@@ -66,11 +66,11 @@ Some derived units of special interest for urban simulation like kW·h (encodes
| W·h | [L]²·[M]/[T]²
| kW·h | [L]²·[M]/[T]²
| MW·h | [L]²·[M]/[T]²
| m³/min | [L]³/[T]
| m³/h | [L]³/[T]
| m³/s | [L]³/[T]
| m³/d | [L]³/[T]
| l/min | [L]³/[T]
| m³/min | [L]³/[T]
VolumetricFlowRate
| m³/h | [L]³/[T]
VolumetricFlowRate
| m³/s | [L]³/[T]
VolumetricFlowRate
| m³/d | [L]³/[T]
VolumetricFlowRate
| l/min | [L]³/[T]
VolumetricFlowRate
Some units of special interest for urban simulation introduced with this plug-in:
...
...
This diff is collapsed.
Click to expand it.
de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
+
3
-
1
View file @
527b8c29
...
...
@@ -16,6 +16,7 @@ import tech.units.indriya.function.LogConverter;
import
tech.units.indriya.function.MultiplyConverter
;
import
tech.units.indriya.unit.AlternateUnit
;
import
tech.units.indriya.unit.BaseUnit
;
import
tech.units.indriya.unit.ProductUnit
;
import
tech.units.indriya.unit.TransformedUnit
;
import
tech.units.indriya.unit.UnitDimension
;
import
tech.units.indriya.unit.Units
;
...
...
@@ -37,13 +38,14 @@ public class UrbanSimulationUnits extends AbstractSystemOfUnits {
AlternateUnit
.
of
(
Units
.
KILOGRAM
,
"kgCO₂eq"
).
asType
(
CarbonEmission
.
class
));
public
static
final
Unit
<
CarbonEmission
>
GRAM_CO2_EQUIVALENT
=
addUnit
(
KILOGRAM_CO2_EQUIVALENT
.
divide
(
1000
));
public
static
final
Unit
<
CarbonEmission
>
TON_CO2_EQUIVALENT
=
addUnit
(
KILOGRAM_CO2_EQUIVALENT
.
multiply
(
1000
));
public
static
final
Unit
<
Dimensionless
>
PARTS_PER_MILLION
=
addUnit
(
new
TransformedUnit
<>(
AbstractUnit
.
ONE
,
MultiplyConverter
.
ofRational
(
BigInteger
.
ONE
,
BigInteger
.
valueOf
(
1000000
))));
public
static
final
Unit
<
Dimensionless
>
DECIBEL
=
addUnit
(
AbstractUnit
.
ONE
.
transform
(
new
LogConverter
(
10
).
inverse
().
concatenate
(
MultiplyConverter
.
ofRational
(
BigInteger
.
ONE
,
BigInteger
.
TEN
))));
public
static
final
Unit
<
Intensity
>
IRRADIANCE
=
addUnit
(
new
AlternateUnit
<
Intensity
>(
Units
.
WATT
.
divide
(
Units
.
SQUARE_METRE
),
"W/m²"
));
public
static
final
Unit
<
VolumetricFlowRate
>
VOLUMETRIC_FLOW
=
addUnit
(
new
ProductUnit
<
VolumetricFlowRate
>(
Units
.
CUBIC_METRE
.
divide
(
Units
.
SECOND
)));
// , "m³/s"
// To model costs I added monetary units quick and dirty as SI base units.
// According to JavaDoc of AbstractUnit, monetary units should rather be
...
...
This diff is collapsed.
Click to expand it.
de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
+
20
-
6
View file @
527b8c29
...
...
@@ -13,10 +13,13 @@ import org.junit.jupiter.api.BeforeAll;
import
org.junit.jupiter.api.Test
;
import
de.hftstuttgart.cityunits.model.CarbonEmission
;
import
de.hftstuttgart.cityunits.model.VolumetricFlowRate
;
import
de.hftstuttgart.cityunits.model.Intensity
;
import
de.hftstuttgart.cityunits.model.UrbanSimulationUnits
;
import
tech.units.indriya.quantity.Quantities
;
import
tech.units.indriya.unit.Units
;
// Quantities.getQuantity("1.50 €"); does not compile in Maven without cast to String ???
// mvn install won't run this tests, since tycho (?) handles tests as integration tests, thus, mvn verify is required
class
QuantityTest
{
...
...
@@ -67,15 +70,26 @@ class QuantityTest {
assertEquals
(
"18720000 W·s/m³"
,
q
.
toSystemUnit
().
toString
());
}
@Test
void
testIrradiance
()
{
Quantity
<
Intensity
>
q
=
Quantities
.
getQuantity
(
"1000 W/m²"
).
asType
(
Intensity
.
class
);
assertEquals
(
"[M]/[T]³"
,
q
.
getUnit
().
getDimension
().
toString
(),
"Wrong dimension!"
);
}
@Test
void
testVolumetricFlows
()
{
Quantity
<
VolumetricFlowRate
>
q
=
Quantities
.
getQuantity
(
"10800000 l/h"
).
asType
(
VolumetricFlowRate
.
class
);
assertEquals
(
"[L]³/[T]"
,
q
.
getUnit
().
getDimension
().
toString
(),
"Wrong dimension!"
);
assertEquals
(
"3 m³/s"
,
q
.
toSystemUnit
().
toString
());
}
@Test
void
testCO2eq
()
{
Quantity
<
CarbonEmission
>
q
=
Quantities
.
getQuantity
((
String
)
"5200.7 kgCO₂eq"
).
asType
(
CarbonEmission
.
class
);
System
.
out
.
println
(
q
);
Quantity
<
CarbonEmission
>
q
=
Quantities
.
getQuantity
((
String
)
"5200.7 kg CO₂eq"
).
asType
(
CarbonEmission
.
class
);
assertEquals
(
"[M]"
,
q
.
getUnit
().
getDimension
().
toString
(),
"Wrong dimension!"
);
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5.2007 tonCO₂eq"
).
asType
(
CarbonEmission
.
class
)),
"Wrong conversion from kg of CO₂eq to ton of CO₂eq!"
);
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5200700 gCO₂eq"
).
asType
(
CarbonEmission
.
class
)),
"Wrong conversion from kg of CO₂eq to gram of CO₂eq!"
);
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5.2007 tonCO₂eq"
).
asType
(
CarbonEmission
.
class
)),
"Wrong conversion from kg of CO₂eq to ton of CO₂eq!"
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets