-
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.
Signed-off-by: lisrte <laurent.issertial@rte-france.com>
- Loading branch information
Showing
11 changed files
with
245 additions
and
25 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/NodeFaultEventGroovyExtension.groovy
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,81 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com/) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.dsl.events | ||
|
||
import com.google.auto.service.AutoService | ||
import com.powsybl.dsl.DslException | ||
import com.powsybl.dynamicsimulation.EventModel | ||
import com.powsybl.dynamicsimulation.groovy.EventModelGroovyExtension | ||
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension | ||
import com.powsybl.dynawaltz.models.events.AbstractEventModel | ||
import com.powsybl.dynawaltz.models.events.NodeFaultEvent | ||
import com.powsybl.iidm.network.Bus | ||
import com.powsybl.iidm.network.Network | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
@AutoService(EventModelGroovyExtension.class) | ||
class NodeFaultEventGroovyExtension extends AbstractPureDynamicGroovyExtension<EventModel> implements EventModelGroovyExtension { | ||
|
||
NodeFaultEventGroovyExtension() { | ||
modelTags = ["NodeFault"] | ||
} | ||
|
||
@Override | ||
protected NodeFaultEventBuilder createBuilder(Network network) { | ||
new NodeFaultEventBuilder(network) | ||
} | ||
|
||
static class NodeFaultEventBuilder extends AbstractEventModelBuilder { | ||
|
||
Bus bus | ||
double faultTime | ||
double rPu | ||
double xPu | ||
|
||
NodeFaultEventBuilder(Network network) { | ||
super(network) | ||
} | ||
|
||
void faultTime(double faultTime) { | ||
this.faultTime = faultTime | ||
} | ||
|
||
void rPu(double rPu) { | ||
this.rPu = rPu | ||
} | ||
|
||
void xPu(double xPu) { | ||
this.xPu = xPu | ||
} | ||
|
||
void checkData() { | ||
super.checkData() | ||
this.bus = network.getBusBreakerView().getBus(staticId) | ||
if (bus == null) { | ||
throw new DslException("Bus static id unknown: " + staticId) | ||
} | ||
if (faultTime <= 0) { | ||
throw new DslException("NodeFault ${bus.getId()} fault time should be strictly positive (${faultTime})") | ||
} | ||
if (rPu < 0) { | ||
throw new DslException("NodeFault ${bus.getId()} rPu should be positive (${rPu})") | ||
} | ||
if (xPu < 0) { | ||
throw new DslException("NodeFault ${bus.getId()} xPu should be positive (${xPu})") | ||
} | ||
} | ||
|
||
@Override | ||
AbstractEventModel build() { | ||
checkData() | ||
new NodeFaultEvent(bus, startTime, faultTime, rPu, xPu) | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
dynawaltz-dsl/src/test/resources/eventModels/nodeFault.groovy
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,17 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package eventModels | ||
|
||
NodeFault { | ||
staticId "NGEN" | ||
startTime 1 | ||
faultTime 0.1 | ||
rPu 0 | ||
xPu 0.01 | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/NodeFaultEvent.java
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,60 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com/) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.models.events; | ||
|
||
import com.powsybl.dynawaltz.DynaWaltzContext; | ||
import com.powsybl.dynawaltz.models.VarConnection; | ||
import com.powsybl.dynawaltz.models.buses.BusModel; | ||
import com.powsybl.dynawaltz.parameters.ParameterType; | ||
import com.powsybl.dynawaltz.xml.ParametersXml; | ||
import com.powsybl.iidm.network.Bus; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamWriter; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
public class NodeFaultEvent extends AbstractEventModel { | ||
|
||
private static final String EVENT_PREFIX = "Node_Fault_"; | ||
|
||
private final double faultTime; | ||
private final double rPu; | ||
private final double xPu; | ||
|
||
public NodeFaultEvent(Bus equipment, double startTime, double faultTime, double rPu, double xPu) { | ||
super(equipment, startTime, EVENT_PREFIX); | ||
this.faultTime = faultTime; | ||
this.rPu = rPu; | ||
this.xPu = xPu; | ||
} | ||
|
||
@Override | ||
public String getLib() { | ||
return "NodeFault"; | ||
} | ||
|
||
@Override | ||
public void createMacroConnections(DynaWaltzContext context) { | ||
createMacroConnections(getEquipment(), BusModel.class, this::getVarConnectionsWithBus, context); | ||
} | ||
|
||
private List<VarConnection> getVarConnectionsWithBus(BusModel connected) { | ||
return List.of(new VarConnection("fault_terminal", connected.getTerminalVarName())); | ||
} | ||
|
||
@Override | ||
protected void writeEventSpecificParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { | ||
ParametersXml.writeParameter(writer, ParameterType.DOUBLE, "fault_RPu", Double.toString(rPu)); | ||
ParametersXml.writeParameter(writer, ParameterType.DOUBLE, "fault_XPu", Double.toString(xPu)); | ||
ParametersXml.writeParameter(writer, ParameterType.DOUBLE, "fault_tBegin", Double.toString(getStartTime())); | ||
ParametersXml.writeParameter(writer, ParameterType.DOUBLE, "fault_tEnd", Double.toString(getStartTime() + faultTime)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/NodeFaultEventXmlTest.java
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,40 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com/) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.xml; | ||
|
||
import com.powsybl.dynawaltz.models.events.NodeFaultEvent; | ||
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; | ||
import org.junit.jupiter.api.Test; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
class NodeFaultEventXmlTest extends AbstractDynamicModelXmlTest { | ||
|
||
@Override | ||
protected void setupNetwork() { | ||
network = EurostagTutorialExample1Factory.create(); | ||
} | ||
|
||
@Override | ||
protected void addDynamicModels() { | ||
eventModels.add(new NodeFaultEvent(network.getBusBreakerView().getBus("NGEN"), 10, 0.1, 0, 0.01)); | ||
} | ||
|
||
@Test | ||
void writeModel() throws SAXException, IOException, XMLStreamException { | ||
DydXml.write(tmpDir, context); | ||
ParametersXml.write(tmpDir, context); | ||
validate("dyd.xsd", "node_fault_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); | ||
validate("parameters.xsd", "node_fault_par.xml", tmpDir.resolve(context.getSimulationParFile())); | ||
} | ||
} |
Oops, something went wrong.