Beispiel #1
0
 def build_transfer_matrices(self):
     V1 = self.V1
     V2 = self.V2
     VO = self.VO
     self.B1 = PETScDMCollection.create_transfer_matrix(V1, VO)
     self.B2 = PETScDMCollection.create_transfer_matrix(V2, VO)
     self.BO1 = PETScDMCollection.create_transfer_matrix(VO, V1)
     self.BO2 = PETScDMCollection.create_transfer_matrix(VO, V2)
coord2[1142] = np.array([0.27136816, 0.27167537, 0.50056124])
coord2[1448] = np.array([0.80807753, 0.90899875, 0.77327936])
coord2[1654] = np.array([0.80824022, 0.90899337, 0.77317984])

# level four
coord3 = mesh3.coordinates()
coord3[235] = np.array([0.73388744, 0.42498976, 0.60173443])


# ==========================================================================

# Find the transfer operators, puse is the prolongation operator list
# note the order is from fine to coarse
puse = []
for il in range(nl-1):
    pmat = PETScDMCollection.create_transfer_matrix(Vspace[il+1], Vspace[il])
    pmat = pmat.mat()
    puse.append(pmat)

# ==========================================================================

# Use FEniCS to formulate the FEM problem. A is the matrix, b is the rhs.
u_D = Constant(0.0)

tol = 1E-14


def boundary_D(x, on_boundary):

    return on_boundary and (near(x[0], 0, tol) or near(x[0], 1.0, tol))
Beispiel #3
0
def save_files_visualization(visualization_folder, dvp_, t, save_deg, v_deg, p_deg, mesh, domains, **namespace):
    # Files for storing results
    if not "d_file" in namespace.keys():
        d_file = XDMFFile(MPI.comm_world, str(visualization_folder.joinpath("displacement.xdmf")))
        v_file = XDMFFile(MPI.comm_world, str(visualization_folder.joinpath("velocity.xdmf")))
        p_file = XDMFFile(MPI.comm_world, str(visualization_folder.joinpath("pressure.xdmf")))
        for tmp_t in [d_file, v_file, p_file]:
            tmp_t.parameters["flush_output"] = True
            tmp_t.parameters["rewrite_function_mesh"] = False

        if save_deg > 1:
          
            # Create function space for d, v and p
            dve = VectorElement('CG', mesh.ufl_cell(), v_deg)
            pe = FiniteElement('CG', mesh.ufl_cell(), p_deg)
            FSdv = FunctionSpace(mesh, dve)   # Higher degree FunctionSpace for d and v
            FSp= FunctionSpace(mesh, pe)     # Higher degree FunctionSpace for p

            # Copy mesh
            mesh_viz = Mesh(mesh)

            for i in range(save_deg-1):
                mesh_viz = refine(mesh_viz)  # refine the mesh
                domains_viz = adapt(domains,mesh_viz)  # refine the domains (so we can output domain IDs of refined mesh)

            # Create visualization function space for d, v and p
            dve_viz = VectorElement('CG', mesh_viz.ufl_cell(), 1)
            pe_viz = FiniteElement('CG', mesh_viz.ufl_cell(), 1)
            FSdv_viz = FunctionSpace(mesh_viz, dve_viz)   # Visualisation FunctionSpace for d and v
            FSp_viz = FunctionSpace(mesh_viz, pe_viz)     # Visualisation FunctionSpace for p

            # Create lower-order function for visualization on refined mesh
            d_viz = Function(FSdv_viz)
            v_viz = Function(FSdv_viz)
            p_viz = Function(FSp_viz)
    
            # Create a transfer matrix between higher degree and lower degree (visualization) function spaces
            dv_trans = PETScDMCollection.create_transfer_matrix(FSdv,FSdv_viz)
            p_trans = PETScDMCollection.create_transfer_matrix(FSp,FSp_viz)

            return_dict = dict(v_file=v_file, d_file=d_file, p_file=p_file, d_viz=d_viz,v_viz=v_viz, p_viz=p_viz, 
                dv_trans=dv_trans, p_trans=p_trans, mesh_viz=mesh_viz, domains_viz=domains_viz)

        else:
            return_dict = dict(v_file=v_file, d_file=d_file, p_file=p_file)

        namespace.update(return_dict)

    else:
        return_dict = {}

    # Split function
    d = dvp_["n"].sub(0, deepcopy=True)
    v = dvp_["n"].sub(1, deepcopy=True)
    p = dvp_["n"].sub(2, deepcopy=True)

    if save_deg > 1: # To save higher-order nodes

        # Interpolate by using the transfer matrix between higher degree and lower degree (visualization) function spaces
        namespace["d_viz"].vector()[:] = namespace["dv_trans"]*d.vector()
        namespace["v_viz"].vector()[:] = namespace["dv_trans"]*v.vector()
        namespace["p_viz"].vector()[:] = namespace["p_trans"]*p.vector()

        write_solution(namespace["d_viz"], namespace["v_viz"], namespace["p_viz"], 
            namespace["d_file"], namespace["v_file"], namespace["p_file"], t) # Write results

    else: # To save only the corner nodes

        write_solution(d, v, p, namespace["d_file"], namespace["v_file"], namespace["p_file"], t) # Write results

    return return_dict