def genMesh(self, h=0.0, cs=3.0, ncx=15, ncz=30, npad=20): """ Generate cylindrically symmetric mesh """ # TODO: Make it adaptive due to z location hx = [(cs, ncx), (cs, npad, 1.3)] hz = [(cs, npad, -1.3), (cs, ncz), (cs, npad, 1.3)] self.mesh = CylMesh([hx, 1, hz], "00C")
def make_example_mesh(): ncr = 20 # number of mesh cells in r ncz = 20 # number of mesh cells in z dh = 5. # cell width hr = [(dh, ncr), (dh, 5, 1.3)] hz = [(dh, 5, -1.3), (dh, ncz), (dh, 5, 1.3)] # Use flag of 1 to denote perfect rotational symmetry mesh = CylMesh([hr, 1, hz], '0CC') return mesh
def setupMesh(self, nc): """ For a given number of cells nc, generate a TensorMesh with uniform cells with edge length h=1/nc. """ if 'TensorMesh' in self._meshType: if 'uniform' in self._meshType: h = [nc, nc, nc] elif 'random' in self._meshType: h1 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h2 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h3 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h = [hi / np.sum(hi) for hi in [h1, h2, h3]] # normalize else: raise Exception('Unexpected meshType') self.M = TensorMesh(h[:self.meshDimension]) max_h = max([np.max(hi) for hi in self.M.h]) return max_h elif 'CylMesh' in self._meshType: if 'uniform' in self._meshType: h = [nc, nc, nc] else: raise Exception('Unexpected meshType') if self.meshDimension == 2: self.M = CylMesh([h[0], 1, h[2]]) max_h = max([np.max(hi) for hi in [self.M.hx, self.M.hz]]) elif self.meshDimension == 3: self.M = CylMesh(h) max_h = max([np.max(hi) for hi in self.M.h]) return max_h elif 'Curv' in self._meshType: if 'uniform' in self._meshType: kwrd = 'rect' elif 'rotate' in self._meshType: kwrd = 'rotate' else: raise Exception('Unexpected meshType') if self.meshDimension == 1: raise Exception('Lom not supported for 1D') elif self.meshDimension == 2: X, Y = Utils.exampleLrmGrid([nc, nc], kwrd) self.M = CurvilinearMesh([X, Y]) elif self.meshDimension == 3: X, Y, Z = Utils.exampleLrmGrid([nc, nc, nc], kwrd) self.M = CurvilinearMesh([X, Y, Z]) return 1. / nc elif 'Tree' in self._meshType: nc *= 2 if 'uniform' in self._meshType or 'notatree' in self._meshType: h = [nc, nc, nc] elif 'random' in self._meshType: h1 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h2 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h3 = np.random.rand(nc) * nc * 0.5 + nc * 0.5 h = [hi / np.sum(hi) for hi in [h1, h2, h3]] # normalize else: raise Exception('Unexpected meshType') levels = int(np.log(nc) / np.log(2)) self.M = Tree(h[:self.meshDimension], levels=levels) def function(cell): if 'notatree' in self._meshType: return levels - 1 r = cell.center - np.array([0.5] * len(cell.center)) dist = np.sqrt(r.dot(r)) if dist < 0.2: return levels return levels - 1 self.M.refine(function, balance=False) self.M.number(balance=False) # self.M.plotGrid(showIt=True) max_h = max([np.max(hi) for hi in self.M.h]) return max_h
tdem_source_list.append( tdem.sources.MagDipole( tdem_receivers_list, location=source_locations[ii], waveform=tdem_waveform, moment=1.0, orientation="z", ) ) tdem_survey = tdem.Survey(tdem_source_list) # Define cylindrical mesh hr = [(10.0, 50), (10.0, 10, 1.5)] hz = [(10.0, 10, -1.5), (10.0, 100), (10.0, 10, 1.5)] mesh = CylMesh([hr, 1, hz], x0="00C") # Define model air_conductivity = 1e-8 background_conductivity = 1e-1 layer_conductivity = 1e-2 pipe_conductivity = 1e1 ind_active = mesh.gridCC[:, 2] < 0 model_map = maps.InjectActiveCells(mesh, ind_active, air_conductivity) conductivity_model = background_conductivity * np.ones(ind_active.sum()) ind_layer = (mesh.gridCC[ind_active, 2] > -200.0) & (mesh.gridCC[ind_active, 2] < -0) conductivity_model[ind_layer] = layer_conductivity ind_pipe = ( (mesh.gridCC[ind_active, 0] < 50.0)
ncr = 10 # number of mesh cells in r ncp = 8 # number of mesh cells in phi ncz = 15 # number of mesh cells in z dr = 15 # cell width r dz = 10 # cell width z hr = dr * np.ones(ncr) hp = (2 * np.pi / ncp) * np.ones(ncp) hz = dz * np.ones(ncz) x0 = 0. y0 = 0. z0 = -150. mesh = CylMesh([hr, hp, hz], x0=[x0, y0, z0]) mesh.plotGrid() ############################################### # Padding Cells and Extracting Properties # --------------------------------------- # # For practical purposes, the user may want to define a region where the cell # widths are increasing/decreasing in size. For example, padding is often used # to define a large domain while reducing the total number of mesh cells. # Here we demonstrate how to create cylindrical meshes that have padding cells. # We then show some properties that can be extracted from cylindrical meshes. # ncr = 10 # number of mesh cells in r
def setupMesh(meshType, nC, nDim): """ For a given number of cells nc, generate a TensorMesh with uniform cells with edge length h=1/nc. """ if 'TensorMesh' in meshType: if 'uniform' in meshType: h = [nC, nC, nC] elif 'random' in meshType: h1 = np.random.rand(nC)*nC*0.5 + nC*0.5 h2 = np.random.rand(nC)*nC*0.5 + nC*0.5 h3 = np.random.rand(nC)*nC*0.5 + nC*0.5 h = [hi/np.sum(hi) for hi in [h1, h2, h3]] # normalize else: raise Exception('Unexpected meshType') mesh = TensorMesh(h[:nDim]) max_h = max([np.max(hi) for hi in mesh.h]) elif 'CylMesh' in meshType: if 'uniform' in meshType: h = [nC, nC, nC] elif 'random' in meshType: h1 = np.random.rand(nC)*nC*0.5 + nC*0.5 h2 = np.random.rand(nC)*nC*0.5 + nC*0.5 h3 = np.random.rand(nC)*nC*0.5 + nC*0.5 h = [hi/np.sum(hi) for hi in [h1, h2, h3]] # normalize h[1] = h[1]*2*np.pi else: raise Exception('Unexpected meshType') if nDim == 2: mesh = CylMesh([h[0], 1, h[2]]) max_h = max([np.max(hi) for hi in [mesh.hx, mesh.hz]]) elif nDim == 3: mesh = CylMesh(h) max_h = max([np.max(hi) for hi in mesh.h]) elif 'Curv' in meshType: if 'uniform' in meshType: kwrd = 'rect' elif 'rotate' in meshType: kwrd = 'rotate' else: raise Exception('Unexpected meshType') if nDim == 1: raise Exception('Lom not supported for 1D') elif nDim == 2: X, Y = utils.exampleLrmGrid([nC, nC], kwrd) mesh = CurvilinearMesh([X, Y]) elif nDim == 3: X, Y, Z = utils.exampleLrmGrid([nC, nC, nC], kwrd) mesh = CurvilinearMesh([X, Y, Z]) max_h = 1./nC elif 'Tree' in meshType: if Tree is None: raise Exception( "Tree Mesh not installed. Run 'python setup.py install'" ) nC *= 2 if 'uniform' in meshType or 'notatree' in meshType: h = [nC, nC, nC] elif 'random' in meshType: h1 = np.random.rand(nC)*nC*0.5 + nC*0.5 h2 = np.random.rand(nC)*nC*0.5 + nC*0.5 h3 = np.random.rand(nC)*nC*0.5 + nC*0.5 h = [hi/np.sum(hi) for hi in [h1, h2, h3]] # normalize else: raise Exception('Unexpected meshType') levels = int(np.log(nC)/np.log(2)) mesh = Tree(h[:nDim], levels=levels) def function(cell): if 'notatree' in meshType: return levels - 1 r = cell.center - 0.5 dist = np.sqrt(r.dot(r)) if dist < 0.2: return levels return levels - 1 mesh.refine(function) # mesh.number() # mesh.plotGrid(showIt=True) max_h = max([np.max(hi) for hi in mesh.h]) return mesh, max_h
ncr = 10 # number of mesh cells in r ncp = 8 # number of mesh cells in phi ncz = 15 # number of mesh cells in z dr = 15 # cell width r dz = 10 # cell width z hr = dr * np.ones(ncr) hp = (2 * np.pi / ncp) * np.ones(ncp) hz = dz * np.ones(ncz) x0 = 0.0 y0 = 0.0 z0 = -150.0 mesh = CylMesh([hr, hp, hz], x0=[x0, y0, z0]) mesh.plotGrid() ############################################### # Padding Cells and Extracting Properties # --------------------------------------- # # For practical purposes, the user may want to define a region where the cell # widths are increasing/decreasing in size. For example, padding is often used # to define a large domain while reducing the total number of mesh cells. # Here we demonstrate how to create cylindrical meshes that have padding cells. # We then show some properties that can be extracted from cylindrical meshes. #