7 from adaptivity
import metric_pnorm, logproject, adapt, polyhedron_surfmesh
12 def minimal_example3D(meshsz=20, Nadapt=10, dL=0.05, eta = 0.01, returnmesh=False, hax=False):
14 class inlet(SubDomain):
15 def inside(self, x, on_boundary):
16 return 0.5-DOLFIN_EPS < x[0] \
17 and -dL-DOLFIN_EPS < x[1]
and x[1] < dL+DOLFIN_EPS \
18 and -dL-DOLFIN_EPS < x[2]
and x[2] < dL+DOLFIN_EPS
20 return on_boundary
and ((0.5-DOLFIN_EPS >= x[0] \
21 or -dL-DOLFIN_EPS >= x[1]
or x[1] >= dL+DOLFIN_EPS \
22 or -dL-DOLFIN_EPS >= x[2]
or x[2] >= dL+DOLFIN_EPS))
24 def get_bnd_mesh(mesh):
25 coords = mesh.coordinates()
27 bcoords = (coords[bfaces[:,0],:]+coords[bfaces[:,1],:]+coords[bfaces[:,2],:])/3.
28 I = (bcoords[:,0] > 0.5-DOLFIN_EPS) & (bcoords[:,1] < dL) & (bcoords[:,1] > -dL) \
29 & (bcoords[:,2] < dL) & (bcoords[:,2] > -dL)
30 I2 = (bcoords[:,0] > 0.5-DOLFIN_EPS) & (bcoords[:,1] < dL) & (bcoords[:,1] > -dL) \
32 I3 = (bcoords[:,0] > 0.5-DOLFIN_EPS) & (bcoords[:,1] < dL) & (bcoords[:,1] > -dL) \
33 & (bcoords[:,2] < -dL)
39 c1 = numpy.array([0.5, -dL, -dL]).repeat(coords.shape[0]).reshape([3,coords.shape[0]]).T
40 c2 = numpy.array([0.5, -dL, dL]).repeat(coords.shape[0]).reshape([3,coords.shape[0]]).T
41 c3 = numpy.array([0.5, dL, -dL]).repeat(coords.shape[0]).reshape([3,coords.shape[0]]).T
42 c4 = numpy.array([0.5, dL, dL]).repeat(coords.shape[0]).reshape([3,coords.shape[0]]).T
43 crnds = numpy.where((numpy.sqrt(((coords - c1)**2).sum(1)) < 1e3*DOLFIN_EPS) | \
44 (numpy.sqrt(((coords - c2)**2).sum(1)) < 1e3*DOLFIN_EPS) | \
45 (numpy.sqrt(((coords - c3)**2).sum(1)) < 1e3*DOLFIN_EPS) | \
46 (numpy.sqrt(((coords - c4)**2).sum(1)) < 1e3*DOLFIN_EPS))[0]
48 return [bfaces,bfaces_IDs]
51 mesh = BoxMesh(-0.5,-0.5,-0.5,0.5,0.5,0.5,meshsz,meshsz,meshsz)
54 for iii
in range(Nadapt):
55 V = FunctionSpace(mesh,
"CG" ,2); dis = TrialFunction(V); dus = TestFunction(V); u = Function(V)
56 a = inner(grad(dis), grad(dus))*dx
57 boundaries = FacetFunction(
"size_t",mesh)
60 Inlet.mark(boundaries, 1)
61 ds = Measure(
"ds")[boundaries]
64 bc = DirichletBC(V, Constant(0.), boundary)
68 H =
metric_pnorm(u, eta, max_edge_length=2., max_edge_ratio=50, CG1out=
True)
71 [bfaces,bfaces_IDs] = get_bnd_mesh(mesh)
72 mesh =
adapt(H, bfaces=bfaces, bfaces_IDs=bfaces_IDs)
73 log(INFO+1,
"total (adapt+metric) time was %0.1fs, nodes: %0.0f" % (time()-startTime, mesh.num_vertices()))
75 plot(u,interactive=
True)
76 plot(mesh,interactive=
True)
79 if __name__==
"__main__":