Ejemplo n.º 1
0
def foo():
    NN = 2 * 4
    parameters["form_compiler"]["quadrature_degree"] = -1
    nn = int(2**(NN))
    omega = 1
    mesh = UnitSquareMesh(nn, nn)
    order = 1
    parameters['reorder_dofs_serial'] = False
    Magnetic = FunctionSpace(mesh, "N1curl", order)
    Lagrange = FunctionSpace(mesh, "CG", order)
    W = Magnetic * Lagrange
    Magnetic = None
    #del Magnetic, Lagrange
    Vdim = W.sub(0).dim()
    Qdim = W.sub(1).dim()
    Wdim = W.dim()
    print "\n\nV:  ", Vdim, "Q:  ", Qdim, "W:  ", Wdim, "\n\n"
    parameters['reorder_dofs_serial'] = False

    parameters['linear_algebra_backend'] = 'uBLAS'
    dim = 2
    #@print_memory
    G, P = HiptmairSetup.HiptmairMatrixSetupBoundary(mesh,
                                                     W.sub(0).dim(),
                                                     W.sub(1).dim(), dim)
    G, P = HiptmairSetup.HiptmairBCsetupBoundary(G, P, mesh)
    a = 1
Ejemplo n.º 2
0
def MagneticSetup(Magnetic, Lagrange, u0, p0, CGtol,params):
    MO.PrintStr("Preconditioning Magnetic setup",3,"=")

    # parameters['linear_algebra_backend'] = 'uBLAS'
    if Magnetic.__str__().find("N1curl2") == -1:
        C, P = HiptmairSetup.HiptmairMatrixSetupBoundary(Magnetic.mesh(), Magnetic.dim(), Lagrange.dim(),Magnetic.mesh().geometry().dim())
        G, P = HiptmairSetup.HiptmairBCsetupBoundary(C,P,Magnetic.mesh())
    else:
        G = None
        P = None

    u = TrialFunction(Magnetic)
    v = TestFunction(Magnetic)
    p = TrialFunction(Lagrange)
    q = TestFunction(Lagrange)


    def boundary(x, on_boundary):
        return on_boundary
    bcp = DirichletBC(Lagrange, p0, boundary)
    bcu = DirichletBC(Magnetic, u0, boundary)

    tic()
    ScalarLaplacian, b1 = assemble_system(inner(grad(p),grad(q))*dx,inner(p0,q)*dx,bcp)
    VectorLaplacian, b2 = assemble_system(inner(grad(p),grad(q))*dx+inner(p,q)*dx,inner(p0,q)*dx,bcp)
    del b1, b2
    print ("{:40}").format("Hiptmair Laplacians BC assembled, time: "), " ==>  ",("{:4f}").format(toc()),  ("{:9}").format("   time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])

    tic()
    VectorLaplacian = CP.Assemble(VectorLaplacian)
    ScalarLaplacian = CP.Assemble(ScalarLaplacian)
    print ("{:40}").format("PETSc Laplacians assembled, time: "), " ==>  ",("{:4f}").format(toc()),  ("{:9}").format("   time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])

    tic()
    if params[0] == 0:
        CurlCurlShift, b2 = assemble_system(params[1]*inner(curl(u),curl(v))*dx+inner(u,v)*dx,inner(u0,v)*dx,bcu)
    else:
        CurlCurlShift, b2 = assemble_system(params[0]*params[1]*inner(curl(u),curl(v))*dx+inner(u,v)*dx,inner(u0,v)*dx,bcu)
    CurlCurlShift = CP.Assemble(CurlCurlShift)
    print ("{:40}").format("Shifted Curl-Curl assembled, time: "), " ==>  ",("{:4f}").format(toc()),  ("{:9}").format("   time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])

    tic()
    kspVector, kspScalar, kspCGScalar, diag = HiptmairSetup.HiptmairKSPsetup(VectorLaplacian, ScalarLaplacian, CurlCurlShift, CGtol)
    del VectorLaplacian, ScalarLaplacian
    print ("{:40}").format("Hiptmair Setup time:"), " ==>  ",("{:4f}").format(toc()),  ("{:9}").format("   time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])


    return [G, P, kspVector, kspScalar, kspCGScalar, diag, CurlCurlShift]
Ejemplo n.º 3
0
def MagneticSetup(Magnetic, Lagrange, u0, p0, CGtol):
    MO.PrintStr("Preconditioning Magnetic setup", 3, "=")

    parameters['linear_algebra_backend'] = 'uBLAS'
    C, P = HiptmairSetup.HiptmairMatrixSetupBoundary(
        Magnetic.mesh(), Magnetic.dim(), Lagrange.dim(),
        Magnetic.mesh().geometry().dim())
    G, P = HiptmairSetup.HiptmairBCsetupBoundary(C, P, Magnetic.mesh())

    u = TrialFunction(Magnetic)
    v = TestFunction(Magnetic)
    p = TrialFunction(Lagrange)
    q = TestFunction(Lagrange)

    def boundary(x, on_boundary):
        return on_boundary

    bcp = DirichletBC(Lagrange, p0, boundary)
    bcu = DirichletBC(Magnetic, u0, boundary)

    tic()
    ScalarLaplacian, b1 = assemble_system(
        inner(grad(p), grad(q)) * dx,
        inner(p0, q) * dx, bcp)
    VectorLaplacian, b2 = assemble_system(
        inner(grad(p), grad(q)) * dx + inner(p, q) * dx,
        inner(p0, q) * dx, bcp)
    del b1, b2
    print("{:40}"
          ).format("Hiptmair Laplacians BC assembled, time: "), " ==>  ", (
              "{:4f}").format(
                  toc()), ("{:9}").format("   time: "), ("{:4}").format(
                      time.strftime('%X %x %Z')[0:5])

    tic()
    VectorLaplacian = PETSc.Mat().createAIJ(
        size=VectorLaplacian.sparray().shape,
        csr=(VectorLaplacian.sparray().indptr,
             VectorLaplacian.sparray().indices,
             VectorLaplacian.sparray().data))
    ScalarLaplacian = PETSc.Mat().createAIJ(
        size=ScalarLaplacian.sparray().shape,
        csr=(ScalarLaplacian.sparray().indptr,
             ScalarLaplacian.sparray().indices,
             ScalarLaplacian.sparray().data))
    print("{:40}").format("PETSc Laplacians assembled, time: "), " ==>  ", (
        "{:4f}").format(toc()), ("{:9}").format("   time: "), ("{:4}").format(
            time.strftime('%X %x %Z')[0:5])

    tic()
    CurlCurlShift, b2 = assemble_system(
        inner(curl(u), curl(v)) * dx + inner(u, v) * dx,
        inner(u0, v) * dx, bcu)
    CurlCurlShift = PETSc.Mat().createAIJ(size=CurlCurlShift.sparray().shape,
                                          csr=(CurlCurlShift.sparray().indptr,
                                               CurlCurlShift.sparray().indices,
                                               CurlCurlShift.sparray().data))
    print("{:40}").format("Shifted Curl-Curl assembled, time: "), " ==>  ", (
        "{:4f}").format(toc()), ("{:9}").format("   time: "), ("{:4}").format(
            time.strftime('%X %x %Z')[0:5])

    tic()
    kspVector, kspScalar, kspCGScalar, diag = HiptmairSetup.HiptmairKSPsetup(
        VectorLaplacian, ScalarLaplacian, CurlCurlShift, CGtol)
    del VectorLaplacian, ScalarLaplacian
    print("{:40}").format("Hiptmair Setup time:"), " ==>  ", ("{:4f}").format(
        toc()), ("{:9}").format("   time: "), ("{:4}").format(
            time.strftime('%X %x %Z')[0:5])

    return [G, P, kspVector, kspScalar, kspCGScalar, diag, CurlCurlShift]
Ejemplo n.º 4
0
    Magnetic = FunctionSpace(mesh, "N1curl", order)
    Lagrange = FunctionSpace(mesh, "CG", order)
    W = Magnetic*Lagrange
    print ("{:40}").format("Function space setup, time: "), " ==>  ",("{:4f}").format(toc()),  ("{:9}").format("   time: "), ("{:4}").format(time.strftime('%X %x %Z')[0:5])
    Vdim[xx-1] = Magnetic.dim()
    Qdim[xx-1] = Lagrange.dim()
    Wdim[xx-1] = W.dim()
    print "\n\nV:  ",Vdim[xx-1],"Q:  ",Qdim[xx-1],"W:  ",Wdim[xx-1],"\n\n"
    parameters['reorder_dofs_serial'] = False

    DimSave[xx-1] = Magnetic.dim()
    print Magnetic.dim()
    parameters['linear_algebra_backend'] = 'uBLAS'

    C, P = HiptmairSetup.HiptmairMatrixSetupBoundary(mesh, Magnetic.dim(), Lagrange.dim(),dim)
    G, P = HiptmairSetup.HiptmairBCsetupBoundary(C,P,mesh)



    def boundary(x, on_boundary):
        return on_boundary

    bcb = DirichletBC(W.sub(0),u0, boundary)
    bcr = DirichletBC(W.sub(1), p0, boundary)
    bcs = [bcb,bcr]

    (v,q) = TestFunctions(W)
    (u,p) = TrialFunctions(W)

    a11 = inner(curl(u),curl(v))*dx
    a12 = inner(v,grad(p))*dx