source: issm/trunk/src/m/classes/public/ismodelselfconsistent.m@ 1298

Last change on this file since 1298 was 1298, checked in by Mathieu Morlighem, 16 years ago

some fixing (new enum names)

File size: 14.1 KB
Line 
1function bool=ismodelselfconsistent(md,package),
2%ISMODELSELFCONSISTENT - check that model forms a closed form solvable problem.
3%
4% Usage:
5% bool=ismodelselfconsistent(md,package),
6
7%tolerance we use in litmus tests for the consistency of the model
8tolerance=10^-12;
9if (nargin~=2 )
10 help ismodelselfconsistent
11 error('ismodelselfconsistent error message: wrong usage');
12end
13
14%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMMON CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16%COUNTER
17if md.counter<3,
18 disp(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize)!']);
19 bool=0;return;
20end
21
22%NAME
23if isempty(md.name),
24 disp(['model is not correctly configured: missing name!']);
25 bool=0;return;
26end
27
28%MESH
29if md.numberofelements<=0,
30 disp(['model ' md.name ' does not have any elements!']);
31 bool=0; return;
32end
33if md.numberofgrids<=0,
34 disp(['model ' md.name ' does not have any grids!']);
35 bool=0; return;
36end
37
38%ELEMENTSTYPE
39if size(md.elements_type,1)~=md.numberofelements | size(md.elements_type,2)~=2,
40 disp(['Types of elements have not been set properly, run setelementstype first'])
41 bool=0;return;
42end
43if any(ones(md.numberofelements,1)-((md.elements_type(:,1)==HutterEnum) + (md.elements_type(:,1)==MacAyealEnum) + (md.elements_type(:,1)==PattynEnum)))
44 disp(['Types of elements have not been set properly, run setelementstype first'])
45 bool=0;return;
46end
47if any(ones(md.numberofelements,1)-((md.elements_type(:,2)==StokesEnum) + (md.elements_type(:,2)==NoneEnum)))
48 disp(['Types of elements have not been set properly, run setelementstype first'])
49 bool=0;return;
50end
51if strcmpi(md.type,'2d'),
52 if (ismember(PattynEnum,md.elements_type(:,1)) | ismember(StokesEnum,md.elements_type(:,2))),
53 disp(['For a 2d model, only MacAyeal''s and Hutter''s elements are allowed']);
54 bool=0;return;
55 end
56end
57
58if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0),
59 disp(['no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']);
60 bool=0;return;
61end
62
63
64%NO NAN
65fields={'numberofelements','numberofgrids','x','y','z','segmentonneumann_diag','drag','drag_type','p','q','gridondirichlet_diag',...
66 'rho_ice','rho_water','B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',...
67 'tolx','np','eps_rel','exclusive','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
68for i=1:length(fields),
69 if ~isempty(md.(fields{i})),
70 if any(isnan(md.(fields{i}))),
71 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']);
72 bool=0; return;
73 end
74 end
75end
76
77%FIELDS > 0
78fields={'numberofelements','numberofgrids','elements','segmentonneumann_diag','drag','drag_type','p','q','gridondirichlet_diag',...
79 'rho_ice','rho_water','B','elementoniceshelf','thickness','g','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',...
80 'sparsity','lowmem','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
81for i=1:length(fields),
82 if ~isempty(md.(fields{i})),
83 if any(md.(fields{i})<0),
84 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']);
85 bool=0; return;
86 end
87 end
88end
89if any(md.p<=0),
90 disp(['model ' md.name ' has some p<0 friction coefficientsin sliding law']);
91 bool=0; return;
92end
93
94%FIELDS ~=0
95fields={'numberofelements','numberofgrids','elements','segmentonneumann_diag','drag_type',...
96 'rho_ice','rho_water','B','thickness','g','eps_rel','eps_abs','maxiter','tolx',...
97 'sparsity','deltaH','DeltaH','timeacc','timedec'};
98for i=1:length(fields),
99 if ~isempty(md.(fields{i})),
100 if any(md.(fields{i})==0),
101 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']);
102 bool=0; return;
103 end
104 end
105end
106
107%SIZE NUMBEROFELEMENTS
108fields={'elements','p','q','elementoniceshelf','n','elementonbed'};
109for i=1:size(fields,2),
110 if (size(md.(fields{i}),1)~=md.numberofelements),
111 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofelements) '!']);
112 bool=0; return;
113 end
114end
115
116%SIZE NUMBEROFGRIDS
117fields={'x','y','z','B','drag','gridondirichlet_diag','melting','accumulation','surface','thickness','bed','gridonbed','gridonsurface'};
118for i=1:length(fields),
119 if length(md.(fields{i}))~=md.numberofgrids,
120 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofgrids) '!']);
121 bool=0; return;
122 end
123end
124
125%THICKNESS = SURFACE - BED
126if any((md.thickness-md.surface+md.bed)>tolerance),
127 disp(['model ' md.name ' violates the equality thickness=surface-bed!']);
128 bool=0; return;
129end
130
131%RIFTS
132if md.numrifts,
133 if ~strcmpi(md.type,'2d'),
134 disp(['Models with rifts are only supported in 2d for now!']);
135 bool=0;return;
136 end
137end
138if ~isstruct(md.rifts),
139 if ~isnan(md.rifts),
140 if ~isempty(find(md.segmentmarkers>=2)),
141 %We have segments with rift markers, but no rift structure!
142 disp(['model ' md.name ' should be processed for rifts (run meshprocessrifts)!']);
143 bool=0; return;
144 end
145 end
146end
147
148%ARTIFICIAL DIFFUSIVITY
149if ~isscalar(md.artificial_diffusivity),
150 disp('artificial_diffusivity should be a scalar (1 or 0)');
151 bool=0;return;
152end
153
154%CLUSTER
155if ~strcmpi(package,'cielo') & ~strcmpi(md.cluster,'none')
156 disp(['parallel solution not supported by package ' package '. Use cluster=''none'' ']);
157 bool=0;return;
158end
159
160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SOLUTION CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161%QMU
162if md.qmu_analysis,
163 if md.qmu_params.evaluation_concurrency~=1,
164 disp(['concurrency should be set to 1 when running dakota in library mode']);
165 bool=0;return;
166 end
167 if ~isempty(md.part),
168 if numel(md.part)~=md.numberofgrids,
169 disp(['user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']);
170 bool=0;return;
171 end
172 if find(md.part)>=md.numberofgrids,
173 disp(['user supplied partition should be indexed from 0 (c-convention)']);
174 bool=0;return;
175 end
176 if md.npart~=md.numberofgrids,
177 disp(['user supplied partition should have same size as md.npart']);
178 bool=0;return;
179 end
180
181 end
182end
183
184%DIAGNOSTIC
185if strcmpi(md.analysis_type,'diagnostic')
186
187 %HUTTER ON ICESHELF WARNING
188 if any(md.elements_type(:,1)==HutterEnum & md.elementoniceshelf),
189 disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
190 end
191
192 %SINGULAR
193 if ~any(md.gridondirichlet_diag),
194 disp(['model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
195 bool=0;return;
196 end
197
198 %DIRICHLET VALUES
199 if isempty(md.gridondirichlet_diag) | isempty(md.dirichletvalues_diag),
200 disp(['model ' md.name ' is not well posed. Missing dirichlet values for diagnostic run']);
201 bool=0;return;
202 end
203
204 %DIRICHLET IF THICKNESS <= 0
205 if any(md.thickness<=0),
206 pos=find(md.thickness<=0);
207 if ~isempty(find(md.gridondirichlet_diag(pos)==0)),
208 disp(['model ' md.name ' has some grids with 0 thickness']);
209 bool=0; return;
210 end
211 end
212end
213
214%PROGNOSTIC
215if strcmp(md.analysis_type,'prognostic'),
216 %old testing
217 % if isempty(find(md.gridondirichlet_diag)),
218 % disp(['model ' md.name ' diagnostic is not well posed (singular). You need at least one grid with fixed velocity!'])
219 % bool=0;return;
220 % end
221 % if isempty(find(md.gridondirichlet_prog)),
222 % disp(['model ' md.name ' prognostic is not well posed (singular). You need at least one grid with fixed thickness!'])
223 % bool=0;return;
224 % end
225
226 %VELOCITIES
227 if (size(md.vx,1)~=md.numberofgrids | size(md.vy,1)~=md.numberofgrids),
228 disp(['a 3d velocity is required. Run ''diagnostic'' solution first!'])
229 bool=0; return;
230 end
231end
232
233%THERMAL TRANSIENT
234if strcmp(md.analysis_type,'thermal')
235 if strcmp(md.sub_analysis_type,'transient')
236
237 %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
238 if isempty(md.temperature),
239 disp(['An initial temperature is needed for a transient thermal computation'])
240 bool=0;return;
241 end
242 if isstruct(md.temperature) | isstruct(md.melting) | isstruct(md.accumulation),
243 disp(['The initial temperature, melting or accumulation should be a list and not a structure'])
244 bool=0;return;
245 end
246 end
247end
248
249%THERMAL STEADY AND THERMAL TRANSIENT
250if strcmpi(md.analysis_type,'thermal'),
251
252 %EXTRUSION
253 if strcmp(md.type,'2d'),
254 disp(['For a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
255 bool=0;return;
256 end
257
258 %VELOCITIES AND PRESSURE
259 if (isempty(md.vx) | isnan(md.vx) | isempty(md.vy) | isnan(md.vy) | isempty(md.vz) | isnan(md.vz)),
260 disp(['a 3d velocity is required. Run ''diagnostic'' solution first!'])
261 bool=0;return;
262 end
263 if (isempty(md.pressure) | isnan(md.pressure)),
264 disp(['pressure is required. Run ''diagnostic'' solution first!'])
265 bool=0;return;
266 end
267end
268
269%THERMAL TRANSIENT AND TRANSIENT
270if strcmp(md.analysis_type,'thermal'),
271
272 %DT and NDT
273 fields={'dt','ndt'};
274 for i=1:length(fields),
275 if any(md.(fields{i})<0),
276 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']);
277 bool=0; return;
278 end
279 end
280
281 %INITIAL TEMPERATURE
282 if isstruct(md.temperature),
283 disp(['The initial temperature should be empty or a list but not a structure'])
284 bool=0;return;
285 end
286end
287
288%PARAMETERS
289if strcmp(md.analysis_type,'parameters')
290
291 %PACKAGE
292 if ~strcmpi(package,'ice'),
293 disp('parameter solution only supported by package ice yet');
294 bool=0;return;
295 end
296
297 %OUTPUT
298 if ~iscell(md.parameteroutput)
299 disp(['parameteroutput field must be a cell, example {''strainrate'',''stress'',''deviatoricstress'',''viscousheating''}']);
300 bool=0; return;
301 end
302 for i=1:length(md.parameteroutput)
303 if ~strcmpi(md.parameteroutput(i),'strainrate') & ~strcmpi(md.parameteroutput(i),'stress') & ~strcmpi(md.parameteroutput(i),'deviatoricstress') & ~strcmpi(md.parameteroutput(i),'viscousheating') ...
304 & ~strcmpi(md.parameteroutput(i),'pressure_elem') & ~strcmpi(md.parameteroutput(i),'stress_bed') & ~strcmpi(md.parameteroutput(i),'stress_surface')
305 disp(['one of the parameteroutput is not supported yet']);
306 bool=0; return;
307 end
308 end
309 %VELOCITY
310 if ~(size(md.vx,1)==md.numberofgrids & size(md.vy,1)==md.numberofgrids & (size(md.vz,1)==md.numberofgrids | strcmpi(md.type,'2d')))
311 disp(['velocities are required!']);
312 bool=0;return;
313 end
314
315 %HUTTER
316 if any(md.elements_type(:,1)==HutterEnum);
317 disp(['The model has Hutter''s elements. Impossible to compute parameters']);
318 bool=0;return;
319 end
320end
321
322%CONTROL
323if strcmpi(md.analysis_type,'control'),
324
325 %CONTROL TYPE
326 if ~ischar(md.control_type),
327 disp('control_type should be a string');
328 bool=0;return;
329 end
330
331 %LENGTH CONTROL FIELDS
332 if (length(md.maxiter)~=md.nsteps | length(md.optscal)~=md.nsteps | length(md.fit)~=md.nsteps)
333 disp('maxiter, optscal and fit must have the length specified by nsteps')
334 bool=0;return;
335 end
336
337 %FIT
338 if sum((double(md.fit==1) + double(md.fit==0) + double(md.fit==2))==1)~=md.nsteps
339 disp('wrong fits: fit should be a vector of size nsteps holding 0, 1 and 2 only')
340 bool=0;return;
341 end
342
343 %OBSERVED VELOCITIES
344 fields={'vx_obs','vy_obs'};
345 for i=1:length(fields),
346 if any(length(md.(fields{i}))~=md.numberofgrids),
347 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofgrids) '!']);
348 bool=0; return;
349 end
350 end
351end
352
353%QMU
354if strcmpi(md.analysis_type,'qmu'),
355 if ~strcmpi(md.cluster,'none'),
356 if md.waitonlock==0,
357 disp(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']);
358 bool=0;return;
359 end
360 end
361end
362
363%MESH
364if strcmpi(md.analysis_type,'mesh'),
365 %this solution is a little special. It should come right after the md=model; operation. So a lot less checks!
366
367 bool=1;
368 return;
369end
370
371%MESH2GRID
372if strcmpi(md.analysis_type,'mesh2grid'),
373 if ~strcmpi(md.cluster,'none'),
374 disp(['model is not correctly configured: mesh2grid not supported in parallel yet!']);
375 bool=0;return;
376 end
377end
378
379
380%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PACKAGE CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381
382%CIELO
383if strcmpi(package,'cielo'),
384
385 %NAN VALUES
386 fields={'sparsity'};
387 for i=1:length(fields),
388 if ~isempty(md.(fields{i})),
389 if any(isnan(md.(fields{i}))),
390 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']);
391 bool=0; return;
392 end
393 end
394 end
395
396 %FIELD > 0
397 fields={'sparsity'};
398 for i=1:length(fields),
399 if ~isempty(md.(fields{i})),
400 if any(md.(fields{i})<0),
401 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']);
402 bool=0; return;
403 end
404 end
405 end
406
407 %FIELD ~= 0
408 fields={'sparsity'};
409 for i=1:length(fields),
410 if ~isempty(md.(fields{i})),
411 if any(md.(fields{i})==0),
412 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']);
413 bool=0; return;
414 end
415 end
416 end
417
418 %SPARSITY BETWEEN 0 AND 1
419 if ( (md.sparsity<=0) | (md.sparsity>1)),
420 disp(['model ' md.name ' sparsity should be inside the [0 1] range']);
421 bool=0; return;
422 end
423
424 %RIFTS
425 if md.numrifts,
426 if ~strcmpi(md.cluster,'none')
427 if isempty(findstr('aijmumps',md.solverstring)),
428 disp(['For a 2d model with rifts, running on a cluster, you should use a direct solver like MUMPS!']);
429 bool=0;return;
430 end
431 end
432 end
433
434 %CONNECTIVITY
435 if strcmpi(md.type,'2d'),
436 if md.connectivity<9,
437 disp('connectivity should be at least 9 for 2d models');
438 bool=0;return;
439 end
440 end
441 if strcmpi(md.type,'3d'),
442 if md.connectivity<24,
443 disp('connectivity should be at least 24 for 3d models');
444 bool=0;return;
445 end
446 end
447
448 %LOWMEM = 0 or 1
449 if ((md.lowmem ~= 1) & (md.lowmem~=0)),
450 disp(['model ' md.name ' lowmem field should be 0 or 1']);
451 bool=0; return;
452 end
453
454%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARALLEL CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
455
456 if ~strcmpi(md.cluster,'none'),
457
458 %NAN VALUES
459 fields={'time','np'};
460 for i=1:length(fields),
461 if ~isempty(md.(fields{i})),
462 if any(isnan(md.(fields{i}))),
463 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']);
464 bool=0; return;
465 end
466 end
467 end
468
469 %FIELD > 0
470 fields={'time','np'};
471 for i=1:length(fields),
472 if ~isempty(md.(fields{i})),
473 if any(md.(fields{i})<0),
474 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']);
475 bool=0; return;
476 end
477 end
478 end
479
480 %FIELD ~= 0
481 fields={'time','np'};
482 for i=1:length(fields),
483 if ~isempty(md.(fields{i})),
484 if any(md.(fields{i})==0),
485 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']);
486 bool=0; return;
487 end
488 end
489 end
490
491 end
492
493end
494
495%No problems, just return 1;
496bool=1;
497return;
Note: See TracBrowser for help on using the repository browser.