Skip to content

Refactor PhasorDynamics hierarchy to consolidate duplicate code#386

Draft
PhilipFackler wants to merge 1 commit intodevelopfrom
PhilipFackler/phasor-hierarchy-refactor
Draft

Refactor PhasorDynamics hierarchy to consolidate duplicate code#386
PhilipFackler wants to merge 1 commit intodevelopfrom
PhilipFackler/phasor-hierarchy-refactor

Conversation

@PhilipFackler
Copy link
Copy Markdown
Collaborator

@PhilipFackler PhilipFackler commented Apr 30, 2026

Description

Proposed changes

This inserts a class (ConnectedElement) into the phasor dynamics hierarchy which will manage signal node ports and monitors. This new class takes its child class as its template parameter and uses traits to get more detailed type information (for variable enums, etc...) and also to customize the inheritance graph. Each leaf node device type must inherit from ConnectedElementTraits with itself as the template argument and define a customization of ConnectedElementTraits with the appropriate type information. The InterfaceT member determines which interface is inherited. For example...

For Bus

    template <typename ScalarP, typename IdxP>
    struct ConnectedElementTraits<Bus<ScalarP, IdxP>>
    {
      using BusT = Bus<ScalarP, IdxP>;

      using ElementT           = BusT;
      using ScalarT            = ScalarP;
      using IdxT               = IdxP;
      using RealT              = typename ScalarTraits<ScalarT>::RealT;
      using ModelDataT         = BusData<RealT, IdxT>;
      using InternalVariablesT = BusInternalVariables;
      using ExternalVariablesT = BusExternalVariables;
      using InterfaceT         = BusBase<ScalarT, IdxT>;  // using BusBase interface
    };

    template <typename ScalarP, typename IdxP>
    class Bus : public ConnectedElement<Bus<ScalarP, IdxP>>
    { /*...*/ };

// The inheritance graph for Bus is then:
// Bus <- ConnectedElement<Bus> <- BusBase <- GridElement <- Model::Evaluator

And for Branch

    template <typename ScalarP, typename IdxP>
    struct ConnectedElementTraits<Branch<ScalarP, IdxP>>
    {
      using BranchT = Branch<ScalarP, IdxP>;

      using ElementT           = BranchT;
      using ScalarT            = ScalarP;
      using IdxT               = IdxP;
      using RealT              = typename ScalarTraits<ScalarT>::RealT;
      using ModelDataT         = BranchData<RealT, IdxT>;
      using InternalVariablesT = BranchInternalVariables;
      using ExternalVariablesT = BranchExternalVariables;
      using InterfaceT         = Component<ScalarT, IdxT>;
    };

    template <typename ScalarP, typename IdxP>
    class Branch : public ConnectedElement<Branch<ScalarP, IdxP>>
    { /* ... */ };

// The inheritance graph for Branch is then:
// Branch <- ConnectedElement<Branch> <- Component <- GridElement <- Model::Evaluator

Checklist

  • All tests pass.
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • [1] The new code follows GridKit™ style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • [2] The feature branch is rebased with respect to the target branch.
  • I have updated CHANGELOG.md to reflect the changes in this PR. If this is a minor PR that is part of a larger fix already included in the file, state so.
  1. This PR changes the style guidelines with respect to template parameters and type aliases.

  2. This PR was developed on top of Refactoring phasor dynamics constituent models #381 and will need to be rebased.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining
why you chose the solution you did and what alternatives you considered, etc...

@PhilipFackler PhilipFackler force-pushed the PhilipFackler/phasor-hierarchy-refactor branch from e65a100 to d0bcf0a Compare April 30, 2026 19:00
@PhilipFackler PhilipFackler force-pushed the PhilipFackler/phasor-hierarchy-refactor branch from d0bcf0a to e2d066a Compare May 1, 2026 16:01
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.

1 participant