Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into jb/#671-externaldatase…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
Johannes Bao committed Jul 25, 2024
2 parents f6f8ba8 + b7d3a96 commit 2cc7018
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 172 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Making configuration of `RefSystem` via config optional [#769](https://github.com/ie3-institute/simona/issues/769)
- Updated PSDM to version 5.1.0 [#835](https://github.com/ie3-institute/simona/issues/835)
- Refactor `WeatherSource` and `WeatherSourceWrapper` [#180](https://github.com/ie3-institute/simona/issues/180)
- Remove unnecessary dependency `pekko-connectors-csv` [#857](https://github.com/ie3-institute/simona/issues/857)
- Rewrote RefSystemTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)
- Rewrote FixedFeedModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)

### Fixed
- Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658)
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext {

scalaVersion = '2.13'
scalaBinaryVersion = '2.13.14'
pekkoVersion = '1.0.2'
pekkoVersion = '1.0.3'
jtsVersion = '1.19.0'
confluentKafkaVersion = '7.4.0'
tscfgVersion = '1.0.0'
Expand Down Expand Up @@ -133,7 +133,6 @@ dependencies {
implementation "org.apache.pekko:pekko-actor_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-actor-typed_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-slf4j_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-connectors-csv_${scalaVersion}:${pekkoVersion}"

/* config */
implementation 'com.typesafe:config:1.4.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ final case class ResultEntityCsvSink private (
logger.debug(logPrefix(s"Compressed $outfileName."))
FileIOUtils.deleteFileIfExists(outFileName).asScala
case Failure(_) =>
Future.failed[IOResult](
new ProcessResultEventException(
s"Failed to zip file $outFileName!"
)
throw new ProcessResultEventException(
s"Failed to zip file $outFileName!"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final case class FixedFeedInModel(
* @return
* Active power
*/
override protected def calculateActivePower(
override def calculateActivePower(
modelState: ConstantState.type,
data: FixedRelevantData.type = FixedRelevantData,
): Power =
Expand Down
74 changes: 0 additions & 74 deletions src/test/groovy/edu/ie3/simona/model/grid/RefSystemTest.groovy

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package edu.ie3.simona.io.result

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.FileIO
import org.apache.pekko.util.ByteString
import com.typesafe.config.ConfigFactory
import edu.ie3.datamodel.exceptions.EntityProcessorException
import edu.ie3.datamodel.io.processor.result.ResultEntityProcessor
Expand All @@ -18,14 +15,14 @@ import edu.ie3.simona.exceptions.ProcessResultEventException
import edu.ie3.simona.test.common.{IOTestCommons, TestKitWithShutdown, UnitSpec}
import edu.ie3.util.TimeUtil
import edu.ie3.util.io.FileIOUtils
import org.apache.pekko.actor.ActorSystem
import tech.units.indriya.quantity.Quantities

import java.io.File
import java.nio.file.Paths
import java.nio.charset.StandardCharsets
import java.nio.file.StandardOpenOption.{CREATE, TRUNCATE_EXISTING, WRITE}
import java.nio.file.{Files, Paths}
import java.util.UUID
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.io.Source
import scala.language.postfixOps

Expand Down Expand Up @@ -98,12 +95,12 @@ class ResultEntityCsvSinkSpec

val path = Paths.get(outFileName)
// create output file (should not exist yet at this point)
Await.ready(
org.apache.pekko.stream.scaladsl.Source
.single(testText)
.map(t => ByteString(t))
.runWith(FileIO.toPath(path, Set(WRITE, TRUNCATE_EXISTING, CREATE))),
5.seconds,
Files.write(
path,
testText.getBytes(StandardCharsets.UTF_8),
WRITE,
TRUNCATE_EXISTING,
CREATE,
)

val resultEntityProcessor = new ResultEntityProcessor(classOf[PvResult])
Expand Down
56 changes: 56 additions & 0 deletions src/test/scala/edu/ie3/simona/model/grid/RefSystemSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* © 2020. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

package edu.ie3.simona.model.grid

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import squants.{Dimensionless, Each}
import squants.electro.{Amperes, ElectricPotential, Kilovolts, Ohms}
import squants.energy.{Megawatts, Power, Kilowatts}

class RefSystemSpec extends AnyFlatSpec with Matchers {

"A RefSystem with nominal power and nominal voltage" should "provide corresponding nominal current and nominal impedance" in {

val nominalPower: Power = Kilowatts(600)
val nominalVoltage: ElectricPotential = Kilovolts(10)

val refSystem = RefSystem(nominalPower, nominalVoltage)

refSystem.nominalPower should be(nominalPower)
refSystem.nominalVoltage should be(nominalVoltage)
refSystem.nominalCurrent should be(
Amperes(34.64101615137754774109785366023500d)
)
refSystem.nominalImpedance should be(
Ohms(166.6666666666666666666666666666666d)
)
}

"A dimensionless impedance" should "be transferred correctly between reference systems" in {
val from = RefSystem(Megawatts(60d), Kilovolts(110d))
val to = RefSystem(Megawatts(40d), Kilovolts(110d))
val impedance = Each(0.1d)
val expected = Each(0.06666666666666667d)

val actual: Dimensionless = RefSystem.transferImpedance(impedance, from, to)

actual should be(expected)
}

"A dimensionless admittance" should "be transferred correctly between reference systems" in {
val from = RefSystem(Megawatts(60d), Kilovolts(110d))
val to = RefSystem(Megawatts(40d), Kilovolts(110d))
val admittance = Each(0.1d)
val expected = Each(0.15000000000000002d)

val actual: Dimensionless =
RefSystem.transferAdmittance(admittance, from, to)

actual should be(expected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

package edu.ie3.simona.model.participant

import edu.ie3.simona.model.participant.control.QControl
import edu.ie3.simona.test.common.UnitSpec
import edu.ie3.simona.test.common.input.FixedFeedInputTestData
import edu.ie3.util.quantities.PowerSystemUnits
import edu.ie3.util.scala.quantities.Sq
import org.scalatest.prop.TableDrivenPropertyChecks
import squants.energy.{Kilowatts, Power, Watts}

class FixedFeedModelSpec
extends UnitSpec
with FixedFeedInputTestData
with TableDrivenPropertyChecks {
implicit val tolerance: Power = Watts(1d)
"Having a fixed feed model" when {

"The fixed feed model" should {
"return approximately correct power calculations" in {
val expectedPower = Kilowatts(
fixedFeedInput
.getsRated()
.to(PowerSystemUnits.KILOWATT)
.getValue
.doubleValue() * -1 * fixedFeedInput.getCosPhiRated
)

val actualModel = new FixedFeedInModel(
fixedFeedInput.getUuid,
fixedFeedInput.getId,
defaultOperationInterval,
QControl.apply(fixedFeedInput.getqCharacteristics()),
Kilowatts(
fixedFeedInput
.getsRated()
.to(PowerSystemUnits.KILOWATT)
.getValue
.doubleValue()
),
fixedFeedInput.getCosPhiRated,
)

actualModel.calculateActivePower(
ModelState.ConstantState,
CalcRelevantData.FixedRelevantData,
) =~ expectedPower
}
}

}
}

0 comments on commit 2cc7018

Please sign in to comment.