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. Creating a simulation batch file for multiport simulation

Creating a simulation batch file for multiport simulation

Scheduled Pinned Locked Moved Python API
2 Posts 2 Posters 578 Views 2 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.
  • S Offline
    S Offline
    Spuky
    wrote on last edited by
    #1

    Hello everybody,

    When trying to convert one of my SEMCAD X 14.8 scripts which loops though the certain directory at the hard-drive, opens all simulations, check if simulation has a EM results and if not add it to the simulation *.batch file (code bellow)

    import SEMCAD
    import os
    import time
    import PostPro
    import numpy, scipy
    import math
    import XNumPy
    
    clear_console()
    os.chdir(sys.path[0])
    test_dir = os.getcwd() # Directory to check - current directory where script is located
    
    ### List of all simulation files (*.sem) in directory
    sem_files = []
    mat_files = []
    add_string = ''
    for root, dirs, files in os.walk(test_dir):
    	if len(files)>0:
    		for ff in files:
    			if '.sem' in ff and add_string in ff:
    				sem_files.append(root+'\\'+ff)
    
    for sem in sem_files:
    	SEMCAD.OpenProject(sem)
    	SEMCAD.SetSimulationMode()
    	for sim in SEMCAD.simulations.List:
    		if not sim.HasResults():
    			if not sim.HasVoxels():
    				sim.ComputeVoxels()
    			sim.PrepareForRemoteSolver()
    
    			file_name = 'c:\\Sim_Batch.bat'
    			project_path_name = SEMCAD.GetProjectPath()
    			if os.path.isfile(file_name):
    				file = open(file_name,"a")
    				file.write("\""+SEMCAD.Preferences.Solver+"\" "+"\t"+" \""+sim.GetSolverInputFilePath()+"\"\n")
    				file.close()
    			else:
    				file = open(file_name,"w")
    				file.write("REM This file was automatically generated\n")
    				file.write("REM by the BatchFile Function of SEMCAD X.\n")
    				file.write("REM \n\n")
    				file.write("\""+SEMCAD.Preferences.Solver+"\" "+"\t"+" \""+sim.GetSolverInputFilePath()+"\"\n")
    			file.close()
    

    I struggle in Sim4Life in getting the list of input files *.h5 files from multi-port simulation. Would somebody knows how to do that?

    Thanks,

    Spuky

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

      This should work:

      [outputname.replace('Output', 'Input') for outputname in [sim.GetOutputFileName(i) for i in range(sim.NumberOfResults)]]
      

      however, I could not find a way to programmatically generate the input files themselves, in case they are missing.

      First of all, the WriteInputFile() function is only available via sim.raw.WriteInputFile() (instead of simply sim.WriteInputFile()) and it only generates the input file for the first port (which is probably a bug in the API).

      One possible workaround (albeit not entirely satisfactory) is to call sim.RunSimulation(wait_for_submission=True) for all the multiport simulations, which will ensure that all input files are generated and all simulations are enqueued in ARES. You can then manually kill all of these submitted jobs from the Task manager of Sim4Life....

      1 Reply Last reply
      1
      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