2010-06-09 07:22:54 +00:00
|
|
|
function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
2012-08-02 11:29:22 +00:00
|
|
|
% function RunOpenEMS(Sim_Path, Sim_File, <opts, Settings>)
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2012-08-02 11:29:22 +00:00
|
|
|
% Run an openEMS simulation.
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2012-08-02 11:29:22 +00:00
|
|
|
% arguments:
|
2019-05-19 20:09:04 +00:00
|
|
|
% Sim_Path: specify the simulation folder (folder must exist!)
|
2012-08-02 11:29:22 +00:00
|
|
|
% Sim_File: xml-filename to simulate, created by WriteOpenEMS
|
|
|
|
%
|
|
|
|
% optional arguments
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2012-08-02 11:29:22 +00:00
|
|
|
% opts: list of openEMS options
|
|
|
|
% possible options:
|
2012-11-16 20:44:46 +00:00
|
|
|
% --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=<type> Choose engine type
|
|
|
|
% --engine=fastest fastest available engine (default)
|
|
|
|
% --engine=basic basic FDTD engine
|
|
|
|
% --engine=sse engine using sse vector extensions
|
2016-06-27 05:53:41 +00:00
|
|
|
% --engine=sse-compressed engine using compressed operator + sse vector extensions
|
2012-11-16 20:44:46 +00:00
|
|
|
% --engine=MPI engine using compressed operator + sse vector extensions + MPI parallel processing
|
|
|
|
% --engine=multithreaded engine using compressed operator + sse vector extensions + MPI + multithreading
|
|
|
|
% --numThreads=<n> Force use n threads for multithreaded engine
|
|
|
|
% --no-simulation only run preprocessing; do not simulate
|
2013-03-27 10:59:06 +00:00
|
|
|
% --dump-statistics dump simulation statistics to 'openEMS_run_stats.txt' and 'openEMS_stats.txt'
|
2012-08-02 11:29:22 +00:00
|
|
|
%
|
|
|
|
% Additional global arguments
|
2012-11-16 20:44:46 +00:00
|
|
|
% --showProbeDiscretization Show probe discretization information
|
|
|
|
% --nativeFieldDumps Dump all fields using the native field components
|
|
|
|
% -v,-vv,-vvv Set debug level: 1 to 3
|
2012-08-02 11:29:22 +00:00
|
|
|
%
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2012-08-02 11:29:22 +00:00
|
|
|
% 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 = '<hostname or ip>'
|
|
|
|
% Settings.SSH.bin = '<path_to_openEMS>/openEMS.sh'
|
|
|
|
% ssh optional:
|
|
|
|
% Settings.SSH.host_list = {'list','of','hosts'}; %searches for a free host
|
|
|
|
% %on Windows needed additionally
|
|
|
|
% Settings.SSH.Putty.Path = '<path_to>\putty';
|
|
|
|
% Settings.SSH.Putty.Key = '<path_to>\putty_private_key.ppk';
|
|
|
|
%
|
|
|
|
% MPI settings:
|
|
|
|
% Settings.MPI.xxx --> help RunOpenEMS_MPI
|
2011-02-24 13:44:29 +00:00
|
|
|
%
|
2010-06-21 10:17:19 +00:00
|
|
|
%
|
2012-08-02 11:29:22 +00:00
|
|
|
% example:
|
|
|
|
% %create CSX and FDTD
|
|
|
|
% WriteOpenEMS('/tmp/path_to_run_in/myfile.xml', FDTD, CSX)
|
|
|
|
% RunOpenEMS('/tmp/path_to_run_in','myfile.xml','-v')
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2013-05-15 14:03:48 +00:00
|
|
|
% See also WriteOpenEMS FindFreeSSH InitCSX InitFDTD RunOpenEMS_MPI
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
|
|
|
% openEMS matlab interface
|
|
|
|
% -----------------------
|
|
|
|
% author: Thorsten Liebig
|
|
|
|
|
2011-09-13 08:50:08 +00:00
|
|
|
if nargin < 2
|
2010-06-09 07:22:54 +00:00
|
|
|
error 'specify the Sim_Path and Sim_file to simulate'
|
|
|
|
end
|
|
|
|
|
2011-09-13 08:50:08 +00:00
|
|
|
if nargin < 3
|
|
|
|
opts = '';
|
|
|
|
end
|
|
|
|
|
2010-06-09 07:22:54 +00:00
|
|
|
if (nargin<4)
|
|
|
|
Settings = [];
|
|
|
|
end
|
|
|
|
|
2011-03-21 13:46:35 +00:00
|
|
|
if (isfield(Settings,'MPI') && isunix)
|
2011-02-24 13:44:29 +00:00
|
|
|
if (Settings.MPI.NrProc>1)
|
|
|
|
RunOpenEMS_MPI(Sim_Path, Sim_File, opts, Settings);
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-07 09:46:38 +00:00
|
|
|
ssh_command = 'ssh';
|
|
|
|
scp_command = 'scp';
|
|
|
|
scp_options = '';
|
|
|
|
ssh_options = '';
|
|
|
|
|
|
|
|
enable_ssh = 0;
|
|
|
|
enable_ssh = isfield(Settings,'SSH') && isunix;
|
|
|
|
|
|
|
|
if ~isunix
|
|
|
|
enable_ssh = isfield(Settings,'SSH') && isfield(Settings.SSH,'Putty');
|
|
|
|
if (enable_ssh)
|
|
|
|
ssh_command = [Settings.SSH.Putty.Path '/plink '];
|
|
|
|
ssh_options = [ssh_options ' -i ' Settings.SSH.Putty.Key];
|
|
|
|
|
|
|
|
scp_command = [Settings.SSH.Putty.Path '/pscp '];
|
|
|
|
scp_options = [scp_options ' -i ' Settings.SSH.Putty.Key];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-09 07:22:54 +00:00
|
|
|
savePath = pwd;
|
|
|
|
cd(Sim_Path);
|
2012-11-16 20:44:46 +00:00
|
|
|
|
2012-02-07 09:46:38 +00:00
|
|
|
if (enable_ssh)
|
|
|
|
scp_options = [scp_options ' -C'];
|
|
|
|
ssh_options = [ssh_options ' -x -C'];
|
|
|
|
|
|
|
|
% ssh options: no X forwarding; no password prompt (use pub keys!); no host checking
|
|
|
|
if (isunix)
|
|
|
|
ssh_options = [ssh_options ' -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"'];
|
|
|
|
scp_options = [scp_options ' -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"'];
|
|
|
|
end
|
|
|
|
|
2011-07-07 06:11:39 +00:00
|
|
|
if isfield(Settings.SSH,'host_list')
|
2012-02-07 09:46:38 +00:00
|
|
|
host = FindFreeSSH(Settings.SSH.host_list, Settings);
|
2011-07-07 06:11:39 +00:00
|
|
|
if ~isempty(host)
|
|
|
|
Settings.SSH.host = host;
|
|
|
|
else
|
|
|
|
error('openEMS:RunOpenEMS', 'unable to find host, abort openEMS');
|
|
|
|
end
|
|
|
|
end
|
2012-11-16 20:44:46 +00:00
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
% create a tmp working dir
|
2015-08-09 13:05:46 +00:00
|
|
|
[status, result] = system([ssh_command ' ' ssh_options ' ' Settings.SSH.host ' "mktemp -d /tmp/openEMS_XXXXXXXXXXXX"']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
2010-08-09 14:56:35 +00:00
|
|
|
error('openEMS:RunOpenEMS','mktemp failed to create tmp directory!');
|
2010-06-09 07:22:54 +00:00
|
|
|
end
|
2010-08-09 14:56:35 +00:00
|
|
|
ssh_work_path = strtrim(result); %remove tailing \n
|
2012-11-16 20:44:46 +00:00
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
disp(['Running remote openEMS on ' Settings.SSH.host ' at working dir: ' ssh_work_path]);
|
2012-11-16 20:44:46 +00:00
|
|
|
|
2010-11-26 13:48:47 +00:00
|
|
|
%copy openEMS all simulation files to the ssh host
|
2015-08-09 13:05:46 +00:00
|
|
|
[stat, res] = system([scp_command ' ' scp_options ' * ' Settings.SSH.host ':' ssh_work_path '/']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0)
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS','scp failed!');
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%run openEMS (with log file if requested)
|
2012-02-07 09:46:38 +00:00
|
|
|
if isfield(Settings,'LogFile') && isunix
|
2010-06-21 10:17:19 +00:00
|
|
|
append_unix = [' 2>&1 | tee ' Settings.LogFile];
|
|
|
|
else
|
|
|
|
append_unix = [];
|
|
|
|
end
|
2015-08-09 13:05:46 +00:00
|
|
|
status = system([ssh_command ' ' ssh_options ' ' Settings.SSH.host ' "cd ' ssh_work_path ' && ' Settings.SSH.bin ' ' Sim_File ' ' opts '"' append_unix]);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
|
|
|
error('openEMS:RunOpenEMS','ssh openEMS failed!');
|
|
|
|
end
|
|
|
|
|
2010-07-20 09:38:06 +00:00
|
|
|
disp( 'Remote simulation done... copying back results and cleaning up...' );
|
2010-06-09 07:22:54 +00:00
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%copy back all results
|
2020-01-27 11:27:31 +00:00
|
|
|
[stat, res] = system([scp_command ' -r ' scp_options ' ' Settings.SSH.host ':' ssh_work_path '/* ./']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS','scp failed!');
|
2012-11-16 20:44:46 +00:00
|
|
|
end
|
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%cleanup
|
2015-08-09 13:05:46 +00:00
|
|
|
[stat, res] = system([ssh_command ' ' ssh_options ' ' Settings.SSH.host ' rm -r ' ssh_work_path]);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
2010-08-09 14:56:35 +00:00
|
|
|
warning('openEMS:RunOpenEMS','remote cleanup failed!');
|
2012-11-16 20:44:46 +00:00
|
|
|
end
|
2010-06-09 07:22:54 +00:00
|
|
|
else
|
2018-01-04 09:08:51 +00:00
|
|
|
args = ['"' Sim_File '" ' opts]
|
2010-07-20 09:38:06 +00:00
|
|
|
if isfield(Settings,'LogFile') && isfield(Settings,'Silent')
|
2018-01-04 09:08:51 +00:00
|
|
|
invoke_openEMS(args,['"' Settings.LogFile '"'],Settings.Silent);
|
2010-07-20 09:38:06 +00:00
|
|
|
elseif isfield(Settings,'LogFile')
|
2018-01-04 09:08:51 +00:00
|
|
|
invoke_openEMS(args,['"' Settings.LogFile '"']);
|
2010-07-20 09:38:06 +00:00
|
|
|
elseif isfield(Settings,'Silent')
|
|
|
|
invoke_openEMS(args,[],Settings.Silent);
|
2010-06-21 10:17:19 +00:00
|
|
|
else
|
|
|
|
invoke_openEMS(args);
|
|
|
|
end
|
2010-06-09 07:22:54 +00:00
|
|
|
end
|
2012-11-16 20:44:46 +00:00
|
|
|
|
2010-06-09 07:22:54 +00:00
|
|
|
cd(savePath);
|
|
|
|
return
|