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

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

Added folds

File size: 17.1 KB
RevLine 
[2326]1function ismodelselfconsistent(md),
[1]2%ISMODELSELFCONSISTENT - check that model forms a closed form solvable problem.
3%
4% Usage:
[2326]5% ismodelselfconsistent(md),
[1]6
[2366]7%tolerance we use in litmus checks for the consistency of the model
[1]8tolerance=10^-12;
[4756]9%check usage {{{1
[2326]10if nargin~=1,
[27]11 help ismodelselfconsistent
12 error('ismodelselfconsistent error message: wrong usage');
[1]13end
[4756]14%}}}
[1]15
[4756]16%recursive call for TRANSIENT {{{1
[4303]17if (md.analysis_type==Transient2DSolutionEnum | md.analysis_type==Transient3DSolutionEnum),
[2326]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
[3994]23 if (md.dim==2),
[4303]24 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum];
[2528]25 else
[4303]26 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum ThermalSolutionEnum];
[2528]27 end
28
[2326]29 for i=1:length(analysis),
[2520]30 md.analysis_type=analysis(i);
[2326]31 ismodelselfconsistent(md);
32 end
33end
[4756]34%}}}
[2326]35
[4756]36% Common checks
37%COUNTER {{{1
[27]38if md.counter<3,
[2326]39 error(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize,setelementstype)!']);
[1]40end
[4756]41%}}}
42%NAME{{{1
[1]43if isempty(md.name),
[2326]44 error(['model is not correctly configured: missing name!']);
[1]45end
[4756]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
[1]56if size(md.elements_type,1)~=md.numberofelements | size(md.elements_type,2)~=2,
[2326]57 error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
[1]58end
[1651]59if any(ones(md.numberofelements,1)-((md.elements_type(:,1)==HutterFormulationEnum) + (md.elements_type(:,1)==MacAyealFormulationEnum) + (md.elements_type(:,1)==PattynFormulationEnum)))
[2326]60 error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
[1]61end
[1651]62if any(ones(md.numberofelements,1)-((md.elements_type(:,2)==StokesFormulationEnum) + (md.elements_type(:,2)==NoneFormulationEnum)))
[2326]63 error(['model not consistent: types of elements have not been set properly, run setelementstype first'])
[1]64end
[3994]65if (md.dim==2),
[1651]66 if (ismember(PattynFormulationEnum,md.elements_type(:,1)) | ismember(StokesFormulationEnum,md.elements_type(:,2))),
[2326]67 error(['model not consistent: for a 2d model, only MacAyeal''s and Hutter''s elements are allowed']);
[1]68 end
69end
[358]70if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0),
[2326]71 error(['model not consistent: no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']);
[358]72end
[4303]73if (md.analysis_type==DiagnosticSolutionEnum & any(ismember(MacAyealFormulationEnum,md.elements_type(:,1)) & ismember(PattynFormulationEnum,md.elements_type(:,1))))
[2326]74 error(['model not consistent: coupling MacAyeal/Pattyn not implemented yet']);
[2164]75end
[4303]76if (md.isstokes & md.analysis_type==Transient3DSolutionEnum());
[2326]77 error(['model not consistent: Stokes transient not implemented yet']);
[2164]78end
[4756]79%}}}
80%DG {{{1
81if md.prognostic_DG=1;
82 %CHECK THE COMPATIBILITY OF THE EDGES
83 fields={'edges'};
84 checksize(md,fields,[NaN 4]);
85 checknan(md,fields);
86end
87%}}}
88%PRESSURELOAD{{{1
[3994]89if (md.dim==2),
[2326]90 fields={'pressureload'};
[3099]91 checksize(md,fields,[NaN 4]);
[3994]92elseif md.dim==3,
[2326]93 fields={'pressureload'};
[3099]94 checksize(md,fields,[NaN 6]);
[3356]95else
[3357]96 error('type should be either ''2d'' or ''3d''');
[1796]97end
[4756]98%}}}
99%NO NAN {{{1
[3758]100fields={'numberofelements','numberofgrids','x','y','z','drag_coefficient','drag_type','drag_p','drag_q',...
101 'rho_ice','rho_water','rheology_B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',...
102 'tolx','np','eps_res','max_nonlinear_iterations','exclusive','rheology_n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
[2366]103checknan(md,fields);
[4756]104%}}}}
105%FIELDS >= 0 {{{1
[3758]106fields={'numberofelements','numberofgrids','elements','drag_coefficient','drag_type','drag_p','drag_q',...
107 'rho_ice','rho_water','rheology_B','elementoniceshelf','thickness','g','eps_res','max_nonlinear_iterations','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',...
108 'sparsity','lowmem','rheology_n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'};
[2366]109checkgreater(md,fields,0);
[4756]110%}}}
111%FIELDS > 0 {{{1
[3758]112fields={'numberofelements','numberofgrids','elements','drag_type','drag_p',...
113 'rho_ice','rho_water','rheology_B','thickness','g','max_nonlinear_iterations','eps_res','eps_rel','eps_abs','maxiter','tolx',...
[27]114 'sparsity','deltaH','DeltaH','timeacc','timedec'};
[2366]115checkgreaterstrict(md,fields,0);
[4756]116%}}}
117%SIZE NUMBEROFELEMENTS {{{1
[3759]118fields={'drag_p','drag_q','elementoniceshelf','rheology_n','elementonbed'};
[2991]119checksize(md,fields,[md.numberofelements 1]);
[4756]120%}}}
121%SIZE NUMBEROFGRIDS {{{1
[3758]122fields={'x','y','z','rheology_B','drag_coefficient','melting_rate','accumulation_rate','surface','thickness','bed','gridonbed','gridonsurface'};
[2991]123checksize(md,fields,[md.numberofgrids 1]);
[4756]124%}}}
125%OTHER SIZES {{{1
[2405]126fields={'spcvelocity'};
127checksize(md,fields,[md.numberofgrids 6]);
[4756]128%}}}
129%THICKNESS = SURFACE - BED {{{1
[681]130if any((md.thickness-md.surface+md.bed)>tolerance),
[2326]131 error(['model not consistent: model ' md.name ' violates the equality thickness=surface-bed!']);
[27]132end
[4756]133%}}}
134%RIFTS{{{1
[27]135if md.numrifts,
[3994]136 if ~(md.dim==2),
[2326]137 error(['model not consistent: models with rifts are only supported in 2d for now!']);
[1]138 end
[2660]139 if ~isstruct(md.rifts),
140 error(['model not consistent: md.rifts should be a structure!']);
141 end
142 if ~isempty(find(md.segmentmarkers>=2)),
143 %We have segments with rift markers, but no rift structure!
144 error(['model not consistent: model ' md.name ' should be processed for rifts (run meshprocessrifts)!']);
145 end
146 %Check that rifts are filled with proper material
147 checkvalues(md,{'rifts.fill'},[WaterEnum() AirEnum() IceEnum() MelangeEnum()]);
148else
[2748]149 if ~isnans(md.rifts),
[2660]150 error(['model not consistent: md.rifts shoud be NaN since md.numrifts is 0!']);
[27]151 end
152end
[4756]153%}}}
154%FLAGS (0 or 1){{{1
[2326]155if ~ismember(md.artificial_diffusivity,[0 1]),
156 error('model not consistent: artificial_diffusivity should be a scalar (1 or 0)');
[1]157end
[4756]158if ~ismember(md.prognostic_DG,[0 1]),
159 error('model not consistent: prognostic_DG should be a scalar (1 or 0)');
160end
161if ~ismember(md.lowmem,[0 1]),
162 error(['model not consistent: model ' md.name ' lowmem field should be 0 or 1']);
163end
164%}}}
165%PARAMETEROUTPUT {{{1
[2307]166if md.numoutput~=length(md.parameteroutput),
[2326]167 error('model not consistent: numoutput should be the same size as parameteroutput');
[2307]168end
[4756]169%}}}
170%CONNECTIVITY {{{1
[3994]171if (md.dim==2),
[2326]172 if md.connectivity<9,
173 error('model not consistent: connectivity should be at least 9 for 2d models');
174 end
175end
[3994]176if md.dim==3,
[2326]177 if md.connectivity<24,
178 error('model not consistent: connectivity should be at least 24 for 3d models');
179 end
180end
[4756]181%}}}
182%PARALLEL{{{1
[2326]183if ~strcmpi(md.cluster,'none'),
184
185 %NAN VALUES
186 fields={'time','np'};
[2366]187 checknan(md,fields);
[2326]188
189 %FIELD > 0
190 fields={'time','np'};
[2366]191 checkgreaterstrict(md,fields,0);
[2326]192
193end
[4756]194%}}}
[2326]195
[4756]196% Solution checks
197%DIAGNOSTIC{{{1
[4303]198if md.analysis_type==DiagnosticSolutionEnum,
[27]199
[2208]200 %CHECK THAT WE ARE NOT FULLY CONSTRAINED
[4683]201 if isempty(find(~md.spcvelocity(:,1:2))),
202 error(['model not consistent: model ' md.name ' is totally constrained horizontally, no need to solve!']);
203 end
204 if (md.dim==3),
205 if isempty(find(~md.spcvelocity(:,3))),
206 error(['model not consistent: model ' md.name ' is totally constrained vertically, no need to solve!']);
[2208]207 end
208 end
209
[27]210 %HUTTER ON ICESHELF WARNING
[1651]211 if any(md.elements_type(:,1)==HutterFormulationEnum & md.elementoniceshelf),
[27]212 disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
213 end
214
215 %SINGULAR
[2282]216 if ~any(sum(md.spcvelocity(:,1:2),2)==2),
[2326]217 error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
[1]218 end
219
[27]220 %DIRICHLET IF THICKNESS <= 0
[681]221 if any(md.thickness<=0),
[27]222 pos=find(md.thickness<=0);
[1755]223 if any(find(md.spcthickness(pos,1)==0)),
[2326]224 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
[27]225 end
226 end
[2357]227
[2367]228 %INITIAL VELOCITY
229 if length(md.vx)==md.numberofgrids & length(md.vy)==md.numberofgrids,
230 fields={'vx','vy'};
231 checknan(md,fields);
232 end
[1]233end
[4756]234%}}}
235%PROGNOSTIC{{{1
[4303]236if md.analysis_type==PrognosticSolutionEnum,
[1]237
[2357]238 %INITIAL VELOCITIES
239 fields={'vx','vy'};
[2366]240 checksize(md,fields,[md.numberofgrids 1]);
241 checknan(md,fields);
[2357]242
[2519]243 %CHECK THAT WE ARE NOT FULLY CONSTRAINED
[3994]244 if (md.dim==2),
[2519]245 if isempty(find(~md.spcthickness(:,1))),
246 error(['model not consistent: model ' md.name ' is totally constrained for prognostic, no need to solve!']);
247 end
248 end
249
[1]250end
[4756]251%}}}
252%STEADYSTATE{{{1
[4303]253if md.analysis_type==SteadystateSolutionEnum,
[2326]254
[1901]255 %NDT
256 if md.dt~=0,
[2326]257 error(['model not consistent: for a steadystate computation, dt must be zero.']);
[1901]258 end
[2326]259
[1787]260 %PRESSURE
261 if isnans(md.pressure),
[2326]262 error(['model not consistent: for a steadystate computation, the model must have an initial pressure, even lithostatic will do.']);
[1787]263 end
264
265 %eps:
266 if isnan(md.eps_rel),
[2326]267 error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']);
[1787]268 end
269
270 %dim:
[3994]271 if (md.dim==2),
[2326]272 error(['model not consistent: for a steadystate computation, model needs to be 3d']);
[1787]273 end
274end
[4756]275%}}}
276%THERMAL {{{1
[27]277%THERMAL STEADY AND THERMAL TRANSIENT
[4303]278if md.analysis_type==ThermalSolutionEnum,
[27]279
280 %EXTRUSION
[3994]281 if (md.dim==2),
[2326]282 error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
[1]283 end
[27]284
[2519]285 %CHECK THAT WE ARE NOT FULLY CONSTRAINED
[3994]286 if isempty(find(~md.spctemperature(:,1))),
287 error(['model not consistent: model ' md.name ' is totally constrained for temperature, no need to solve!']);
[2519]288 end
289
[27]290 %VELOCITIES AND PRESSURE
[2357]291 fields={'vx','vy','vz','pressure'};
[2366]292 checksize(md,fields,[md.numberofgrids 1]);
293 checknan(md,fields);
[2357]294
[1]295end
296
[1311]297%THERMAL TRANSIENT
[4303]298if md.analysis_type==ThermalSolutionEnum & md.dt~=0,
[27]299
300 %DT and NDT
301 fields={'dt','ndt'};
[2366]302 checkgreaterstrict(md,fields,0);
[27]303
[1311]304 %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
[3758]305 fields={'temperature','accumulation_rate','melting_rate'};
[2366]306 checksize(md,fields,[md.numberofgrids 1]);
[2440]307 checknan(md,fields);
[1]308
[2714]309 %INITIAL TEMPERATURE
[2669]310 fields={'temperature','spctemperature(:,2)','observed_temperature'};
311 checkgreater(md,fields,0)
312
[1]313end
[4756]314%}}}
315%BALANCEDTHICKNESS{{{1
[4303]316if md.analysis_type==BalancedthicknessSolutionEnum
[2714]317
318 %VELOCITIES MELTING AND ACCUMULATION
[4756]319 fields={'vx','vy','accumulation_rate','melting_rate','dhdt'};
[3589]320 checksize(md,fields,[md.numberofgrids 1]);
321 checknan(md,fields);
322
323 %SPC
324 if any(md.spcthickness(find(md.gridonboundary))~=1),
325 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcthickness']);
326 end
327end
[4756]328%}}}
329%BALANCEDVELOCITIES{{{1
[4303]330if md.analysis_type==BalancedvelocitiesSolutionEnum
[2723]331
332 %VELOCITIES MELTING AND ACCUMULATION
[3758]333 fields={'vx','vy','accumulation_rate','melting_rate'};
[2723]334 checksize(md,fields,[md.numberofgrids 1]);
335 checknan(md,fields);
336
337 %SPC
338 if any(md.spcvelocity(find(md.gridonboundary),[1:2])~=1),
339 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcvelocity']);
340 end
341end
[4756]342%}}}
343%CONTROL{{{1
[1907]344if md.control_analysis,
[1]345
[27]346 %CONTROL TYPE
[45]347 if ~ischar(md.control_type),
[2326]348 error('model not consistent: control_type should be a string');
[1]349 end
350
[27]351 %LENGTH CONTROL FIELDS
[2326]352 fields={'maxiter','optscal','fit','cm_jump'};
[2991]353 checksize(md,fields,[md.nsteps 1]);
[27]354
355 %FIT
[3189]356 checkvalues(md,{'fit'},[0 1 2 3 4]);
[1]357
[3203]358 %WEIGHTS
359 fields={'weights'};
360 checksize(md,fields,[md.numberofgrids 1]);
361 checkgreater(md,fields,0);
362
[27]363 %OBSERVED VELOCITIES
364 fields={'vx_obs','vy_obs'};
[2366]365 checksize(md,fields,[md.numberofgrids 1]);
366 checknan(md,fields);
[1361]367
368 %DIRICHLET IF THICKNESS <= 0
369 if any(md.thickness<=0),
370 pos=find(md.thickness<=0);
[1755]371 if any(find(md.spcthickness(pos,1)==0)),
[2326]372 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
[1361]373 end
374 end
[2686]375
376 %parameters
377 fields={'cm_noisedmp'};
378 checknan(md,fields);
[1]379end
[4756]380%}}}
381%QMU {{{1
382if md.qmu_analysis,
383 if md.qmu_params.evaluation_concurrency~=1,
384 error(['model not consistent: concurrency should be set to 1 when running dakota in library mode']);
385 end
386 if ~isempty(md.part),
387 if numel(md.part)~=md.numberofgrids,
388 error(['model not consistent: user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']);
389 end
390 if find(md.part)>=md.numberofgrids,
391 error(['model not consistent: user supplied partition should be indexed from 0 (c-convention)']);
392 end
393 if min(md.part)~=0,
394 error(['model not consistent: partition vector not indexed from 0 on']);
395 end
396 if max(md.part)>=md.numberofgrids,
397 error(['model not consistent: partition vector cannot have maximum index larger than number of grids']);
398 end
399 if ~isempty(find(md.part<0)),
400 error(['model not consistent: partition vector cannot have values less than 0']);
401 end
402 if ~isempty(find(md.part>=md.npart)),
403 error(['model not consistent: partition vector cannot have values more than md.npart-1']);
404 end
405 if max(md.part)>=md.npart,
406 error(['model not consistent: for qmu analysis, partitioning vector cannot go over npart, number of partition areas']);
407 end
408 end
409 if md.eps_rel>1.1*10^-5,
410 error(['model not consistent: for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']);
411 end
412end
[1]413
[465]414if strcmpi(md.analysis_type,'qmu'),
[27]415 if ~strcmpi(md.cluster,'none'),
416 if md.waitonlock==0,
[2326]417 error(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']);
[1]418 end
419 end
420end
[4756]421%}}}
[1]422
[4756]423end
[1]424
[4756]425%checks additional functions
426%checklength {{{1
[2366]427function checklength(md,fields,fieldlength)
428 %CHECKSIZE - check length of a field
[2326]429 for i=1:length(fields),
430 if length(eval(['md.' fields{i}]))~=fieldlength,
431 error(['model not consistent: field ' fields{i} ' length should be ' num2str(fieldlength)]);
[2164]432 end
433 end
434end
[4756]435%}}}
436%checksize {{{1
[2366]437function checksize(md,fields,fieldsize)
438 %CHECKSIZE - check size of a field
[2326]439 for i=1:length(fields),
440 if isnan(fieldsize(1)),
441 if (size(eval(['md.' fields{i}]),2)~=fieldsize(2)),
[3203]442 %LOG warnings:
[3104]443 if strcmpi(fields{i},'pressureload'),
444 disp(' ');
445 disp(' If pressureload does not have the right size (one column missing), this is due to a change in md.pressure.');
446 disp(' To update your model, use the following line');
447 disp(' md.pressureload=[md.pressureload WaterEnum*md.elementoniceshelf(md.pressureload(:,end))+AirEnum*md.elementonicesheet(md.pressureload(:,end))];');
448 disp(' ');
449 end
[2326]450 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(2)) ' columns']);
451 end
452 elseif isnan(fieldsize(2)),
453 if (size(eval(['md.' fields{i}]),1)~=fieldsize(1)),
454 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(1)) ' rows']);
455 end
456 else
457 if ((size(eval(['md.' fields{i}]),1)~=fieldsize(1)) | (size(eval(['md.' fields{i}]),2)~=fieldsize(2)))
[3219]458 %LOG warnings:
459 if strcmpi(fields{i},'weights'),
460 disp(' ');
461 disp(' ''weights'' is a new field that should be of length numberofgrids.');
462 disp(' To update your model, use the following line');
463 disp(' md.weights=ones(md.numberofgrids,1)');
464 disp(' ');
465 end
[2326]466 error(['model not consistent: field ' fields{i} ' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]);
467 end
[2164]468 end
469 end
470end
[4756]471%}}}
472%checknan {{{1
[2366]473function checknan(md,fields)
474 %CHECKNAN - check nan values of a field
[2326]475 for i=1:length(fields),
476 if any(isnan(eval(['md.' fields{i}]))),
477 error(['model not consistent: NaN values in field ' fields{i}]);
[2164]478 end
479 end
480end
[4756]481%}}}
482%checkreal{{{1
[2366]483function checkreal(md,fields)
484 %CHECKREAL - check real values of a field
[2326]485 for i=1:length(fields),
486 if any(eval(['~isreal(md.' fields{i} ')'])),
487 error(['model not consistent: complex values in field ' fields{i}]);
488 end
489 end
[2164]490end
[4756]491%}}}
492%checkgreaterstrict{{{1
[2366]493function checkgreaterstrict(md,fields,lowerbound)
494 %CHECKGREATERSTRICT - check values of a field
[2326]495 for i=1:length(fields),
496 if any(eval(['md.' fields{i} '<=' num2str(lowerbound) ])),
497 error(['model not consistent: field ' fields{i} ' should have values stricly above ' num2str(lowerbound)]);
498 end
[2164]499 end
500end
[4756]501%}}}
502%checkgreater{{{1
[2366]503function checkgreater(md,fields,lowerbound)
504 %CHECKGREATER - check values of a field
[27]505 for i=1:length(fields),
[2326]506 if any(eval(['md.' fields{i} '<' num2str(lowerbound) ])),
507 error(['model not consistent: field ' fields{i} ' should have values above ' num2str(lowerbound)]);
[27]508 end
509 end
[2326]510end
[4756]511%}}}
512%checklessstrict{{{1
[2366]513function checklessstrict(md,fields,upperbound)
514 %CHECKLESSSTRICT - check values of a field
[27]515 for i=1:length(fields),
[2326]516 if any(eval(['md.' fields{i} '>=' num2str(upperbound) ])),
517 error(['model not consistent: field ' fields{i} ' should have values stricly below ' num2str(upperbound)]);
[27]518 end
519 end
[2326]520end
[4756]521%}}}
522%checkless{{{1
[2366]523function checkless(md,fields,upperbound)
524 %CHECKLESS - check values of a field
[27]525 for i=1:length(fields),
[2326]526 if any(eval(['md.' fields{i} '>' num2str(upperbound) ])),
527 error(['model not consistent: field ' fields{i} ' should have values below ' num2str(upperbound)]);
[27]528 end
[1]529 end
530end
[4756]531%}}}
532%checkvalues {{{1
[2660]533function checkvalues(md,fields,values)
534 %CHECKVALUE - check that a field has a certain value
535 for i=1:length(fields),
536 if eval(['~ismember( md.' fields{i} ',values)']),
537 error(['model not consistent: field ' fields{i} ' should have values in ' num2str(values)]);
538 end
539 end
540end
[4756]541%}}}
Note: See TracBrowser for help on using the repository browser.