I am connecting to PLECS through XML-RPC and modifying the circuit parameters using a Python script. At the end of the simulation, I want to store the results of the final simulation step (or the last couple of cycles) in a variable in Python. How should I modify these lines of code:
model = ‘BuckConverter’
file_type = ‘.plecs’
output = plecs.simulate(model)
The optional field SolverOpts
is a struct variable that allows you to override the solver settings specified in the Simulation Parameters dialog. In particular see the OutputTimes
, OutputTimesOption
and TimeSpan
settings. These settings are described in the “Simulation Scripts + Scripted Simulation and Analysis Options” section of the PLECS Manual.
A simple example is below, where the output times are 1001 equidistant points between 0 and 0.1 seconds, however you can set the OutpuTimes
to be the data range you desire. The varL
value is also modified in the simulation script through the ModelVars
field.
varL = 10; # uH
time_span=0.1
# List of output times, using numpy for convenience in this example.
output_times_vec = np.linspace(0,time_span,1001).tolist()
simStructs = {"ModelVars": {"varL": varL * 1e-6},
"Name" : f"L = {varL}μH",
"SolverOpts": {"OutputTimes": output_times_vec,
"TimeSpan": time_span}}
output = plecs.simulate(model,simStructs)