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

Last change on this file since 5359 was 5359, checked in by Mathieu Morlighem, 15 years ago

Control_type is now an enum and moved RheologyB2d to RheologyBbar

File size: 17.2 KB
Line 
1function 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
8tolerance=10^-12;
9%check usage {{{1
10if nargin~=1,
11 help ismodelselfconsistent
12 error('ismodelselfconsistent error message: wrong usage');
13end
14%}}}
15
16%recursive call for TRANSIENT {{{1
17if (md.analysis_type==Transient2DSolutionEnum | md.analysis_type==Transient3DSolutionEnum),
18 if md.dt<=0,
19 error('model not consistent: field dt must be positive for a transient run')
20 end
21
22 %recursive call to ismodelselfconsistent
23 if (md.dim==2),
24 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum];
25 else
26 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum ThermalSolutionEnum];
27 end
28
29 for i=1:length(analysis),
30 md.analysis_type=analysis(i);
31 ismodelselfconsistent(md);
32 end
33end
34%}}}
35
36% Common checks
37%COUNTER {{{1
38if md.counter<3,
39 error(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize,setelementstype)!']);
40end
41%}}}
42%NAME{{{1
43if isempty(md.name),
44 error(['model is not correctly configured: missing name!']);
45end
46%}}}
47%ELEMENTS{{{1
48fields={'elements'};
49if (md.dim==2),
50 checksize(md,fields,[md.numberofelements 3]);
51else
52 checksize(md,fields,[md.numberofelements 6]);
53end
54%}}}
55%ELEMENTSTYPE{{{1
56%Check the size of elements_type
57fields={'elements_type'};
58checksize(md,fields,[md.numberofelements 2]);
59%Check the values of elements_type(1)
60checkvalues(md,{'elements_type(:,1)'},[MacAyealApproximationEnum() HutterApproximationEnum() PattynApproximationEnum() MacAyealPattynApproximationEnum()]);
61%Check the values of elements_type(2)
62checkvalues(md,{'elements_type(:,2)'},[StokesApproximationEnum() NoneApproximationEnum()]);
63if (md.dim==2),
64 checkvalues(md,{'elements_type(:,1)'},[MacAyealApproximationEnum() HutterApproximationEnum()]);
65end
66if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0),
67 error(['model not consistent: no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']);
68end
69%}}}
70%VERTICESTYPE{{{1
71%Check the size of verticess_type
72fields={'vertices_type'};
73checksize(md,fields,[md.numberofgrids 2]);
74%Check the values of elements_type(1)
75checkvalues(md,{'elements_type(:,1)'},[MacAyealApproximationEnum() HutterApproximationEnum() PattynApproximationEnum() MacAyealPattynApproximationEnum()]);
76%Check the values of elements_type(2)
77checkvalues(md,{'elements_type(:,2)'},[StokesApproximationEnum() NoneApproximationEnum()]);
78if (md.dim==2),
79 checkvalues(md,{'elements_type(:,1)'},[MacAyealApproximationEnum() HutterApproximationEnum()]);
80end
81if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0),
82 error(['model not consistent: no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']);
83end
84%}}}
85%DG {{{1
86if md.prognostic_DG==1;
87 %CHECK THE COMPATIBILITY OF THE EDGES
88 fields={'edges'};
89 checksize(md,fields,[NaN 4]);
90 checknan(md,fields);
91end
92%}}}
93%PRESSURELOAD{{{1
94if (md.dim==2),
95 fields={'pressureload'};
96 checksize(md,fields,[NaN 4]);
97elseif md.dim==3,
98 fields={'pressureload'};
99 checksize(md,fields,[NaN 6]);
100else
101 error('dim should be either 2 3');
102end
103checkvalues(md,{'pressureload(:,end)'},[WaterEnum() AirEnum()]);
104%}}}
105%NO NAN {{{1
106fields={'numberofelements','numberofgrids','x','y','z','drag_coefficient','drag_type','drag_p','drag_q',...
107 'rho_ice','rho_water','rheology_B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',...
108 'tolx','np','eps_res','max_nonlinear_iterations','exclusive','rheology_n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
109checknan(md,fields);
110%}}}}
111%FIELDS >= 0 {{{1
112fields={'numberofelements','numberofgrids','elements','drag_coefficient','drag_type','drag_p','drag_q',...
113 'rho_ice','rho_water','rheology_B','elementoniceshelf','thickness','g','eps_res','max_nonlinear_iterations','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',...
114 'sparsity','lowmem','rheology_n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
115checkgreater(md,fields,0);
116%}}}
117%FIELDS > 0 {{{1
118fields={'numberofelements','numberofgrids','elements','drag_type','drag_p',...
119 'rho_ice','rho_water','rheology_B','thickness','g','max_nonlinear_iterations','eps_res','eps_rel','eps_abs','maxiter','tolx',...
120 'sparsity','deltaH','DeltaH','timeacc','timedec'};
121checkgreaterstrict(md,fields,0);
122%}}}
123%SIZE NUMBEROFELEMENTS {{{1
124fields={'drag_p','drag_q','elementoniceshelf','rheology_n','elementonbed'};
125checksize(md,fields,[md.numberofelements 1]);
126%}}}
127%SIZE NUMBEROFGRIDS {{{1
128fields={'x','y','z','rheology_B','drag_coefficient','melting_rate','accumulation_rate','surface','thickness','bed','gridonbed','gridonsurface'};
129checksize(md,fields,[md.numberofgrids 1]);
130%}}}
131%OTHER SIZES {{{1
132fields={'spcvelocity'};
133checksize(md,fields,[md.numberofgrids 6]);
134%}}}
135%THICKNESS = SURFACE - BED {{{1
136if any((md.thickness-md.surface+md.bed)>tolerance),
137 error(['model not consistent: model ' md.name ' violates the equality thickness=surface-bed!']);
138end
139%}}}
140%RIFTS{{{1
141if md.numrifts,
142 if ~(md.dim==2),
143 error(['model not consistent: models with rifts are only supported in 2d for now!']);
144 end
145 if ~isstruct(md.rifts),
146 error(['model not consistent: md.rifts should be a structure!']);
147 end
148 if ~isempty(find(md.segmentmarkers>=2)),
149 %We have segments with rift markers, but no rift structure!
150 error(['model not consistent: model ' md.name ' should be processed for rifts (run meshprocessrifts)!']);
151 end
152 %Check that rifts are filled with proper material
153 checkvalues(md,{'rifts.fill'},[WaterEnum() AirEnum() IceEnum() MelangeEnum()]);
154else
155 if ~isnans(md.rifts),
156 error(['model not consistent: md.rifts shoud be NaN since md.numrifts is 0!']);
157 end
158end
159%}}}
160%FLAGS (0 or 1){{{1
161if ~ismember(md.artificial_diffusivity,[0 1]),
162 error('model not consistent: artificial_diffusivity should be a scalar (1 or 0)');
163end
164if ~ismember(md.prognostic_DG,[0 1]),
165 error('model not consistent: prognostic_DG should be a scalar (1 or 0)');
166end
167if ~ismember(md.lowmem,[0 1]),
168 error(['model not consistent: model ' md.name ' lowmem field should be 0 or 1']);
169end
170%}}}
171%PARAMETEROUTPUT {{{1
172if md.numoutput~=length(md.parameteroutput),
173 error('model not consistent: numoutput should be the same size as parameteroutput');
174end
175%}}}
176%CONNECTIVITY {{{1
177if (md.dim==2),
178 if md.connectivity<9,
179 error('model not consistent: connectivity should be at least 9 for 2d models');
180 end
181end
182if md.dim==3,
183 if md.connectivity<24,
184 error('model not consistent: connectivity should be at least 24 for 3d models');
185 end
186end
187%}}}
188%PARALLEL{{{1
189if ~strcmpi(md.cluster,'none'),
190
191 %NAN VALUES
192 fields={'time','np'};
193 checknan(md,fields);
194
195 %FIELD > 0
196 fields={'time','np'};
197 checkgreaterstrict(md,fields,0);
198
199end
200%}}}
201
202% Solution checks
203%DIAGNOSTIC{{{1
204if md.analysis_type==DiagnosticSolutionEnum,
205
206 %HUTTER ON ICESHELF WARNING
207 if any(md.elements_type(:,1)==HutterApproximationEnum & md.elementoniceshelf),
208 disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
209 end
210
211 %SINGULAR
212 if ~any(sum(md.spcvelocity(:,1:2),2)==2),
213 error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
214 end
215
216 %DIRICHLET IF THICKNESS <= 0
217 if any(md.thickness<=0),
218 pos=find(md.thickness<=0);
219 if any(find(md.spcthickness(pos,1)==0)),
220 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
221 end
222 end
223
224 %INITIAL VELOCITY
225 if length(md.vx)==md.numberofgrids & length(md.vy)==md.numberofgrids,
226 fields={'vx','vy'};
227 checknan(md,fields);
228 end
229end
230%}}}
231%PROGNOSTIC{{{1
232if md.analysis_type==PrognosticSolutionEnum,
233
234 %INITIAL VELOCITIES
235 fields={'vx','vy'};
236 checksize(md,fields,[md.numberofgrids 1]);
237 checknan(md,fields);
238
239 %CHECK THAT WE ARE NOT FULLY CONSTRAINED
240 if (md.dim==2),
241 if isempty(find(~md.spcthickness(:,1))),
242 error(['model not consistent: model ' md.name ' is totally constrained for prognostic, no need to solve!']);
243 end
244 end
245
246end
247%}}}
248%STEADYSTATE{{{1
249if md.analysis_type==SteadystateSolutionEnum,
250
251 %NDT
252 if md.dt~=0,
253 error(['model not consistent: for a steadystate computation, dt must be zero.']);
254 end
255
256 %PRESSURE
257 if isnans(md.pressure),
258 error(['model not consistent: for a steadystate computation, the model must have an initial pressure, even lithostatic will do.']);
259 end
260
261 %eps:
262 if isnan(md.eps_rel),
263 error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']);
264 end
265
266 %dim:
267 if (md.dim==2),
268 error(['model not consistent: for a steadystate computation, model needs to be 3d']);
269 end
270end
271%}}}
272%THERMAL {{{1
273%THERMAL STEADY AND THERMAL TRANSIENT
274if md.analysis_type==ThermalSolutionEnum,
275
276 %EXTRUSION
277 if (md.dim==2),
278 error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
279 end
280
281 %CHECK THAT WE ARE NOT FULLY CONSTRAINED
282 if isempty(find(~md.spctemperature(:,1))),
283 error(['model not consistent: model ' md.name ' is totally constrained for temperature, no need to solve!']);
284 end
285
286 %VELOCITIES AND PRESSURE
287 fields={'vx','vy','vz','pressure'};
288 checksize(md,fields,[md.numberofgrids 1]);
289 checknan(md,fields);
290
291end
292
293%THERMAL TRANSIENT
294if md.analysis_type==ThermalSolutionEnum & md.dt~=0,
295
296 %DT and NDT
297 fields={'dt','ndt'};
298 checkgreaterstrict(md,fields,0);
299
300 %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
301 fields={'temperature','accumulation_rate','melting_rate'};
302 checksize(md,fields,[md.numberofgrids 1]);
303 checknan(md,fields);
304
305 %INITIAL TEMPERATURE
306 fields={'temperature','spctemperature(:,2)','observed_temperature'};
307 checkgreater(md,fields,0)
308
309end
310%}}}
311%BALANCEDTHICKNESS{{{1
312if md.analysis_type==BalancedthicknessSolutionEnum
313
314 %VELOCITIES MELTING AND ACCUMULATION
315 fields={'vx','vy','accumulation_rate','melting_rate','dhdt'};
316 checksize(md,fields,[md.numberofgrids 1]);
317 checknan(md,fields);
318
319 %SPC
320 if ~md.prognostic_DG,
321 if any(md.spcthickness(find(md.gridonboundary))~=1),
322 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcthickness']);
323 end
324 end
325end
326%}}}
327%BALANCEDVELOCITIES{{{1
328if md.analysis_type==BalancedvelocitiesSolutionEnum
329
330 %VELOCITIES MELTING AND ACCUMULATION
331 fields={'vx','vy','accumulation_rate','melting_rate'};
332 checksize(md,fields,[md.numberofgrids 1]);
333 checknan(md,fields);
334
335 %SPC
336 if any(md.spcvelocity(find(md.gridonboundary),[1:2])~=1),
337 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcvelocity']);
338 end
339end
340%}}}
341%CONTROL{{{1
342if md.control_analysis,
343
344 %CONTROL TYPE
345 if ~isnumeric(md.control_type),
346 error('model not consistent: control_type should be an enum');
347 end
348 checkvalues(md,{'control_type'},[DhDtEnum DragCoefficientEnum RheologyBbarEnum]);
349
350 %LENGTH CONTROL FIELDS
351 %fields={'maxiter','optscal','cm_responses','cm_jump'};
352 fields={'maxiter','optscal','cm_jump'};
353 checksize(md,fields,[md.nsteps 1]);
354
355 %RESPONSES
356 checkvalues(md,{'cm_responses'},[SurfaceAbsVelMisfitEnum SurfaceRelVelMisfitEnum SurfaceLogVelMisfitEnum SurfaceLogVxVyMisfitEnum SurfaceAverageVelMisfitEnum ThicknessAbsMisfitEnum]);
357
358 %WEIGHTS
359 fields={'weights'};
360 checksize(md,fields,[md.numberofgrids 1]);
361 checkgreater(md,fields,0);
362
363 %OBSERVED VELOCITIES
364 if md.analysis_type==BalancedthicknessSolutionEnum
365 fields={'thickness_obs'};
366 checksize(md,fields,[md.numberofgrids 1]);
367 checknan(md,fields);
368 else
369 fields={'vx_obs','vy_obs'};
370 checksize(md,fields,[md.numberofgrids 1]);
371 checknan(md,fields);
372 end
373
374 %DIRICHLET IF THICKNESS <= 0
375 if any(md.thickness<=0),
376 pos=find(md.thickness<=0);
377 if any(find(md.spcthickness(pos,1)==0)),
378 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
379 end
380 end
381
382 %parameters
383 fields={'cm_noisedmp'};
384 checknan(md,fields);
385end
386%}}}
387%QMU {{{1
388if md.qmu_analysis,
389 if md.qmu_params.evaluation_concurrency~=1,
390 error(['model not consistent: concurrency should be set to 1 when running dakota in library mode']);
391 end
392 if ~isempty(md.part),
393 if numel(md.part)~=md.numberofgrids,
394 error(['model not consistent: user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']);
395 end
396 if find(md.part)>=md.numberofgrids,
397 error(['model not consistent: user supplied partition should be indexed from 0 (c-convention)']);
398 end
399 if min(md.part)~=0,
400 error(['model not consistent: partition vector not indexed from 0 on']);
401 end
402 if max(md.part)>=md.numberofgrids,
403 error(['model not consistent: partition vector cannot have maximum index larger than number of grids']);
404 end
405 if ~isempty(find(md.part<0)),
406 error(['model not consistent: partition vector cannot have values less than 0']);
407 end
408 if ~isempty(find(md.part>=md.npart)),
409 error(['model not consistent: partition vector cannot have values more than md.npart-1']);
410 end
411 if max(md.part)>=md.npart,
412 error(['model not consistent: for qmu analysis, partitioning vector cannot go over npart, number of partition areas']);
413 end
414 end
415 if md.eps_rel>1.1*10^-5,
416 error(['model not consistent: for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']);
417 end
418end
419
420if strcmpi(md.analysis_type,'qmu'),
421 if ~strcmpi(md.cluster,'none'),
422 if md.waitonlock==0,
423 error(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']);
424 end
425 end
426end
427%}}}
428
429end
430
431%checks additional functions
432%checklength {{{1
433function checklength(md,fields,fieldlength)
434 %CHECKSIZE - check length of a field
435 for i=1:length(fields),
436 if length(eval(['md.' fields{i}]))~=fieldlength,
437 error(['model not consistent: field ' fields{i} ' length should be ' num2str(fieldlength)]);
438 end
439 end
440end
441%}}}
442%checksize {{{1
443function checksize(md,fields,fieldsize)
444 %CHECKSIZE - check size of a field
445 for i=1:length(fields),
446 if isnan(fieldsize(1)),
447 if (size(eval(['md.' fields{i}]),2)~=fieldsize(2)),
448 %LOG warnings:
449 if strcmpi(fields{i},'pressureload'),
450 disp(' ');
451 disp(' If pressureload does not have the right size (one column missing), this is due to a change in md.pressure.');
452 disp(' To update your model, use the following line');
453 disp(' md.pressureload=[md.pressureload WaterEnum*md.elementoniceshelf(md.pressureload(:,end))+AirEnum*md.elementonicesheet(md.pressureload(:,end))];');
454 disp(' ');
455 end
456 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(2)) ' columns']);
457 end
458 elseif isnan(fieldsize(2)),
459 if (size(eval(['md.' fields{i}]),1)~=fieldsize(1)),
460 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(1)) ' rows']);
461 end
462 else
463 if ((size(eval(['md.' fields{i}]),1)~=fieldsize(1)) | (size(eval(['md.' fields{i}]),2)~=fieldsize(2)))
464 %LOG warnings:
465 if strcmpi(fields{i},'weights'),
466 disp(' ');
467 disp(' ''weights'' is a new field that should be of length numberofgrids.');
468 disp(' To update your model, use the following line');
469 disp(' md.weights=ones(md.numberofgrids,1)');
470 disp(' ');
471 end
472 error(['model not consistent: field ' fields{i} ' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]);
473 end
474 end
475 end
476end
477%}}}
478%checknan {{{1
479function checknan(md,fields)
480 %CHECKNAN - check nan values of a field
481 for i=1:length(fields),
482 if any(isnan(eval(['md.' fields{i}]))),
483 error(['model not consistent: NaN values in field ' fields{i}]);
484 end
485 end
486end
487%}}}
488%checkreal{{{1
489function checkreal(md,fields)
490 %CHECKREAL - check real values of a field
491 for i=1:length(fields),
492 if any(eval(['~isreal(md.' fields{i} ')'])),
493 error(['model not consistent: complex values in field ' fields{i}]);
494 end
495 end
496end
497%}}}
498%checkgreaterstrict{{{1
499function checkgreaterstrict(md,fields,lowerbound)
500 %CHECKGREATERSTRICT - check values of a field
501 for i=1:length(fields),
502 if any(eval(['md.' fields{i} '<=' num2str(lowerbound) ])),
503 error(['model not consistent: field ' fields{i} ' should have values stricly above ' num2str(lowerbound)]);
504 end
505 end
506end
507%}}}
508%checkgreater{{{1
509function checkgreater(md,fields,lowerbound)
510 %CHECKGREATER - check values of a field
511 for i=1:length(fields),
512 if any(eval(['md.' fields{i} '<' num2str(lowerbound) ])),
513 error(['model not consistent: field ' fields{i} ' should have values above ' num2str(lowerbound)]);
514 end
515 end
516end
517%}}}
518%checklessstrict{{{1
519function checklessstrict(md,fields,upperbound)
520 %CHECKLESSSTRICT - check values of a field
521 for i=1:length(fields),
522 if any(eval(['md.' fields{i} '>=' num2str(upperbound) ])),
523 error(['model not consistent: field ' fields{i} ' should have values stricly below ' num2str(upperbound)]);
524 end
525 end
526end
527%}}}
528%checkless{{{1
529function checkless(md,fields,upperbound)
530 %CHECKLESS - check values of a field
531 for i=1:length(fields),
532 if any(eval(['md.' fields{i} '>' num2str(upperbound) ])),
533 error(['model not consistent: field ' fields{i} ' should have values below ' num2str(upperbound)]);
534 end
535 end
536end
537%}}}
538%checkvalues {{{1
539function checkvalues(md,fields,values)
540 %CHECKVALUE - check that a field has specified values
541 for i=1:length(fields),
542 if eval(['any(~ismember( md.' fields{i} ',values))']),
543 error(['model not consistent: field ' fields{i} ' should have values in ' num2str(values)]);
544 end
545 end
546end
547%}}}
Note: See TracBrowser for help on using the repository browser.