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

Last change on this file since 4613 was 4613, checked in by Eric.Larour, 15 years ago

some qmu checks

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