def test_radius_ratio_min_radius_ratio_max(): mesh1d = UnitIntervalMesh(MPI.comm_self, 4) x = mesh1d.geometry.points x[4] = mesh1d.geometry.points[3] # Create 2D mesh with one equilateral triangle mesh2d = RectangleMesh.create( MPI.comm_world, [Point(0, 0)._cpp_object, Point(1, 1)._cpp_object], [1, 1], CellType.Type.triangle, cpp.mesh.GhostMode.none, 'left') x = mesh2d.geometry.points x[3] += 0.5 * (sqrt(3.0) - 1.0) # Create 3D mesh with regular tetrahedron and degenerate cells mesh3d = UnitCubeMesh(MPI.comm_self, 1, 1, 1) x = mesh3d.geometry.points x[6][0] = 1.0 x[3][1] = 0.0 rmin, rmax = MeshQuality.radius_ratio_min_max(mesh1d) assert round(rmin - 0.0, 7) == 0 assert round(rmax - 1.0, 7) == 0 rmin, rmax = MeshQuality.radius_ratio_min_max(mesh2d) assert round(rmin - 2.0 * sqrt(2.0) / (2.0 + sqrt(2.0)), 7) == 0 assert round(rmax - 1.0, 7) == 0 rmin, rmax = MeshQuality.radius_ratio_min_max(mesh3d) assert round(rmin - 0.0, 7) == 0 assert round(rmax - 1.0, 7) == 0
def test_lhs_rhs_simple(): """Test taking lhs/rhs of DOLFIN specific forms (constants without cell). """ mesh = RectangleMesh.create(MPI.comm_world, [Point(0, 0), Point(2, 1)], [3, 5], CellType.Type.triangle) V = FunctionSpace(mesh, "CG", 1) f = 2.0 g = 3.0 v = TestFunction(V) u = TrialFunction(V) F = inner(g * grad(f * v), grad(u)) * dx + f * v * dx a, L = system(F) Fl = lhs(F) Fr = rhs(F) assert (Fr) a0 = inner(grad(v), grad(u)) * dx n = assemble(a).norm("frobenius") # noqa nl = assemble(Fl).norm("frobenius") # noqa n0 = 6.0 * assemble(a0).norm("frobenius") # noqa assert round(n - n0, 7) == 0 assert round(n - nl, 7) == 0
def mesh2d(): # Create 2D mesh with one equilateral triangle mesh2d = RectangleMesh.create( MPI.comm_world, [Point(0, 0)._cpp_object, Point(1, 1)._cpp_object], [1, 1], CellType.Type.triangle, cpp.mesh.GhostMode.none, 'left') mesh2d.geometry.points[3] += 0.5 * (sqrt(3.0) - 1.0) return mesh2d
def rectangle(): return RectangleMesh.create( MPI.comm_world, [Point(0, 0)._cpp_object, Point(2, 2)._cpp_object], [5, 5], CellType.Type.triangle, cpp.mesh.GhostMode.none)
"Wall clock time", ) ) for (nx, dt, pres, store_step) in zip(nx_list, dt_list, pres_list, storestep_list): if comm.Get_rank() == 0: print("Starting computation with grid resolution " + str(nx)) output_field = File(outdir + "psi_h" + "_nx" + str(nx) + ".pvd") # Compute num steps till completion num_steps = np.rint(Tend / float(dt)) # Generate mesh mesh = RectangleMesh.create( [Point(xmin, ymin), Point(xmax, ymax)], [nx, nx], CellType.Type.triangle ) # Velocity and initial condition V = VectorFunctionSpace(mesh, "CG", 1) uh = Function(V) uh.assign(Expression((ux, vy), degree=1)) psi0_expression = SineHump(center=[0.5, 0.5], U=[float(ux), float(vy)], time=0.0, degree=6) # Generate particles x = RegularRectangle(Point(xmin, ymin), Point(xmax, ymax)).generate([pres, pres]) s = np.zeros((len(x), 1), dtype=np.float_) # Initialize particles with position x and scalar property s at the mesh p = particles(x, [s], mesh)
# Initial composition field class StepFunction(UserExpression): def eval_cell(self, values, x, cell): c = Cell(mesh, cell.index) if c.midpoint()[1] > db + 0.02 * np.cos(np.pi * x[0] / float(lmbda)): values[0] = 1.0 else: values[0] = 0.0 mesh = RectangleMesh.create( comm, [Point(0.0, 0.0), Point(float(lmbda), 1.0)], [nx, ny], CellType.Type.triangle, "left/right", ) # Shift the mesh to line up with the initial step function condition scale = db * (1.0 - db) shift = Expression(("0.0", "x[1]*(H - x[1])/S*A*cos(pi/L*x[0])"), A=0.02, L=lmbda, H=1.0, S=scale, degree=4) V = VectorFunctionSpace(mesh, "CG", 1) displacement = interpolate(shift, V)
from dolfin import (MPI, CellType, DirichletBC, Function, FunctionSpace, Point, RectangleMesh, SpatialCoordinate, TestFunction, TrialFunction, solve) from dolfin.io import XDMFFile from ufl import ds, dx, grad, inner # We begin by defining a mesh of the domain and a finite element # function space :math:`V` relative to this mesh. As the unit square is # a very standard domain, we can use a built-in mesh provided by the # class :py:class:`UnitSquareMesh <dolfin.cpp.UnitSquareMesh>`. In order # to create a mesh consisting of 32 x 32 squares with each square # divided into two triangles, we do as follows :: # Create mesh and define function space mesh = RectangleMesh.create( MPI.comm_world, [Point(0, 0)._cpp_object, Point(1, 1)._cpp_object], [32, 32], CellType.Type.triangle, dolfin.cpp.mesh.GhostMode.none) V = FunctionSpace(mesh, ("Lagrange", 1)) cmap = dolfin.fem.create_coordinate_map(mesh.ufl_domain()) mesh.geometry.coord_mapping = cmap # The second argument to :py:class:`FunctionSpace # <dolfin.functions.functionspace.FunctionSpace>` is the finite element # family, while the third argument specifies the polynomial # degree. Thus, in this case, our space ``V`` consists of first-order, # continuous Lagrange finite element functions (or in order words, # continuous piecewise linear polynomials). # # Next, we want to consider the Dirichlet boundary condition. A simple # Python function, returning a boolean, can be used to define the