-
Notifications
You must be signed in to change notification settings - Fork 3
/
initialize.m
424 lines (336 loc) · 13.5 KB
/
initialize.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
function run = initialize(ini)
% This routine runs through all of the initialization variables testing to see if they've been
% set by user input. If not, then they are defaulted with a message to warn that a default
% value has been set. The values are parsed from the ini structure and then passed back as
% separate variables for explicit use in the code.
%
%>> ini structure containing run related variable information struct
%<< run initialized results ImogenManager H
%% ============================= BEGIN RUNVAL PROPERTY INITIALIZATION =========================== %
%--- Clear all manager singletons from possible previous runs ---%
clear('ImogenManager','SaveManager','TimeManager','ImageManager','GravityManager', ...
'FluidManager', 'MagnetManager', 'ParallelManager', 'BCManager', 'TreadmillManager');
fclose all; % Prevent any lingering saves from disrupting run.
run = ImogenManager.getInstance();
run.gridSize = ini.grid;
[run.version, run.detailedVersion] = versionInfo();
[run.paths.hostName, run.paths.imogen, run.paths.results] = determineHostVariables();
%% .bcMode Edge condition modes
try
if isa(ini.bcMode, 'struct')
run.bc.modes = ini.bcMode;
run.appendInfo('BC Mode', run.bc.modes);
elseif isa(ini.bcMode, 'char')
modes.x = ini.bcMode; modes.y = ini.bcMode; modes.z = ini.bcMode;
run.bc.modes = modes;
else
error(['BoundaryConditionError: Boundary condition field of type %s is not recognized.' ...
' bcMode recognizes string or structure input. Run aborted.'],class(ini.bcMode));
end
run.appendInfo('Boundary Conditions', run.bc.modes);
catch MERR, loc_initializationError('bcMode',MERR);
end
%% .bcInfinity # of cells for infinity of transparent edge condition
try
run.bc.infinity = ini.bcInfinity;
run.appendInfo('Infinity Distance', run.bc.infinity);
catch MERR, loc_initializationError('infinity',MERR);
end
%% .fluxLimiter # type of flux limiter to use globally or in each dimension.
try
run.fluid.setFluxLimiters(ini.fluxLimiter);
run.magnet.limiter = run.fluid.limiter;
run.appendInfo('Flux Limiters', run.fluid.limiter);
catch MERR, loc_initializationError('infinity',MERR);
end
%% .cfl CFL prefactor
try
run.time.CFL = ini.cfl;
run.appendInfo('CFL Prefactor', run.time.CFL);
catch MERR, loc_initializationError('cfl',MERR);
end
%% .timeUpdateMode How frequently the timestep should be updated.
try
run.time.updateMode = ini.timeUpdateMode;
run.appendInfo('Time Update Mode', run.time.updateMode);
catch MERR, loc_initializationError('timeUpdateMode',MERR);
end
%% .thresholdMass Threshold value below which gravity will not act
try
run.fluid.MASS_THRESHOLD = ini.thresholdMass;
run.appendInfo('Mass Threshold', run.fluid.MASS_THRESHOLD);
catch MERR, loc_initializationError('thresholdmass',MERR);
end
%% .minMass Minimum allowed mass density value
try
run.fluid.MINMASS = ini.minMass;
run.appendInfo('Minimum mass density', run.fluid.MINMASS);
catch MERR, loc_initializationError('minmass',MERR);
end
%% .profile Enable the profiler to record execution information
try
run.PROFILE = ini.profile;
if (run.PROFILE); run.appendWarning('MATLAB profiler will be active for this run.'); end
run.appendInfo('Profiler', run.PROFILE);
catch MERR, loc_initializationError('profile',MERR);
end
%% .iterMax Maximum number of iterations
try
run.time.ITERMAX = ini.iterMax;
run.appendInfo('Maximum iteration',run.time.ITERMAX);
catch MERR, loc_initializationError('iterMax',MERR);
end
%% .timeMax Maximum simulation time
try
run.time.TIMEMAX = ini.timeMax;
run.appendInfo('Maximum simulation time.',run.time.TIMEMAX);
catch MERR, loc_initializationError('timeMax',MERR);
end
%% .wallMax Maximum wall time used for the run
try
run.time.WALLMAX = ini.wallMax;
run.appendInfo('Maximum allowed wall time (hours).',run.time.WALLMAX);
catch MERR, loc_initializationError('wallTimeMax',MERR);
end
%% .runCode Run code for the simulation
try
run.paths.runCode = ini.runCode;
catch MERR, loc_initializationError('runCode',MERR);
end
%% .alias Alias for the simulation
try
run.paths.alias = ini.alias;
catch MERR, loc_initializationError('alias',MERR);
end
%% .info Run information String
try
run.about = ini.info;
catch MERR, loc_initializationError('info',MERR);
end
%% .notes Add notes (user generated)
try
run.notes = ini.notes;
catch MERR, loc_initializationError('notes',MERR);
end
%% .iniInfo Add initialization information (procedurally generated)
try
run.iniInfo = ini.iniInfo;
catch MERR, loc_initializationError('iniinfo',MERR);
end
%% .mode Activate code mode types (e.g. fluid, magnet, etc...)
try
run.initializeMode(ini.mode);
catch MERR, loc_initializationError('mode',MERR);
end
%% .dGrid Grid cell dimensions
try
if isempty(ini.dGrid)
run.setGridSpacing([1 1 1]);
run.appendWarning('No dGrid parameter specified. Defaulting to isotropic unity values.');
elseif isa(ini.dGrid,'double')
len = length(ini.dGrid);
switch (len)
case 1; run.setGridSpacing(ini.dGrid * ones(1,3), run.gridSize);
case 2; run.setGridSpacing([ini.dGrid, max(ini.dgrid)], run.gridSize);
case 3; run.setGridSpacing(ini.dGrid, run.gridSize);
otherwise; error('Unable to parse ini.dGrid value.');
end
else
run.setGridSpacing(ini.dGrid, run.gridSize);
end
run.appendInfo('Grid spacing', ImogenRecord.valueToString(run.DGRID));
catch MERR, loc_initializationError('dgrid',MERR);
end
%% .gamma Polytropic index for equation of state
try
run.GAMMA = ini.gamma;
run.appendInfo('Gamma', run.GAMMA);
catch MERR, loc_initializationError('gamma',MERR);
end
%% .debug Run the code in debug mode
try
run.DEBUG = ini.debug;
if (run.DEBUG), run.appendWarning('Running in debug mode.'); end
catch MERR, loc_initializationError('debug',MERR);
end
%% .save Save data to files
try
run.save.FSAVE = logical(ini.save);
catch MERR, loc_initializationError('save',MERR);
end
%% .ppSave Percentage executed between saves
try
run.save.PERSLICE(1) = ini.ppSave.dim1;
run.save.PERSLICE(2) = ini.ppSave.dim2;
run.save.PERSLICE(3) = ini.ppSave.dim3;
run.save.PERSLICE(4) = ini.ppSave.cust;
catch MERR, loc_initializationError('ppSave',MERR);
end
%% .slice Index Locations for slice and image save files
try
run.save.SLICEINDEX = ini.slice;
run.appendInfo('Slices will be saved at',run.save.SLICEINDEX);
catch MERR, loc_initializationError('slice',MERR);
end
%% .activeSlices Which data slices to save
try
slLabels = {'x','y','z','xy','xz','yz','xyz','cust'};
for i=1:8
if ~isfield(ini.activeSlices,slLabels{i}); run.save.ACTIVE(i) = false;
else run.save.ACTIVE(i) = logical(ini.activeSlices.(slLabels{i}));
end
if run.save.ACTIVE(i)
run.appendInfo('Saving slice', upper(slLabels{i}));
end
end
catch MERR, loc_initializationError('activeSlices',MERR);
end
%% .customSave Custom saving properties
try
saveStr = '''slTime'',''slAbout'',''version'',''slGamma'',''sldGrid''';
custom = ini.customSave;
if isstruct(custom)
if (isfield(custom,'mass') && custom.mass), saveStr = [saveStr ',''slMass''']; end
if (isfield(custom,'mom') && custom.mom), saveStr = [saveStr ',''slMom''']; end
if (isfield(custom,'ener') && custom.ener), saveStr = [saveStr ',''slEner''']; end
if (isfield(custom,'mag') && custom.mag), saveStr = [saveStr ',''slMag''']; end
run.save.customSaveStr = saveStr;
customStr = 'Active';
else
run.save.customSaveStr = '';
customStr = 'Inactive';
end
run.appendInfo('Custom save', customStr);
catch MERR, loc_initializationError('customSave',MERR);
end
%% .specSaves Specific save iterations
try
if ~isempty(ini.specSaves) && isa(ini.specSaves,'double')
run.save.specialSaves3D = ini.specSaves;
run.appendInfo('Special save points 3D', run.save.specialSaves3D);
else
if isfield(ini.specSaves,'dim1')
run.save.specialSaves1D = ini.specSaves.dim1;
run.appendInfo('Special save points 1D', run.save.specialSaves1D);
end
if isfield(ini.specSaves,'dim2')
run.save.specialSaves2D = ini.specSaves.dim2;
run.appendInfo('Special save points 2D', run.save.specialSaves2D);
end
if isfield(ini.specSaves,'dim3')
run.save.specialSaves3D = ini.specSaves.dim3;
run.appendInfo('Special save points 3D', run.save.specialSaves3D);
end
end
catch MERR, loc_initializationError('specSaves',MERR);
end
%% .image Image saving properties
try
fields = ImageManager.FIELDS;
for i=1:length(fields)
if isfield(ini.image,fields{i})
run.image.(fields{i}) = ini.image.(fields{i});
end
if isfield(ini.image,'logarithmic') && isfield(ini.image.logarithmic,fields{i})
run.image.logarithmic.(fields{i}) = ini.image.logarithmic.(fields{i});
end
end
run.image.activate();
if run.image.ACTIVE
if isfield(ini.image,'interval')
run.image.INTERVAL = max(1,ini.image.interval);
else
run.image.INTERVAL = 1;
run.appendWarning('Image saving interval set to every step.');
end
if isfield(ini.image,'colordepth'); colordepth = ini.image.colordepth;
else colordepth = 256;
end
if isfield(ini.image,'colormap'); run.image.createColormap(ini.image.colormap, colordepth);
else run.image.createColormap('jet',colordepth);
end
imageSaveState = 'Active';
else imageSaveState = 'Inactive';
end
run.appendInfo('Image saving is', imageSaveState);
catch MERR, loc_initializationError('image',MERR);
end
%% .treadmill Grid treadmill action
try
if ini.treadmill > 0
run.treadmill.ACTIVE = true;
run.treadmill.DIRECTION = ini.treadmill;
run.appendInfo('Treadmill', sprintf('Active along %g',run.treadmill.DIRECTION));
end
catch MERR, loc_initializationError('treadmill',MERR);
end
%% .fades Fade objects
try
run.addFades(ini.fades);
catch MERR, loc_initializationError('fades',MERR);
end
%% .gravity.fixedPotential Carries over any fixed
try
if isfield(ini.gravity,'fixedPotential')
run.gravity.fixedPotential = ini.gravity.fixedPotential;
else
run.gravity.fixedPotential = 0;
end
gpsize = size(run.gravity.fixedPotential);
if gpsize(1) > 1; run.appendInfo('Including fixed gravitational potential',1); end;
catch MERR, loc_initializationError('gravity.vars',MERR);
end
%% .gravity.CONSTANT
try
if isfield(ini.gravity,'constant')
run.gravity.constant = ini.gravity.constant;
else
run.gravity.constant = 1;
end
if isfield(ini.gravity,'iterMax')
run.gravity.iterMax = ini.gravity.iterMax;
else
run.gravity.iterMax = 100;
end;
if isfield(ini.gravity,'tolerance')
run.gravity.tolerance = ini.gravity.tolerance;
else
run.gravity.tolerance = 1e-6;
end;
if isfield(ini.gravity,'bconditionSource')
run.gravity.bconditionSource = ini.gravity.bconditionSource;
else
run.gravity.bconditionSource = GRAV_BCSOURCE_FULL;
end
run.gravity.mirrorZ = ini.gravity.mirrorZ;
catch MERR, loc_initializationError('gravity.constant',MERR);
end
%% .gravity.solver Gravity solver
try
run.gravity.setSolver(ini.gravity.solver);
run.appendInfo('Gravity solver', run.gravity.TYPE);
catch MERR, loc_initializationError('gravity.solver',MERR);
end
%% .viscosity Artificial viscosity settings
try
run.fluid.viscosity.type = ini.viscosity.type;
run.fluid.viscosity.linearViscousStrength = ini.viscosity.linear;
run.fluid.viscosity.quadraticViscousStrength = ini.viscosity.quadratic;
catch MERR, loc_initializationError('viscosity', MERR);
end
%% .radiation Radiation settings
try
run.fluid.radiation.type = ini.radiation.type;
run.fluid.radiation.exponent = ini.radiation.exponent;
run.fluid.radiation.initialMaximum = ini.radiation.initialMaximum;
catch MERR, loc_initializationError('radiation', MERR);
end
end
function loc_initializationError(property, caughtError)
% Handles errors thrown by the try statements in the initialization routine.
%
%>> property the property that threw the error str
%>> caughtError The error captured by a try block error
fprintf('\n\n--- Unable to parse property %s. Run aborted. ---\n', property);
rethrow(caughtError);
end