Changeset 12943


Ignore:
Timestamp:
08/08/12 11:37:55 (13 years ago)
Author:
jschierm
Message:

NEW: Python checkconsistency and marshall methods for mesh sub-class (plus other changes to make them work).

Location:
issm/trunk-jpl/src/m
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/mesh.m

    r12663 r12943  
    5757                function obj = setdefaultparameters(obj) % {{{
    5858
    59                         %the connectivity is the avergaded number of nodes linked to a
     59                        %the connectivity is the averaged number of nodes linked to a
    6060                        %given node through an edge. This connectivity is used to initially
    6161                        %allocate memory to the stiffness matrix. A value of 16 seems to
  • issm/trunk-jpl/src/m/classes/mesh.py

    r12123 r12943  
    11#module imports
     2import numpy
    23from fielddisplay import fielddisplay
     4from checkfield import *
     5from EnumDefinitions import *
     6from MatlabFuncs import *
    37
    48class mesh:
     
    6569                else:
    6670                        string="\n%s"%("      Elements and vertices:")
    67 
    6871                string="%s\n%s"%(string,fielddisplay(obj,"numberofelements","number of elements"))
    69                
    70 
    71 
    72 
    7372                string="%s\n%s"%(string,fielddisplay(obj,"numberofvertices","number of vertices"))
    7473                string="%s\n%s"%(string,fielddisplay(obj,"elements","index into (x,y,z), coordinates of the vertices"))
     
    8079
    8180                string="%s%s"%(string,"\n      Properties:")
    82                
    8381                string="%s\n%s"%(string,fielddisplay(obj,"dimension","mesh dimension (2d or 3d)"))
    8482                string="%s\n%s"%(string,fielddisplay(obj,"numberoflayers","number of extrusion layers"))
     
    9290                string="%s\n%s"%(string,fielddisplay(obj,"lowerelements","lower element list (NaN for element on the lower layer"))
    9391                string="%s\n%s"%(string,fielddisplay(obj,"vertexonboundary","vertices on the boundary of the domain flag list"))
    94                
    9592                string="%s\n%s"%(string,fielddisplay(obj,"segments","edges on domain boundary (vertex1 vertex2 element)"))
    9693                string="%s\n%s"%(string,fielddisplay(obj,"segmentmarkers","number associated to each segment"))
     
    10097
    10198                string="%s%s"%(string,"\n      Extracted model:")
    102 
    10399                string="%s\n%s"%(string,fielddisplay(obj,"extractedvertices","vertices extracted from the model"))
    104100                string="%s\n%s"%(string,fielddisplay(obj,"extractedelements","elements extracted from the model"))
     
    114110                # {{{setdefaultparameters
    115111               
    116                 #the connectivity is the avergaded number of nodes linked to a
     112                #the connectivity is the averaged number of nodes linked to a
    117113                #given node through an edge. This connectivity is used to initially
    118114                #allocate memory to the stiffness matrix. A value of 16 seems to
     
    124120        #}}}
    125121
     122        def checkconsistency(self,md,solution,analyses):    # {{{
     123
     124                md = checkfield(md,'mesh.x','NaN',1,'size',[md.mesh.numberofvertices])
     125                md = checkfield(md,'mesh.y','NaN',1,'size',[md.mesh.numberofvertices])
     126                md = checkfield(md,'mesh.z','NaN',1,'size',[md.mesh.numberofvertices])
     127                md = checkfield(md,'mesh.elements','NaN',1,'>',0,'values',range(1,md.mesh.numberofvertices+1))
     128                if md.mesh.dimension==2:
     129                        md = checkfield(md,'mesh.elements','size',[md.mesh.numberofelements,3])
     130                else:
     131                        md = checkfield(md,'mesh.elements','size',[md.mesh.numberofelements,6])
     132                if any(numpy.logical_not(ismember(range(1,md.mesh.numberofvertices+1),md.mesh.elements))):
     133                        md = checkmessage(md,"orphan nodes have been found. Check the mesh outline")
     134                md = checkfield(md,'mesh.dimension','values',[2,3])
     135                md = checkfield(md,'mesh.numberoflayers','>=',0)
     136                md = checkfield(md,'mesh.numberofelements','>',0)
     137                md = checkfield(md,'mesh.numberofvertices','>',0)
     138                #no checks for numberofedges lat long and hemisphere
     139                md = checkfield(md,'mesh.elementonbed','size',[md.mesh.numberofelements],'values',[0,1])
     140                md = checkfield(md,'mesh.elementonsurface','size',[md.mesh.numberofelements],'values',[0,1])
     141                md = checkfield(md,'mesh.vertexonbed','size',[md.mesh.numberofvertices],'values',[0,1])
     142                md = checkfield(md,'mesh.vertexonsurface','size',[md.mesh.numberofvertices],'values',[0,1])
     143                if md.mesh.dimension==2:
     144                        md = checkfield(md,'mesh.average_vertex_connectivity','>=',9,'message',"'mesh.average_vertex_connectivity' should be at least 9 in 2d")
     145                else:
     146                        md = checkfield(md,'mesh.average_vertex_connectivity','>=',24,'message',"'mesh.average_vertex_connectivity' should be at least 24 in 3d")
     147                md = checkfield(md,'mesh.elementconnectivity','size',[md.mesh.numberofelements,3],'NaN',1)
     148
     149                #Solution specific checks
     150                if   solution==PrognosticSolutionEnum:
     151                        if md.prognostic.stabilization==3:
     152                                md = checkfield(md,'mesh.dimension','values',2,'message',"Discontinuous Galerkin only supported for 2d meshes")
     153                                md = checkfield(md,'mesh.edges','size',[float('NaN'),4])
     154                                md = checkfield(md,'mesh.edges[:,1:3]','>',0)
     155                elif solution==BalancethicknessSolutionEnum:
     156                        if md.balancethickness.stabilization==3:
     157                                md = checkfield(md,'mesh.dimension','values',2,'message',"Discontinuous Galerkin only supported for 2d meshes")
     158                                md = checkfield(md,'mesh.edges','size',[float('NaN'),4])
     159                                md = checkfield(md,'mesh.edges[:,1:3]','>',0)
     160                elif solution==TransientSolutionEnum:
     161                        if md.transient.isprognostic and md.prognostic.stabilization==3:
     162                                md = checkfield(md,'mesh.dimension','values',2,'message',"Discontinuous Galerkin only supported for 2d meshes")
     163                                md = checkfield(md,'mesh.edges','size',[float('NaN'),4])
     164                                md = checkfield(md,'mesh.edges[:,1:3]','>',0)
     165                elif solution==ThermalSolutionEnum:
     166                        md = checkfield(md,'mesh.dimension','values',3,'message','thermal solution only supported on 3d meshes')
     167
     168                return md
     169        # }}}
     170
     171        def marshall(self,fid):    # {{{
     172                WriteData(fid,'object',self,'fieldname','x','format','DoubleMat','mattype',1)
     173                WriteData(fid,'object',self,'fieldname','y','format','DoubleMat','mattype',1)
     174                WriteData(fid,'object',self,'fieldname','z','format','DoubleMat','mattype',1)
     175                WriteData(fid,'object',self,'fieldname','elements','format','DoubleMat','mattype',2)
     176                WriteData(fid,'object',self,'fieldname','dimension','format','Integer')
     177                WriteData(fid,'object',self,'fieldname','numberoflayers','format','Integer')
     178                WriteData(fid,'object',self,'fieldname','numberofelements','format','Integer')
     179                WriteData(fid,'object',self,'fieldname','numberofvertices','format','Integer')
     180                WriteData(fid,'object',self,'fieldname','numberofedges','format','Integer')
     181                WriteData(fid,'object',self,'fieldname','elementonbed','format','BooleanMat','mattype',2)
     182                WriteData(fid,'object',self,'fieldname','elementonsurface','format','BooleanMat','mattype',2)
     183                WriteData(fid,'object',self,'fieldname','vertexonbed','format','BooleanMat','mattype',1)
     184                WriteData(fid,'object',self,'fieldname','vertexonsurface','format','BooleanMat','mattype',1)
     185                WriteData(fid,'object',self,'fieldname','lowerelements','format','DoubleMat','mattype',2)
     186                WriteData(fid,'object',self,'fieldname','upperelements','format','DoubleMat','mattype',2)
     187                WriteData(fid,'object',self,'fieldname','edges','format','DoubleMat','mattype',3)
     188                WriteData(fid,'object',self,'fieldname','elementconnectivity','format','DoubleMat','mattype',3)
     189                WriteData(fid,'object',self,'fieldname','average_vertex_connectivity','format','Integer')
     190                WriteData(fid,'object',self,'fieldname','elements2d','format','DoubleMat','mattype',3)
     191                WriteData(fid,'object',self,'fieldname','numberofvertices2d','format','Integer')
     192                WriteData(fid,'object',self,'fieldname','numberofelements2d','format','Integer')
     193        # }}}
     194
  • issm/trunk-jpl/src/m/classes/private.m

    r12663 r12943  
    3131                        fielddisplay(obj,'isconsistent','is model self consistent');
    3232                        fielddisplay(obj,'runtimename','name of the run launched');
    33                         fielddisplay(obj,'bamg','structure with mesh properties construced if bamg is used to mesh the domain');
     33                        fielddisplay(obj,'bamg','structure with mesh properties constructed if bamg is used to mesh the domain');
    3434                        fielddisplay(obj,'solution','type of solution launched');
    3535
  • issm/trunk-jpl/src/m/classes/private.py

    r12123 r12943  
    66        def __init__(self):
    77                # {{{ Properties
    8                 self.runtimename = ''
    9                 self.bamg        = {}
    10                 self.solution    = '';
     8                self.isconsistent = True;
     9                self.runtimename  = ''
     10                self.bamg         = {}
     11                self.solution     = '';
    1112
    1213                #set defaults
     
    1718                # {{{ Display
    1819                string='   private parameters: do not change'
     20
     21                string="%s\n%s"%(string,fielddisplay(obj,'isconsistent','is model self consistent'))
    1922                string="%s\n%s"%(string,fielddisplay(obj,'runtimename','name of the run launched'))
    20                 string="%s\n%s"%(string,fielddisplay(obj,'bamg','structure with mesh properties construced if bamg is used to mesh the domain'))
     23                string="%s\n%s"%(string,fielddisplay(obj,'bamg','structure with mesh properties constructed if bamg is used to mesh the domain'))
    2124                string="%s\n%s"%(string,fielddisplay(obj,'solution','type of solution launched'))
    2225                return string
  • issm/trunk-jpl/src/m/model/WriteData.py

    r12827 r12943  
    99 
    1010            Usage:
    11                WriteData(fid,*args)
     11               WriteData(fid,varargin)
    1212        """
    1313
    1414        #process options
    15         options=pairoptions(args)
     15        options=pairoptions(*args)
    1616
    1717        #Get data properties
  • issm/trunk-jpl/src/m/model/ismodelselfconsistent.py

    r12889 r12943  
    1717
    1818        #Go through a model fields, check that it is a class, and call checkconsistency
    19 #       fields=vars('model')
    20         fields=dir(md)
    21         for field in fields:
     19        fields=vars(md)
     20        for field in fields.iterkeys():
    2221
    2322                #Some properties do not need to be checked
  • issm/trunk-jpl/src/m/model/marshall.py

    r12889 r12943  
    2626        fields=vars(md)
    2727
    28         for field in fields.interkeys():
     28        for field in fields.iterkeys():
    2929
    3030                #Some properties do not need to be marshalled
  • issm/trunk-jpl/src/m/utils/consistency/checkfield.py

    r12842 r12943  
    88        CHECKFIELD - check field consistency
    99
    10             Used to check model consistency.
    11             Available options:
    12                - NaN: 1 if check that there is no NaN
    13                - size: [lines cols], NaN for non checked dimensions
    14                - >:  greater than provided value
    15                - >=: greater or equal to provided value
    16                - <:  smallerthan provided value
    17                - <=: smaller or equal to provided value
    18                - < vec:  smallerthan provided values on each vertex
    19                - forcing: 1 if check forcing consistency (size and time)
    20                - values: cell of strings or vector of acceptable values
    21                - numel: list of acceptable number of elements
    22                - cell: 1 if check that is cell
    23                - empty: 1 if check that non empty
    24                - message: overloaded error message
     10           Used to check model consistency.
     11           Available options:
     12              - NaN: 1 if check that there is no NaN
     13              - size: [lines cols], NaN for non checked dimensions
     14              - >:  greater than provided value
     15              - >=: greater or equal to provided value
     16              - <:  smallerthan provided value
     17              - <=: smaller or equal to provided value
     18              - < vec:  smallerthan provided values on each vertex
     19              - forcing: 1 if check forcing consistency (size and time)
     20              - values: cell of strings or vector of acceptable values
     21              - numel: list of acceptable number of elements
     22              - cell: 1 if check that is cell
     23              - empty: 1 if check that non empty
     24              - message: overloaded error message
    2525
    26             Usage:
    27                md = checkfield(md,fieldname,options);
     26           Usage:
     27              md = checkfield(md,fieldname,options);
    2828
    29             Example:
    30                md = checkfield(md,'mesh.elementonbed','size',[md.mesh.numberofelements 1],'values',[0 1]);
    31                md = checkfield(md,'diagnostic.icefront','size',[NaN 4],'NaN',1);
    32                md = checkfield(md,'diagnostic.icefront(:,end)','values',[0 1 2]);
     29           Example:
     30              md = checkfield(md,'mesh.elementonbed','size',[md.mesh.numberofelements 1],'values',[0 1]);
     31              md = checkfield(md,'diagnostic.icefront','size',[NaN 4],'NaN',1);
     32              md = checkfield(md,'diagnostic.icefront(:,end)','values',[0 1 2]);
    3333        """
    3434
     
    3737
    3838        #get field from model
    39         field=getattr(md,fieldname)
     39#       field=getattr(md,fieldname)
     40        exec("field=md.%s" % fieldname)
    4041
    4142        #check empty
    42         if 'empty' in options:
     43        if options.exist('empty'):
    4344                if not field:
    4445                        md = md.checkmessage(options.getfieldvalue('message',\
     
    4647
    4748        #Check size
    48         if 'size' in options:
     49        if options.exist('size'):
    4950                fieldsize=options.getfieldvalue('size')
    50                 if   numpy.isnan(fieldsize[0]):
    51                         if not numpy.size(field,1)==fieldsize[1]:
     51                if   len(fieldsize) == 1:
     52                        if (not numpy.size(field,0)==fieldsize[0]):
    5253                                md = md.checkmessage(options.getfieldvalue('message',\
    53                                         "field '%s' should have %d columns" % (fieldname,fieldsize[1])))
    54                 elif numpy.isnan(fieldsize[1]):
    55                         if not numpy.size(field,0)==fieldsize[0]:
    56                                 md = md.checkmessage(options.getfieldvalue('message',\
    57                                         "field '%s' should have %d lines" % (fieldname,fieldsize[0])))
    58                 else:
    59                         if (not numpy.size(field,0)==fieldsize[0]) or (not numpy.size(field,1)==fieldsize[1]):
    60                                 md = md.checkmessage(options.getfieldvalue('message',\
    61                                         "field '%s' size should be %d x %d" % (fieldname,fieldsize[0],fieldsize[1])))
     54                                        "field '%s' size should be %d" % (fieldname,fieldsize[0])))
     55                elif len(fieldsize) == 2:
     56                        if   numpy.isnan(fieldsize[0]):
     57                                if not numpy.size(field,1)==fieldsize[1]:
     58                                        md = md.checkmessage(options.getfieldvalue('message',\
     59                                                "field '%s' should have %d columns" % (fieldname,fieldsize[1])))
     60                        elif numpy.isnan(fieldsize[1]):
     61                                if not numpy.size(field,0)==fieldsize[0]:
     62                                        md = md.checkmessage(options.getfieldvalue('message',\
     63                                                "field '%s' should have %d lines" % (fieldname,fieldsize[0])))
     64                        else:
     65                                if (not numpy.size(field,0)==fieldsize[0]) or (not numpy.size(field,1)==fieldsize[1]):
     66                                        md = md.checkmessage(options.getfieldvalue('message',\
     67                                                "field '%s' size should be %d x %d" % (fieldname,fieldsize[0],fieldsize[1])))
    6268       
    6369        #Check numel
    64         if 'numel' in options:
     70        if options.exist('numel'):
    6571                fieldnumel=options.getfieldvalue('numel')
    6672                if not numpy.size(field) in fieldnumel:
     
    8894
    8995        #check values
    90         if 'values' in options:
     96        if options.exist('values'):
    9197                fieldvalues=options.getfieldvalue('values')
    9298                if False in ismember(field,fieldvalues):
     
    102108
    103109        #check greater
    104         if '>=' in options:
     110        if options.exist('>='):
    105111                lowerbound=options.getfieldvalue('>=')
    106112                if numpy.any(field<lowerbound):
    107113                        md = md.checkmessage(options.getfieldvalue('message',\
    108114                                "field '%s' should have values above %d" % (fieldname,lowerbound)))
    109         if '>' in options:
     115        if options.exist('>'):
    110116                lowerbound=options.getfieldvalue('>')
    111117                if numpy.any(field<=lowerbound):
     
    114120
    115121        #check smaller
    116         if '<=' in options:
     122        if options.exist('<='):
    117123                upperbound=options.getfieldvalue('<=')
    118124                if numpy.any(field>upperbound):
    119125                        md = md.checkmessage(options.getfieldvalue('message',\
    120126                                "field '%s' should have values below %d" % (fieldname,upperbound)))
    121         if '<' in options:
     127        if options.exist('<'):
    122128                upperbound=options.getfieldvalue('<')
    123129                if numpy.any(field>=upperbound):
Note: See TracChangeset for help on using the changeset viewer.