def construct_boundary_faces(self, mesh): # Get boundary facets function facet_funcs = FacetFunction('size_t', mesh) # Dirichlet part of the boudary is marked by 0 dirichlet_marker = 0 facet_funcs.set_all(dirichlet_marker) neumann_marker = dirichlet_marker + 1 # Mark different parts of the domain for non-homogeneous Dirichlet BC if test_num == 45: # Creat parts of the boundary as subdomains bottom = AutoSubDomain(lambda x: near(x[1], 0)) # Mark part of the domain with non-zero Dirichlet condition bottom.mark(facet_funcs, dirichlet_marker + 1) elif test_num == 48: # Creat parts of the boundary as subdomains right = AutoSubDomain(lambda x: near(x[0], 1)) # Mark part of the domain with non-zero Dirichlet condition right.mark(facet_funcs, neumann_marker) ds = Measure('ds')[facet_funcs] dS = Measure('dS')[facet_funcs] return facet_funcs, ds, dS
def construct_boundary_faces(self, mesh): # Get boundary facets function facet_funcs = FacetFunction('size_t', mesh) facet_funcs.set_all(0) # Dirichlet part of the boudary is marked by 0 # dirichlet_bc_marker = 1 # By default left and right is Dirichlet BC left = AutoSubDomain(lambda x: near(x[0], 0.0)) # x_min right = AutoSubDomain(lambda x: near(x[0], 1.0)) # x_max left.mark(facet_funcs, dirichlet_bc_marker) right.mark(facet_funcs, dirichlet_bc_marker) if dim == 3: # By default left and right is Dirichlet BC top = AutoSubDomain(lambda x: near(x[1], 0.0)) # x_min bottom = AutoSubDomain(lambda x: near(x[1], 1.0)) # x_max top.mark(facet_funcs, dirichlet_bc_marker) bottom.mark(facet_funcs, dirichlet_bc_marker) #neumann_bc_marker = dirichlet_bc_marker + 1 if self.test_num == 24: left = AutoSubDomain(lambda x: near(x[0], 0.0)) # x_min right = AutoSubDomain(lambda x: near(x[0], 10.0)) # x_max left.mark(facet_funcs, neumann_bc_marker) right.mark(facet_funcs, neumann_bc_marker) if self.test_num == 37: right = AutoSubDomain(lambda x: near(x[0], 1.0)) # x_max right.mark(facet_funcs, neumann_bc_marker) if self.test_num == 38 or test_num == 39 or test_num == 40 or test_num == 41 or test_num == 42: left = AutoSubDomain(lambda x: near(x[0], 0.0)) # x_min right = AutoSubDomain(lambda x: near(x[0], 1.0)) # x_max left.mark(facet_funcs, neumann_bc_marker) right.mark(facet_funcs, neumann_bc_marker) # The boundary with IC #init_bc_marker = neumann_bc_marker + 1 # = 3 sigma_0 = AutoSubDomain(lambda x: near(x[1], 0.0)) sigma_0.mark(facet_funcs, init_bc_marker) # The top of the space-time cylinder #do_nothing_bc_marker = init_bc_marker + 1 # = 4 sigma_T = AutoSubDomain(lambda x: near(x[1], self.T)) sigma_T.mark(facet_funcs, do_nothing_bc_marker) ds = Measure('ds')[facet_funcs] dS = Measure('dS')[facet_funcs] return facet_funcs, ds, dS
def geometry_3d(): """Prepares 3D geometry. Returns facet function with 1, 2 on parts of the boundary.""" mesh = Mesh('lego_beam.xml') gdim = mesh.geometry().dim() x0 = mesh.coordinates()[:, 0].min() x1 = mesh.coordinates()[:, 0].max() boundary_parts = FacetFunction('size_t', mesh) left = AutoSubDomain(lambda x: near(x[0], x0)) right = AutoSubDomain(lambda x: near(x[0], x1)) left.mark(boundary_parts, 1) right.mark(boundary_parts, 2) boundary_parts._mesh = mesh # Workaround issue #467 return boundary_parts
def geometry_2d(length): """Prepares 2D geometry. Returns facet function with 1, 2 on parts of the boundary.""" n = 4 x0 = 0.0 x1 = x0 + length y0 = 0.0 y1 = 1.0 mesh = RectangleMesh(x0, y0, x1, y1, int((x1 - x0) * n), int( (y1 - y0) * n), 'crossed') boundary_parts = FacetFunction('size_t', mesh) left = AutoSubDomain(lambda x: near(x[0], x0)) right = AutoSubDomain(lambda x: near(x[0], x1)) left.mark(boundary_parts, 1) right.mark(boundary_parts, 2) boundary_parts._mesh = mesh # Workaround issue #467 return boundary_parts
def test_majorant(self, problem_params): # Define the project path # --------------------------------------------------------------------------------------------------------------# project_path = postprocess.get_project_path() # Check if it does exist and create folder for the results # --------------------------------------------------------------------------------------------------------------# results_folder_name = postprocess.construct_result_folder_name( self.dim, test_num, problem_params) postprocess.create_results_folder(results_folder_name) # --------------------------------------------------------------------------------------------------------------# # Define problem data # --------------------------------------------------------------------------------------------------------------# # Define the mesh based on the domain geometry # --------------------------------------------------------------------------------------------------------------# # Function to generate the mesh mesh = self.construct_mesh(test_params["nx0"], test_params["nx1"], test_params["nx2"], test_params["res"], project_path) """ # Plot and save the initial mesh if self.dim == 2: postprocess.plot_mesh(mesh, project_path + results_folder_name + 'initial-mesh') elif self.dim == 3: postprocess.plot_mesh_3d(mesh, project_path + results_folder_name + 'initial-mesh') """ # Get boundary facets function facet_funcs = FacetFunction('size_t', mesh) facet_funcs.set_all(0) # Calculate the estimate for Freidrichs constant based on the domain C_FD = problem.calculate_CF_of_domain(domain, self.dim) # Define functional spaces based on the mesh # --------------------------------------------------------------------------------------------------------------# V, VV, V_exact, VV_exact, H_div = problem.functional_spaces( mesh, problem_params, self.dim) # Define problem data functions # --------------------------------------------------------------------------------------------------------------# f, sq_f, phi, grad_phi, u_e, grad_u_e, sq_grad_u_e = self.convert_problem_data_to_expressions( ) #f, A, invA, adjA, lmbd, a, uD, u_e, grad_u_e = self.convert_problem_data_to_expressions(mesh, test_params) # Majorant parameter delta = 1.0 # Output to console the problem data problem.output_problem_characteristics( self.test_num, self.u_expr, self.grad_u_expr, self.f_expr, self.A_expr, self.lambda_expr, self.a_expr, self.uD_expr, self.domain, self.T, self.dim, mesh.num_cells(), mesh.num_vertices(), test_params["nt"], test_params["v_approx_order"], test_params["flux_approx_order"], delta) # Run the solver with a posteriori error control # --------------------------------------------------------------------------------------------------------------# t0_problem = time.clock() self.solve_problem_nd_t( mesh, V, VV, V_exact, VV_exact, H_div, f, sq_f, phi, grad_phi, u_e, grad_u_e, sq_grad_u_e, u_e, self.u0_boundary, # Dirichlet boundary condition self.dim, self.T, self.domain, C_FD, delta, self.test_num, test_params, project_path, results_folder_name) t1_problem = time.clock() print "time = ", t1_problem - t0_problem
# Load mesh from the xml-file project_path = postprocess.get_project_path() mesh = Mesh(project_path + file_path + file_name) print "mesh: %s, h_max = %f" % (file_name, mesh.hmax()) class ZeroBoundary(SubDomain): def inside(self, x, on_boundary): return on_boundary and x[1] <= DOLFIN_EPS # Mark boundaries zero_boundary = ZeroBoundary() boundaries = FacetFunction("uint", mesh) boundaries.set_all(0) zero_boundary.mark(boundaries, 1) # Redefine boundary measure ds = Measure('ds')[boundaries] V = FunctionSpace(mesh, "Lagrange", 3) for n_power in range(N_power.size): N = N_power[n_power] phi = get_list_of_power_type_basis_functions(N) #phi = get_list_of_fourier_type_basis_functions(N) M = len(phi)
# vector product of normal and center gives d in ax+by+cz = d equation for obj in itertools.chain(inflows, outflows): obj['d'] = vec(obj['center'], obj['normal']) # returns number of plane the given point is in def point_in_subdomain(p): for obj in itertools.chain(inflows, outflows): if abs(vec(p, obj['normal']) - obj['d']) < tol: return obj['number'] # Create boundary markers facet_function = FacetFunction("size_t", mesh) for f_mesh in facets(mesh): if f_mesh.exterior(): set = False for num in number_list: if not set and all( point_in_subdomain(v.point()) == num for v in vertices(f_mesh)): facet_function[f_mesh] = num set = True if not set: facet_function[f_mesh] = 1 # wall plot(facet_function) f_mesh = HDF5File(mpi_comm_world(), 'meshes/' + meshName + '.hdf5', 'w')
timestep = 0.1 time = 0.2 nu_factor = 10. length = 20.0 v_in = 10.0 nu = Constant(3.7 * nu_factor) dt = Constant(timestep) f = Constant(0.0) mesh_size = 10 # Create meshes and facet function mesh = IntervalMesh(mesh_size, 0.0, length) mesh_plot = IntervalMesh(8 * mesh_size, 0.0, length) boundary_parts = FacetFunction('size_t', mesh) right = AutoSubDomain(lambda x: near(x[0], length)) left = AutoSubDomain(lambda x: near(x[0], 0.0)) right.mark(boundary_parts, 2) left.mark(boundary_parts, 1) # Create function spaces V = FunctionSpace(mesh, 'Lagrange', 2) # Vplot = FunctionSpace(mesh_plot, 'Lagrange', 1) Vplot = V Q = FunctionSpace(mesh, 'Lagrange', 1) # BC conditions, nullspace v_in_expr = Constant(v_in) plt = plot(interpolate(v_in_expr, V), range_min=0.,