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 create voxels using a script?

How to create voxels using a script?

Scheduled Pinned Locked Moved Python API
2 Posts 2 Posters 149 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.
  • L Offline
    L Offline
    lucky_lin
    wrote on last edited by
    #1

    Hi, I checked the Python code for the simulation using the To Python option, but I found that running the script alone only completed the basic setup of the solver and did not create the voxels or save files, so it cannot run successfully. Can I use the script to complete the entire simulation and post-processing process?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lauener
      wrote on last edited by lauener
      #2

      Hi!
      In all the tutorial python scripts this is shown. Within the python scripter you can click on the folder icon and choose "Open Example Script". There you will find lots of python scripts, that show how this is done.
      Here a small excerpt from the script "tutorial_emlf_parallel_plate.py":

      sim = CreateSimulation()
      s4l_v1.document.AllSimulations.Add(sim)
      sim.UpdateGrid()
      sim.CreateVoxels(path)
      sim.RunSimulation(wait=True)
      

      I suggest always creating a simulation, and an analysis function, that is then called in the RunTutorial function. It's best to then also create a main:

      def RunTutorial( path ):
      
      	import s4l_v1.document
      	s4l_v1.document.New()
      
      	CreateModel()
      	sim = CreateSimulation()
      
      	s4l_v1.document.AllSimulations.Add(sim)
      	sim.UpdateGrid()
      	sim.CreateVoxels(path)
      	sim.RunSimulation(wait=True)
      
      	AnalyzeSimulation(sim)
      
      def main(data_path=None, project_dir=None):
      	"""
      		data_path = path to a folder that contains data for this simulation (e.g. model files)
      		project_dir = path to a folder where this project and its results will be saved
      	"""
      	import sys
      	import os
      	print("Python ", sys.version)
      	print("Running in ", os.getcwd(), "@", os.environ['COMPUTERNAME'])
      
      	if project_dir is None:
      		project_dir = os.path.expanduser(os.path.join('~', 'Documents', 's4l_python_tutorials') )
      
      	if not os.path.exists(project_dir):
      		os.makedirs(project_dir)
      
      	fname = os.path.splitext(os.path.basename(_CFILE))[0] + '.smash'
      	project_path = os.path.join(project_dir, fname)
      
      	RunTutorial( project_path )
      
      if __name__ == '__main__':
      	main()
      
      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