Changeset 7626


Ignore:
Timestamp:
03/04/11 14:19:31 (14 years ago)
Author:
Mathieu Morlighem
Message:

nicer modelcheck

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk/src/m/model/ismodelselfconsistent.m

    r7623 r7626  
    1111        help ismodelselfconsistent
    1212        error('ismodelselfconsistent error message: wrong usage');
    13 end
    14 %}}}
    15 
    16 %recursive call for TRANSIENT {{{1
    17 if (md.analysis_type==Transient2DSolutionEnum | md.analysis_type==Transient3DSolutionEnum),
    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
    23         if (md.dim==2),
    24                 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum];
    25         else
    26                 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum ThermalSolutionEnum];
    27         end
    28 
    29         for i=1:length(analysis),
    30                 md.analysis_type=analysis(i);
    31                 ismodelselfconsistent(md);
    32         end
    33 
    34         if(md.cfl_coefficient>1 | md.cfl_coefficient<0),
    35                 error(['model not consistent: model ' md.name ' cfl_coefficient field should between  0 and 1']);
    36         end
    37 end
    38 %}}}
    39 %recursive call for STEADYSTATE{{{1
    40 if md.analysis_type==SteadystateSolutionEnum,
    41 
    42         %NDT
    43         if md.dt~=0,
    44                 error(['model not consistent: for a steadystate computation, dt must be zero.']);
    45         end
    46 
    47         %PRESSURE
    48         if isnans(md.pressure),
    49                 error(['model not consistent: for a steadystate computation, the model must have an initial pressure, even lithostatic will do.']);
    50         end
    51 
    52         %eps:
    53         if isnan(md.eps_rel),
    54                 error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']);
    55         end
    56 
    57         %recursive call to ismodelselfconsistent
    58         analysis=[DiagnosticSolutionEnum ThermalSolutionEnum];
    59 
    60         for i=1:length(analysis),
    61                 md.analysis_type=analysis(i);
    62                 ismodelselfconsistent(md);
    63         end
    64 
    65 end
    66 %}}}
    67 %recursive call for GROUNDINGLINEMIGRATION2D{{{1
    68 if md.analysis_type==GroundingLineMigration2DSolutionEnum,
    69         if strcmpi(md.cluster.name,'none'),
    70                 error(['model not consistent: ' md.analysis_type ' is only implemented in parallel mode !'])
    71         end
    72 
    73         if md.dt<=0,
    74                 error('model not consistent: field dt must be positive for a transient run')
    75         end
    76 
    77         %recursive call to ismodelselfconsistent
    78         if (md.dim==2),
    79                 analysis=[DiagnosticSolutionEnum PrognosticSolutionEnum];
    80         else
    81                 error(['model not consistent: for a ' md.analysis_type ' computation, the grounding line module is only implemented in 2d !'])
    82         end
    83 
    84         for i=1:length(analysis),
    85                 md.analysis_type=analysis(i);
    86                 ismodelselfconsistent(md);
    87         end
    88 
    89         if(md.cfl_coefficient>1 | md.cfl_coefficient<0),
    90                 error(['model not consistent: model ' md.name ' cfl_coefficient field should between  0 and 1']);
    91         end
    9213end
    9314%}}}
     
    276197IsConsistent(md.cluster);
    277198%}}}
    278 
    279 % Solution checks
    280 %DIAGNOSTIC{{{1
    281 if md.analysis_type==DiagnosticSolutionEnum,
    282 
    283         %HUTTER ON ICESHELF WARNING
    284         if any(md.elements_type==HutterApproximationEnum & md.elementoniceshelf),
    285                 disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
    286         end
    287 
    288         %SINGULAR
    289         if ~any(sum(md.spcvelocity(:,1:2),2)==2),
    290                 error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
    291         end
    292 
    293         %DIRICHLET IF THICKNESS <= 0
    294         if any(md.thickness<=0),
    295                 pos=find(md.thickness<=0);
    296                 if any(find(md.spcthickness(pos,1)==0)),
    297                         error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
    298                 end
    299         end
    300 
    301         %INITIAL VELOCITY
    302         if length(md.vx)==md.numberofgrids & length(md.vy)==md.numberofgrids,
    303                 fields={'vx','vy'};
    304                 checknan(md,fields);
    305         end
    306 end
    307 %}}}
    308 %PROGNOSTIC{{{1
    309 if md.analysis_type==PrognosticSolutionEnum,
    310 
    311         %INITIAL VELOCITIES
    312         fields={'vx','vy'};
    313         checksize(md,fields,[md.numberofgrids 1]);
    314         checknan(md,fields);
    315 
    316         %CHECK THAT WE ARE NOT FULLY CONSTRAINED
    317         if (md.dim==2),
    318                 if isempty(find(~md.spcthickness(:,1))),
    319                         error(['model not consistent: model ' md.name ' is totally constrained for prognostic, no need to solve!']);
    320                 end
    321         end
    322 
    323 end
    324 %}}}
    325 %THERMAL {{{1
    326 %THERMAL STEADY AND THERMAL TRANSIENT
    327 if md.analysis_type==ThermalSolutionEnum,
    328 
    329         %EXTRUSION
    330         if (md.dim==2),
    331                 error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
    332         end
    333 
    334         %CHECK THAT WE ARE NOT FULLY CONSTRAINED
    335         if isempty(find(~md.spctemperature(:,1))),
    336                 error(['model not consistent: model ' md.name ' is totally constrained for temperature, no need to solve!']);
    337         end
    338 
    339         %VELOCITIES AND PRESSURE
    340         fields={'vx','vy','vz','pressure','geothermalflux'};
    341         checksize(md,fields,[md.numberofgrids 1]);
    342         checknan(md,fields);
    343 
    344 end
    345 
    346 %THERMAL TRANSIENT
    347 if md.analysis_type==ThermalSolutionEnum & md.dt~=0,
    348 
    349         %DT and NDT
    350         fields={'dt','ndt'};
    351         checkgreaterstrict(md,fields,0);
    352 
    353         %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
    354         fields={'temperature','accumulation_rate','melting_rate'};
    355         checksize(md,fields,[md.numberofgrids 1]);
    356         checknan(md,fields);
    357 
    358         %INITIAL TEMPERATURE
    359         fields={'temperature','spctemperature(:,2)','observed_temperature'};
    360         checkgreater(md,fields,0)
    361 
    362 end
    363 %}}}
    364 %BALANCEDTHICKNESS{{{1
    365 if md.analysis_type==BalancedthicknessSolutionEnum
    366 
    367         %VELOCITIES MELTING AND ACCUMULATION
    368         fields={'vx','vy','accumulation_rate','melting_rate','dhdt'};
    369         checksize(md,fields,[md.numberofgrids 1]);
    370         checknan(md,fields);
    371 
    372         %SPC                             
    373 %       if ~md.prognostic_DG,
    374 %               if any(md.spcthickness(find(md.gridonboundary))~=1),             
    375 %                       error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcthickness']);                     
    376 %               end
    377 %       end
    378 
    379         %Triangle with zero velocity
    380         if any(sum(abs(md.vx(md.elements)),2)==0 & sum(abs(md.vy(md.elements)),2)==0)
    381                 error('model not consistent: at least one triangle has all its vertices with a zero velocity');
    382         end
    383 end
    384 %}}}
    385 %BALANCEDVELOCITIES{{{1
    386 if md.analysis_type==BalancedvelocitiesSolutionEnum
    387 
    388         %VELOCITIES MELTING AND ACCUMULATION
    389         fields={'vx','vy','accumulation_rate','melting_rate'};
    390         checksize(md,fields,[md.numberofgrids 1]);
    391         checknan(md,fields);
    392 
    393         %SPC
    394         if any(md.spcvelocity(find(md.gridonboundary),[1:2])~=1),
    395                 error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcvelocity']);
    396         end
    397 end
    398 %}}}
    399199%CONTROL{{{1
    400200if md.control_analysis,
     
    488288%}}}
    489289
    490 end
     290%Solution specific check
     291%TRANSIENT {{{1
     292if (md.analysis_type==Transient2DSolutionEnum | md.analysis_type==Transient3DSolutionEnum),
     293
     294        if md.dt<=0,
     295                error('model not consistent: field dt must be positive for a transient run')
     296        end
     297
     298        if(md.cfl_coefficient>1 | md.cfl_coefficient<0),
     299                error(['model not consistent: model ' md.name ' cfl_coefficient field should between  0 and 1']);
     300        end
     301end
     302%}}}
     303%STEADYSTATE{{{1
     304if md.analysis_type==SteadystateSolutionEnum,
     305
     306        %NDT
     307        if md.dt~=0,
     308                error(['model not consistent: for a steadystate computation, dt must be zero.']);
     309        end
     310
     311        %eps:
     312        if isnan(md.eps_rel),
     313                error(['model not consistent: for a steadystate computation, eps_rel (relative convergence criterion) must be defined!']);
     314        end
     315end
     316%}}}
     317%GROUNDINGLINEMIGRATION2D{{{1
     318if md.analysis_type==GroundingLineMigration2DSolutionEnum,
     319        if strcmpi(md.cluster.name,'none'),
     320                error(['model not consistent: ' md.analysis_type ' is only implemented in parallel mode !'])
     321        end
     322
     323        if md.dt<=0,
     324                error('model not consistent: field dt must be positive for a transient run')
     325        end
     326
     327        %recursive call to ismodelselfconsistent
     328        if (md.dim~=2),
     329                error(['model not consistent: for a ' md.analysis_type ' computation, the grounding line module is only implemented in 2d !'])
     330        end
     331
     332        if(md.cfl_coefficient>1 | md.cfl_coefficient<0),
     333                error(['model not consistent: model ' md.name ' cfl_coefficient field should between  0 and 1']);
     334        end
     335end
     336%}}}
     337%ANALYSESCHECKS {{{1
     338[analyses,numanalyses,solutioncore]=SolutionConfiguration(md.analysis_type);
     339for i=1:numanalyses,
     340        checkforanalysis(md,analyses(i));
     341end
     342%}}}
     343end
     344
     345%analysis checks
     346%checkforanalysis {{{1
     347function checkforanalysis(md,analysis_enum)
     348
     349        switch(analysis_enum),
     350                case DiagnosticHorizAnalysisEnum,
     351                        % {{{2
     352                        %SINGULAR
     353                        if ~any(sum(md.spcvelocity(:,1:2),2)==2),
     354                                error(['model not consistent: model ' md.name ' is not well posed (singular). You need at least one grid with fixed velocity!'])
     355                        end
     356
     357                        %DIRICHLET IF THICKNESS <= 0
     358                        if any(md.thickness<=0),
     359                                pos=find(md.thickness<=0);
     360                                if any(find(md.spcthickness(pos,1)==0)),
     361                                        error(['model not consistent: model ' md.name ' has some grids with 0 thickness']);
     362                                end
     363                        end
     364
     365                        %INITIAL VELOCITY
     366                        if ~isempty(md.vx) & ~isempty(md.vy),
     367                                fields={'vx','vy'};
     368                                checknan(md,fields);
     369                                checksize(md,fields,[md.numberofgrids 1]);
     370                        end
     371                        %}}}
     372                case DiagnosticVertAnalysisEnum,
     373                        % {{{2
     374                        if md.dim==3,
     375                                % No checks for now
     376                        end
     377                        %}}}
     378                case DiagnosticHutterAnalysisEnum,
     379                        % {{{2
     380                        %HUTTER ON ICESHELF WARNING
     381                        if any(md.elements_type==HutterApproximationEnum & md.elementoniceshelf),
     382                                disp(sprintf('\n !!! Warning: Hutter''s model is not consistent on ice shelves !!!\n'));
     383                        end
     384                        %}}}
     385                case BedSlopeAnalysisEnum,
     386                        % {{{2
     387                        % No checks for now
     388                        %}}}
     389                case SurfaceSlopeAnalysisEnum,
     390                        % {{{2
     391                        % No checks for now
     392                        %}}}
     393                case PrognosticAnalysisEnum,
     394                        % {{{2
     395                        %INITIAL VELOCITIES
     396                        fields={'vx','vy'};
     397                        checksize(md,fields,[md.numberofgrids 1]);
     398                        checknan(md,fields);
     399
     400                        %CHECK THAT WE ARE NOT FULLY CONSTRAINED
     401                        if (md.dim==2),
     402                                if isempty(find(~md.spcthickness(:,1))),
     403                                        error(['model not consistent: model ' md.name ' is totally constrained for prognostic, no need to solve!']);
     404                                end
     405                        end
     406                        %}}}
     407                case ThermalAnalysisEnum,
     408                        % {{{2
     409                        %EXTRUSION
     410                        if (md.dim==2),
     411                                error(['model not consistent: for a ' md.analysis_type ' computation, the model must be 3d, extrude it first!'])
     412                        end
     413
     414                        %CHECK THAT WE ARE NOT FULLY CONSTRAINED
     415                        if isempty(find(~md.spctemperature(:,1))),
     416                                error(['model not consistent: model ' md.name ' is totally constrained for temperature, no need to solve!']);
     417                        end
     418
     419                        %VELOCITIES AND PRESSURE
     420                        fields={'vx','vy','vz','pressure','geothermalflux'};
     421                        checksize(md,fields,[md.numberofgrids 1]);
     422                        checknan(md,fields);
     423
     424                        %THERMAL TRANSIENT
     425                        if md.dt~=0,
     426
     427                                %DT and NDT
     428                                fields={'dt','ndt'};
     429                                checkgreaterstrict(md,fields,0);
     430
     431                                %INITIAL TEMPERATURE, MELTING AND ACCUMULATION
     432                                fields={'temperature','accumulation_rate','melting_rate'};
     433                                checksize(md,fields,[md.numberofgrids 1]);
     434                                checknan(md,fields);
     435
     436                                %INITIAL TEMPERATURE
     437                                fields={'temperature','spctemperature(:,2)','observed_temperature'};
     438                                checkgreater(md,fields,0)
     439                        end
     440                        %}}}
     441                case MeltingAnalysisEnum,
     442                        % {{{2
     443                        % No checks for now
     444                        %}}}
     445                case BalancedthicknessAnalysisEnum,
     446                        % {{{2
     447                        %VELOCITIES MELTING AND ACCUMULATION
     448                        fields={'vx','vy','accumulation_rate','melting_rate','dhdt'};
     449                        checksize(md,fields,[md.numberofgrids 1]);
     450                        checknan(md,fields);
     451
     452                        %SPC                             
     453                        %       if ~md.prognostic_DG,
     454                        %               if any(md.spcthickness(find(md.gridonboundary))~=1),             
     455                        %                       error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcthickness']);                     
     456                        %               end
     457                        %       end
     458
     459                        %Triangle with zero velocity
     460                        if any(sum(abs(md.vx(md.elements)),2)==0 & sum(abs(md.vy(md.elements)),2)==0)
     461                                error('model not consistent: at least one triangle has all its vertices with a zero velocity');
     462                        end
     463                        %}}}
     464                case BalancedvelocitiesAnalysisEnum,
     465                        % {{{2
     466                        %VELOCITIES MELTING AND ACCUMULATION
     467                        fields={'vx','vy','accumulation_rate','melting_rate'};
     468                        checksize(md,fields,[md.numberofgrids 1]);
     469                        checknan(md,fields);
     470
     471                        %SPC
     472                        if any(md.spcvelocity(find(md.gridonboundary),[1:2])~=1),
     473                                error(['model not consistent: model ' md.name ' should have all the nodes on boundary constrained in field spcvelocity']);
     474                        end
     475                        %}}}
     476                otherwise
     477                        disp(['WARNING: no check implemented for analysis ' EnumToString(analysis_enum) '!']);
     478                        error('stop')
     479        end
     480
     481end
     482%}}}
    491483
    492484%checks additional functions
Note: See TracChangeset for help on using the changeset viewer.