Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. Extracting Inductance value from total magnetic energy using python script

Extracting Inductance value from total magnetic energy using python script

Scheduled Pinned Locked Moved Python API
3 Posts 2 Posters 451 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jexyll_S
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1
    • SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      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))
      
      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jexyll_S
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Search