-
Notifications
You must be signed in to change notification settings - Fork 1
/
runBatchIEW.m
129 lines (110 loc) · 3.41 KB
/
runBatchIEW.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function iewAll = runBatchIEW(varargin)
% This function interprets and executes a batch of simulations specified by
% batchIEW.
tic
%% ----- Interpret the input flags -----
% Parse the inputs:
p = inputParser;
p.addParamValue('N',-1,@(x) isnumeric(x) && x>0);
p.addParamValue('R',2,@(x) isnumeric(x) && all(x>0));
p.addParamValue('W',1,@(x) isnumeric(x) && all(x>0));
p.addParamValue('lam',-1,@(x) isnumeric(x) && all(x>0));
p.addParamValue('b',-1,@(x) isnumeric(x) && all(x>0));
p.addParamValue('crenN',-1,@(x) (isnumeric(x) && all(x>0)) || iscell(x));
p.addParamValue('iewArgs',{},@iscell)
p.parse(varargin{:});
N = p.Results.N;
R = p.Results.R;
W = p.Results.W;
lam = p.Results.lam;
b = p.Results.b;
crenN = p.Results.crenN;
iewArgs = p.Results.iewArgs;
% Determine if lambda and b were specified in the command line:
lamSpecified = all(lam ~= -1);
bSpecified = all(b ~= -1);
% --- Determine N from input parameters if not specified ---
if N == -1 % N not specified
if length(R) > 1 && length(W) > 1 % Both R and W vary
assert(length(R) == length(W),'Length(R) ~= length(W)')
N = length(R);
elseif length(R) > 1 % Just R varies; W is fixed
N = length(R);
elseif length(W) > 1 % Just W varies; R is fixed
N = length(W);
elseif length(crenN) > 1 % Geometry fixed, crenN varies
assert(length(R) == 1 && length(W) == 1,'Geometry should be fixed.')
N = length(crenN);
else % Nothing is recognized as varying
N = 1;
end
end
% Set up the geometry parameters:
if length(R) == 1
Rs = R*ones(1,N);
elseif length(R) == 2
Rs = logspace(log10(R(1)),log10(R(2)),N);
elseif length(R) > 2
Rs = R;
end
if length(W) == 1
Ws = W*ones(1,N);
elseif length(W) == 2
Ws = logspace(log10(W(1)),log10(W(2)),N);
elseif length(W) > 2
Ws = W;
end
if lamSpecified % only do if lam is specified
if length(lam) == 1
lams = lam*ones(1,N);
elseif length(lam) == 2
lams = logspace(log10(lam(1)),log10(lam(2)),N);
elseif length(lam) > 2
lams = lam;
end
end
if bSpecified % only do if b is specified
if length(b) == 1
bs = b*ones(1,N);
elseif length(b) == 2
bs = logspace(log10(b(1)),log10(b(2)),N);
elseif length(b) > 2
bs = b;
end
end
% Interpret the number of crenellations crenN:
if length(crenN) == 1 && crenN == -1
% Default crenN = [18 18]:
crenNmat = repmat([18 18],N,1);
elseif length(crenN) == 1 && crenN ~= -1
% Single crenN specified, e.g. crenN = 12:
crenNmat = repmat(crenN*[1 1],N,1);
elseif length(crenN) >= 2
% All crenN specified as a vector:
crenNmat = repmat(reshape(crenN,N,1),1,2);
end
% Default parameters for iewasher:
if isempty(iewArgs)
iewArgs = {'maxIter',3,'calcbsurf','iter','calcbedge','end'};
end
%% ----- Run the batch -----
iewAll = iewasher.empty(0,0);
disp('Starting simulations...')
for i = 1:length(Ws)
fprintf(1,'Current iteration: %d\n',i);
iewAll(i).geom.fixedParam = 'R';
iewAll(i).R = Rs(i);
iewAll(i).W = Ws(i);
% Write lambda if specified:
if lamSpecified, iewAll(i).lambda = lams(i); end
% Write b if specified:
if bSpecified, iewAll(i).thickness = bs(i); end
iewAll(i).cren.N = crenNmat(i,:);
iewAll(i).plotOptimizeCrenWidths = false;
% iewAll(i).run('maxIter',3,'plot')
% iewAll(i).run('maxIter',3,'calcbsurf','iter','calcbedge','end');
iewAll(i).run(iewArgs{:});
fprintf(1,'<Phi^2> for edges: \t%g\t%g\t%g\n', iewAll(i).Phi2edge);
end
toc
end