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

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

Added check for Balancedthickness

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