Changeset 22299
- Timestamp:
- 12/22/17 08:13:13 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/mesh/bamg.py
r22271 r22299 22 22 23 23 - domain : followed by an ARGUS file that prescribes the domain outline 24 - holes : followed by an ARGUS file that prescribes the holes 25 - subdomains : followed by an ARGUS file that prescribes the list of 26 subdomains (that need to be inside domain) 27 24 28 - hmin : minimum edge length (default is 10^-100) 25 29 - hmax : maximum edge length (default is 10^100) … … 74 78 bamg_mesh=bamgmesh() 75 79 76 77 80 subdomain_ref = 1 81 hole_ref = 1 78 82 79 83 # Bamg Geometry parameters {{{ 80 84 if options.exist('domain'): 81 82 85 #Check that file exists 83 86 domainfile=options.getfieldvalue('domain') … … 92 95 count=0 93 96 for i,domaini in enumerate(domain): 94 95 97 #Check that the domain is closed 96 98 if (domaini['x'][0]!=domaini['x'][-1] or domaini['y'][0]!=domaini['y'][-1]): 97 99 raise RuntimeError("bamg error message: all contours provided in ''domain'' should be closed") 98 100 99 #Checks that all holes are INSIDE the principle domain outline 101 #Checks that all holes are INSIDE the principle domain outline princial domain should be index 0 100 102 if i: 101 103 flags=ContourToNodes(domaini['x'],domaini['y'],domainfile,0)[0] … … 103 105 raise RuntimeError("bamg error message: All holes should be strictly inside the principal domain") 104 106 107 #Check orientation 108 nods=domaini['nods']-1#the domain are closed 1=end; 109 110 test = np.sum((domaini['x'][1:nods+1] - domaini['x'][0:nods])*(domaini['y'][1:nods+1] + domaini['y'][0:nods])) 111 if (i==0 and test>0) or (i>0 and test<0): 112 print('At least one contour was not correctly oriented and has been re-oriented') 113 domaini['x'] = np.flipud(domaini['x']) 114 domaini['y'] = np.flipud(domaini['y']) 115 116 105 117 #Add all points to bamg_geometry 106 118 nods=domaini['nods']-1 #the domain are closed 0=end 107 119 bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((domaini['x'][0:nods],domaini['y'][0:nods],np.ones((nods)))).T)) 108 120 bamg_geometry.Edges =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T)) 109 if i: 110 bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,-subdomain_ref])) 111 subdomain_ref = subdomain_ref+1; 112 else: 113 bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,0])) 114 115 # bamg_geometry.Vertices=np.hstack((bamg_geometry.Vertices,np.vstack((domaini['x'][0:nods].reshape(-1),domaini['y'][0:nods].reshape(-1),np.ones((nods)))))) 116 # bamg_geometry.Edges =np.vstack((bamg_geometry.Edges,np.hstack((np.arange(count+1,count+nods+1).reshape(-1,),np.hstack((np.arange(count+2,count+nods+1),count+1)).reshape(-1,),1.*np.ones((nods,)))))) 117 # if i: 118 # bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,1])) 119 121 if i: 122 bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,-subdomain_ref])) 123 subdomain_ref = subdomain_ref+1; 124 else: 125 bamg_geometry.SubDomains=np.vstack((bamg_geometry.SubDomains,[2,count+1,1,0])) 126 120 127 #update counter 121 128 count+=nods 122 129 130 #Deal with domain holes 131 if options.exist('holes'): 132 holesfile=options.getfieldvalue('holes') 133 if type(holesfile) == str: 134 if not os.path.exists(holesfile): 135 raise IOError("bamg error message: file '%s' not found" % holesfile) 136 holes=expread(holesfile) 137 else: 138 holes=holesfile 139 140 #Build geometry 141 for i,holei in enumerate(holes): 142 #Check that the hole is closed 143 if (holei['x'][0]!=holei['x'][-1] or holei['y'][0]!=holei['y'][-1]): 144 raise RuntimeError("bamg error message: all contours provided in ''hole'' should be closed") 145 146 #Checks that all holes are INSIDE the principle domain outline princial domain should be index 0 147 flags=ContourToNodes(holei['x'],holei['y'],domainfile,0)[0] 148 if np.any(np.logical_not(flags)): 149 raise RuntimeError("bamg error message: All holes should be strictly inside the principal domain") 150 151 #Check orientation 152 nods=holei['nods']-1#the hole are closed 1=end; 153 test = np.sum((holei['x'][1:nods+1] - holei['x'][0:nods])*(holei['y'][1:nods+1] + holei['y'][0:nods])) 154 if test<0: 155 print('At least one hole was not correctly oriented and has been re-oriented') 156 holei['x'] = np.flipud(holei['x']) 157 holei['y'] = np.flipud(holei['y']) 158 159 #Add all points to bamg_geometry 160 nods=holei['nods']-1 #the hole are closed 0=end 161 bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((holei['x'][0:nods],holei['y'][0:nods],np.ones((nods)))).T)) 162 bamg_geometry.Edges =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T)) 163 #update counter 164 count+=nods 165 166 #And subdomains 167 if options.exist('subdomains'): 168 subdomainfile=options.getfieldvalue('subdomains') 169 if type(subdomainfile) == str: 170 if not os.path.exists(subdomainfile): 171 raise IOError("bamg error message: file '%s' not found" % subdomainfile) 172 subdomains=expread(subdomainfile) 173 else: 174 subdomains=subdomainfile 175 176 #Build geometry 177 for i,subdomaini in enumerate(subdomains): 178 #Check that the subdomain is closed 179 if (subdomaini['x'][0]!=subdomaini['x'][-1] or subdomaini['y'][0]!=subdomaini['y'][-1]): 180 raise RuntimeError("bamg error message: all contours provided in ''subdomain'' should be closed") 181 182 #Checks that all subdomains are INSIDE the principle subdomain outline princial domain should be index 0 183 if i: 184 flags=ContourToNodes(subdomaini['x'],subdomaini['y'],domainfile,0)[0] 185 if np.any(np.logical_not(flags)): 186 raise RuntimeError("bamg error message: All subdomains should be strictly inside the principal subdomain") 187 188 #Check orientation 189 nods=subdomaini['nods']-1#the subdomain are closed 1=end; 190 191 test = np.sum((subdomaini['x'][1:nods+1] - subdomaini['x'][0:nods])*(subdomaini['y'][1:nods+1] + subdomaini['y'][0:nods])) 192 if test>0: 193 print('At least one subcontour was not correctly oriented and has been re-oriented') 194 subdomaini['x'] = np.flipud(subdomaini['x']) 195 subdomaini['y'] = np.flipud(subdomaini['y']) 196 197 #Add all points to bamg_geometry 198 nods=subdomaini['nods']-1 #the subdomain are closed 0=end 199 bamg_geometry.Vertices=np.vstack((bamg_geometry.Vertices,np.vstack((subdomaini['x'][0:nods],subdomaini['y'][0:nods],np.ones((nods)))).T)) 200 bamg_geometry.Edges =np.vstack((bamg_geometry.Edges,np.vstack((np.arange(count+1,count+nods+1),np.hstack((np.arange(count+2,count+nods+1),count+1)),1.*np.ones((nods)))).T)) 201 #update counter 202 count+=nods 203 123 204 if options.getfieldvalue('vertical',0): 124 205 if np.size(options.getfieldvalue('Markers',[]))!=np.size(bamg_geometry.Edges,0):
Note:
See TracChangeset
for help on using the changeset viewer.