-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09da4a7
commit 8f18116
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package testDataFactory | ||
|
||
import com.github.statnett.loadflowservice.AutoSerializableSensitivityFactor | ||
import io.ktor.client.request.forms.* | ||
import io.ktor.http.content.* | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
@Serializable | ||
data class Contingencies( | ||
val type: String, | ||
val version: String, | ||
val name: String, | ||
val contingencies: List<Contingency> | ||
) | ||
|
||
@Serializable | ||
data class Contingency( | ||
val id: String, | ||
val elements: List<ContingencyElement> | ||
) | ||
|
||
@Serializable | ||
data class ContingencyElement( | ||
val id: String, | ||
val type: String, | ||
) | ||
|
||
fun ieee14BusContingencies(): Contingencies { | ||
val generator = ContingencyElement(id = "B1-G", type = "GENERATOR") | ||
val br1 = ContingencyElement(id = "L7-8-0", type = "BRANCH") | ||
val br2 = ContingencyElement(id = "L9-8-0", type = "BRANCH") | ||
|
||
return Contingencies( | ||
type = "default", | ||
version = "1.0", | ||
name = "list", | ||
contingencies = listOf( | ||
Contingency(id = "generatorContingency", listOf(generator)), | ||
Contingency(id = "branchContingency", listOf(br1, br2)) | ||
) | ||
) | ||
} | ||
|
||
fun ieee14SensitivityFactor(): AutoSerializableSensitivityFactor { | ||
return AutoSerializableSensitivityFactor( | ||
functionType = "BRANCH_ACTIVE_POWER_2", | ||
functionId = "l", | ||
variableType = "INJECTION_ACTIVE_POWER", | ||
variableId = "g", | ||
variableSet = false, | ||
contingencyContextType = "ALL" | ||
) | ||
} | ||
|
||
fun ieee14SensitivityLoadParams(): String { | ||
return "{\"dc\": true}" | ||
} | ||
|
||
fun ieee14SensitivityParams(): String { | ||
return "{\"voltage-voltage-sensitivity-threshold\": 0.001}" | ||
} | ||
|
||
data class SensitivityAnalysisConfig( | ||
val withContingencies: Boolean, | ||
val withSensitivityFactors: Boolean, | ||
val withLoadParameters: Boolean, | ||
val withSensitivityParameters: Boolean | ||
) | ||
|
||
fun allSensitivityAnalysisConfigs(): List<SensitivityAnalysisConfig> { | ||
val options = listOf(true, false) | ||
return options.map { withCtg -> | ||
options.map { withSf -> | ||
options.map { withLp -> | ||
options.map { withSensParam -> | ||
SensitivityAnalysisConfig(withCtg, withSf, withLp, withSensParam) | ||
} | ||
}.flatten() | ||
}.flatten() | ||
}.flatten() | ||
} | ||
|
||
fun sensitivityAnalysisFormData(config: SensitivityAnalysisConfig): List<PartData> { | ||
val cgmesFile = formDataFromFile(ieeeCdfNetwork14CgmesFile()).toMutableList() | ||
val sensFactors = formData { | ||
append( | ||
"sensitivity-factors", | ||
Json.encodeToString(ieee14SensitivityFactor()) | ||
) | ||
} | ||
|
||
val loadParams = formData { | ||
append( | ||
"load-parameters", | ||
ieee14SensitivityLoadParams() | ||
) | ||
} | ||
|
||
val contingencies = formData { | ||
append( | ||
"contingencies", | ||
Json.encodeToString(ieee14BusContingencies()) | ||
) | ||
} | ||
|
||
val sensParams = formData { | ||
append( | ||
"sensitivity-analysis-parameters", | ||
ieee14SensitivityParams() | ||
) | ||
} | ||
|
||
if (config.withContingencies) { | ||
cgmesFile += contingencies | ||
} | ||
|
||
if (config.withSensitivityFactors) { | ||
cgmesFile += sensFactors | ||
} | ||
|
||
if (config.withLoadParameters) { | ||
cgmesFile += loadParams | ||
} | ||
|
||
if (config.withSensitivityParameters) { | ||
cgmesFile += sensParams | ||
} | ||
return cgmesFile | ||
} |