Beispiel #1
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]
Beispiel #2
0
    # ksp.setTolerances(1e-6)
    ksp.setType('minres')
    ksp.setOperators(A)
    # OptDB = PETSc.Options()
    # OptDB['pc_factor_mat_solver_package']  = 'mumps'
    # OptDB["pc_factor_mat_ordering_type"] = "rcm"
    pc = ksp.getPC()
    pc.setType(PETSc.PC.Type.PYTHON)
    ksp.setFromOptions()

    CGtol = 1e-2
    Hiptmairtol = 1e-3


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

    reshist = {}
    def monitor(ksp, its, rnorm):
        print rnorm
        reshist[its] = rnorm


    ksp.setMonitor(monitor)
    pc.setPythonContext(MaxwellPrecond.Hiptmair(W, kspScalar, kspCGScalar, kspVector, G, P, Prec,Hiptmairtol))
    scale = b.norm()
    b = b/scale
    start_time = time.time()
    ksp.solve(b, x)
Beispiel #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]
Beispiel #4
0
             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 "PETSc Laplacians assembled, time: ", toc()

    ksp = PETSc.KSP().create()
    ksp.setTolerances(1e-6)
    ksp.setType('cg')
    ksp.setOperators(A, A)
    pc = ksp.getPC()
    pc.setType(PETSc.PC.Type.PYTHON)
    kspVector, kspScalar, diag = HiptmairSetup.HiptmairKSPsetup(
        VectorLaplacian, ScalarLaplacian, A)
    del A, VectorLaplacian, ScalarLaplacian
    pc.setPythonContext(
        HiptmairPrecond.GSvector(G, P, kspVector, kspScalar, diag))
    scale = b.norm()
    b = b / scale
    tic()
    ksp.solve(b, x)
    TimeSave[xx - 1] = toc()
    x = x * scale
    print ksp.its
    print TimeSave[xx - 1]
    ItsSave[xx - 1] = ksp.its
    print " \n\n\n\n"

import pandas as pd