-
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.
* Refactor GroovyExtension hierarchy * Refactor GeneratorSynchronous * Add Model Builder hierarchy * Rename classes Signed-off-by: lisrte <laurent.issertial@rte-france.com>
- Loading branch information
Showing
20 changed files
with
362 additions
and
431 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractDynamicModelBuilder.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,49 @@ | ||
/* | ||
* 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 | ||
|
||
import com.powsybl.dsl.DslException | ||
import com.powsybl.dynamicsimulation.DynamicModel | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
abstract class AbstractDynamicModelBuilder implements ModelBuilder<DynamicModel> { | ||
|
||
String dynamicModelId | ||
String staticId | ||
String parameterSetId | ||
|
||
void dynamicModelId(String dynamicModelId) { | ||
this.dynamicModelId = dynamicModelId | ||
} | ||
|
||
void staticId(String staticId) { | ||
this.staticId = staticId | ||
} | ||
|
||
void parameterSetId(String parameterSetId) { | ||
this.parameterSetId = parameterSetId | ||
} | ||
|
||
void checkData() { | ||
if (!staticId) { | ||
throw new DslException("'staticId' field is not set") | ||
} | ||
if (!parameterSetId) { | ||
throw new DslException("'parameterSetId' field is not set") | ||
} | ||
if (!dynamicModelId) { | ||
dynamicModelId = staticId | ||
} | ||
} | ||
|
||
@Override | ||
abstract DynamicModel build(); | ||
} |
40 changes: 40 additions & 0 deletions
40
...dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractPowsyblDynawoGroovyExtension.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,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.dsl | ||
|
||
import com.powsybl.dynawaltz.DynaWaltzProvider | ||
|
||
import java.util.function.Consumer | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
abstract class AbstractPowsyblDynawoGroovyExtension<T> { | ||
|
||
protected List<String> modelTags | ||
|
||
abstract protected ModelBuilder<T> createBuilder(String currentTag) | ||
|
||
String getName() { | ||
return DynaWaltzProvider.NAME | ||
} | ||
|
||
void load(Binding binding, Consumer<T> consumer) { | ||
modelTags.forEach { | ||
binding.setVariable(it, { Closure<Void> closure -> | ||
def cloned = closure.clone() | ||
ModelBuilder<T> builder = createBuilder(it) | ||
cloned.delegate = builder | ||
cloned() | ||
consumer.accept(builder.build()) | ||
}) | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/ModelBuilder.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 com.powsybl.dynawaltz.dsl | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
interface ModelBuilder<T> { | ||
|
||
T build() | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...ltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/AbstractEventModelBuilder.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,50 @@ | ||
/* | ||
* 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.powsybl.dsl.DslException | ||
import com.powsybl.dynamicsimulation.EventModel | ||
import com.powsybl.dynawaltz.dsl.ModelBuilder | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
abstract class AbstractEventModelBuilder implements ModelBuilder<EventModel> { | ||
|
||
String eventModelId | ||
String staticId | ||
double startTime | ||
|
||
void eventModelId(String eventModelId) { | ||
this.eventModelId = eventModelId | ||
} | ||
|
||
void staticId(String staticId) { | ||
this.staticId = staticId | ||
} | ||
|
||
void startTime(double startTime) { | ||
this.startTime = startTime | ||
} | ||
|
||
void checkData() { | ||
if (!staticId) { | ||
throw new DslException("'staticId' field is not set") | ||
} | ||
if (!startTime) { | ||
throw new DslException("'startTime' field is not set") | ||
} | ||
if (!eventModelId) { | ||
eventModelId = staticId | ||
} | ||
} | ||
|
||
@Override | ||
abstract EventModel build(); | ||
} |
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
Oops, something went wrong.