Changeset 2326
- Timestamp:
- 09/25/09 10:48:01 (15 years ago)
- Location:
- issm/trunk/src/m/classes/public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/classes/public/ismodelselfconsistent.m
r2322 r2326 1 function bool=ismodelselfconsistent(md),1 function ismodelselfconsistent(md), 2 2 %ISMODELSELFCONSISTENT - check that model forms a closed form solvable problem. 3 3 % 4 4 % Usage: 5 % bool=ismodelselfconsistent(md),5 % ismodelselfconsistent(md), 6 6 7 7 %tolerance we use in litmus tests for the consistency of the model 8 8 tolerance=10^-12; 9 if (nargin~=1 ) 9 10 %check usage 11 if nargin~=1, 10 12 help ismodelselfconsistent 11 13 error('ismodelselfconsistent error message: wrong usage'); 12 14 end 13 15 14 %initialize output 15 bool=1; 16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRANSIENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 18 %check analysis 19 if 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 30 end 31 16 32 17 33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMMON CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 19 35 %COUNTER 20 36 if md.counter<3, 21 disp(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize)!']); 22 bool=0;return; 37 error(['model ' md.name ' is not correctly configured. You forgot one step in the following sequence (mesh, geography, parameterize,setelementstype)!']); 23 38 end 24 39 25 40 %NAME 26 41 if isempty(md.name), 27 disp(['model is not correctly configured: missing name!']); 28 bool=0;return; 29 end 30 31 %MESH 32 if md.numberofelements<=0, 33 disp(['model ' md.name ' does not have any elements!']); 34 bool=0; return; 35 end 36 if md.numberofgrids<=0, 37 disp(['model ' md.name ' does not have any grids!']); 38 bool=0; return; 42 error(['model is not correctly configured: missing name!']); 39 43 end 40 44 41 45 %ELEMENTSTYPE 42 46 if size(md.elements_type,1)~=md.numberofelements | size(md.elements_type,2)~=2, 43 disp(['Types of elements have not been set properly, run setelementstype first']) 44 bool=0;return; 47 error(['model not consistent: types of elements have not been set properly, run setelementstype first']) 45 48 end 46 49 if any(ones(md.numberofelements,1)-((md.elements_type(:,1)==HutterFormulationEnum) + (md.elements_type(:,1)==MacAyealFormulationEnum) + (md.elements_type(:,1)==PattynFormulationEnum))) 47 disp(['Types of elements have not been set properly, run setelementstype first']) 48 bool=0;return; 50 error(['model not consistent: types of elements have not been set properly, run setelementstype first']) 49 51 end 50 52 if any(ones(md.numberofelements,1)-((md.elements_type(:,2)==StokesFormulationEnum) + (md.elements_type(:,2)==NoneFormulationEnum))) 51 disp(['Types of elements have not been set properly, run setelementstype first']) 52 bool=0;return; 53 error(['model not consistent: types of elements have not been set properly, run setelementstype first']) 53 54 end 54 55 if strcmpi(md.type,'2d'), 55 56 if (ismember(PattynFormulationEnum,md.elements_type(:,1)) | ismember(StokesFormulationEnum,md.elements_type(:,2))), 56 disp(['For a 2d model, only MacAyeal''s and Hutter''s elements are allowed']); 57 bool=0;return; 57 error(['model not consistent: for a 2d model, only MacAyeal''s and Hutter''s elements are allowed']); 58 58 end 59 59 end 60 60 if (md.ismacayealpattyn==0 && md.ishutter==0 && md.isstokes==0), 61 disp(['no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']); 62 bool=0;return; 61 error(['model not consistent: no elements type set for this model. at least one of ismacayealpattyn, ishutter and isstokes need to be =1']); 63 62 end 64 63 if (md.analysis_type==DiagnosticAnalysisEnum & any(ismember(MacAyealFormulationEnum,md.elements_type(:,1)) & ismember(PattynFormulationEnum,md.elements_type(:,1)))) 65 disp(['coupling MacAyeal/Pattyn not implemented yet']); 66 bool=0;return; 64 error(['model not consistent: coupling MacAyeal/Pattyn not implemented yet']); 67 65 end 68 66 if (md.isstokes & md.analysis_type==TransientAnalysisEnum()); 69 disp(['Stokes transient not implemented yet']); 70 bool=0;return; 67 error(['model not consistent: Stokes transient not implemented yet']); 71 68 end 72 69 73 70 %ICEFRONT 74 71 if strcmpi(md.type,'2d'), 75 if size(md.pressureload,2)~=3 , 76 disp(['pressureload in ' md.name ' shoud have three columns']); 77 bool=0;return; 78 end 72 fields={'pressureload'}; 73 testsize(md,fields,[NaN 3]); 79 74 elseif strcmpi(md.type,'3d'), 80 if size(md.pressureload,2)~=5 , 81 disp(['pressureload in ' md.name ' shoud have five columns']); 82 bool=0;return; 83 end 75 fields={'pressureload'}; 76 testsize(md,fields,[NaN 5]); 84 77 end 85 78 … … 88 81 'rho_ice','rho_water','B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',... 89 82 'tolx','np','eps_res','exclusive','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'}; 90 for i=1:length(fields), 91 if ~isempty(md.(fields{i})), 92 if any(isnan(md.(fields{i}))), 93 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']); 94 bool=0; return; 95 end 96 end 97 end 83 testnan(md,fields); 98 84 99 85 %FIELDS >= 0 … … 101 87 'rho_ice','rho_water','B','elementoniceshelf','thickness','g','eps_res','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',... 102 88 'sparsity','lowmem','n','gridonbed','gridonsurface','elementonbed','elementonsurface','deltaH','DeltaH','timeacc','timedec'}; 103 for i=1:length(fields), 104 if ~isempty(md.(fields{i})), 105 if any(md.(fields{i})<0), 106 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']); 107 bool=0; return; 108 end 109 end 110 end 111 if any(md.p<=0), 112 disp(['model ' md.name ' has some p<0 friction coefficientsin sliding law']); 113 bool=0; return; 114 end 115 116 %FIELDS ~=0 117 fields={'numberofelements','numberofgrids','elements','drag_type',... 89 testgreater(md,fields,0); 90 91 %FIELDS > 0 92 fields={'numberofelements','numberofgrids','elements','drag_type','p',... 118 93 'rho_ice','rho_water','B','thickness','g','eps_res','eps_rel','eps_abs','maxiter','tolx',... 119 94 'sparsity','deltaH','DeltaH','timeacc','timedec'}; 120 for i=1:length(fields), 121 if ~isempty(md.(fields{i})), 122 if any(md.(fields{i})==0), 123 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']); 124 bool=0; return; 125 end 126 end 127 end 95 testgreaterstrict(md,fields,0); 128 96 129 97 %SIZE NUMBEROFELEMENTS 130 98 fields={'elements','p','q','elementoniceshelf','n','elementonbed'}; 131 for i=1:size(fields,2), 132 if (size(md.(fields{i}),1)~=md.numberofelements), 133 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofelements) '!']); 134 bool=0; return; 135 end 136 end 99 testlength(md,fields,md.numberofelements); 137 100 138 101 %SIZE NUMBEROFGRIDS 139 102 fields={'x','y','z','B','drag','spcvelocity','melting','accumulation','surface','thickness','bed','gridonbed','gridonsurface'}; 140 for i=1:length(fields), 141 if length(md.(fields{i}))~=md.numberofgrids, 142 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofgrids) '!']); 143 bool=0; return; 144 end 145 end 103 testlength(md,fields,md.numberofgrids); 146 104 147 105 %THICKNESS = SURFACE - BED 148 106 if any((md.thickness-md.surface+md.bed)>tolerance), 149 disp(['model ' md.name ' violates the equality thickness=surface-bed!']); 150 bool=0; return; 107 error(['model not consistent: model ' md.name ' violates the equality thickness=surface-bed!']); 151 108 end 152 109 … … 154 111 if md.numrifts, 155 112 if ~strcmpi(md.type,'2d'), 156 disp(['Models with rifts are only supported in 2d for now!']); 157 bool=0;return; 113 error(['model not consistent: models with rifts are only supported in 2d for now!']); 158 114 end 159 115 end … … 162 118 if ~isempty(find(md.segmentmarkers>=2)), 163 119 %We have segments with rift markers, but no rift structure! 164 disp(['model ' md.name ' should be processed for rifts (run meshprocessrifts)!']); 165 bool=0; return; 120 error(['model not consistent: model ' md.name ' should be processed for rifts (run meshprocessrifts)!']); 166 121 end 167 122 end … … 169 124 170 125 %ARTIFICIAL DIFFUSIVITY 171 if ~isscalar(md.artificial_diffusivity), 172 disp('artificial_diffusivity should be a scalar (1 or 0)'); 173 bool=0;return; 126 if ~ismember(md.artificial_diffusivity,[0 1]), 127 error('model not consistent: artificial_diffusivity should be a scalar (1 or 0)'); 174 128 end 175 129 176 130 %PARAMETEROUTPUT 177 131 if md.numoutput~=length(md.parameteroutput), 178 disp('numoutput should be the same size as parameteroutput'); 179 bool=0;return; 132 error('model not consistent: numoutput should be the same size as parameteroutput'); 133 end 134 135 %CONNECTIVITY 136 if 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 140 end 141 if 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 145 end 146 147 %LOWMEM = 0 or 1 148 if ((md.lowmem ~= 1) & (md.lowmem~=0)), 149 error(['model not consistent: model ' md.name ' lowmem field should be 0 or 1']); 150 end 151 152 %PARALLEL 153 if ~strcmpi(md.cluster,'none'), 154 155 %NAN VALUES 156 fields={'time','np'}; 157 testnan(md,fields); 158 159 %FIELD > 0 160 fields={'time','np'}; 161 testgreaterstrict(md,fields,0); 162 180 163 end 181 164 182 165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SOLUTION CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 166 183 167 %QMU 184 168 if md.qmu_analysis, 185 169 if md.qmu_params.evaluation_concurrency~=1, 186 disp(['concurrency should be set to 1 when running dakota in library mode']); 187 bool=0;return; 170 error(['model not consistent: concurrency should be set to 1 when running dakota in library mode']); 188 171 end 189 172 if ~isempty(md.part), 190 173 if numel(md.part)~=md.numberofgrids, 191 disp(['user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']); 192 bool=0;return; 174 error(['model not consistent: user supplied partition for qmu analysis should have size md.numberofgrids x 1 ']); 193 175 end 194 176 if find(md.part)>=md.numberofgrids, 195 disp(['user supplied partition should be indexed from 0 (c-convention)']); 196 bool=0;return; 177 error(['model not consistent: user supplied partition should be indexed from 0 (c-convention)']); 197 178 end 198 179 if md.npart~=md.numberofgrids, 199 disp(['user supplied partition should have same size as md.npart']); 200 bool=0;return; 201 end 202 180 error(['model not consistent: user supplied partition should have same size as md.npart']); 181 end 203 182 end 204 183 if md.eps_rel>10^-3, 205 disp(['for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']); 206 bool=0;return; 184 error(['model not consistent: for qmu analysis, eps_rel should be least than 10^-5, 10^-15 being a better value']); 207 185 end 208 186 end … … 214 192 if strcmpi(md.type,'2d'), 215 193 if isempty(find(~md.spcvelocity(:,1:2))), 216 disp(['model ' md.name ' is totally constrained, no need to solve!']); 217 bool=0;return; 194 error(['model not consistent: model ' md.name ' is totally constrained, no need to solve!']); 218 195 end 219 196 end … … 226 203 %SINGULAR 227 204 if ~any(sum(md.spcvelocity(:,1:2),2)==2), 228 disp(['model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!']) 229 bool=0;return; 205 error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!']) 230 206 end 231 207 … … 234 210 pos=find(md.thickness<=0); 235 211 if any(find(md.spcthickness(pos,1)==0)), 236 disp(['model ' md.name ' has some grids with 0 thickness']); 237 bool=0; return; 212 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']); 238 213 end 239 214 end … … 245 220 %VELOCITIES 246 221 if (size(md.vx,1)~=md.numberofgrids | size(md.vy,1)~=md.numberofgrids), 247 disp(['a 3d velocity is required. Run ''diagnostic'' solution first!']) 248 bool=0; return; 222 error(['model not consistent: a 3d velocity is required. Run ''diagnostic'' solution first!']) 249 223 end 250 224 end … … 252 226 %STEADYSTATE 253 227 if md.analysis_type==SteadystateAnalysisEnum, 228 254 229 %NDT 255 230 if md.dt~=0, 256 disp(['For a steadystate computation, dt must be zero.']);257 bool=0;return;258 end 231 error(['model not consistent: for a steadystate computation, dt must be zero.']); 232 end 233 259 234 %PRESSURE 260 235 if isnans(md.pressure), 261 disp(['For a steadystate computation, the model must have an initial pressure, even lithostatic will do.']); 262 bool=0;return; 236 error(['model not consistent: for a steadystate computation, the model must have an initial pressure, even lithostatic will do.']); 263 237 end 264 238 265 239 %eps: 266 240 if isnan(md.eps_rel), 267 disp(['For a steadystate computation, eps_rel (relative convergence criterion) must be defined!']); 268 bool=0;return; 241 error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']); 269 242 end 270 243 271 244 %dim: 272 245 if strcmpi(md.type,'2d'), 273 disp(['For a steadystate computation, model needs to be 3d']); 274 bool=0;return; 246 error(['model not consistent: for a steadystate computation, model needs to be 3d']); 275 247 end 276 248 end … … 281 253 %EXTRUSION 282 254 if strcmp(md.type,'2d'), 283 disp(['For a ' md.analysis_type ' computation, the model must be 3d, extrude it first!']) 284 bool=0;return; 255 error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!']) 285 256 end 286 257 287 258 %VELOCITIES AND PRESSURE 288 259 if (length(md.vx)~=md.numberofgrids | length(md.vy)~=md.numberofgrids | length(md.vz)~=md.numberofgrids), 289 disp(['a 3d velocity is required. Run ''diagnostic'' solution first!']) 290 bool=0;return; 260 error(['model not consistent: a 3d velocity is required. Run ''diagnostic'' solution first!']) 291 261 end 292 262 if (length(md.pressure)~=md.numberofgrids), 293 disp(['pressure is required. Run ''diagnostic'' solution first!']) 294 bool=0;return; 263 error(['model not consistent: pressure is required. Run ''diagnostic'' solution first!']) 295 264 end 296 265 end … … 301 270 %DT and NDT 302 271 fields={'dt','ndt'}; 303 for i=1:length(fields), 304 if any(md.(fields{i})<0), 305 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']); 306 bool=0; return; 307 end 308 end 272 testgreaterstrict(md,fields,0); 309 273 310 274 %INITIAL TEMPERATURE, MELTING AND ACCUMULATION 311 if (length(md.temperature)~=md.numberofgrids), 312 disp(['An initial temperature is needed for a transient thermal computation']) 313 bool=0;return; 314 end 315 if (length(md.temperature)~=md.numberofgrids | length(md.accumulation)~=md.numberofgrids | length(md.melting)~=md.numberofgrids), 316 disp(['The initial temperature, melting or accumulation should be a list and not a structure']) 317 bool=0;return; 318 end 319 end 320 321 %PARAMETERS 322 if md.analysis_type==ParametersAnalysisEnum, 323 324 %OUTPUT 325 if ~iscell(md.parameteroutput) 326 disp(['parameteroutput field must be a cell, example {''strainrate'',''stress'',''deviatoricstress'',''viscousheating''}']); 327 bool=0; return; 328 end 329 for i=1:length(md.parameteroutput) 330 if ~strcmpi(md.parameteroutput(i),'strainrate') & ~strcmpi(md.parameteroutput(i),'stress') & ~strcmpi(md.parameteroutput(i),'deviatoricstress') & ~strcmpi(md.parameteroutput(i),'viscousheating') ... 331 & ~strcmpi(md.parameteroutput(i),'pressure_elem') & ~strcmpi(md.parameteroutput(i),'stress_bed') & ~strcmpi(md.parameteroutput(i),'stress_surface') 332 disp(['one of the parameteroutput is not supported yet']); 333 bool=0; return; 334 end 335 end 336 %VELOCITY 337 if ~(size(md.vx,1)==md.numberofgrids & size(md.vy,1)==md.numberofgrids & (size(md.vz,1)==md.numberofgrids | strcmpi(md.type,'2d'))) 338 disp(['velocities are required!']); 339 bool=0;return; 340 end 341 342 %HUTTER 343 if any(md.elements_type(:,1)==HutterFormulationEnum); 344 disp(['The model has Hutter''s elements. Impossible to compute parameters']); 345 bool=0;return; 346 end 275 fields={'temperature','accumulation','melting'}; 276 testsize(md,fields,[md.numberofgrids 1]); 277 347 278 end 348 279 … … 352 283 %CONTROL TYPE 353 284 if ~ischar(md.control_type), 354 disp('control_type should be a string'); 355 bool=0;return; 285 error('model not consistent: control_type should be a string'); 356 286 end 357 287 358 288 %LENGTH CONTROL FIELDS 359 if (length(md.maxiter)~=md.nsteps | length(md.optscal)~=md.nsteps | length(md.fit)~=md.nsteps | length(md.cm_jump)~=md.nsteps) 360 disp('maxiter, optscal, fit and cm_jump must have the length specified by nsteps') 361 bool=0;return; 362 end 289 fields={'maxiter','optscal','fit','cm_jump'}; 290 testlength(md,fields,md.nsteps); 363 291 364 292 %FIT 365 293 if sum((double(md.fit==1) + double(md.fit==0) + double(md.fit==2))==1)~=md.nsteps 366 disp('wrong fits: fit should be a vector of size nsteps holding 0, 1 and 2 only') 367 bool=0;return; 294 error('model not consistent: wrong fits: fit should be a vector of size nsteps holding 0, 1 and 2 only') 368 295 end 369 296 370 297 %OBSERVED VELOCITIES 371 298 fields={'vx_obs','vy_obs'}; 372 for i=1:length(fields), 373 if any(length(md.(fields{i}))~=md.numberofgrids), 374 disp(['model ' md.name ' field ' fields{i} ' should be of size ' num2str(md.numberofgrids) '!']); 375 bool=0; return; 376 end 377 end 378 379 %SINGULAR 380 if ~any(sum(md.spcvelocity(:,1:2),2)==2), 381 disp(['model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!']) 382 bool=0;return; 383 end 299 testsize(md,fields,[md.numberofgrids 1]); 384 300 385 301 %DIRICHLET IF THICKNESS <= 0 … … 387 303 pos=find(md.thickness<=0); 388 304 if any(find(md.spcthickness(pos,1)==0)), 389 disp(['model ' md.name ' has some grids with 0 thickness']); 390 bool=0; return; 305 error(['model not consistent: model ' md.name ' has some grids with 0 thickness']); 391 306 end 392 307 end … … 397 312 if ~strcmpi(md.cluster,'none'), 398 313 if md.waitonlock==0, 399 disp(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']); 400 bool=0;return; 401 end 402 end 403 end 404 405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PACKAGE CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 406 407 %NAN VALUES 408 fields={'sparsity'}; 409 for i=1:length(fields), 410 if ~isempty(md.(fields{i})), 411 if any(isnan(md.(fields{i}))), 412 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']); 413 bool=0; return; 414 end 415 end 416 end 417 418 %FIELD > 0 419 fields={'sparsity'}; 420 for i=1:length(fields), 421 if ~isempty(md.(fields{i})), 422 if any(md.(fields{i})<0), 423 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']); 424 bool=0; return; 425 end 426 end 427 end 428 429 %FIELD ~= 0 430 fields={'sparsity'}; 431 for i=1:length(fields), 432 if ~isempty(md.(fields{i})), 433 if any(md.(fields{i})==0), 434 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']); 435 bool=0; return; 436 end 437 end 438 end 439 440 %SPARSITY BETWEEN 0 AND 1 441 if ( (md.sparsity<=0) | (md.sparsity>1)), 442 disp(['model ' md.name ' sparsity should be inside the [0 1] range']); 443 bool=0; return; 444 end 445 446 %CONNECTIVITY 447 if strcmpi(md.type,'2d'), 448 if md.connectivity<9, 449 disp('connectivity should be at least 9 for 2d models'); 450 bool=0;return; 451 end 452 end 453 if strcmpi(md.type,'3d'), 454 if md.connectivity<24, 455 disp('connectivity should be at least 24 for 3d models'); 456 bool=0;return; 457 end 458 end 459 460 %LOWMEM = 0 or 1 461 if ((md.lowmem ~= 1) & (md.lowmem~=0)), 462 disp(['model ' md.name ' lowmem field should be 0 or 1']); 463 bool=0; return; 464 end 465 466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARALLEL CHECKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 467 468 if ~strcmpi(md.cluster,'none'), 469 470 %NAN VALUES 471 fields={'time','np'}; 472 for i=1:length(fields), 473 if ~isempty(md.(fields{i})), 474 if any(isnan(md.(fields{i}))), 475 disp(['model ' md.name ' has an NaN value in field ' fields{i} '!']); 476 bool=0; return; 314 error(['model is not correctly configured: waitonlock should be activated when running qmu in parallel mode!']); 315 end 316 end 317 end 318 319 end %end function 320 321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 322 323 function testlength(md,fields,fieldlength) 324 %TESTSIZE - test length of a field 325 for i=1:length(fields), 326 if length(eval(['md.' fields{i}]))~=fieldlength, 327 error(['model not consistent: field ' fields{i} ' length should be ' num2str(fieldlength)]); 328 end 329 end 330 end 331 332 function testsize(md,fields,fieldsize) 333 %TESTSIZE - test size of a field 334 for i=1:length(fields), 335 if isnan(fieldsize(1)), 336 if (size(eval(['md.' fields{i}]),2)~=fieldsize(2)), 337 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(2)) ' columns']); 477 338 end 478 end 479 end 480 481 %FIELD > 0 482 fields={'time','np'}; 483 for i=1:length(fields), 484 if ~isempty(md.(fields{i})), 485 if any(md.(fields{i})<0), 486 disp(['model ' md.name ' has a <0 value in field ' fields{i} '!']); 487 bool=0; return; 339 elseif isnan(fieldsize(2)), 340 if (size(eval(['md.' fields{i}]),1)~=fieldsize(1)), 341 error(['model not consistent: field ' fields{i} ' should have ' num2str(fieldsize(1)) ' rows']); 488 342 end 489 end 490 end 491 492 %FIELD ~= 0 493 fields={'time','np'}; 494 for i=1:length(fields), 495 if ~isempty(md.(fields{i})), 496 if any(md.(fields{i})==0), 497 disp(['model ' md.name ' has a =0 value in field ' fields{i} '!']); 498 bool=0; return; 343 else 344 if ((size(eval(['md.' fields{i}]),1)~=fieldsize(1)) | (size(eval(['md.' fields{i}]),2)~=fieldsize(2))) 345 error(['model not consistent: field ' fields{i} ' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]); 499 346 end 500 347 end 501 348 end 502 503 end 349 end 350 351 function testnan(md,fields) 352 %TESTNAN - test nan values of a field 353 for i=1:length(fields), 354 if any(isnan(eval(['md.' fields{i}]))), 355 error(['model not consistent: NaN values in field ' fields{i}]); 356 end 357 end 358 end 359 360 function testreal(md,fields) 361 %TESTREAL - test real values of a field 362 for i=1:length(fields), 363 if any(eval(['~isreal(md.' fields{i} ')'])), 364 error(['model not consistent: complex values in field ' fields{i}]); 365 end 366 end 367 end 368 369 function testgreaterstrict(md,fields,lowerbound) 370 %TESTGREATERSTRICT - test values of a field 371 for i=1:length(fields), 372 if any(eval(['md.' fields{i} '<=' num2str(lowerbound) ])), 373 error(['model not consistent: field ' fields{i} ' should have values stricly above ' num2str(lowerbound)]); 374 end 375 end 376 end 377 378 function testgreater(md,fields,lowerbound) 379 %TESTGREATER - test values of a field 380 for i=1:length(fields), 381 if any(eval(['md.' fields{i} '<' num2str(lowerbound) ])), 382 error(['model not consistent: field ' fields{i} ' should have values above ' num2str(lowerbound)]); 383 end 384 end 385 end 386 387 function testlessstrict(md,fields,upperbound) 388 %TESTLESSSTRICT - test values of a field 389 for i=1:length(fields), 390 if any(eval(['md.' fields{i} '>=' num2str(upperbound) ])), 391 error(['model not consistent: field ' fields{i} ' should have values stricly below ' num2str(upperbound)]); 392 end 393 end 394 end 395 396 function testless(md,fields,upperbound) 397 %TESTLESS - test values of a field 398 for i=1:length(fields), 399 if any(eval(['md.' fields{i} '>' num2str(upperbound) ])), 400 error(['model not consistent: field ' fields{i} ' should have values below ' num2str(upperbound)]); 401 end 402 end 403 end -
issm/trunk/src/m/classes/public/solve.m
r2298 r2326 27 27 md.sub_analysis_type=options.sub_analysis_type; 28 28 29 if ~ismodelselfconsistent(md), 30 error(' '); %previous error messages should explain what is going on. 31 end 29 %check model consistency 30 displaystring(md.debug,'\n%s\n','checking model consistency'); 31 ismodelselfconsistent(md), 32 32 33 33 %preprocesses model before solving
Note:
See TracChangeset
for help on using the changeset viewer.