1 | function ismodelselfconsistent(md),
|
---|
2 | %ISMODELSELFCONSISTENT - check that model forms a closed form solvable problem.
|
---|
3 | %
|
---|
4 | % Usage:
|
---|
5 | % ismodelselfconsistent(md),
|
---|
6 |
|
---|
7 | %tolerance we use in litmus checks for the consistency of the model
|
---|
8 | tolerance=10^-12;
|
---|
9 |
|
---|
10 | %check usage
|
---|
11 | if nargin~=1,
|
---|
12 | help ismodelselfconsistent
|
---|
13 | error('ismodelselfconsistent error message: wrong usage');
|
---|
14 | end
|
---|
15 |
|
---|
16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRANSIENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
17 |
|
---|
18 | %check analysis
|
---|
19 | if md.analysis_type==TransientAnalysisEnum,
|
---|
20 | if md.dt<=0,
|
---|
21 | error('model not consistent: field dt must be positive for a transient run')
|
---|
22 | end
|
---|
23 |
|
---|
24 | %recursive call to ismodelselfconsistent
|
---|
25 | analysis=[DiagnosticAnalysisEnum PrognosticAnalysisEnum ThermalAnalysisEnum];
|
---|
26 | for i=1:length(analysis),
|
---|
27 | md.analysis_type=analysis;
|
---|
28 | ismodelselfconsistent(md);
|
---|
29 | end
|
---|
30 | end
|
---|
31 |
|
---|
32 |
|
---|
33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMMON CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
34 |
|
---|
35 | %COUNTER
|
---|
36 | if md.counter<3,
|
---|
37 | error(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize,setelementstype)!']);
|
---|
38 | end
|
---|
39 |
|
---|
40 | %NAME
|
---|
41 | if isempty(md.name),
|
---|
42 | error(['model is not correctly configured: missing name!']);
|
---|
43 | end
|
---|
44 |
|
---|
45 | %ELEMENTSTYPE
|
---|
46 | if size(md.elements_type,1)~=md.numberofelements | size(md.elements_type,2)~=2,
|
---|
47 | error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
|
---|
48 | end
|
---|
49 | if any(ones(md.numberofelements,1)-((md.elements_type(:,1)==HutterFormulationEnum) + (md.elements_type(:,1)==MacAyealFormulationEnum) + (md.elements_type(:,1)==PattynFormulationEnum)))
|
---|
50 | error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
|
---|
51 | end
|
---|
52 | if any(ones(md.numberofelements,1)-((md.elements_type(:,2)==StokesFormulationEnum) + (md.elements_type(:,2)==NoneFormulationEnum)))
|
---|
53 | error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
|
---|
54 | end
|
---|
55 | if strcmpi(md.type,'2d'),
|
---|
56 | if (ismember(PattynFormulationEnum,md.elements_type(:,1)) | ismember(StokesFormulationEnum,md.elements_type(:,2))),
|
---|
57 | error(['model not consistent: for a 2d model, only MacAyeal''s and Hutter''s elements are allowed']);
|
---|
58 | end
|
---|
59 | end
|
---|
60 | if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0),
|
---|
61 | error(['model not consistent: no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']);
|
---|
62 | end
|
---|
63 | if (md.analysis_type==DiagnosticAnalysisEnum & any(ismember(MacAyealFormulationEnum,md.elements_type(:,1)) & ismember(PattynFormulationEnum,md.elements_type(:,1))))
|
---|
64 | error(['model not consistent: coupling MacAyeal/Pattyn not implemented yet']);
|
---|
65 | end
|
---|
66 | if (md.isstokes & md.analysis_type==TransientAnalysisEnum());
|
---|
67 | error(['model not consistent: Stokes transient not implemented yet']);
|
---|
68 | end
|
---|
69 |
|
---|
70 | %ICEFRONT
|
---|
71 | if strcmpi(md.type,'2d'),
|
---|
72 | fields={'pressureload'};
|
---|
73 | checksize(md,fields,[NaN 3]);
|
---|
74 | elseif strcmpi(md.type,'3d'),
|
---|
75 | fields={'pressureload'};
|
---|
76 | checksize(md,fields,[NaN 5]);
|
---|
77 | end
|
---|
78 |
|
---|
79 | %NO NAN
|
---|
80 | fields={'numberofelements','numberofgrids','x','y','z','drag','drag_type','p','q',...
|
---|
81 | 'rho_ice','rho_water','B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',...
|
---|
82 | 'tolx','np','eps_res','exclusive','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
|
---|
83 | checknan(md,fields);
|
---|
84 |
|
---|
85 | %FIELDS >= 0
|
---|
86 | fields={'numberofelements','numberofgrids','elements','drag','drag_type','p','q',...
|
---|
87 | 'rho_ice','rho_water','B','elementoniceshelf','thickness','g','eps_res','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',...
|
---|
88 | 'sparsity','lowmem','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
|
---|
89 | checkgreater(md,fields,0);
|
---|
90 |
|
---|
91 | %FIELDS > 0
|
---|
92 | fields={'numberofelements','numberofgrids','elements','drag_type','p',...
|
---|
93 | 'rho_ice','rho_water','B','thickness','g','eps_res','eps_rel','eps_abs','maxiter','tolx',...
|
---|
94 | 'sparsity','deltaH','DeltaH','timeacc','timedec'};
|
---|
95 | checkgreaterstrict(md,fields,0);
|
---|
96 |
|
---|
97 | %SIZE NUMBEROFELEMENTS
|
---|
98 | fields={'elements','p','q','elementoniceshelf','n','elementonbed'};
|
---|
99 | checklength(md,fields,md.numberofelements);
|
---|
100 |
|
---|
101 | %SIZE NUMBEROFGRIDS
|
---|
102 | fields={'x','y','z','B','drag','spcvelocity','melting','accumulation','surface','thickness','bed','gridonbed','gridonsurface'};
|
---|
103 | checklength(md,fields,md.numberofgrids);
|
---|
104 |
|
---|
105 | %THICKNESS = SURFACE - BED
|
---|
106 | if any((md.thickness-md.surface+md.bed)>tolerance),
|
---|
107 | error(['model not consistent: model ' md.name ' violates the equality thickness=surface-bed!']);
|
---|
108 | end
|
---|
109 |
|
---|
110 | %RIFTS
|
---|
111 | if md.numrifts,
|
---|
112 | if ~strcmpi(md.type,'2d'),
|
---|
113 | error(['model not consistent: models with rifts are only supported in 2d for now!']);
|
---|
114 | end
|
---|
115 | end
|
---|
116 | if ~isstruct(md.rifts),
|
---|
117 | if ~isnan(md.rifts),
|
---|
118 | if ~isempty(find(md.segmentmarkers>=2)),
|
---|
119 | %We have segments with rift markers, but no rift structure!
|
---|
120 | error(['model not consistent: model ' md.name ' should be processed for rifts (run meshprocessrifts)!']);
|
---|
121 | end
|
---|
122 | end
|
---|
123 | end
|
---|
124 |
|
---|
125 | %ARTIFICIAL DIFFUSIVITY
|
---|
126 | if ~ismember(md.artificial_diffusivity,[0 1]),
|
---|
127 | error('model not consistent: artificial_diffusivity should be a scalar (1 or 0)');
|
---|
128 | end
|
---|
129 |
|
---|
130 | %PARAMETEROUTPUT
|
---|
131 | if md.numoutput~=length(md.parameteroutput),
|
---|
132 | error('model not consistent: numoutput should be the same size as parameteroutput');
|
---|
133 | end
|
---|
134 |
|
---|
135 | %CONNECTIVITY
|
---|
136 | if strcmpi(md.type,'2d'),
|
---|
137 | if md.connectivity<9,
|
---|
138 | error('model not consistent: connectivity should be at least 9 for 2d models');
|
---|
139 | end
|
---|
140 | end
|
---|
141 | if strcmpi(md.type,'3d'),
|
---|
142 | if md.connectivity<24,
|
---|
143 | error('model not consistent: connectivity should be at least 24 for 3d models');
|
---|
144 | end
|
---|
145 | end
|
---|
146 |
|
---|
147 | %LOWMEM = 0 or 1
|
---|
148 | if ((md.lowmem ~= 1) & (md.lowmem~=0)),
|
---|
149 | error(['model not consistent: model ' md.name ' lowmem field should be 0 or 1']);
|
---|
150 | end
|
---|
151 |
|
---|
152 | %PARALLEL
|
---|
153 | if ~strcmpi(md.cluster,'none'),
|
---|
154 |
|
---|
155 | %NAN VALUES
|
---|
156 | fields={'time','np'};
|
---|
157 | checknan(md,fields);
|
---|
158 |
|
---|
159 | %FIELD > 0
|
---|
160 | fields={'time','np'};
|
---|
161 | checkgreaterstrict(md,fields,0);
|
---|
162 |
|
---|
163 | end
|
---|
164 |
|
---|
165 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SOLUTION CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
166 |
|
---|
167 | %QMU
|
---|
168 | if md.qmu_analysis,
|
---|
169 | if md.qmu_params.evaluation_concurrency~=1,
|
---|
170 | error(['model not consistent: concurrency should be set to 1 when running dakota in library mode']);
|
---|
171 | end
|
---|
172 | if ~isempty(md.part),
|
---|
173 | if numel(md.part)~=md.numberofgrids,
|
---|
174 | error(['model not consistent: user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']);
|
---|
175 | end
|
---|
176 | if find(md.part)>=md.numberofgrids,
|
---|
177 | error(['model not consistent: user supplied partition should be indexed from 0 (c-convention)']);
|
---|
178 | end
|
---|
179 | if md.npart~=md.numberofgrids,
|
---|
180 | error(['model not consistent: user supplied partition should have same size as md.npart']);
|
---|
181 | end
|
---|
182 | end
|
---|
183 | if md.eps_rel>10^-3,
|
---|
184 | error(['model not consistent: for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']);
|
---|
185 | end
|
---|
186 | end
|
---|
187 |
|
---|
188 | %DIAGNOSTIC
|
---|
189 | if md.analysis_type==DiagnosticAnalysisEnum,
|
---|
190 |
|
---|
191 | %CHECK THAT WE ARE NOT FULLY CONSTRAINED
|
---|
192 | if strcmpi(md.type,'2d'),
|
---|
193 | if isempty(find(~md.spcvelocity(:,1:2))),
|
---|
194 | error(['model not consistent: model ' md.name ' is totally constrained, no need to solve!']);
|
---|
195 | end
|
---|
196 | end
|
---|
197 |
|
---|
198 | %HUTTER ON ICESHELF WARNING
|
---|
199 | if any(md.elements_type(:,1)==HutterFormulationEnum & md.elementoniceshelf),
|
---|
200 | disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
|
---|
201 | end
|
---|
202 |
|
---|
203 | %SINGULAR
|
---|
204 | if ~any(sum(md.spcvelocity(:,1:2),2)==2),
|
---|
205 | error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
|
---|
206 | end
|
---|
207 |
|
---|
208 | %DIRICHLET IF THICKNESS <= 0
|
---|
209 | if any(md.thickness<=0),
|
---|
210 | pos=find(md.thickness<=0);
|
---|
211 | if any(find(md.spcthickness(pos,1)==0)),
|
---|
212 | error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
|
---|
213 | end
|
---|
214 | end
|
---|
215 |
|
---|
216 | end
|
---|
217 |
|
---|
218 | %PROGNOSTIC
|
---|
219 | if md.analysis_type==PrognosticAnalysisEnum,
|
---|
220 |
|
---|
221 | %INITIAL VELOCITIES
|
---|
222 | fields={'vx','vy'};
|
---|
223 | checksize(md,fields,[md.numberofgrids 1]);
|
---|
224 | checknan(md,fields);
|
---|
225 |
|
---|
226 | end
|
---|
227 |
|
---|
228 | %STEADYSTATE
|
---|
229 | if md.analysis_type==SteadystateAnalysisEnum,
|
---|
230 |
|
---|
231 | %NDT
|
---|
232 | if md.dt~=0,
|
---|
233 | error(['model not consistent: for a steadystate computation, dt must be zero.']);
|
---|
234 | end
|
---|
235 |
|
---|
236 | %PRESSURE
|
---|
237 | if isnans(md.pressure),
|
---|
238 | error(['model not consistent: for a steadystate computation, the model must have an initial pressure, even lithostatic will do.']);
|
---|
239 | end
|
---|
240 |
|
---|
241 | %eps:
|
---|
242 | if isnan(md.eps_rel),
|
---|
243 | error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']);
|
---|
244 | end
|
---|
245 |
|
---|
246 | %dim:
|
---|
247 | if strcmpi(md.type,'2d'),
|
---|
248 | error(['model not consistent: for a steadystate computation, model needs to be 3d']);
|
---|
249 | end
|
---|
250 | end
|
---|
251 |
|
---|
252 | %THERMAL STEADY AND THERMAL TRANSIENT
|
---|
253 | if md.analysis_type==ThermalAnalysisEnum,
|
---|
254 |
|
---|
255 | %EXTRUSION
|
---|
256 | if strcmp(md.type,'2d'),
|
---|
257 | error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
|
---|
258 | end
|
---|
259 |
|
---|
260 | %VELOCITIES AND PRESSURE
|
---|
261 | fields={'vx','vy','vz','pressure'};
|
---|
262 | checksize(md,fields,[md.numberofgrids 1]);
|
---|
263 | checknan(md,fields);
|
---|
264 |
|
---|
265 | end
|
---|
266 |
|
---|
267 | %THERMAL TRANSIENT
|
---|
268 | if md.analysis_type==ThermalAnalysisEnum & md.dt~=0
|
---|
269 |
|
---|
270 | %DT and NDT
|
---|
271 | fields={'dt','ndt'};
|
---|
272 | checkgreaterstrict(md,fields,0);
|
---|
273 |
|
---|
274 | %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
|
---|
275 | fields={'temperature','accumulation','melting'};
|
---|
276 | checksize(md,fields,[md.numberofgrids 1]);
|
---|
277 |
|
---|
278 | end
|
---|
279 |
|
---|
280 | %CONTROL
|
---|
281 | if md.control_analysis,
|
---|
282 |
|
---|
283 | %CONTROL TYPE
|
---|
284 | if ~ischar(md.control_type),
|
---|
285 | error('model not consistent: control_type should be a string');
|
---|
286 | end
|
---|
287 |
|
---|
288 | %LENGTH CONTROL FIELDS
|
---|
289 | fields={'maxiter','optscal','fit','cm_jump'};
|
---|
290 | checklength(md,fields,md.nsteps);
|
---|
291 |
|
---|
292 | %FIT
|
---|
293 | if sum((double(md.fit==1) + double(md.fit==0) + double(md.fit==2))==1)~=md.nsteps
|
---|
294 | error('model not consistent: wrong fits: fit should be a vector of size nsteps holding 0, 1 and 2 only')
|
---|
295 | end
|
---|
296 |
|
---|
297 | %OBSERVED VELOCITIES
|
---|
298 | fields={'vx_obs','vy_obs'};
|
---|
299 | checksize(md,fields,[md.numberofgrids 1]);
|
---|
300 | checknan(md,fields);
|
---|
301 |
|
---|
302 | %DIRICHLET IF THICKNESS <= 0
|
---|
303 | if any(md.thickness<=0),
|
---|
304 | pos=find(md.thickness<=0);
|
---|
305 | if any(find(md.spcthickness(pos,1)==0)),
|
---|
306 | error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
|
---|
307 | end
|
---|
308 | end
|
---|
309 | end
|
---|
310 |
|
---|
311 | %QMU
|
---|
312 | if strcmpi(md.analysis_type,'qmu'),
|
---|
313 | if ~strcmpi(md.cluster,'none'),
|
---|
314 | if md.waitonlock==0,
|
---|
315 | error(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']);
|
---|
316 | end
|
---|
317 | end
|
---|
318 | end
|
---|
319 |
|
---|
320 | end %end function
|
---|
321 |
|
---|
322 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CHECK FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
323 |
|
---|
324 | function checklength(md,fields,fieldlength)
|
---|
325 | %CHECKSIZE - check length of a field
|
---|
326 | for i=1:length(fields),
|
---|
327 | if length(eval(['md.' fields{i}]))~=fieldlength,
|
---|
328 | error(['model not consistent: field ' fields{i} ' length should be ' num2str(fieldlength)]);
|
---|
329 | end
|
---|
330 | end
|
---|
331 | end
|
---|
332 |
|
---|
333 | function checksize(md,fields,fieldsize)
|
---|
334 | %CHECKSIZE - check size of a field
|
---|
335 | for i=1:length(fields),
|
---|
336 | if isnan(fieldsize(1)),
|
---|
337 | if (size(eval(['md.' fields{i}]),2)~=fieldsize(2)),
|
---|
338 | error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(2)) ' columns']);
|
---|
339 | end
|
---|
340 | elseif isnan(fieldsize(2)),
|
---|
341 | if (size(eval(['md.' fields{i}]),1)~=fieldsize(1)),
|
---|
342 | error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(1)) ' rows']);
|
---|
343 | end
|
---|
344 | else
|
---|
345 | if ((size(eval(['md.' fields{i}]),1)~=fieldsize(1)) | (size(eval(['md.' fields{i}]),2)~=fieldsize(2)))
|
---|
346 | error(['model not consistent: field ' fields{i} ' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]);
|
---|
347 | end
|
---|
348 | end
|
---|
349 | end
|
---|
350 | end
|
---|
351 |
|
---|
352 | function checknan(md,fields)
|
---|
353 | %CHECKNAN - check nan values of a field
|
---|
354 | for i=1:length(fields),
|
---|
355 | if any(isnan(eval(['md.' fields{i}]))),
|
---|
356 | error(['model not consistent: NaN values in field ' fields{i}]);
|
---|
357 | end
|
---|
358 | end
|
---|
359 | end
|
---|
360 |
|
---|
361 | function checkreal(md,fields)
|
---|
362 | %CHECKREAL - check real values of a field
|
---|
363 | for i=1:length(fields),
|
---|
364 | if any(eval(['~isreal(md.' fields{i} ')'])),
|
---|
365 | error(['model not consistent: complex values in field ' fields{i}]);
|
---|
366 | end
|
---|
367 | end
|
---|
368 | end
|
---|
369 |
|
---|
370 | function checkgreaterstrict(md,fields,lowerbound)
|
---|
371 | %CHECKGREATERSTRICT - check values of a field
|
---|
372 | for i=1:length(fields),
|
---|
373 | if any(eval(['md.' fields{i} '<=' num2str(lowerbound) ])),
|
---|
374 | error(['model not consistent: field ' fields{i} ' should have values stricly above ' num2str(lowerbound)]);
|
---|
375 | end
|
---|
376 | end
|
---|
377 | end
|
---|
378 |
|
---|
379 | function checkgreater(md,fields,lowerbound)
|
---|
380 | %CHECKGREATER - check values of a field
|
---|
381 | for i=1:length(fields),
|
---|
382 | if any(eval(['md.' fields{i} '<' num2str(lowerbound) ])),
|
---|
383 | error(['model not consistent: field ' fields{i} ' should have values above ' num2str(lowerbound)]);
|
---|
384 | end
|
---|
385 | end
|
---|
386 | end
|
---|
387 |
|
---|
388 | function checklessstrict(md,fields,upperbound)
|
---|
389 | %CHECKLESSSTRICT - check values of a field
|
---|
390 | for i=1:length(fields),
|
---|
391 | if any(eval(['md.' fields{i} '>=' num2str(upperbound) ])),
|
---|
392 | error(['model not consistent: field ' fields{i} ' should have values stricly below ' num2str(upperbound)]);
|
---|
393 | end
|
---|
394 | end
|
---|
395 | end
|
---|
396 |
|
---|
397 | function checkless(md,fields,upperbound)
|
---|
398 | %CHECKLESS - check values of a field
|
---|
399 | for i=1:length(fields),
|
---|
400 | if any(eval(['md.' fields{i} '>' num2str(upperbound) ])),
|
---|
401 | error(['model not consistent: field ' fields{i} ' should have values below ' num2str(upperbound)]);
|
---|
402 | end
|
---|
403 | end
|
---|
404 | end
|
---|