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. How to get the bounding box of the computational domain of a given simulation from Python?

How to get the bounding box of the computational domain of a given simulation from Python?

Scheduled Pinned Locked Moved Solved Python API
pythongrid
5 Posts 3 Posters 952 Views 3 Watching
  • 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.
  • SylvainS Offline
    SylvainS Offline
    Sylvain
    ZMT
    wrote on last edited by
    #1

    Let's say I have a simulation object and that its grid is already up-to-date. How can I find the locations of the 6 boundary planes? (or other grid properties, as those shown in the Options window).

    0_1521116401535_a793114e-bdd1-416d-aec5-02a02e9a9852-image.png

    1 Reply Last reply
    0
    • PeterStijnmanP Offline
      PeterStijnmanP Offline
      PeterStijnman
      wrote on last edited by
      #2

      So I only know how to get the grid settings when the simulation already has results. Don't know if this is what you are looking for, but I'll post it anyway :)

      import s4l_v1.document as doc
      import numpy as np 
      
      #get all the simulations
      sims = list(doc.AllSimulations)
      
      #select a simulation here
      firstSim = sims[0]
      
      #get the results
      result_firstSim = firstSim.Results()
      result_firstSim = result_firstSim['Overall Field']
      
      #get the grid settings
      GridData = result_firstSim[0]
      GridData.Update()
      GridData = GridData.Data.Grid
      
      #get the axis
      X = GridData.XAxis
      Y = GridData.YAxis
      Z = GridData.ZAxis
      
      #create the matrix that is shown in the options mene
      numGridLines = GridData.Dimensions
      numCells     = np.array(numGridLines) -1
      minStep = np.array([np.min(np.diff(X)),np.min(np.diff(Y)),np.min(np.diff(Z))])*1000
      maxStep = np.array([np.max(np.diff(X)),np.max(np.diff(Y)),np.max(np.diff(Z))])*1000
      boundaryMin = np.array([X[0],Y[0],Z[0]])*1000
      boundaryPlus = np.array([X[-1],Y[-1],Z[-1]])*1000
      
      MainGridOptionsArray = np.array([numCells,numGridLines,minStep,maxStep,boundaryMin,boundaryPlus])
      

      Maybe it is also possible to get this data without running the simulation.

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

        I was indeed looking for a way to access this data before running the simulation (so that I can detect in advance that the simulation is likely to be very slow, or to fail, for this or that reason). So your solution does not yet solve my problem.

        But thanks a lot for contributing: this piece of code will for sure end up being useful to someone!

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CEiber
          wrote on last edited by
          #4

          one thing you could try is

          import XCoreModeling as xcm
          
          # get the simulation 
          sim = doc.AllSimulations[0]
          
          # get bounding box of everything in your simulation
          bounding_planes = xcm.GetBoundingBox(list(sim.AllComponents))
          
          # returns a 2-tuple of Vec3 which give the opposite corners of the bounding box
          
          # get the padding added by the grid settings
          grid_settings = sim.GlobalGridSettings
          
          for xyz in range(3):
              grid_bounds[0][xyz] -= grid_settings.BottomPadding[xyz]
              grid_bounds[1][xyz] += grid_settings.TopPadding[xyz]
          
          

          This should be accessible once the simulation has been set up, but before it has been run. Hope this helps!

          SylvainS 1 Reply Last reply
          2
          • C CEiber

            one thing you could try is

            import XCoreModeling as xcm
            
            # get the simulation 
            sim = doc.AllSimulations[0]
            
            # get bounding box of everything in your simulation
            bounding_planes = xcm.GetBoundingBox(list(sim.AllComponents))
            
            # returns a 2-tuple of Vec3 which give the opposite corners of the bounding box
            
            # get the padding added by the grid settings
            grid_settings = sim.GlobalGridSettings
            
            for xyz in range(3):
                grid_bounds[0][xyz] -= grid_settings.BottomPadding[xyz]
                grid_bounds[1][xyz] += grid_settings.TopPadding[xyz]
            
            

            This should be accessible once the simulation has been set up, but before it has been run. Hope this helps!

            SylvainS Offline
            SylvainS Offline
            Sylvain
            ZMT
            wrote on last edited by
            #5

            @CEiber That's a very good idea, thanks a lot!

            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