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. Simulations & Solvers
  4. Simulation outputs

Simulation outputs

Scheduled Pinned Locked Moved Simulations & Solvers
6 Posts 3 Posters 309 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.
  • A Offline
    A Offline
    andrea_h
    wrote on last edited by
    #1

    Hello everyone!

    I'm currently running an electrical simulation using Sim4Life. So far, I've been using the analysis options provided by S4L, but I'm curious if there's a way to directly access and manipulate the output.

    The electric field generated is of type <class 's4l_v1._api.analysiswrappers.AlgorithmOutput'>. According to the API, this represents "the output port of an algorithm, which is passed to the input connection of another algorithm. This class is the intermediate object used in a connection between two algorithms."

    Is there a way to access the field matrix without exporting it to MATLAB?

    Thanks in advance for your help!

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

      You can directly access the data of any algorithm. Here is an example to get you started:

      import numpy as np
      
      simulation = document.AllSimulations[0]
      simulation_extractor = simulation.Results()
      
      em_sensor_extractor = simulation_extractor["Overall Field"]
      
      efield_sensor = em_sensor_extractor['EM E(x,y,z,f0)']
      efield_sensor.Update()   # THIS IS NECESSARY, otherwise the algorithm output will not contain any data and there will be an allocation error when trying to access it...
      
      field_data= efield_sensor.Data
      
      grid = field_data.Grid
      print(grid.XAxis) # for example...
      
      e_field = field_data.Field(0)   # 0 is the first "snapshot", typically this is the recorded frequency
      
      print(e_field.shape)  # should be the dimensions of the numpy array
      
      num_components = e_field.shape[1]  # 3 for vectors
      
      nx, ny, nz = grid.XAxis.size, grid.YAxis.size, grid.ZAxis.size
          
      if field_data.ValueLocation == s4l.analysis.core.eValueLocation.kCellCenter:
              nx, ny, nz = nx - 1, ny - 1, nz - 1
      
       e_field_reshaped= np.reshape(e_field, (nz, ny, nx, -1))
      
      A 1 Reply Last reply
      1
      • A Offline
        A Offline
        andrea_h
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SylvainS Sylvain

          You can directly access the data of any algorithm. Here is an example to get you started:

          import numpy as np
          
          simulation = document.AllSimulations[0]
          simulation_extractor = simulation.Results()
          
          em_sensor_extractor = simulation_extractor["Overall Field"]
          
          efield_sensor = em_sensor_extractor['EM E(x,y,z,f0)']
          efield_sensor.Update()   # THIS IS NECESSARY, otherwise the algorithm output will not contain any data and there will be an allocation error when trying to access it...
          
          field_data= efield_sensor.Data
          
          grid = field_data.Grid
          print(grid.XAxis) # for example...
          
          e_field = field_data.Field(0)   # 0 is the first "snapshot", typically this is the recorded frequency
          
          print(e_field.shape)  # should be the dimensions of the numpy array
          
          num_components = e_field.shape[1]  # 3 for vectors
          
          nx, ny, nz = grid.XAxis.size, grid.YAxis.size, grid.ZAxis.size
              
          if field_data.ValueLocation == s4l.analysis.core.eValueLocation.kCellCenter:
                  nx, ny, nz = nx - 1, ny - 1, nz - 1
          
           e_field_reshaped= np.reshape(e_field, (nz, ny, nx, -1))
          
          A Offline
          A Offline
          andrea_h
          wrote on last edited by
          #4

          @Sylvain Hello!
          Thank you so much!
          So as far as I understand the coordinates are located on the grid. Which I guess depends on the meshes for the simulation.

          On the other hand, the e_field is store in .Field(0) which holds a vector for each point.

          And the reshape np.reshape(e_field, (nz, ny, nx, -1)). Its because the first coordinate with respect to the e_field is in the z axis?

          1 Reply Last reply
          0
          • brynB Offline
            brynB Offline
            bryn
            ZMT
            wrote on last edited by bryn
            #5

            it is because the data is ordered using x-fastest indexing. This means (for a scalar field)

            • if you increase the index by 1, you move one position in x direction (unless you are at the boundary).
            • if you move by nx, you move by one position in y direction (the stride is nx)
            • if you move by nx * nz, you move by one position in z direction (the stride is nx * ny)
            1 Reply Last reply
            0
            • A Offline
              A Offline
              andrea_h
              wrote on last edited by
              #6

              Great! Goit it, thank you so much.
              One last question regarding where the simulation outputs are located and saved. The coordinates of the voxelized entities where can be found?

              Thank you so much for your time :)

              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