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

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

renamed test -> check

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