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

To/#137 convert grid #141

Merged
merged 31 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c646a5b
include models into processed grid
t-ober Oct 24, 2021
19a0584
convert models
t-ober Oct 25, 2021
7148821
convert static generators
t-ober Oct 25, 2021
5614c40
use psdm snapshot version
t-ober Oct 26, 2021
a53e6b7
extend config with io
t-ober Oct 26, 2021
f99b0c2
static generator conversion
t-ober Oct 26, 2021
0bd570b
grid conversion and persistence
t-ober Oct 26, 2021
16fea36
persist jointGridContainer
t-ober Oct 26, 2021
86b7755
ignore converted grids
t-ober Oct 26, 2021
570de0d
fixes
t-ober Oct 26, 2021
a17181c
add grid converter test
t-ober Oct 27, 2021
8e9b33c
add some docs
t-ober Oct 27, 2021
73f3341
Merge remote-tracking branch 'origin/main' into to/#137-convert-grid
t-ober Oct 27, 2021
b87abff
avoid exceptions in converter test data
t-ober Oct 28, 2021
0a306b8
fix test
t-ober Oct 28, 2021
dfed070
Merge branch 'main' into to/#137-convert-grid
t-ober Nov 2, 2021
b691769
Merge branch 'main' into to/#137-convert-grid
t-ober Nov 18, 2021
c9c2d8a
Merge remote-tracking branch 'origin/main' into to/#137-convert-grid
t-ober Nov 18, 2021
5938206
remove unused import
t-ober Nov 18, 2021
c8521a5
recreate schema
t-ober Nov 18, 2021
263f164
fmt
t-ober Nov 18, 2021
2a715d6
udpate test grid
t-ober Nov 18, 2021
fa6c3e8
be more type specific
t-ober Nov 18, 2021
727e03c
docstring
t-ober Nov 18, 2021
f63f920
add tests
t-ober Nov 22, 2021
6d96bd1
fmt
t-ober Nov 22, 2021
93b8e38
Merge branch 'main' into to/#137-convert-grid
t-ober Nov 22, 2021
d13d770
Merge branch 'main' into to/#137-convert-grid
t-ober Nov 24, 2021
069de84
update test grid
t-ober Nov 24, 2021
cb2e136
remove unused import
t-ober Nov 24, 2021
147c3b3
Merge branch 'main' into to/#137-convert-grid
ckittl Nov 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,8 @@ build
# Ignore out folder
out

# Ignore default folder for converted grids
convertedGrids

