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

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

added check on spcs

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