1 | from numpy import *
|
---|
2 | import TriMesh as tm
|
---|
3 | import NodeConnectivity as nc
|
---|
4 | import ElementConnectivity as ec
|
---|
5 |
|
---|
6 | def triangle(md, domainname, resolution,riftname=''):
|
---|
7 | #TRIANGLE - create model mesh using the triangle package
|
---|
8 | #
|
---|
9 | # This routine creates a model mesh using TriMesh and a domain outline, to within a certain resolution
|
---|
10 | # where md is a @model object, domainname is the name of an Argus domain outline file,
|
---|
11 | # and resolution is a characteristic length for the mesh (same unit as the domain outline
|
---|
12 | # unit). Riftname is an optional argument (Argus domain outline) describing rifts.
|
---|
13 | #
|
---|
14 | # Usage:
|
---|
15 | # md=triangle(md,domainname,resolution)
|
---|
16 | # or md=triangle(md,domainname, resolution, riftname)
|
---|
17 | #
|
---|
18 | # Examples:
|
---|
19 | # md=triangle(md,'DomainOutline.exp',1000);
|
---|
20 | # md=triangle(md,'DomainOutline.exp',1000,'Rifts.exp');
|
---|
21 |
|
---|
22 |
|
---|
23 | #Figure out a characteristic area. Resolution is a node oriented concept (ex a 1000m resolution node would
|
---|
24 | #be made of 1000*1000 area squares).
|
---|
25 |
|
---|
26 | #Check that mesh was not already run, and warn user:
|
---|
27 | if md.mesh.numberofelements != 0.:
|
---|
28 | choice = input('This model already has a mesh. Are you sure you want to go ahead? (y/n)')
|
---|
29 | if choice != 'y':
|
---|
30 | print 'no meshing done ... exiting'
|
---|
31 | return []
|
---|
32 |
|
---|
33 | area = resolution**2.
|
---|
34 |
|
---|
35 | #Mesh using TriMesh
|
---|
36 | [md.mesh.elements,md.mesh.x,md.mesh.y,md.mesh.segments,md.mesh.segmentmarkers]=tm.TriMesh(domainname,riftname,area)
|
---|
37 |
|
---|
38 | #Fill in rest of fields:
|
---|
39 | md.mesh.numberofelements = size(md.mesh.elements)
|
---|
40 | md.mesh.numberofvertices = size(md.mesh.x)
|
---|
41 | md.mesh.z = zeros(md.mesh.numberofvertices)
|
---|
42 | md.mesh.vertexonboundary = zeros(md.mesh.numberofvertices)
|
---|
43 | md.mesh.vertexonboundary[md.mesh.segments[:,0:2].astype(int)] = 1.
|
---|
44 | md.mesh.vertexonbed = ones(md.mesh.numberofvertices)
|
---|
45 | md.mesh.vertexonsurface = ones(md.mesh.numberofvertices)
|
---|
46 | md.mesh.elementonbed = ones(md.mesh.numberofelements)
|
---|
47 | md.mesh.elementonsurface = ones(md.mesh.numberofelements)
|
---|
48 |
|
---|
49 | #Now, build the connectivity tables for this mesh.
|
---|
50 | [md.mesh.vertexconnectivity]= nc.NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices)
|
---|
51 | [md.mesh.elementconnectivity] = ec.ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity)
|
---|
52 |
|
---|
53 | #type of model
|
---|
54 | md.mesh.dimension = 2.
|
---|
55 | return md
|
---|