Cloning Components in PowerElectronics Module - #552
Conversation
ab34f6c to
1802d2f
Compare
1802d2f to
6e29664
Compare
superwhiskers
left a comment
There was a problem hiding this comment.
this change looks pretty inoffensive. one comment, however:
why are we adding isCloneable for only one component (the Bus) to not support cloning? additionally, might it be better to implement this by using a subclass of CircuitComponent that implies cloneability, or something else? it's not like cloning is going to change at runtime, so it might be cleaner to add some structural way to ensure a component being used supports cloning without doing a runtime check by calling isCloneable.
nkoukpaizan
left a comment
There was a problem hiding this comment.
A few comments. At a higher level:
- I don't see anything preventing calling the copy constructor on non-clonable components.
- It's not clear to me what is the intended functionality of the clones. More documentation would be helpful.
| template <typename ComponentT, typename ScalarT, typename IdxT> | ||
| bool verifyComponentClone(ComponentT& component) |
There was a problem hiding this comment.
This should be in the Testing namespace. Perhaps a private method of CircuitComponentCloneTests?
|
|
||
| CircuitComponent() = default; | ||
|
|
||
| CircuitComponent(const CircuitComponent& other) |
There was a problem hiding this comment.
Please add some documentation for this constructor.
There was a problem hiding this comment.
I have added more documentation to this.
| template <class ScalarT, typename IdxT> | ||
| CircuitComponent<ScalarT, IdxT>* Capacitor<ScalarT, IdxT>::clone() const | ||
| { | ||
| return new Capacitor<ScalarT, IdxT>(*this); |
There was a problem hiding this comment.
We are currently not checking that the components are clonable before cloning...
There was a problem hiding this comment.
I expect a user to call isCloneable before calling clone.
There was a problem hiding this comment.
I have gotten rid of isCloneable. Now non-cloneable classes just throw an error as suggested by @alexander-novo .
I added clone to I think having a cloneable subclass such as |
|
I talked to @abdourahmanbarry in person. I think it makes a lot more sense to have all components be cloneable and remove the The problem with a |
I am using clone as part of my implementation for partition interfaces in the next pull request on this stack. I have also updated the implementation of the copy constructor such that it should be okay to call it independently of the clone. Let me know if these changes look good. |
Description
This pull request implements clone functionality for components in the
PowerElectronicsmodule. This gives us the ability to create independent copies of components such that modifications to one do not affect the other.Proposed changes
Each component implements the
isCloneableandclonemethods. TheisCloneablemethod returnstrueif the component is cloneable andfalseotherwise. Theclonemethod returns a pointer to a new object with the same state as the component from which it was cloned. After cloning a component, the user should set the data pointers for the clone.Checklist
-Wall -Wpedantic -Wconversion -Wextra.Further Comments
This functionality is useful for the partitioning implementation.