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

Last change on this file since 2519 was 2519, checked in by seroussi, 16 years ago

added check for consistency of the model if all temperature or thickness are spcs

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