def inside(self, x, on_boundary): if between(x[1], [0, self.h1]): xx = (self.b / self.h1) * x[1] + self.L1 x_cond = between(x[0], [self.L1, xx]) return x_cond else: return False
def inside(self, x, on_boundary): if near(x[1], self.h1): x_top = between(x[0], [self.L1, self.L1 + self.b]) return on_boundary and x_top elif near(x[0], self.L1): y_left = between(x[1], [0., self.h1]) return on_boundary and y_left
def inside(self, x, on_boundary): cond1 = x[0] > -self.a cond2 = x[0] < -self.a - self.f + self.L if (cond1 and cond2): if between(x[0], [-self.a, -self.fx]): yy = np.sqrt((self.b**2) * (1 - ((x[1] / self.a)**2))) return between(x[1], [-yy, +yy]) else: return between(x[1], [-self.h / 2, +self.h / 2]) else: return False
def inside(self, x, on_boundary): y_top = near(x[1], self.h + self.h) y_bot = near(x[1], -self.h) y_cond = y_top or y_bot x_right = near(x[0], self.L + self.L) x_left = near(x[0], self.L) and not between(x[1], [0., self.h]) x_cond = x_right or x_left cond = y_cond or x_cond return on_boundary and cond
def inside(self, x, on_boundary): if param.tab_p_location == 't': return df.near(x[1], 1.0) and \ df.between(x[0], (param.tab_p_centre - param.L_tab_p / 2, param.tab_p_centre + param.L_tab_p / 2) ) elif param.tab_p_location == 'b': return df.near(x[1], 0.0) and \ df.between(x[0], (param.tab_p_centre - param.L_tab_p / 2, param.tab_p_centre + param.L_tab_p / 2) ) elif param.tab_p_location == 'l': return df.near(x[0], 0.0) and \ df.between(x[1], (param.tab_p_centre - param.L_tab_p / 2, param.tab_p_centre + param.L_tab_p / 2) ) elif param.tab_p_location == 'r': return df.near(x[0], param.Ly) and \ df.between(x[1], (param.tab_p_centre - param.L_tab_p / 2, param.tab_p_centre + param.L_tab_p / 2) ) else: raise ValueError("Pos. tab location must be one of " "t, b, l, r!")
def inside(self, x, on_boundary): if np.abs(self.electrode.angle) > 1e-16: if self.point_inside_polygon(x[0], x[1]): # print(x, "True without modification.") return True elif self.point_inside_polygon(x[0]+self.tol,x[1]) or \ self.point_inside_polygon(x[0]+self.tol,x[1]+self.tol) or \ self.point_inside_polygon(x[0]+self.tol,x[1]-self.tol) or \ self.point_inside_polygon(x[0]-self.tol,x[1]) or \ self.point_inside_polygon(x[0]-self.tol,x[1]+self.tol) or \ self.point_inside_polygon(x[0]-self.tol,x[1]-self.tol) or \ self.point_inside_polygon(x[0],x[1]+self.tol) or \ self.point_inside_polygon(x[0],x[1]-self.tol): return True else: return False else: return ( self.point_inside_polygon(x[0], x[1]) \ and dolfin.between(x[2], (self.zs[0], self.zs[1])))
def inside(self, x, on_boundary): #----------------------------------------------------------------------------------- if self.tDim == 1: return not(df.between(x[0], \ (self.pmlOpt['minLimit'][0],self.pmlOpt['maxLimit'][0]))) if self.tDim == 2: return not(df.between(x[0], \ (self.pmlOpt['minLimit'][0],self.pmlOpt['maxLimit'][0])) \ and \ df.between(x[1], \ (self.pmlOpt['minLimit'][1],self.pmlOpt['maxLimit'][1]))) if self.tDim == 3: return not(df.between(x[0], \ (self.pmlOpt['minLimit'][0],self.pmlOpt['maxLimit'][0])) \ and \ df.between(x[1], \ (self.pmlOpt['minLimit'][1],self.pmlOpt['maxLimit'][1])) and \ df.between(x[2], \ (self.pmlOpt['minLimit'][2],self.pmlOpt['maxLimit'][2])))
def inside(self, x, on_boundary): return df.between(x[0]**2 + x[1]**2, (0, 1)) and df.between(x[1], (0, 1))
def inside(self, x, on_boundary): x_right = between(x[0], [self.L1, self.L1 + self.b]) y_right = between(x[1], [0, self.h1]) cond = x_right and y_right return on_boundary and cond
def inside(self, x, on_boundary): return dolfin.between(x[0]**2 + x[1]**2 + x[2]**2, (0, 3.**2))
def inside(self, x, on_boundary): return between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0))
def inside(self, x, on_boundary): x_cond = near(x[0], self.L) y_cond = between(x[1], [0., self.h]) cond = x_cond and y_cond return on_boundary and cond
def inside(self, x, on_boundary): return on_boundary and between(x[0], [self.L, self.L + self.c])
def inside(self, x, on_boundary): return (between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0)))
def test_3d(): x0, y0, z0 = np.zeros(3) x1, y1, z1 = np.ones(3) points = [(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0), (x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)] # Add points model = gmsh.model gmsh.initialize([]) gmsh.option.setNumber("General.Terminal", 1) # Add components to model for point in points: model.geo.addPoint(*point) lines = [(1, 2), (2, 3), (3, 4), (4, 1), (5, 6), (6, 7), (7, 8), (8, 5), (1, 5), (2, 6), (3, 7), (4, 8)] lines_ = [] for lidx, line in enumerate(lines, 1): lines_.append(model.geo.addLine(*line, tag=lidx)) surfs = [(1, 2, 3, 4), (5, 6, 7, 8), (1, 10, -5, -9), (2, 11, -6, -10), (11, 7, -12, -3), (12, 8, -9, -4)] plane_tags = [] for sidx, surf in enumerate(surfs, 1): tag = model.geo.addCurveLoop(surf, tag=sidx) plane_tags.append(model.geo.addPlaneSurface([tag])) surface_loop = [model.geo.addSurfaceLoop(plane_tags)] volume = model.geo.addVolume(surface_loop) model.addPhysicalGroup(1, lines_, 23) model.addPhysicalGroup(2, plane_tags[0:3], 2) model.addPhysicalGroup(2, plane_tags[3:4], 32) model.addPhysicalGroup(2, plane_tags[4:5], 22) model.addPhysicalGroup(3, [volume], 42) model.geo.synchronize() # gmsh.fltk.initialize() # gmsh.fltk.run() model.mesh.generate(3) # Finally mesh, foos = mesh_from_gmshModel(model, include_mesh_functions=-1) # We get the cells and nodes right elm, nodes = model.mesh.getElementsByType(4) assert len(elm) == mesh.num_cells() assert len(set(nodes)) == mesh.num_vertices() # We have all the mappings assert set((1, 2, 3)) == set(foos.keys()) # Volume vol_tags = np.unique(foos[3].array()) assert len(vol_tags) == 1 assert vol_tags[0] == 42 coords = mesh.coordinates() # Surfaces mesh.init(2, 0) f2v = mesh.topology()(2, 0) for f in range(mesh.num_entities(2)): mid = np.mean(coords[f2v(f)], axis=0) if foos[2][f] == 2: assert df.near(mid[1], 0) or df.near(mid[2]*(1-mid[2]), 0) elif foos[2][f] == 32: assert df.near(mid[0], 1) elif foos[2][f] == 22: assert df.near(mid[1], 1) else: assert foos[2][f] == 0 okay_edge = lambda mid: np.array([[df.near(xi, 0) for xi in mid], [df.near(xi, 1) for xi in mid], [0 < xi < 1 for xi in mid]]) # Edge mesh.init(1) e2v = mesh.topology()(1, 0) for edge in range(mesh.num_entities(1)): if foos[1][edge] == 23: mid = np.mean(coords[e2v(edge)], axis=0) assert all([df.near(xi, 0) or df.near(xi, 1) or df.between(xi, (0, 1)) for xi in mid]) gmsh.clear()
def test_2d(): x0, y0 = np.zeros(2) x1, y1 = np.ones(2) points = [(x0, y0, 0), (x1, y0, 0), (x1, y1, 0), (x0, y1, 0)] # Add points model = gmsh.model gmsh.initialize([]) gmsh.option.setNumber("General.Terminal", 1) # # Add components to model for point in points: model.geo.addPoint(*point) # 3< # 4v 5/ 2^ # 1> lines_ = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)] lines = [] for lidx, line in enumerate(lines_, 1): lines.append(model.geo.addLine(*line, tag=lidx)) surfs = [(1, 2, -5), (5, 3, 4)] plane_tags = [] for sidx, surf in enumerate(surfs, 1): tag = model.geo.addCurveLoop(surf, tag=sidx) plane_tags.append(model.geo.addPlaneSurface([tag])) model.addPhysicalGroup(2, plane_tags[0:1], 2) # y < x model.addPhysicalGroup(2, plane_tags[1:2], 3) # y > x model.addPhysicalGroup(1, lines[0:2], 22) # y = 0, x = 1 model.addPhysicalGroup(1, lines[2:4], 42) # y = 1, x = 0 model.addPhysicalGroup(0, [1, 2, 3, 4], 3) model.geo.synchronize() model.mesh.generate(2) # Finally mesh, foos = mesh_from_gmshModel(model, include_mesh_functions=-1) # We get the cells and nodes right elm, nodes = model.mesh.getElementsByType(2) assert len(elm) == mesh.num_cells() assert len(set(nodes)) == mesh.num_vertices() # We have all the mappings assert set((0, 1, 2)) == set(foos.keys()) coords = mesh.coordinates() # Cell f for cell in df.cells(mesh): x, y = cell.midpoint().array()[:2] if foos[2][cell] == 2: assert y < x else: assert foos[2][cell] == 3, foos[2][cell] assert x < y # Facet f mesh.init(1) f2v = mesh.topology()(1, 0) for facet in range(mesh.num_entities(1)): x, y = np.mean(coords[f2v(facet)], axis=0)[:2] if foos[1][facet] == 22: assert df.near(y, 0) or df.near(x, 1) elif foos[1][facet] == 42: assert df.near(y, 1) or df.near(x, 0) else: assert df.between(x, (0, 1)) and df.between(y, (0, 1)) assert foos[1][facet] == 0 # Vertex vf = foos[0].array() nodes, = np.where(vf == 3) assert len(nodes) == 4 coords = coords[nodes] for x in coords: assert df.near(x[0], 0) or df.near(x[0], 1) assert df.near(x[1], 0) or df.near(x[1], 1) gmsh.clear()
def inside(self, x, on_boundary): return near(x[0], self.xmax) and between(x[1], (self.ymin, self.ymax))
def inside(self, x, on_boundary): return on_boundary and between(x[0], [0, self.L])
def inside(self, x, on_boundary): return (between(x[0], (-self.w_wg / 2, self.w_wg / 2)) and between(x[1], (-self.h_wg / 2, self.h_wg / 2)))
def inside(self,x,on_boundary): return dolfin.between(x[0]**2+x[1]**2+x[2]**2,(0,3.**2))
def inside(self,x,on_boundary): return df.between(x[0]**2+x[1]**2,(0,1)) and df.between(x[1],(0,1))
def inside(self, x, on_boundary): x_cond = between(x[0], [self.L, self.L + self.c]) y_cond = between(x[1], [0., self.h]) return x_cond and y_cond
def inside(self, x, on_boundary): return (dolfin.between(x[0], (self.minxy[0], self.maxxy[0])) and dolfin.between(x[1], (self.minxy[1], self.maxxy[1])))
def inside(self, x, on_boundary): return between(x[0], [self.b, self.b + self.o * self.L])
def inside(self, x, on_boundary): return (dolfin.between( x[2], (self.boundary_dielectric, self.boundary_z_max)))