sogno-platform / dpsim

Real-time power system simulator including powerflow, (dynamic) phasors and EMT
https://sogno.energy/dpsim/
Mozilla Public License 2.0
67 stars 49 forks source link

Ensure that virtual nodes of subcomponents are created before function `collectVirtualNodes` #270

Open martinmoraga opened 6 months ago

martinmoraga commented 6 months ago

When a component has subcompoenents with virtual nodes, the constructor of the subcomponents has to be called before the function initializeFromNodesAndTerminals (for example in the constructor) of the parent component, otherwise the subcomponent will not be correctly stamped in the system matrix. That is because the simulation structure looks like the following:

  1. Simulator class calls MNASolver->initialize
  2. MNASolver->initialize calls MNASolver->collectVirtualNodes
  3. MNASolver->initialize calls MNASolver->initializeComponents
  4. MNASolver->initializeComponents calls MNAComp->initializeFromNodesAndTerminals
  5. initializeFromNodesAndTerminals of the parent component is called, which sometimes calls the constructor of the subComponents (e.g. PiLine). However, if the subComponent adds virtual nodes (e.g. a VoltageSource), the previous call of MNASolver->collectVirtualNodes is not going to consider the virtual nodes of the new subcomponent which leads to a wrong stamp of the system matrix.

We should add a function (e.g. createSubComponents) which is called before MNASolver->collectVirtualNodes to ensure that virtualNodes are created before the function MNASolver->collectVirtualNodes is called