matlab: RunOpenEMS + ssh remote simulation support
Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
This commit is contained in:
parent
88b319cbba
commit
db846ad853
78
matlab/RunOpenEMS.m
Normal file
78
matlab/RunOpenEMS.m
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
||||||
|
% function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
||||||
|
%
|
||||||
|
% Run an openEMS simulation
|
||||||
|
%
|
||||||
|
% example:
|
||||||
|
% Sim_Path = 'MySimPath';
|
||||||
|
% Sim_File = 'helix.xml'; %should be created by WriteOpenEMS
|
||||||
|
% opts = '--engine=fastest';
|
||||||
|
%
|
||||||
|
% optinal:
|
||||||
|
% (ssh only on unix with working ssh client)
|
||||||
|
% Settings.SSH.host = '<hostname or ip>'
|
||||||
|
% Settings.SSH.bin = '<path_to_openEMS>/openEMS.sh'
|
||||||
|
%
|
||||||
|
% RunOpenEMS(Sim_Path,Sim_File,opts,Settings)
|
||||||
|
%
|
||||||
|
% See also WriteOpenEMS
|
||||||
|
%
|
||||||
|
% openEMS matlab interface
|
||||||
|
% -----------------------
|
||||||
|
% author: Thorsten Liebig
|
||||||
|
|
||||||
|
if nargin < 3
|
||||||
|
error 'specify the Sim_Path and Sim_file to simulate'
|
||||||
|
end
|
||||||
|
|
||||||
|
if (nargin<4)
|
||||||
|
Settings = [];
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
savePath = pwd;
|
||||||
|
cd(Sim_Path);
|
||||||
|
|
||||||
|
if (isfield(Settings,'SSH') && isunix)
|
||||||
|
ssh_work_path = ['openEMS_' int2str(randi([1e8 9e8],1))];
|
||||||
|
|
||||||
|
disp(['Running remote openEMS on ' Settings.SSH.host ' at working dir: ' ssh_work_path]);
|
||||||
|
|
||||||
|
[status, result] = unix(['ssh ' Settings.SSH.host ' "mkdir /tmp/' ssh_work_path '"']);
|
||||||
|
if (status~=0)
|
||||||
|
disp(result);
|
||||||
|
error('openEMS:RunOpenEMS','mkdir failed!');
|
||||||
|
end
|
||||||
|
|
||||||
|
[stat, res] = unix(['scp ' Sim_File ' ' Settings.SSH.host ':/tmp/' ssh_work_path '/' Sim_File]);
|
||||||
|
if (stat~=0)
|
||||||
|
disp(res);
|
||||||
|
error('openEMS:RunOpenEMS','scp failed!');
|
||||||
|
end
|
||||||
|
|
||||||
|
status = unix(['ssh ' Settings.SSH.host ' "cd /tmp/' ssh_work_path ' && ' Settings.SSH.bin ' ' Sim_File ' ' opts '"'])
|
||||||
|
if (status~=0)
|
||||||
|
disp(result);
|
||||||
|
error('openEMS:RunOpenEMS','ssh openEMS failed!');
|
||||||
|
end
|
||||||
|
|
||||||
|
disp(['Remote simulation done... copying back results and cleaning up...']);
|
||||||
|
|
||||||
|
[stat, res] = unix(['scp -r ' Settings.SSH.host ':/tmp/' ssh_work_path '/* ' pwd '/']);
|
||||||
|
if (stat~=0);
|
||||||
|
disp(res);
|
||||||
|
error('openEMS:RunOpenEMS','scp failed!');
|
||||||
|
end
|
||||||
|
|
||||||
|
[stat, res] = unix(['ssh ' Settings.SSH.host ' rm -r /tmp/' ssh_work_path]);
|
||||||
|
if (stat~=0);
|
||||||
|
disp(res);
|
||||||
|
error('openEMS:RunOpenEMS','remote cleanup failed!');
|
||||||
|
end
|
||||||
|
else
|
||||||
|
args = [Sim_File ' ' opts];
|
||||||
|
invoke_openEMS(args);
|
||||||
|
end
|
||||||
|
|
||||||
|
cd(savePath);
|
||||||
|
return
|
@ -22,8 +22,8 @@ openEMS_opts = '';
|
|||||||
% openEMS_opts = [openEMS_opts ' --debug-boxes'];
|
% openEMS_opts = [openEMS_opts ' --debug-boxes'];
|
||||||
% openEMS_opts = [openEMS_opts ' --debug-operator'];
|
% openEMS_opts = [openEMS_opts ' --debug-operator'];
|
||||||
|
|
||||||
% openEMS_opts = [openEMS_opts ' --disable-dumps --engine=fastest'];
|
openEMS_opts = [openEMS_opts ' --disable-dumps --engine=fastest'];
|
||||||
openEMS_opts = [openEMS_opts ' --engine=sse-compressed'];
|
% openEMS_opts = [openEMS_opts ' --engine=sse-compressed'];
|
||||||
|
|
||||||
Sim_Path = 'tmp';
|
Sim_Path = 'tmp';
|
||||||
Sim_CSX = 'helix.xml';
|
Sim_CSX = 'helix.xml';
|
||||||
@ -120,12 +120,8 @@ CSX = AddBox(CSX,'Ht_',0 , start,stop);
|
|||||||
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
|
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
|
||||||
|
|
||||||
%% cd to working dir and run openEMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% run openEMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
savePath = pwd;
|
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts);
|
||||||
cd(Sim_Path); %cd to working dir
|
|
||||||
args = [Sim_CSX ' ' openEMS_opts];
|
|
||||||
invoke_openEMS(args);
|
|
||||||
cd(savePath);
|
|
||||||
|
|
||||||
%% postproc & do the plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% postproc & do the plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
U = ReadUI('ut1','tmp/');
|
U = ReadUI('ut1','tmp/');
|
||||||
|
@ -70,13 +70,8 @@ CSX = AddBox(CSX,'Ht',0,start,stop);
|
|||||||
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
|
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
|
||||||
|
|
||||||
%% cd to working dir and run openEMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% run openEMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
savePath = pwd();
|
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts);
|
||||||
cd(Sim_Path); %cd to working dir
|
|
||||||
|
|
||||||
args = [Sim_CSX ' ' openEMS_opts];
|
|
||||||
invoke_openEMS(args);
|
|
||||||
cd(savePath);
|
|
||||||
|
|
||||||
%% do the plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%% do the plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
PlotArgs.slice = {mesh.x(round(end/2)) mesh.y(round(end/2)) mesh.z(round(end/2))};
|
PlotArgs.slice = {mesh.x(round(end/2)) mesh.y(round(end/2)) mesh.z(round(end/2))};
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
function invoke_openEMS( opts )
|
function invoke_openEMS( opts )
|
||||||
|
% function invoke_openEMS( opts )
|
||||||
|
%
|
||||||
|
% internal method to invoke openEMS, use RunOpenEMS instead
|
||||||
|
%
|
||||||
|
% See also RunOpenEMS
|
||||||
|
%
|
||||||
|
% openEMS matlab interface
|
||||||
|
% -----------------------
|
||||||
|
% author: Sebastian Held
|
||||||
|
|
||||||
if nargin < 1
|
if nargin < 1
|
||||||
error 'specify the xml file to simulate'
|
error 'specify the xml file to simulate'
|
||||||
|
Loading…
Reference in New Issue
Block a user