Extracting Inductance value from total magnetic energy using python script
-
Hi all,
I have been trying to use python scripting to automatically set up a number of simulations with different coil arrangements and measure the total magnetic energy to calculate the mutual inductances. However, the only way that I know how to extract the magnetic energy is through the table viewer (as described in the 'Measuring Self-Inductance' tutorial), and when I try to convert this to python, there is an error saying that table viewer is not implemented in python.
I was wondering if there was any way to directly extract the magnetic energy from the simulation. I am using the unstructured magneto static biot savart solver.
Many thanks for your help. -
You need to get the data from the Magnetic Energy Evaluator, i.e., from the "input" of the Table Viewer, not from the Table Viewer itself (which does nothing else than viewing the data...).
Here is an example code:
import numpy import s4l_v1.analysis as analysis import s4l_v1.document as document import s4l_v1.model as model # Creating the analysis pipeline # Adding a new SimulationExtractor simulation = document.AllSimulations["Self Inductance"] simulation_extractor = simulation.Results() # Adding a new EmSensorExtractor em_sensor_extractor = simulation_extractor["Overall Field"] document.AllAlgorithms.Add(em_sensor_extractor) # Adding a new MagneticEnergyEvaluator inputs = [em_sensor_extractor.Outputs["B(x,y,z,f0)"], em_sensor_extractor.Outputs["EM H(x,y,z,f0)"]] magnetic_energy_evaluator = analysis.em_evaluators.MagneticEnergyEvaluator(inputs=inputs) magnetic_energy_evaluator.UpdateAttributes() document.AllAlgorithms.Add(magnetic_energy_evaluator) # perform the actual computation, throw an exception if an error occurs assert magnetic_energy_evaluator.Update(), 'ERROR, failed to compute W' # get the data mag_data = magnetic_energy_evaluator.Outputs["Magnetic Energy"].Data frequency = mag_data.Axis[0] magnetic_energy = mag_data.GetComponent(0)[0] print('Total Magnetic Energy: {:.3g}J, @{}Hz'.format(magnetic_energy, frequency))
-
Thank you for your prompt reply! That's helped a lot, I didn't know how to implement the 'magnetic_energy_evaluator.Outputs["Magnetic Energy"].Data' or the 'mag_data.GetComponent(0)[0]' lines.
I realise now that I probably should have posted the code which I had attempted already. Thanks for helping me anyway!