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

Last change on this file since 4891 was 4891, checked in by seroussi, 15 years ago

put back penalties for MacAyeal/Pattyn models

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