Changeset 24115 for issm/trunk-jpl/src/m/mesh/triangle.py
- Timestamp:
- 07/30/19 07:52:21 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/mesh/triangle.py
r23716 r24115 5 5 from ElementConnectivity import ElementConnectivity 6 6 from Triangle_python import Triangle_python 7 import MatlabFuncs as m8 7 9 def triangle(md,domainname,*args):10 """11 TRIANGLE - create model mesh using the triangle package12 8 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. 9 def triangle(md, domainname, *args): 10 """ 11 TRIANGLE - create model mesh using the triangle package 17 12 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. 21 17 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) 26 21 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 """ 29 26 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). 36 29 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] 43 36 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 45 46 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 49 48 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) 56 52 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) 62 59 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 66 65 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.