source: issm/trunk/src/m/classes/mesh3dsurface.py@ 20500

Last change on this file since 20500 was 20500, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 20497

File size: 9.1 KB
Line 
1from MatlabFuncs import *
2from model import *
3from EnumDefinitions import *
4from numpy import *
5from fielddisplay import fielddisplay
6from checkfield import checkfield
7from WriteData import WriteData
8
9class mesh3dsurface(object):
10#MESH3DSURFACE class definition
11#
12# Usage:
13# mesh3dsurface=mesh3dsurface();
14 def __init__(self,*args): # {{{
15 self.x = NaN
16 self.y = NaN
17 self.z = NaN
18 self.elements = NaN
19 self.numberofelements = 0
20 self.numberofvertices = 0
21 self.numberofedges = 0
22
23 self.lat = NaN
24 self.long = NaN
25 self.r = NaN
26
27 self.vertexonboundary = NaN
28 self.edges = NaN
29 self.segments = NaN
30 self.segmentmarkers = NaN
31 self.vertexconnectivity = NaN
32 self.elementconnectivity = NaN
33 self.average_vertex_connectivity = 0
34
35 self.extractedvertices = NaN
36 self.extractedelements = NaN
37
38 if not len(args):
39 self.setdefaultparameters()
40 elif len(args)==1:
41 self=mesh3dsurface()
42 arg=args[1]
43 fields=fieldnames(arg)
44 for i in range(len(fields)):
45 field=fields[i]
46 if ismember(field,properties('mesh3dsurface')):
47 self.field=arg.field
48 else:
49 raise RuntimeError('constructor not supported')
50
51 # }}}
52 def __repr__(self): # {{{
53 string=' 2D tria Mesh (horizontal):'
54
55 string+='\n Elements and vertices:'
56 string="%s\n%s"%(string,fielddisplay(self,'numberofelements','number of elements'))
57 string="%s\n%s"%(string,fielddisplay(self,'numberofvertices','number of vertices'))
58 string="%s\n%s"%(string,fielddisplay(self,'elements','vertex indices of the mesh elements'))
59 string="%s\n%s"%(string,fielddisplay(self,'x','vertices x coordinate [m]'))
60 string="%s\n%s"%(string,fielddisplay(self,'y','vertices y coordinate [m]'))
61 string="%s\n%s"%(string,fielddisplay(self,'z','vertices z coordinate [m]'))
62 string="%s\n%s"%(string,fielddisplay(self,'lat','vertices latitude [degrees]'))
63 string="%s\n%s"%(string,fielddisplay(self,'long','vertices longitude [degrees]'))
64 string="%s\n%s"%(string,fielddisplay(self,'r','vertices radius [m]'))
65
66 string="%s\n%s"%(string,fielddisplay(self,'edges','edges of the 2d mesh (vertex1 vertex2 element1 element2)'))
67 string="%s\n%s"%(string,fielddisplay(self,'numberofedges','number of edges of the 2d mesh'))
68
69 string+='\n Properties:'
70 string="%s\n%s"%(string,fielddisplay(self,'vertexonboundary','vertices on the boundary of the domain flag list'))
71 string="%s\n%s"%(string,fielddisplay(self,'segments','edges on domain boundary (vertex1 vertex2 element)'))
72 string="%s\n%s"%(string,fielddisplay(self,'segmentmarkers','number associated to each segment'))
73 string="%s\n%s"%(string,fielddisplay(self,'vertexconnectivity','list of vertices connected to vertex_i'))
74 string="%s\n%s"%(string,fielddisplay(self,'elementconnectivity','list of vertices connected to element_i'))
75 string="%s\n%s"%(string,fielddisplay(self,'average_vertex_connectivity','average number of vertices connected to one vertex'))
76
77 string+='\n Extracted model():'
78 string="%s\n%s"%(string,fielddisplay(self,'extractedvertices','vertices extracted from the model()'))
79 string="%s\n%s"%(string,fielddisplay(self,'extractedelements','elements extracted from the model()'))
80
81 return string
82 # }}}
83 def loadobj(self): # {{{
84 # This def is directly called by matlab when a model() selfect is
85 # loaded. Update old properties here
86
87 #2014 Oct. 1st
88 if isstruct(self):
89 oldself=self
90 #Assign property values from struct
91 self=structtoobj(mesh3dsurface(),oldself)
92 if isfield(oldself,'hemisphere'):
93 print ('md.mesh.hemisphere has been automatically converted to EPSG code')
94 if strcmpi(oldself.hemisphere,'n'):
95 self.epsg=3413
96 else:
97 self.epsg=3031
98 return self
99 # }}}
100 def setdefaultparameters(self): # {{{
101
102 #the connectivity is the averaged number of nodes linked to a
103 #given node through an edge. This connectivity is used to initially
104 #allocate memory to the stiffness matrix. A value of 16 seems to
105 #give a good memory/time ration. This value can be checked in
106 #trunk/test/Miscellaneous/runme.m
107 self.average_vertex_connectivity=25
108 return self
109 # }}}
110 def checkconsistency(self,md,solution,analyses): # {{{
111
112 md = checkfield(md,'fieldname','mesh.x','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
113 md = checkfield(md,'fieldname','mesh.y','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
114 md = checkfield(md,'fieldname','mesh.z','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
115 md = checkfield(md,'fieldname','mesh.lat','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
116 md = checkfield(md,'fieldname','mesh.long','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
117 md = checkfield(md,'fieldname','mesh.r','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices])
118 md = checkfield(md,'fieldname','mesh.elements','NaN',1,'Inf',1,'>',0,'values',arange(1,md.mesh.numberofvertices+1))
119 md = checkfield(md,'fieldname','mesh.elements','size',[md.mesh.numberofelements,3])
120 if any(not ismember([md.mesh.numberofvertices],sort(unique(md.mesh.elements)))):
121 md = checkmessage(md,'orphan nodes have been found. Check the mesh outline')
122
123 md = checkfield(md,'fieldname','mesh.numberofelements','>',0)
124 md = checkfield(md,'fieldname','mesh.numberofvertices','>',0)
125 md = checkfield(md,'fieldname','mesh.average_vertex_connectivity','>=',9,'message','"mesh.average_vertex_connectivity" should be at least 9 in 2d')
126
127 if (solution==ThermalSolutionEnum()):
128 md = checkmessage(md,'thermal not supported for 2d mesh');
129
130 return md
131 # }}}
132 def marshall(self,md,fid): # {{{
133 WriteData(fid,'enum',DomainTypeEnum(),'data',StringToEnum('Domain' + self.domaintype())[0],'format','Integer')
134 WriteData(fid,'enum',DomainDimensionEnum(),'data',self.dimension(),'format','Integer')
135 WriteData(fid,'enum',MeshElementtypeEnum(),'data',StringToEnum(self.elementtype())[0],'format','Integer')
136 WriteData(fid,'object',self,'class','mesh','fieldname','x','format','DoubleMat','mattype',1)
137 WriteData(fid,'object',self,'class','mesh','fieldname','y','format','DoubleMat','mattype',1)
138 WriteData(fid,'object',self,'class','mesh','fieldname','z','format','DoubleMat','mattype',1)
139 WriteData(fid,'enum',MeshLatEnum(),'data',md.mesh.lat,'format','DoubleMat','mattype',1)
140 WriteData(fid,'enum',MeshLongEnum(),'data',md.mesh.long,'format','DoubleMat','mattype',1)
141 WriteData(fid,'object',self,'class','mesh','fieldname','r','format','DoubleMat','mattype',1)
142 WriteData(fid,'enum',MeshZEnum(),'data',zeros(md.mesh.numberofvertices),'format','DoubleMat','mattype',1)
143 WriteData(fid,'object',self,'class','mesh','fieldname','elements','format','DoubleMat','mattype',2)
144 WriteData(fid,'object',self,'class','mesh','fieldname','numberofelements','format','Integer')
145 WriteData(fid,'object',self,'class','mesh','fieldname','numberofvertices','format','Integer')
146 WriteData(fid,'object',self,'class','mesh','fieldname','average_vertex_connectivity','format','Integer')
147 WriteData(fid,'object',self,'class','mesh','fieldname','vertexonboundary','format','DoubleMat','mattype',1)
148 # }}}
149 def domaintype(self): # {{{
150 return '3Dsurface'
151 # }}}
152 def dimension(self): # {{{
153 return 2
154 # }}}
155 def elementtype(self): # {{{
156 return 'Tria'
157 # }}}
158 def processmesh(self,options): # {{{
159
160 isplanet = 1
161 is2d = 0
162
163 elements = self.elements
164 x = self.x
165 y = self.y
166 z = self.z
167 return [x, y, z, elements, is2d, isplanet]
168 # }}}
169 def savemodeljs(self,fid,modelname): # {{{
170
171 fid.write('#s.mesh=new mesh3dsurface()\n'%modelname)
172 writejs1Darray(fid,[modelname, '.mesh.x'],self.x)
173 writejs1Darray(fid,[modelname, '.mesh.y'],self.y)
174 writejs1Darray(fid,[modelname, '.mesh.z'],self.z)
175 writejs2Darray(fid,[modelname, '.mesh.elements'],self.elements)
176 writejsdouble(fid,[modelname, '.mesh.numberofelements'],self.numberofelements)
177 writejsdouble(fid,[modelname, '.mesh.numberofvertices'],self.numberofvertices)
178 writejsdouble(fid,[modelname, '.mesh.numberofedges'],self.numberofedges)
179 writejs1Darray(fid,[modelname, '.mesh.lat'],self.lat)
180 writejs1Darray(fid,[modelname, '.mesh.long'],self.long)
181 writejs1Darray(fid,[modelname, '.mesh.r'],self.r)
182 writejs1Darray(fid,[modelname, '.mesh.vertexonboundary'],self.vertexonboundary)
183 writejs2Darray(fid,[modelname, '.mesh.edges'],self.edges)
184 writejs2Darray(fid,[modelname, '.mesh.segments'],self.segments)
185 writejs2Darray(fid,[modelname, '.mesh.segmentmarkers'],self.segmentmarkers)
186 writejs2Darray(fid,[modelname, '.mesh.vertexconnectivity'],self.vertexconnectivity)
187 writejs2Darray(fid,[modelname, '.mesh.elementconnectivity'],self.elementconnectivity)
188 writejsdouble(fid,[modelname, '.mesh.average_vertex_connectivity'],self.average_vertex_connectivity)
189 writejs1Darray(fid,[modelname, '.mesh.extractedvertices'],self.extractedvertices)
190 writejs1Darray(fid,[modelname, '.mesh.extractedelements'],self.extractedelements)
191
192 # }}}
193
Note: See TracBrowser for help on using the repository browser.