Skip to content

Refactor Microgrid Examples to Facilitate Code Reuse - #551

Open
abdourahmanbarry wants to merge 8 commits into
developfrom
abdou/microgrid_refactor
Open

Refactor Microgrid Examples to Facilitate Code Reuse#551
abdourahmanbarry wants to merge 8 commits into
developfrom
abdou/microgrid_refactor

Conversation

@abdourahmanbarry

@abdourahmanbarry abdourahmanbarry commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Description

In this pull request, we separated the construction of the microgrid network from the examples to improve code reuse.

This is the first of four stacked pull requests that split PR #492 into smaller, more manageable chunks.

Proposed changes

Two functions, buildScaleMicrogridNetwork and assembleSystem, were introduced to build the microgrid network and add the components of the network to SystemPowerElectronicsModel, respectively. These functions are then used to replace the network construction and the system model assembly code in all examples. This helps facilitate code reuse as more examples rely on this model.

Checklist

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

@abdourahmanbarry abdourahmanbarry self-assigned this Aug 26, 2026
@abdourahmanbarry abdourahmanbarry changed the title Abdou/microgrid refactor Refactor Microgrid Examples to Facilitate Code Reuse Aug 26, 2026
Comment thread examples/PowerElectronics/Microgrid/Microgrid.cpp Outdated
Comment thread examples/PowerElectronics/PowerElectronicsExamplesHelper/MicrogridNetwork.hpp Outdated
* @note Components are dynamically allocated and their pointers are stored
* in the corresponding network component vectors.
*/
inline void buildScaleMicrogridNetwork(ScaleMicrogridNetwork& network)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few thoughts:

  1. This should be a method on ScaleMicrogridNetwork, not a function.

  2. This should probably just be done in the constructor. I don't see any reason to construct a ScaleMicrogridNetwork without calling this after.

  3. This should be implemented in an implementation file, not inline in a header file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated for 1 and 2. I do not think 3 is necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

3 may be helpful to build a shared library for this and link to it. That would also help with the #include and remove the need for target_include_directories(something PRIVATE {CMAKE_CURRENT_SOURCE_DIR}/..).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

cc @alexander-novo @nkoukpaizan I have added it as a library and removed the target_include_directories(something PRIVATE {CMAKE_CURRENT_SOURCE_DIR}/..). Let me know if it is still necessary to split it into header and implementation file.

* @note This function only assembles the network into the system model. It
* does not call PowerElectronicsModel::allocate().
*/
inline void assembleSystem(ScaleMicrogridNetwork& network, GridKit::PowerElectronicsModel<real_type, index_type>& sys_model)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similarly to above, this should be a method and implemented in an implementation file.

@abdourahmanbarry abdourahmanbarry Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think having this in a header file should be fine.

Comment thread examples/PowerElectronics/ScaleMicrogrid/CMakeLists.txt Outdated
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/microgrid_refactor branch from bd0a1b9 to e59d353 Compare August 27, 2026 21:02
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/microgrid_refactor branch from 8b19f1b to 44e9da0 Compare August 28, 2026 19:19
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