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

Refactor bus models #261

Merged
merged 13 commits into from
Oct 18, 2023
Merged

Refactor bus models #261

merged 13 commits into from
Oct 18, 2023

Conversation

Lisrte
Copy link
Contributor

@Lisrte Lisrte commented Jul 3, 2023

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce?

Bug fix

What is the new behavior (if this is a feature change)?
Split Bus model in three based on use case :

  • connection point for equipment connection (use static id for macro connect with default bus)
  • measurement point for automaton (replace default bus model)
  • bus of equipment for omegaref (use equipment id instead of bus id for macro connect)

Does this PR introduce a breaking change or deprecate an API?

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

Lisrte added 2 commits July 3, 2023 11:31
 - connection point for equipment connection (use static id for macro connect with default bus)
 - measurement point for automaton (replace default bus model)
 - bus of equipment for omegaref (use equipment id instead of bus id for macro connect)

Signed-off-by: lisrte <[email protected]>
@Lisrte Lisrte requested a review from gautierbureau July 3, 2023 13:11
@gautierbureau
Copy link
Member

I need to look a bit more into this but I like the Connection/Measurement concepts

@gautierbureau gautierbureau self-requested a review July 7, 2023 14:24
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

91.4% 91.4% Coverage
0.0% 0.0% Duplication

@gautierbureau gautierbureau requested a review from flo-dup October 2, 2023 09:02
Lisrte added 2 commits October 2, 2023 13:57
Signed-off-by: lisrte <[email protected]>
Use 'eager initialized singleton' implementation for DefaultBus

Signed-off-by: lisrte <[email protected]>
Copy link
Contributor

@flo-dup flo-dup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor

Signed-off-by: lisrte <[email protected]>
Copy link
Contributor

@flo-dup flo-dup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, some more comments/questions to discuss!

super(staticId);
public final class DefaultBus implements EquipmentConnectionPoint {

private static final DefaultBus INSTANCE = new DefaultBus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we really should use the singleton pattern here. You're using it as an optimization, but I think the memory waste doesn't matter that much regarding the loss of readability and logic. There is one class for all the buses, which might be a bit confusing. It doesn't inherit AbstractDefaultModel, which is also unexpected. And it isn't handled with DefaultModelsHandler, but that's the limit of this PR, as you may have 3 models for the same bus.

@@ -20,7 +20,7 @@
/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public abstract class AbstractBus extends AbstractEquipmentBlackBoxModel<Bus> implements BusModel {
public abstract class AbstractBus extends AbstractEquipmentBlackBoxModel<Bus> implements EquipmentConnectionPoint, ActionConnectionPoint {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove ActionConnectionPoint here, it's not needed anymore


Optional<String> getNumCCVarName();
String getTerminalVarName();

Optional<String> getUImpinVarName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then it could be String getUImpinVarName(); and String getUpuImpinVarName(); instead of the optional

}

@Override
public void createMacroConnections(DynaWaltzContext context) throws PowsyblException {
int index = 0;
for (FrequencySynchronizedModel eq : synchronizedEquipments) {
createMacroConnections(eq, getVarConnectionsWith(eq), context, MacroConnectAttribute.ofIndex1(index));
createMacroConnections(eq.getConnectedBusId(), BusModel.class, this::getVarConnectionsWith, context, MacroConnectAttribute.ofIndex1(index));
BusOfFrequencySynchronizedModel busOf = new DefaultBusOfFrequencySynchronized(eq.getStaticId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using a default ("network") model here even if there is a specific bus model on the corresponding bs, I'm not sure that's ok for dynawo, could you confirm that @gautierbureau?

So in the dyd we might have

<dyn:macroConnector id="MC1">
    <dyn:connect var1="numcc_node_@INDEX@" var2="@@NAME@@@NODE@_numcc"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC1" id1="FREQ_SYNC" index1="0" id2="NETWORK" name2="GEN"/>

And the node mentioned in var2 would be a bus which has got a StandardBus or InfiniteBus model mapped on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have a default bus model other types of models would not work with OmegaRef

@@ -53,7 +53,7 @@ public DefaultModelsHandler() {
StaticVarCompensatorModel.class, new DefaultModelFactory<StaticVarCompensatorModel>(DefaultStaticVarCompensator::new),
TransformerModel.class, new DefaultModelFactory<TransformerModel>(DefaultTransformer::new));

powSyBlTypeToModel.put(IdentifiableType.BUS, BusModel.class);
powSyBlTypeToModel.put(IdentifiableType.BUS, ActionConnectionPoint.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a bus is always a ActionConnectionPoint once you're here, you were forced to bypass this handler for the two other bus interfaces. Ok about that, at least to move on, but could you put a comment here mentioning the two others default bus models being bypassed?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

91.1% 91.1% Coverage
0.0% 0.0% Duplication

@flo-dup flo-dup merged commit f64c6d9 into main Oct 18, 2023
6 checks passed
@flo-dup flo-dup deleted the refactor_bus_models branch October 18, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants