Interrupted simulation multiple sources

Hi everyone,

for a research project I’m working on control strategies for PFC circuits and therefore I need to simulate a passive circuit in conjunction with two half bridges.
Problem is that I need the simulation to interact with a python script since I need to calculate the control signals of the two half bridges externally and thus the simualtion flow is as follows.

First, I need to initialize the simulation which basically means that I need to sample the amplitude and phase of a sinusodial source representing the grid voltage and the component values and initial conditions of the passive components. Next, I need to run the simulation in chunks where I first calculate the four control signals of the half bridges based on the current and voltage signals of the passive circuit followed by a chunk of transient simulation for a given time span (sample rate of the controller).

I tried to implement this flow but I unfortunately I struggle with the following issues.

a) Phase of the AC source:
I tired SinusoidalVoltageSource() but I failed to specify a phase offset. Altough it’s base class SinusoidalMixin() offers a delay attribute, it seems that it just enables the source after a given time and thus this isn’t the desired behaviour for my purpose. Alternatively, I defined my own grid voltage using a NgSpiceShared object according …/examples/ngspice-shared/external-source.html.
This essential does the trick for me but leaves with the next problem.

b) Multiple External Sources:
Give the simulation flow above I need to run the simulation with at least four external sources, two for every half bridge, and five if I define the grid voltage also as external source. So I wonder how I define multiple shared objects.

c) Setting the initial conditions
Since I run the simulation in chunks I wonder if I have to preload the nodes with the latest values and I need to run the simulation with start_time=0 and end_time=timespan according the controller’s sample rate or are the states kept internally and I need just to run the simulation with start_time=(k-1)timespan, end_time=ktimespan in order to run the kth simulation chunk.

Any help is kindly appreciated!