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

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

added test on rifts fill
correcter check on rifts

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