-
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.
Rename DynaWaltzCurve to DynawoCurve
Add DynawoCurveBuilder Signed-off-by: lisrte <[email protected]>
- Loading branch information
Showing
13 changed files
with
324 additions
and
55 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* 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/. | ||
*/ | ||
|
||
package com.powsybl.dynawaltz; | ||
|
||
import com.powsybl.dynamicsimulation.Curve; | ||
|
@@ -14,12 +13,13 @@ | |
/** | ||
* @author Mathieu Bague {@literal <[email protected]>} | ||
*/ | ||
public class DynaWaltzCurve implements Curve { | ||
//TODO switch to record | ||
public class DynawoCurve implements Curve { | ||
|
||
private final String dynamicModelId; | ||
private final String variable; | ||
|
||
public DynaWaltzCurve(String dynamicModelId, String variable) { | ||
public DynawoCurve(String dynamicModelId, String variable) { | ||
this.dynamicModelId = Objects.requireNonNull(dynamicModelId); | ||
this.variable = Objects.requireNonNull(variable); | ||
} | ||
|
81 changes: 81 additions & 0 deletions
81
dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawoCurveBuilder.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,81 @@ | ||
/** | ||
* Copyright (c) 2024, 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; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.dynawaltz.builders.BuilderReports; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
public class DynawoCurveBuilder { | ||
|
||
private static final String DEFAULT_DYNAMIC_MODEL_ID = "NETWORK"; | ||
|
||
private final ReportNode reportNode; | ||
private boolean isInstantiable = true; | ||
private String dynamicModelId; | ||
private String staticId; | ||
private String variable; | ||
private String[] variables; | ||
|
||
public DynawoCurveBuilder(ReportNode reportNode) { | ||
this.reportNode = reportNode; | ||
} | ||
|
||
public DynawoCurveBuilder dynamicModelId(String dynamicModelId) { | ||
this.dynamicModelId = dynamicModelId; | ||
return this; | ||
} | ||
|
||
public DynawoCurveBuilder staticId(String staticId) { | ||
this.staticId = staticId; | ||
return this; | ||
} | ||
|
||
public DynawoCurveBuilder variables(String[] variables) { | ||
this.variables = variables; | ||
return this; | ||
} | ||
|
||
public DynawoCurveBuilder variable(String variable) { | ||
this.variable = variable; | ||
return this; | ||
} | ||
|
||
private String getId() { | ||
return dynamicModelId != null ? dynamicModelId : staticId; | ||
} | ||
|
||
private void checkData() { | ||
if (staticId != null && dynamicModelId != null) { | ||
BuilderReports.reportFieldConflict(reportNode, "dynamicModelId", "staticId"); | ||
} | ||
if (variable == null) { | ||
BuilderReports.reportFieldNotSet(reportNode, "variable"); | ||
isInstantiable = false; | ||
} | ||
} | ||
|
||
private boolean isInstantiable() { | ||
checkData(); | ||
if (!isInstantiable) { | ||
BuilderReports.reportCurveInstantiationFailure(reportNode, getId()); | ||
} | ||
return isInstantiable; | ||
} | ||
|
||
//TODO handle list | ||
public DynawoCurve build() { | ||
if (isInstantiable()) { | ||
return dynamicModelId != null ? new DynawoCurve(dynamicModelId, variable) | ||
: new DynawoCurve(DEFAULT_DYNAMIC_MODEL_ID, staticId + "_" + variable); | ||
} | ||
return null; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawoCurvesBuilder.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,109 @@ | ||
/** | ||
* Copyright (c) 2024, 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; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.dynamicsimulation.Curve; | ||
import com.powsybl.dynawaltz.builders.BuilderReports; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
public class DynawoCurvesBuilder { | ||
|
||
private static final String DEFAULT_DYNAMIC_MODEL_ID = "NETWORK"; | ||
|
||
private final ReportNode reportNode; | ||
private boolean isInstantiable = true; | ||
private String dynamicModelId; | ||
private String staticId; | ||
private String[] variables; | ||
|
||
public DynawoCurvesBuilder(ReportNode reportNode) { | ||
this.reportNode = reportNode; | ||
} | ||
|
||
public DynawoCurvesBuilder dynamicModelId(String dynamicModelId) { | ||
this.dynamicModelId = dynamicModelId; | ||
return this; | ||
} | ||
|
||
public DynawoCurvesBuilder staticId(String staticId) { | ||
this.staticId = staticId; | ||
return this; | ||
} | ||
|
||
public DynawoCurvesBuilder variables(String... variables) { | ||
this.variables = variables; | ||
return this; | ||
} | ||
|
||
//TODO switch to deprecated ? | ||
public DynawoCurvesBuilder variable(String variable) { | ||
this.variables = new String[]{variable}; | ||
return this; | ||
} | ||
|
||
private String getId() { | ||
return dynamicModelId != null ? dynamicModelId : staticId; | ||
} | ||
|
||
private void checkData() { | ||
if (staticId != null && dynamicModelId != null) { | ||
BuilderReports.reportFieldConflict(reportNode, "dynamicModelId", "staticId"); | ||
} | ||
if (variables == null) { | ||
BuilderReports.reportFieldNotSet(reportNode, "variables"); | ||
isInstantiable = false; | ||
} else if (variables.length == 0) { | ||
BuilderReports.reportEmptyList(reportNode, "variables"); | ||
isInstantiable = false; | ||
} | ||
} | ||
|
||
private boolean isInstantiable() { | ||
checkData(); | ||
if (!isInstantiable) { | ||
BuilderReports.reportCurveInstantiationFailure(reportNode, getId()); | ||
} | ||
return isInstantiable; | ||
} | ||
|
||
public void add(Consumer<Curve> curveConsumer) { | ||
if (isInstantiable()) { | ||
boolean hasDynamicModelId = dynamicModelId != null; | ||
String id = hasDynamicModelId ? dynamicModelId : DEFAULT_DYNAMIC_MODEL_ID; | ||
for (String variable : variables) { | ||
curveConsumer.accept(new DynawoCurve(id, hasDynamicModelId ? variable : staticId + "_" + variable)); | ||
} | ||
} | ||
} | ||
|
||
public List<Curve> buildAlt() { | ||
List<Curve> curves = new ArrayList<>(); | ||
add(curves::add); | ||
return curves; | ||
} | ||
|
||
public List<DynawoCurve> build() { | ||
if (isInstantiable()) { | ||
boolean hasDynamicModelId = dynamicModelId != null; | ||
String id = hasDynamicModelId ? dynamicModelId : DEFAULT_DYNAMIC_MODEL_ID; | ||
return Arrays.stream(variables) | ||
.map(v -> new DynawoCurve(id, hasDynamicModelId ? v : staticId + "_" + v)) | ||
.toList(); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
Oops, something went wrong.