# Simulation ## InitFDTD ```{function} InitFDTD(varargin) ``` Full definition: ```{code-block} matlab function FDTD = InitFDTD(varargin) ``` Initialize the FDTD data-structure. optional field arguments for usage with openEMS: - NrTS: max. number of timesteps to simulate (e.g. default=1e9) - EndCriteria: end criteria, e.g. 1e-5, simulations stops if energy has decayed by this value (<1e-4 is recommended, default=1e-5), 0: none, run all timesteps - MaxTime: max. simulated time in seconds (physical time, not wall-clock); typically nanoseconds for RF - OverSampling: nyquist oversampling of the time domain dumps and probes (default 4). Frequency-domain dumps/probes accumulate at the plain Nyquist rate unless a box sets its own 'OverSampling' via CSXCAD's AddDump/AddProbe. - CoordSystem: choose coordinate system (0 Cartesian, 1 Cylindrical) - MultiGrid: define a cylindrical sub-grid radius - TimeStep: force to use a given timestep (dangerous!) - TimeStepFactor: reduce the timestep by a given factor (>0 to <=1) - TimeStepMethod: 1 or 3 chose timestep method (1=CFL, 3=Rennigs (default)) - CellConstantMaterial: set to 1 to assume a material is constant inside a cell (material probing in cell center). Must be set for SAR: the SAR calculation uses one cell-center conductivity and density per cell, which only matches the material the FDTD run stepped with if the cells are homogeneous. IEC/IEEE 62704-1 also requires one material per voxel. examples: %default init with 1e9 max. timesteps and -50dB end-criteria FDTD = InitFDTD(); %init with 1e6 max. timesteps and -60dB end-criteria FDTD = InitFDTD('NrTS', 1e6, 'EndCriteria', 1e-6); %cylindrical FDTD simulation FDTD = InitFDTD('CoordSystem', 1); See also InitCSX ----------------------- author: Thorsten Liebig (c) 2010-2013 ## InitCylindricalFDTD ```{function} InitCylindricalFDTD(NrTS, endCrit, varargin) ``` Full definition: ```{code-block} matlab function FDTD = InitCylindricalFDTD(NrTS, endCrit, varargin) ``` see also InitFDTD e.g FDTD = InitCylindricalFDTD(5e5,1e-6,'OverSampling',10) WARNING: This function is depreciated, use InitFDTD with 'CoordSystem',1 e.g.: InitFDTD(5e5,1e-6,'OverSampling',10, 'CoordSystem',1) ----------------------- author: Thorsten Liebig ## SetBoundaryCond ```{function} SetBoundaryCond(FDTD, BC, varargin) ``` Full definition: ```{code-block} matlab FDTD = SetBoundaryCond(FDTD, BC, varargin) ``` BC = [xmin xmax ymin ymax zmin zmax]; or BC = {xmin xmax ymin ymax zmin zmax}; ?min/?max: - 0 = PEC or 'PEC' - 1 = PMC or 'PMC' - 2 = MUR-ABC or 'MUR' - 3 = PML-ABC or 'PML_x' with pml size x => 4..50 example: BC = [ 1 1 0 0 2 3 ] %using numbers or BC = {'PMC' 'PMC' 'PEC' 'PEC' 'MUR' 'PML_8'} %using equivalent strings mur-abc definitions define a phase-velocity to be used by the mur-abc useful e.g. for dispersive waveguides FDTD = SetBoundaryCond(FDTD,BC,'MUR_PhaseVelocity',299792457.93272); pml definitions arguments: - 'PML_Grading','gradFunction' - Define the pml grading grading function. - Predefined variables in this grading function are: - D = depth in the pml in meter - dl = mesh delta inside the pml in meter - W = width (length) of the pml in meter - N = number of cells for the pml - Z = wave impedance at the current depth and position example: FDTD = SetBoundaryCond(FDTD,BC); or FDTD = SetBoundaryCond(FDTD,BC,'PML_Grading','-log(1e-6)*log(2.5)/(2*dl*pow(2.5,W/dl)-1) * pow(2.5, D/dl) / Z'); ----------------------- author: Thorsten Liebig ## AddPML ```{function} AddPML( mesh, numcells, ) ``` Full definition: ```{code-block} matlab mesh = AddPML( mesh, numcells, ) ``` Adds equidistant cells to the specified directions of the simulation area. This is used to put a PML (perfectly matched layer) absorber there. Remember: this function only adds space for the PML, the boundary conditions need to be set correctly to really add PML material. The mesh is sorted and duplicate lines are removed. input: - mesh: mesh structure - numcells: 1x6 vector (xmin,xmax,ymin,ymax,zmin,zmax) with number of cells to add to this direction - CoordSystem (optional): set to 1 in case of cylindrical mesh using mesh.r, mesh.a and mesh.z output: - mesh: new mesh with the added lines example: % some fixed mesh lines mesh.x = [-100 0 100]; mesh.y = [-100 0 100]; mesh.z = [0 500]; mesh = DetectEdges(CSX, mesh); %detect edges mesh = SmoothMesh(mesh, c0/fmax/20/unit); % smooth the mesh mesh = AddPML(mesh, 8); % add 8 lines to all directions % or mesh = AddPML(mesh, [0 0 0 0 8 8]); % add 8 lines in both z-directions See also DefineRectGrid, SmoothMesh, DetectEdges ----------------------- Sebastian Held ## WriteOpenEMS ```{function} WriteOpenEMS(filename, FDTD, CSX) ``` Full definition: ```{code-block} matlab function WriteOpenEMS(filename, FDTD, CSX) ``` Write the FDTD and CSX structures to a file. example: CSX = InitCSX(); FDTD = InitFDTD(); WriteOpenEMS('test.xml',FDTD,CSX) See also InitFDTD InitCSX CSXGeomPlot ----------------------- author: Thorsten Liebig ## RunOpenEMS ```{function} RunOpenEMS(Sim_Path, Sim_File, ) ``` Full definition: ```{code-block} matlab function RunOpenEMS(Sim_Path, Sim_File, ) ``` Run an openEMS simulation. arguments: _ Sim_Path: specify the simulation folder (folder must exist!) _ Sim_File: xml-filename to simulate, created by WriteOpenEMS optional arguments opts: list of openEMS options possible options: --disable-dumps Disable all field dumps for faster simulation --debug-material Dump material distribution to a vtk file for debugging --debug-PEC Dump metal distribution to a vtk file for debugging --debug-operator Dump operator to vtk file for debugging --debug-boxes Dump e.g. probe boxes to vtk file for debugging --debug-CSX Write CSX geometry file to debugCSX.xml --engine= Choose engine type --engine=fastest fastest available engine (default) --engine=basic basic FDTD engine, multithreaded --engine=multithreaded engine using compressed operator + sse vector extensions + multithreading --engine=sse, --engine=sse-compressed other names of multithreaded --numThreads= Force use n threads (basic and multithreaded engine) --no-simulation only run preprocessing; do not simulate --dump-statistics dump simulation statistics to 'openEMS_run_stats.txt' and 'openEMS_stats.txt' Additional global arguments --showProbeDiscretization Show probe discretization information --nativeFieldDumps Dump all fields using the native field components -v,-vv,-vvv Set debug level: 1 to 3 settings: list of Matlab settings - possible settings: - Settings.LogFile = 'openEMS.log' - Settings.Silent = 0 - additional remote simulation settings Note: ssh only on unix with working ssh client or windows with putty client openEMS Linux server or Windows with cygwin necessary - Settings.SSH.host = '' - Settings.SSH.bin = '/openEMS.sh' - ssh optional: - Settings.SSH.host_list = {'list','of','hosts'}; %searches for a free host - %on Windows needed additionally Settings.SSH.Putty.Path = '\putty'; Settings.SSH.Putty.Key = '\putty_private_key.ppk'; example: %create CSX and FDTD WriteOpenEMS('/tmp/path_to_run_in/myfile.xml', FDTD, CSX) RunOpenEMS('/tmp/path_to_run_in','myfile.xml','-v') See also WriteOpenEMS FindFreeSSH InitCSX InitFDTD ----------------------- author: Thorsten Liebig ## RunOpenEMS_Parallel ```{function} RunOpenEMS_Parallel(Sim_Paths, Sim_Files, opts, Settings, varargin) ``` Full definition: ```{code-block} matlab function [stdout, stderr] = RunOpenEMS_Parallel(Sim_Paths, Sim_Files, opts, Settings, varargin) ``` Run multiple openEMS simulations in parallel, distributed on multiple machines using a ssh host_list! (currently on Linux only) This function relies on InitQueue etc. input: - Sim_Paths: cell array of paths to simulate by RunOpenEMS - Sim_Files: filename or cell array of filenames to simulate - opts: openEMS options. see also RunOpenEMS - Settings: use the settings to define multiple host for simulation e.g.: Settings.SSH.bin ='/openEMS.sh'; Settings.SSH.host_list = {'list','of','hosts'}; Note: If no SSH host_list is defined, this function will skip the parallel run and switch back to a default RunOpenEMS! See also RunOpenEMS, FindFreeSSH, InitQueue ----------------------- author: Thorsten Liebig 2011 ## InitQueue ```{function} InitQueue(varargin) ``` Full definition: ```{code-block} matlab function [queue] = InitQueue(varargin) ``` Use this function to initialize a queue to run one or more matlab scripts in parallel. This can be used to efficiently run an openEMS parameter sweep in parallel on multiple remote machines. Options: - DependPath: Add multiple paths, your script may depend on - UseOctave: Enable/Disable octave usage - MaxThreads: max. number of parallel executions Note: - Currently only Linux/Unix is supported - By default Octave is used to spawn parallel functions (saves licenses), but this can be changed by: [queue] = InitQueue('UseOctave', 0); You may need to change this, if your script is not octave compatible - To efficiently run openEMS in parallel, you need to run it on several machines using a SSH.host_list setting --> See also RunOpenEMS Example: %serial version: for n=1:10 % manipulate parameter etc. [result1(n) result2(n)] = Parallel_Func_Name(param1, param2); end %parallel version: queue = InitQueue('DependPath',{'/opt/openEMS/CSXCAD/matlab', ... '/opt/openEMS/openEMS/matlab'}); for n=1:10 % manipulate parameter etc. queue = Add2Queue(queue, 'Parallel_Func_Name', {param1, param2}); end % wait for all to finish [queue] = FinishQueue(queue); % retrieve result for n=1:numel(stub_sweep) [result1(n) result2(n)] = ResultsQueue(queue,n); end See also: Add2Queue, FinishQueue, ResultsQueue, RunOpenEMS, RunOpenEMS_Parallel, FindFreeSSH ----------------------- author: Thorsten Liebig ## setup ```{function} setup() ``` Full definition: ```{code-block} matlab function setup() ``` setup openEMS Matlab/octave interface ----------------------- author: Thorsten Liebig (2011-2017)