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

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

updated field names

File size: 16.7 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() 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
323end
324%}}}
325%BALANCEDVELOCITIES{{{1
326if md.analysis_type==BalancedvelocitiesSolutionEnum
327
328 %VELOCITIES MELTING AND ACCUMULATION
329 fields={'vx','vy','accumulation_rate','melting_rate'};
330 checksize(md,fields,[md.numberofgrids 1]);
331 checknan(md,fields);
332
333 %SPC
334 if any(md.spcvelocity(find(md.gridonboundary),[1:2])~=1),
335 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcvelocity']);
336 end
337end
338%}}}
339%CONTROL{{{1
340if md.control_analysis,
341
342 %CONTROL TYPE
343 if ~isnumeric(md.control_type),
344 error('model not consistent: control_type should be an enum');
345 end
346 checkvalues(md,{'control_type'},[DhDtEnum DragCoefficientEnum RheologyBbarEnum]);
347
348 %LENGTH CONTROL FIELDS
349 fields={'maxiter','optscal','cm_responses','cm_jump'};
350 checksize(md,fields,[md.nsteps 1]);
351
352 %RESPONSES
353 checkvalues(md,{'cm_responses'},[SurfaceAbsVelMisfitEnum SurfaceRelVelMisfitEnum SurfaceLogVelMisfitEnum SurfaceLogVxVyMisfitEnum SurfaceAverageVelMisfitEnum ThicknessAbsMisfitEnum]);
354
355 %WEIGHTS
356 fields={'weights'};
357 checksize(md,fields,[md.numberofgrids 1]);
358 checkgreater(md,fields,0);
359
360 %OBSERVED VELOCITIES
361 if md.analysis_type==BalancedthicknessSolutionEnum
362 fields={'thickness_obs'};
363 checksize(md,fields,[md.numberofgrids 1]);
364 checknan(md,fields);
365 else
366 fields={'vx_obs','vy_obs'};
367 checksize(md,fields,[md.numberofgrids 1]);
368 checknan(md,fields);
369 end
370
371 %DIRICHLET IF THICKNESS <= 0
372 if any(md.thickness<=0),
373 pos=find(md.thickness<=0);
374 if any(find(md.spcthickness(pos,1)==0)),
375 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
376 end
377 end
378
379 %parameters
380 fields={'cm_noisedmp'};
381 checknan(md,fields);
382end
383%}}}
384%QMU {{{1
385if md.qmu_analysis,
386 if md.qmu_params.evaluation_concurrency~=1,
387 error(['model not consistent: concurrency should be set to 1 when running dakota in library mode']);
388 end
389 if ~isempty(md.part),
390 if numel(md.part)~=md.numberofgrids,
391 error(['model not consistent: user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']);
392 end
393 if find(md.part)>=md.numberofgrids,
394 error(['model not consistent: user supplied partition should be indexed from 0 (c-convention)']);
395 end
396 if min(md.part)~=0,
397 error(['model not consistent: partition vector not indexed from 0 on']);
398 end
399 if max(md.part)>=md.numberofgrids,
400 error(['model not consistent: partition vector cannot have maximum index larger than number of grids']);
401 end
402 if ~isempty(find(md.part<0)),
403 error(['model not consistent: partition vector cannot have values less than 0']);
404 end
405 if ~isempty(find(md.part>=md.npart)),
406 error(['model not consistent: partition vector cannot have values more than md.npart-1']);
407 end
408 if max(md.part)>=md.npart,
409 error(['model not consistent: for qmu analysis, partitioning vector cannot go over npart, number of partition areas']);
410 end
411 end
412 if ~md.qmu_relax,
413 if md.eps_rel>1.1*10^-5,
414 error(['model not consistent: for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']);
415 end
416 end
417end
418
419if strcmpi(md.analysis_type,'qmu'),
420 if ~strcmpi(md.cluster,'none'),
421 if md.waitonlock==0,
422 error(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']);
423 end
424 end
425end
426%}}}
427
428end
429
430%checks additional functions
431%checklength {{{1
432function checklength(md,fields,fieldlength)
433 %CHECKSIZE - check length of a field
434 for i=1:length(fields),
435 eval(['field=md.' fields{i} ';']);
436 if length(field)~=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 eval(['field=md.' fields{i} ';']);
447 if isnan(fieldsize(1)),
448 if (size(field,2)~=fieldsize(2)),
449 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(2)) ' columns']);
450 end
451 elseif isnan(fieldsize(2)),
452 if (size(field,1)~=fieldsize(1)),
453 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(1)) ' rows']);
454 end
455 else
456 if ((size(field)~=fieldsize(1)) | (size(field,2)~=fieldsize(2)))
457 error(['model not consistent: field ' fields{i} ' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]);
458 end
459 end
460 end
461end
462%}}}
463%checknan {{{1
464function checknan(md,fields)
465 %CHECKNAN - check nan values of a field
466 for i=1:length(fields),
467 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
468 if any(isnan(field)),
469 error(['model not consistent: NaN values found in field ' fields{i}]);
470 end
471 end
472end
473%}}}
474%checkreal{{{1
475function checkreal(md,fields)
476 %CHECKREAL - check real values of a field
477 for i=1:length(fields),
478 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
479 if any(~isreal(field)),
480 error(['model not consistent: complex values found in field ' fields{i}]);
481 end
482 end
483end
484%}}}
485%checkgreaterstrict{{{1
486function checkgreaterstrict(md,fields,lowerbound)
487 %CHECKGREATERSTRICT - check values of a field
488 for i=1:length(fields),
489 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
490 if any(field<=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 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
501 if any(field<lowerbound),
502 error(['model not consistent: field ' fields{i} ' should have values above ' num2str(lowerbound)]);
503 end
504 end
505end
506%}}}
507%checklessstrict{{{1
508function checklessstrict(md,fields,upperbound)
509 %CHECKLESSSTRICT - check values of a field
510 for i=1:length(fields),
511 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
512 if any(field>=upperbound),
513 error(['model not consistent: field ' fields{i} ' should have values stricly below ' num2str(upperbound)]);
514 end
515 end
516end
517%}}}
518%checkless{{{1
519function checkless(md,fields,upperbound)
520 %CHECKLESS - check values of a field
521 for i=1:length(fields),
522 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
523 if any(field>upperbound),
524 error(['model not consistent: field ' fields{i} ' should have values below ' num2str(upperbound)]);
525 end
526 end
527end
528%}}}
529%checkvalues {{{1
530function checkvalues(md,fields,values)
531 %CHECKVALUE - check that a field has specified values
532 for i=1:length(fields),
533 eval(['field=reshape(md.' fields{i} ',[prod(size(md.' fields{i} ')) 1]);']);
534 if any(~ismember(field,values)),
535 error(['model not consistent: field ' fields{i} ' should have values in ' num2str(values)]);
536 end
537 end
538end
539%}}}
Note: See TracBrowser for help on using the repository browser.