Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

geertmulders
Copy link

No description provided.

@geertmulders geertmulders requested a review from a team as a code owner October 22, 2024 14:00
Signed-off-by: Geert Mulders <[email protected]>
@geertmulders geertmulders force-pushed the add-voltage-and-current-units branch from b678220 to c4e13b6 Compare October 22, 2024 14:34
@@ -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"
Copy link
Author

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> =
Copy link
Author

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))

Copy link
Contributor

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 */ }


Copy link
Author

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> {
Copy link
Author

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> {
Copy link
Author

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> {
Copy link
Author

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> {
Copy link
Author

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) {
Copy link
Author

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) {
Copy link
Author

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" {
Copy link
Author

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" {
Copy link
Author

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" {
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants