Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into df/#422-exception-caused-by-histor…
Browse files Browse the repository at this point in the history
…ic-data
  • Loading branch information
danielfeismann committed May 7, 2024
2 parents 4bac2fb + 83c8bf2 commit a8f5466
Show file tree
Hide file tree
Showing 23 changed files with 332 additions and 176 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved `SubGridHandling` [#397](https://github.com/ie3-institute/OSMoGrid/issues/397)
- Switched from `osm4scala` to `openstreetmap.osmosis` [#409](https://github.com/ie3-institute/OSMoGrid/issues/409)
- Changed transformer input parameter to PSDM requirements [#417](https://github.com/ie3-institute/OSMoGrid/issues/417)
- Adapted run initialization [#404](https://github.com/ie3-institute/OSMoGrid/issues/404)

### Fixed
- Fixed bug in `LvGridGeneratorSupport` [#388](https://github.com/ie3-institute/OSMoGrid/issues/388)
Expand Down
4 changes: 4 additions & 0 deletions input/fuerweiler/fuerweiler.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ output.csv.directory = "output/fuerweiler"
output.csv.separator = ","
output.csv.hierarchic = false

grids.output.lv = true
grids.output.mv = true
grids.output.hv = true

##################################################################
# Voltage parameters
##################################################################
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config/config-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ output: {
}
}

grids.output: {
lv: Boolean | true
mv: Boolean | true
hv: Boolean | true
}

voltage: {
lv: {
id: String | "lv"
Expand Down
24 changes: 22 additions & 2 deletions src/main/scala/edu/ie3/osmogrid/cfg/ConfigFailFast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import org.apache.pekko.actor.typed.ActorRef
import com.typesafe.scalalogging.LazyLogging
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Generation.{Lv, Mv}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.Input.{Asset, Osm}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{Generation, Input, Output, Voltage}
import edu.ie3.osmogrid.cfg.OsmoGridConfig.{
Generation,
Grids,
Input,
Output,
Voltage
}
import edu.ie3.osmogrid.exception.IllegalConfigException
import edu.ie3.osmogrid.io.input.BoundaryAdminLevel
import edu.ie3.osmogrid.io.output.OutputRequest
Expand All @@ -23,10 +29,11 @@ object ConfigFailFast extends LazyLogging {
additionalListener: Seq[ActorRef[OutputRequest]] = Seq.empty
): Try[OsmoGridConfig] = Try {
cfg match {
case OsmoGridConfig(generation, input, output, voltage) =>
case OsmoGridConfig(generation, grids, input, output, voltage) =>
checkInputConfig(input)
checkOutputConfig(output, additionalListener)
checkGenerationConfig(generation)
checkGridsConfig(grids)
checkVoltageConfig(voltage)
}
cfg
Expand Down Expand Up @@ -155,6 +162,19 @@ object ConfigFailFast extends LazyLogging {
"Output directory and separator must be set when using .csv file sink!"
)

private def checkGridsConfig(grids: Grids): Unit = {
grids.output match {
case Grids.Output(false, false, false) =>
// at least one output must be set
throw IllegalConfigException(s"No grid output defined.")

case Grids.Output(true, false, false) =>
logger.warn(s"Only hv output is currently not supported!")
case _ =>

}
}

// TODO: Check if necessary
private def checkVoltageConfig(voltage: Voltage): Unit = {}
}
50 changes: 48 additions & 2 deletions src/main/scala/edu/ie3/osmogrid/cfg/OsmoGridConfig.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2023. TU Dortmund University,
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
Expand All @@ -8,6 +8,7 @@ package edu.ie3.osmogrid.cfg

final case class OsmoGridConfig(
generation: OsmoGridConfig.Generation,
grids: OsmoGridConfig.Grids,
input: OsmoGridConfig.Input,
output: OsmoGridConfig.Output,
voltage: OsmoGridConfig.Voltage
Expand Down Expand Up @@ -184,6 +185,45 @@ object OsmoGridConfig {
}
}

final case class Grids(
output: OsmoGridConfig.Grids.Output
)
object Grids {
final case class Output(
hv: scala.Boolean,
lv: scala.Boolean,
mv: scala.Boolean
)
object Output {
def apply(
c: com.typesafe.config.Config,
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): OsmoGridConfig.Grids.Output = {
OsmoGridConfig.Grids.Output(
hv = !c.hasPathOrNull("hv") || c.getBoolean("hv"),
lv = !c.hasPathOrNull("lv") || c.getBoolean("lv"),
mv = !c.hasPathOrNull("mv") || c.getBoolean("mv")
)
}
}

def apply(
c: com.typesafe.config.Config,
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): OsmoGridConfig.Grids = {
OsmoGridConfig.Grids(
output = OsmoGridConfig.Grids.Output(
if (c.hasPathOrNull("output")) c.getConfig("output")
else com.typesafe.config.ConfigFactory.parseString("output{}"),
parentPath + "output.",
$tsCfgValidator
)
)
}
}

final case class Input(
asset: OsmoGridConfig.Input.Asset,
osm: OsmoGridConfig.Input.Osm
Expand Down Expand Up @@ -344,7 +384,7 @@ object OsmoGridConfig {
hierarchic =
c.hasPathOrNull("hierarchic") && c.getBoolean("hierarchic"),
separator =
if (c.hasPathOrNull("separator")) c.getString("separator") else ";"
if (c.hasPathOrNull("separator")) c.getString("separator") else ","
)
}
private def $_reqStr(
Expand Down Expand Up @@ -518,6 +558,12 @@ object OsmoGridConfig {
parentPath + "generation.",
$tsCfgValidator
),
grids = OsmoGridConfig.Grids(
if (c.hasPathOrNull("grids")) c.getConfig("grids")
else com.typesafe.config.ConfigFactory.parseString("grids{}"),
parentPath + "grids.",
$tsCfgValidator
),
input = OsmoGridConfig.Input(
if (c.hasPathOrNull("input")) c.getConfig("input")
else com.typesafe.config.ConfigFactory.parseString("input{}"),
Expand Down
42 changes: 18 additions & 24 deletions src/main/scala/edu/ie3/osmogrid/guardian/run/RunGuardian.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ object RunGuardian
ctx
) match {
case Success(childReferences) =>
running(
runGuardianData,
childReferences,
FinishedGridData.empty(
childReferences.lvCoordinator.isDefined,
childReferences.mvCoordinator.isDefined
if (childReferences.canRun) {
running(
runGuardianData,
childReferences,
FinishedGridData.empty
)
)
} else {
// no coordinator alive, stop generation
ctx.log.warn(
s"No coordinators were spawned. Generation can't run!"
)
Behaviors.stopped
}
case Failure(exception) =>
ctx.log.error(
s"Unable to start run ${runGuardianData.runId}.",
Expand Down Expand Up @@ -131,15 +136,10 @@ object RunGuardian
)
}

// store sub grids if they should be put out
val option = if (finishedGridData.lvExpected) {
Some(subGridContainer)
} else None

val updated = finishedGridData.copy(lvData = option)
val updated = finishedGridData.copy(lvData = Some(subGridContainer))

// check if all possible data was received
if (updated.receivedAllData) {
if (!updatedChildReferences.stillRunning) {

// if all data was received,
ctx.self ! HandleGridResults
Expand Down Expand Up @@ -167,22 +167,15 @@ object RunGuardian
childReferences.mvCoordinator.foreach(ctx.unwatch)
val updatedChildReferences = childReferences.copy(mvCoordinator = None)

// store sub grids if they should be put out
val option = if (finishedGridData.mvExpected) {
Some(subGridContainer)
} else None

val nodeUpdates = Option.when(nodeChanges.nonEmpty)(nodeChanges)

val updated = finishedGridData.copy(
mvData = option,
mvData = Some(subGridContainer),
hvData = dummyHvGrid.map(Seq(_)), // converting to sequence
mvNodeChanges = nodeUpdates,
mvNodeChanges = Option.when(nodeChanges.nonEmpty)(nodeChanges),
assetInformation = Some(assetInformation)
)

// check if all possible data was received
if (updated.receivedAllData) {
if (!updatedChildReferences.stillRunning) {

// if all data was received,
ctx.self ! HandleGridResults
Expand All @@ -197,6 +190,7 @@ object RunGuardian
ctx.log.info(s"Starting to handle grid results.")

handleResults(
runGuardianData.cfg.grids.output,
finishedGridData.lvData,
finishedGridData.mvData,
finishedGridData.hvData,
Expand Down
Loading

0 comments on commit a8f5466

Please sign in to comment.