-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add voltage and current units #19
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Geert Mulders <[email protected]>
b678220
to
c4e13b6
Compare
@@ -10,7 +10,7 @@ plugins { | |||
`java-library` | |||
|
|||
// Apply dokka plugin to allow extraction of ducumentation from KDoc comments | |||
id("org.jetbrains.dokka") version "1.4.20" | |||
id("org.jetbrains.dokka") version "1.9.20" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build complained that this plugin could not be found.
this.divide(factor, 0, roundingMode) * factor | ||
this.divide(factor, 0, roundingMode) * factor | ||
|
||
operator fun <U : Units> BigDecimal.times(m: Measure<U>): Measure<U> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some cases you want to multiply your measure with some dimensionless value. e.g. when calculating the effectiveness of an consumer equipment on the congested element effectiveness * (4 * megaWatt)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasnt this functionality already present in measure 1.3? From MeasureKt.class
public fun <A : com.alliander.measure.Units, B : A> baseUnits(first: A, second: B): A { /* compiled code */ }
public operator fun <A : com.alliander.measure.Units, B : A> A.compareTo(other: B): kotlin.Int { /* compiled code */ }
public operator fun <U : com.alliander.measure.Units> java.math.BigDecimal.times(units: U): com.alliander.measure.Measure<U> { /* compiled code */ }
public operator fun <U : com.alliander.measure.Units> kotlin.Double.times(units: U): com.alliander.measure.Measure<U> { /* compiled code */ }
public operator fun <U : com.alliander.measure.Units> kotlin.Float.times(units: U): com.alliander.measure.Measure<U> { /* compiled code */ }
public operator fun <U : com.alliander.measure.Units> kotlin.Int.times(units: U): com.alliander.measure.Measure<U> { /* compiled code */ }
public operator fun <U : com.alliander.measure.Units> kotlin.Long.times(units: U): com.alliander.measure.Measure<U> { /* compiled code */ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, what you are referring to is a multiplication with a Unit --> 13 * kiloWatt
What this does is a multiplication with a Meaure:
val measure: Measure<Power> = 4 * megaWatt
val newMeasure: Measure<Power> = 3 * measure // 12 MW
} | ||
|
||
@JvmName("currentTimesVoltage") | ||
operator fun Measure<Current>.times(voltage: Measure<Voltage>): Measure<Power> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P = I V
} | ||
|
||
@JvmName("voltageTimesCurrent") | ||
operator fun Measure<Voltage>.times(current: Measure<Current>): Measure<Power> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P = V I
} | ||
|
||
@JvmName("powerDivVoltage") | ||
operator fun Measure<Power>.div(voltage: Measure<Voltage>): Measure<Current> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I = P / V
} | ||
|
||
@JvmName("powerDivCurrent") | ||
operator fun Measure<Power>.div(current: Measure<Current>): Measure<Voltage> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V = P / I
return Measure(p / i, volt) | ||
} | ||
|
||
class Voltage(suffix: String, ratio: BigDecimal = BigDecimal.ONE) : Units(suffix, ratio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voltage definition, I don't expect that we will use more then kiloVolts (our distribution grid is max 380kV)
|
||
return Measure(p.amount * dt.amount, joule) | ||
class Current(suffix: String, ratio: BigDecimal = BigDecimal.ONE) : Units(suffix, ratio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current definition, I don't expect that we will use more then kA, that already seems really high to me.
Signed-off-by: Geert Mulders <[email protected]>
import io.kotest.property.checkAll | ||
import java.math.BigDecimal | ||
import java.math.RoundingMode.UP | ||
|
||
class MeasureTest : StringSpec({ | ||
"Joule, Watt and seconds are different units" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to a more elaborate test in the new test file: The units have the correct measure
@@ -47,15 +32,6 @@ class MeasureTest : StringSpec({ | |||
sum shouldBe 2000 * joule | |||
} | |||
|
|||
"power times time is energy" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to the new test file
@@ -123,14 +99,6 @@ class MeasureTest : StringSpec({ | |||
} | |||
} | |||
|
|||
"energySum returns correct amount of energy when given a list of measures of energy" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already covered by another test.
No description provided.