Ignore:
Timestamp:
07/30/19 07:52:21 (6 years ago)
Author:
bdef
Message:

BUG:fixing typos for py3 compatibility

File:
1 edited

Legend:

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

    r23716 r24115  
    55from ElementConnectivity import ElementConnectivity
    66from Triangle_python import Triangle_python
    7 import MatlabFuncs as m
    87
    9 def triangle(md,domainname,*args):
    10         """
    11         TRIANGLE - create model mesh using the triangle package
    128
    13            This routine creates a model mesh using Triangle and a domain outline, to within a certain resolution
    14            where md is a @model object, domainname is the name of an Argus domain outline file,
    15            and resolution is a characteristic length for the mesh (same unit as the domain outline
    16            unit). Riftname is an optional argument (Argus domain outline) describing rifts.
     9def triangle(md, domainname, *args):
     10    """
     11    TRIANGLE - create model mesh using the triangle package
    1712
    18            Usage:
    19               md=triangle(md,domainname,resolution)
    20            or md=triangle(md,domainname, resolution, riftname)
     13       This routine creates a model mesh using Triangle and a domain outline, to within a certain resolution
     14       where md is a @model object, domainname is the name of an Argus domain outline file,
     15       and resolution is a characteristic length for the mesh (same unit as the domain outline
     16       unit). Riftname is an optional argument (Argus domain outline) describing rifts.
    2117
    22            Examples:
    23               md=triangle(md,'DomainOutline.exp',1000);
    24               md=triangle(md,'DomainOutline.exp',1000,'Rifts.exp');
    25         """
     18       Usage:
     19          md=triangle(md,domainname,resolution)
     20       or md=triangle(md,domainname, resolution, riftname)
    2621
    27         #Figure out a characteristic area. Resolution is a node oriented concept (ex a 1000m  resolution node would
    28         #be made of 1000*1000 area squares).
     22       Examples:
     23          md=triangle(md,'DomainOutline.exp',1000);
     24          md=triangle(md,'DomainOutline.exp',1000,'Rifts.exp');
     25    """
    2926
    30         if len(args)==1:
    31                 resolution=args[0]
    32                 riftname=''
    33         if len(args)==2:
    34                 riftname=args[0]
    35                 resolution=args[1]
     27    #Figure out a characteristic area. Resolution is a node oriented concept (ex a 1000m  resolution node would
     28    #be made of 1000*1000 area squares).
    3629
    37         #Check that mesh was not already run, and warn user:
    38         if md.mesh.numberofelements:
    39                 choice = eval(input('This model already has a mesh. Are you sure you want to go ahead? (y/n)'))
    40                 if not m.strcmp(choice,'y'):
    41                         print('no meshing done ... exiting')
    42                         return None
     30    if len(args) == 1:
     31        resolution = args[0]
     32        riftname = ''
     33    if len(args) == 2:
     34        riftname = args[0]
     35        resolution = args[1]
    4336
    44         area = resolution**2
     37    #Check that mesh was not already run, and warn user:
     38    if md.mesh.numberofelements:
     39        choice = eval(input('This model already has a mesh. Are you sure you want to go ahead? (y/n)'))
     40        if choice not in ['y', 'n']:
     41            print("bad answer try you should use 'y' or 'n' ... exiting")
     42            return None
     43        if choice == 'n':
     44            print('no meshing done ... exiting')
     45            return None
    4546
    46         #Check that file exist (this is a very very common mistake)
    47         if not os.path.exists(domainname):
    48                 raise IOError("file '%s' not found" % domainname)
     47    area = resolution**2
    4948
    50         #Mesh using Triangle
    51         md.mesh=mesh2d()
    52         md.mesh.elements,md.mesh.x,md.mesh.y,md.mesh.segments,md.mesh.segmentmarkers=Triangle_python(domainname,riftname,area)
    53         md.mesh.elements=md.mesh.elements.astype(int)
    54         md.mesh.segments=md.mesh.segments.astype(int)
    55         md.mesh.segmentmarkers=md.mesh.segmentmarkers.astype(int)
     49    #Check that file exist (this is a very very common mistake)
     50    if not os.path.exists(domainname):
     51        raise IOError("file '%s' not found" % domainname)
    5652
    57         #Fill in rest of fields:
    58         md.mesh.numberofelements = np.size(md.mesh.elements,axis=0)
    59         md.mesh.numberofvertices = np.size(md.mesh.x)
    60         md.mesh.vertexonboundary = np.zeros(md.mesh.numberofvertices,bool)
    61         md.mesh.vertexonboundary[md.mesh.segments[:,0:2]-1] = True
     53    #Mesh using Triangle
     54    md.mesh = mesh2d()
     55    md.mesh.elements, md.mesh.x, md.mesh.y, md.mesh.segments, md.mesh.segmentmarkers = Triangle_python(domainname, riftname, area)
     56    md.mesh.elements = md.mesh.elements.astype(int)
     57    md.mesh.segments = md.mesh.segments.astype(int)
     58    md.mesh.segmentmarkers = md.mesh.segmentmarkers.astype(int)
    6259
    63         #Now, build the connectivity tables for this mesh.
    64         md.mesh.vertexconnectivity = NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices)[0]
    65         md.mesh.elementconnectivity = ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity)[0]
     60    #Fill in rest of fields:
     61    md.mesh.numberofelements = np.size(md.mesh.elements, axis=0)
     62    md.mesh.numberofvertices = np.size(md.mesh.x)
     63    md.mesh.vertexonboundary = np.zeros(md.mesh.numberofvertices, bool)
     64    md.mesh.vertexonboundary[md.mesh.segments[:, 0:2] - 1] = True
    6665
    67         return md
     66    #Now, build the connectivity tables for this mesh.
     67    md.mesh.vertexconnectivity = NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices)[0]
     68    md.mesh.elementconnectivity = ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity)[0]
     69
     70    return md
Note: See TracChangeset for help on using the changeset viewer.