Creating a simulation batch file for multiport simulation

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

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:

for sem in sem_files:
	for sim in SEMCAD.simulations.List:
		if not sim.HasResults():
			if not sim.HasVoxels():

			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 = 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")

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



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....