Changeset 2326


Ignore:
Timestamp:
09/25/09 10:48:01 (15 years ago)
Author:
Mathieu Morlighem
Message:

simplified ismodelselfconsistent: replaced disps by errors and use always the same routines to check size and values

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),
     1function ismodelselfconsistent(md),
    22%ISMODELSELFCONSISTENT - check that model forms a closed form solvable problem.
    33%
    44%   Usage:
    5 %      bool=ismodelselfconsistent(md),
     5%      ismodelselfconsistent(md),
    66
    77%tolerance we use in litmus tests for the consistency of the model
    88tolerance=10^-12;
    9 if (nargin~=1  )
     9
     10%check usage
     11if nargin~=1,
    1012        help ismodelselfconsistent
    1113        error('ismodelselfconsistent error message: wrong usage');
    1214end
    1315
    14 %initialize output
    15 bool=1;
     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
    1632
    1733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   COMMON CHECKS   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    1935%COUNTER
    2036if 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)!']);
    2338end
    2439
    2540%NAME
    2641if 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!']);
    3943end
    4044
    4145%ELEMENTSTYPE
    4246if 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'])
    4548end
    4649if 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'])
    4951end
    5052if 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'])
    5354end
    5455if strcmpi(md.type,'2d'),
    5556        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']);
    5858        end
    5959end
    6060if (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']);
    6362end
    6463if (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']);
    6765end
    6866if (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']);
    7168end
    7269
    7370%ICEFRONT
    7471if 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]);
    7974elseif 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]);
    8477end
    8578
     
    8881        'rho_ice','rho_water','B','elementoniceshelf','surface','thickness','bed','g','lowmem','sparsity','nsteps','maxiter',...
    8982        '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
     83testnan(md,fields);
    9884
    9985%FIELDS >= 0
     
    10187        'rho_ice','rho_water','B','elementoniceshelf','thickness','g','eps_res','eps_rel','eps_abs','nsteps','maxiter','tolx','exclusive',...
    10288        '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',...
     89testgreater(md,fields,0);
     90
     91%FIELDS > 0
     92fields={'numberofelements','numberofgrids','elements','drag_type','p',...
    11893        'rho_ice','rho_water','B','thickness','g','eps_res','eps_rel','eps_abs','maxiter','tolx',...
    11994        '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
     95testgreaterstrict(md,fields,0);
    12896
    12997%SIZE NUMBEROFELEMENTS
    13098fields={'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
     99testlength(md,fields,md.numberofelements);
    137100
    138101%SIZE NUMBEROFGRIDS
    139102fields={'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
     103testlength(md,fields,md.numberofgrids);
    146104
    147105%THICKNESS = SURFACE - BED
    148106if 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!']);
    151108end
    152109
     
    154111if md.numrifts,
    155112        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!']);
    158114        end
    159115end
     
    162118                if ~isempty(find(md.segmentmarkers>=2)),
    163119                        %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)!']);
    166121                end
    167122        end
     
    169124
    170125%ARTIFICIAL DIFFUSIVITY
    171 if ~isscalar(md.artificial_diffusivity),
    172         disp('artificial_diffusivity should be a scalar (1 or 0)');
    173         bool=0;return;
     126if ~ismember(md.artificial_diffusivity,[0 1]),
     127        error('model not consistent: artificial_diffusivity should be a scalar (1 or 0)');
    174128end
    175129
    176130%PARAMETEROUTPUT
    177131if 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');
     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        testnan(md,fields);
     158
     159        %FIELD > 0
     160        fields={'time','np'};
     161        testgreaterstrict(md,fields,0);
     162
    180163end
    181164
    182165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  SOLUTION CHECKS  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     166
    183167%QMU
    184168if md.qmu_analysis,
    185169        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']);
    188171        end
    189172        if ~isempty(md.part),
    190173                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 ']);
    193175                end
    194176                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)']);
    197178                end
    198179                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
    203182        end
    204183        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']);
    207185        end
    208186end
     
    214192        if strcmpi(md.type,'2d'),
    215193                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!']);
    218195                end
    219196        end
     
    226203        %SINGULAR
    227204        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!'])
    230206        end
    231207
     
    234210                pos=find(md.thickness<=0);
    235211                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']);
    238213                end
    239214        end
     
    245220        %VELOCITIES
    246221        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!'])
    249223        end
    250224end
     
    252226%STEADYSTATE
    253227if md.analysis_type==SteadystateAnalysisEnum,
     228
    254229        %NDT
    255230        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
    259234        %PRESSURE
    260235        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.']);
    263237        end
    264238
    265239        %eps:
    266240        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!']);
    269242        end
    270243
    271244        %dim:
    272245        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']);
    275247        end
    276248end
     
    281253        %EXTRUSION
    282254        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!'])
    285256        end
    286257
    287258        %VELOCITIES AND PRESSURE
    288259        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!'])
    291261        end
    292262        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!'])
    295264        end
    296265end
     
    301270        %DT and NDT
    302271        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);
    309273
    310274        %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
    347278end
    348279
     
    352283        %CONTROL TYPE
    353284        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');
    356286        end
    357287
    358288        %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);
    363291
    364292        %FIT
    365293        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')
    368295        end
    369296
    370297        %OBSERVED VELOCITIES
    371298        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]);
    384300
    385301        %DIRICHLET IF THICKNESS <= 0
     
    387303                pos=find(md.thickness<=0);
    388304                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']);
    391306                end
    392307        end
     
    397312        if ~strcmpi(md.cluster,'none'),
    398313                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
     317end
     318
     319end %end function
     320
     321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     322
     323function 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
     330end
     331
     332function 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']);
    477338                        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']);
    488342                        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))]);
    499346                        end
    500347                end
    501348        end
    502 
    503 end
     349end
     350
     351function 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
     358end
     359
     360function 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
     367end
     368
     369function 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
     376end
     377
     378function 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
     385end
     386
     387function 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
     394end
     395
     396function 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
     403end
  • issm/trunk/src/m/classes/public/solve.m

    r2298 r2326  
    2727md.sub_analysis_type=options.sub_analysis_type;
    2828
    29 if ~ismodelselfconsistent(md),
    30         error(' '); %previous error messages should explain what is going on.
    31 end
     29%check model consistency
     30displaystring(md.debug,'\n%s\n','checking model consistency');
     31ismodelselfconsistent(md),
    3232
    3333%preprocesses model before solving
Note: See TracChangeset for help on using the changeset viewer.