# Ignore grid json
src/main/python/pfGridExport
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ dependencies {
implementation group: 'org.scalameta', name: "scalafmt-dynamic_${scalaVersion}", version: '3.0.8'


implementation('com.github.ie3-institute:PowerSystemDataModel:2.0.1') {
/* PowerSystemDataModel */
implementation ('com.github.ie3-institute:PowerSystemDataModel:2.1-SNAPSHOT') {
/* Exclude nested logging and ie3 related dependencies */
exclude group: 'org.slf4j', module: 'slf4j-api'
/* Exclude our own nested dependencies */
exclude group: 'com.github.ie3-institute'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@

package edu.ie3.powerFactory2psdm.config

import edu.ie3.powerFactory2psdm.config.ConversionConfig.StatGenModelConfigs
import edu.ie3.powerFactory2psdm.config.ConversionConfig.{
OutputConfig,
StatGenModelConfigs
}
import edu.ie3.powerFactory2psdm.config.ConversionConfigUtils.ParameterSource
import edu.ie3.powerFactory2psdm.config.model.{
PvConversionConfig,
WecConversionConfig
}

final case class ConversionConfig(modelConfigs: StatGenModelConfigs)
final case class ConversionConfig(
gridName: String,
modelConfigs: StatGenModelConfigs,
output: OutputConfig
)

/** Config used for the grid conversion
*/
Expand All @@ -35,6 +42,18 @@ object ConversionConfig {
cosPhiSource: ParameterSource
)

final case class OutputConfig(
targetFolder: String,
csvConfig: CsvConfig
)

final case class CsvConfig(
directoryHierarchy: Boolean = true,
fileEncoding: String = "UTF-8",
fileEnding: String = ".csv",
separator: String = ";"
)

sealed trait GenerationMethod

/** Use the given value fixed value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import edu.ie3.powerFactory2psdm.config.model.IndividualModelConfig.ModelConvers

/** Default model config to apply for the model conversion.
*/
trait DefaultModelConfig {
val conversionMode: ModelConversionMode
val individualConfigs: Option[List[IndividualModelConfig]]
}
trait DefaultModelConfig[M <: ModelConversionMode, I <: IndividualModelConfig[
M
]] {
val conversionMode: M
val individualConfigs: Option[List[I]]

object DefaultModelConfig {
def getIndividualModelConfig(modelId: String): Option[I] =
individualConfigs.flatMap(configs => configs.find(_.ids.contains(modelId)))

/** Return conversion modes of the default and all individual model configs.
*/
def getConversionModes(
config: DefaultModelConfig
): Seq[ModelConversionMode] = {
Seq(config.conversionMode) ++ config.individualConfigs
def getConversionModes: Seq[M] = {
Seq(conversionMode) ++ individualConfigs
.getOrElse(Nil)
.map(conf => conf.conversionMode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package edu.ie3.powerFactory2psdm.config.model

import edu.ie3.powerFactory2psdm.config.model.IndividualModelConfig.ModelConversionMode

trait IndividualModelConfig {
trait IndividualModelConfig[M <: ModelConversionMode] {
val ids: Set[String]
val conversionMode: ModelConversionMode
val conversionMode: M
}

object IndividualModelConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import edu.ie3.powerFactory2psdm.generator.ParameterSamplingMethod
final case class PvConversionConfig(
conversionMode: PvModelConversionMode,
individualConfigs: Option[List[IndividualPvConfig]]
) extends DefaultModelConfig
) extends DefaultModelConfig[PvModelConversionMode, IndividualPvConfig] {}

object PvConversionConfig {

Expand All @@ -44,7 +44,7 @@ object PvConversionConfig {
final case class IndividualPvConfig(
ids: Set[String],
conversionMode: PvModelConversionMode
) extends IndividualModelConfig
) extends IndividualModelConfig[PvModelConversionMode]

/** Trait to denote modes for converting pv static generators
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import edu.ie3.powerFactory2psdm.generator.ParameterSamplingMethod
final case class WecConversionConfig(
conversionMode: WecModelConversionMode,
individualConfigs: Option[List[IndividualWecConfig]]
) extends DefaultModelConfig
) extends DefaultModelConfig[WecModelConversionMode, IndividualWecConfig]

object WecConversionConfig {

Expand All @@ -44,7 +44,7 @@ object WecConversionConfig {
final case class IndividualWecConfig(
ids: Set[String],
conversionMode: WecModelConversionMode
) extends IndividualModelConfig
) extends IndividualModelConfig[WecModelConversionMode]

/** Trait to group different methods for generating a value for a model
* parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import edu.ie3.powerFactory2psdm.config.ConversionConfigUtils.{
FixedQCharacteristic,
QCharacteristic
}
import edu.ie3.powerFactory2psdm.config.model.DefaultModelConfig.getConversionModes
import edu.ie3.powerFactory2psdm.config.model.PvConversionConfig.PvModelConversionMode
import edu.ie3.powerFactory2psdm.config.model.WecConversionConfig.WecModelConversionMode
import edu.ie3.powerFactory2psdm.config.validate.conversion.ConversionModeValidator
import edu.ie3.powerFactory2psdm.exception.io.ConversionConfigException
import edu.ie3.powerFactory2psdm.generator.ParameterSamplingMethod
import edu.ie3.powerFactory2psdm.generator.ParameterSamplingMethod.{
Expand All @@ -47,16 +43,12 @@ object ConfigValidator extends LazyLogging {
private[config] def validateModelConfigs(
modelConfigs: StatGenModelConfigs
): Unit = {
Seq(modelConfigs.pvConfig, modelConfigs.wecConfig)
.flatMap(getConversionModes)
.foreach {
case x: PvModelConversionMode => PvConversionModeValidator.validate(x)
case x: WecModelConversionMode => WecConversionModeValidator.validate(x)
case conversionMode =>
logger.warn(
s"The conversion mode $conversionMode is currently not validated."
)
}
modelConfigs.pvConfig.getConversionModes.foreach(
PvConversionModeValidator.validate
)
modelConfigs.wecConfig.getConversionModes.foreach(
WecConversionModeValidator.validate
)
}

private[config] def validateParameterSamplingMethod(
Expand Down
118 changes: 113 additions & 5 deletions src/main/scala/edu/ie3/powerFactory2psdm/converter/GridConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,62 @@

package edu.ie3.powerFactory2psdm.converter

import edu.ie3.powerFactory2psdm.converter.types.LineTypeConverter
import edu.ie3.datamodel.models.input.{MeasurementUnitInput, NodeInput}
import edu.ie3.datamodel.models.input.connector.Transformer3WInput
import edu.ie3.datamodel.models.input.container.{
GraphicElements,
JointGridContainer,
RawGridElements,
SystemParticipants
}
import edu.ie3.datamodel.models.input.graphics.{
LineGraphicInput,
NodeGraphicInput
}
import edu.ie3.datamodel.models.input.system.{
BmInput,
ChpInput,
EvInput,
EvcsInput,
HpInput,
StorageInput
}
import edu.ie3.powerFactory2psdm.config.ConversionConfig
import edu.ie3.powerFactory2psdm.config.ConversionConfig.StatGenModelConfigs
import edu.ie3.powerFactory2psdm.converter.types.{
LineTypeConverter,
Transformer2WTypeConverter
}
import edu.ie3.powerFactory2psdm.model.{PreprocessedPfGridModel, RawPfGridModel}

import scala.jdk.CollectionConverters.SetHasAsJava

/** Functionalities to transform an exported and then parsed PowerFactory grid
* to the PSDM.
*/
case object GridConverter {

def convert(pfGrid: RawPfGridModel) = {
val grid = PreprocessedPfGridModel.build(pfGrid)
val gridElements = convertGridElements(grid)
def convert(
pfGrid: RawPfGridModel,
config: ConversionConfig
): JointGridContainer = {
val grid = PreprocessedPfGridModel.build(
pfGrid,
config.modelConfigs.sRatedSource,
config.modelConfigs.cosPhiSource
)
val (gridElements, convertedNodes) = convertGridElements(grid)
val participants =
convertParticipants(grid, convertedNodes, config.modelConfigs)
new JointGridContainer(
config.gridName,
gridElements,
participants,
new GraphicElements(
Set.empty[NodeGraphicInput].asJava,
Set.empty[LineGraphicInput].asJava
)
)
}

/** Converts the grid elements of the PowerFactory grid
Expand All @@ -26,7 +71,7 @@ case object GridConverter {
*/
def convertGridElements(
grid: PreprocessedPfGridModel
): Unit = {
): (RawGridElements, Map[String, NodeInput]) = {
val graph =
GridGraphBuilder.build(grid.nodes, grid.lines ++ grid.switches)
val nodeId2node = grid.nodes.map(node => (node.id, node)).toMap
Expand All @@ -41,5 +86,68 @@ case object GridConverter {
nodes,
lineTypes
)
val transformer2WTypes = grid.transformerTypes2W
.map(transformerType =>
transformerType.id -> Transformer2WTypeConverter.convert(
transformerType
)
)
.toMap
val transfomers2W = Transformer2WConverter.convertTransformers(
grid.transformers2W,
nodes,
transformer2WTypes
)
val switches =
grid.switches.map(switch => SwitchConverter.convert(switch, nodes))

(
new RawGridElements(
nodes.values.toSet.asJava,
lines.toSet.asJava,
transfomers2W.toSet.asJava,
Set.empty[Transformer3WInput].asJava,
switches.toSet.asJava,
Set.empty[MeasurementUnitInput].asJava
),
nodes
)

}

/** Convert system participants of the power factory grid.
*
* @param grid
* the PF grid
* @param convertedNodes
* the converted nodes
* @param statGenConversionConfig
* the conversion configuration for static generators
* @return
*/
def convertParticipants(
grid: PreprocessedPfGridModel,
convertedNodes: Map[String, NodeInput],
statGenConversionConfig: StatGenModelConfigs
): SystemParticipants = {
val loads = LoadConverter.convertLoads(grid.loads, convertedNodes)
val statGenModelContainer = StaticGeneratorConverter.convert(
grid.staticGenerators,
statGenConversionConfig,
convertedNodes
)
new SystemParticipants(
Set.empty[BmInput].asJava,
Set.empty[ChpInput].asJava,
Set.empty[EvcsInput].asJava,
Set.empty[EvInput].asJava,
statGenModelContainer.fixedFeedIns.toSet.asJava,
Set.empty[HpInput].asJava,
loads.toSet.asJava,
statGenModelContainer.pvInputs.toSet.asJava,
Set.empty[StorageInput].asJava,
statGenModelContainer.wecInputs.toSet.asJava
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import edu.ie3.datamodel.models.{BdewLoadProfile, OperationTime}
import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput}
import edu.ie3.datamodel.models.input.system.LoadInput
import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed
import edu.ie3.powerFactory2psdm.exception.pf.{
ConversionException,
ElementConfigurationException
}
import edu.ie3.powerFactory2psdm.exception.pf.ElementConfigurationException
import edu.ie3.powerFactory2psdm.converter.NodeConverter.getNode
import edu.ie3.powerFactory2psdm.exception.pf.ConversionException
import edu.ie3.powerFactory2psdm.model.entity.Load
import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble

Expand All @@ -22,6 +21,22 @@ import scala.util.{Failure, Success}

object LoadConverter {

def convertLoads(
input: List[Load],
nodes: Map[String, NodeInput]
): List[LoadInput] = {
input map { load =>
getNode(load.nodeId, nodes) match {
case Success(node) => convert(load, node)
case Failure(exc) =>
throw ConversionException(
s"Could not convert load due to inability of finding its converted node with id: ${load.nodeId}",
exc
)
}
}
}

def convert(input: Load, node: NodeInput): LoadInput = {
val id = input.id
val cosPhi = ConversionHelper.determineCosPhiRated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ object NodeConverter {
)
)
}

def missingNodeException(
system: String,
exc: Throwable
): ConversionException =
ConversionException(s"Can't find converted node of $system", exc)
}
Loading