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

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

Now pressure load has one extra column

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