Exemplo n.º 1
0
def search():
    k = 2
    g = pcb.FourierHankel([-1,-1], [0], k)
    bdytag = "BDY"
    bnddata={bdytag:pcbd.dirichlet(g)}
    
    bounds=np.array([[0,1],[0,1]],dtype='d')
    npoints=np.array([200,200])
    gmresits = []
    params = []
    conds = []

    n = 6
    meshinfo = tum.regularsquaremeshinfo(n, bdytag)
    topology = pmm.Topology(meshinfo)
    partition = pmm.BespokePartition(meshinfo, topology, lambda n: np.arange(meshinfo.nelements).reshape(n, -1))    
    mesh = pmm.MeshView(meshinfo, topology, partition)
    
    mesh = pmo.overlappingPartitions(mesh)
    problem = psp.Problem(mesh,k,bnddata)
    
    npw = 7
    basisrule = pcb.planeWaveBases(2,k,npw)
    
    basisrule = pcbr.ReferenceBasisRule(pcbr.Dubiner(0))
    nquad = 4
           
        #    mesh = pmo.overlappingPartitions(pmo.overlappingPartitions(mesh))
            
           
        #    problem = psp.Problem(mesh, k, bnddata)
    dovolumes = True
           
    compinfo = psc.ComputationInfo(problem, basisrule, nquad)
    computation = psc.Computation(compinfo, pcp.HelmholtzSystem)
    sold = computation.solution(psc.DirectOperator(), psc.DirectSolver(), dovolumes=dovolumes)
    pom.output2dsoln(bounds, sold, npoints, show = False)
    for x in np.arange(-10,10,2):#, 1E-6, 1]:# 1j, -0.1, -0.1j]:
        for y in np.arange(-10,10,2):
            q = x + 1j * y
            perturbation = GeneralRobinPerturbation(compinfo, q)
        
            op = psd.GeneralSchwarzOperator(PerturbedSchwarzWorker(perturbation, mesh))
            callback = psi.ItCounter(100)
            solver = psi.GMRESSolver('ctor', callback)
            sol = computation.solution(op, solver, dovolumes=dovolumes)
            nn = len(op.rhs())
            M = np.hstack([op.multiply(xx).reshape(-1,1) for xx in np.eye(nn)])
            conds.append(np.linalg.cond(M))            
            params.append(q)
            gmresits.append(solver.callback.n)
        print conds
        print params
        print gmresits
Exemplo n.º 2
0
def standardoutput(solution, quadpoints, bounds, npoints, fileroot = None, mploutput = False, **kwargs):
    ''' Dumps the solution to a file and also writes the errors out on a mesh'''
    mesh = solution.computation.problem.mesh
    errors = pce.combinedError(solution)[0]
    print "Combined Error: ",np.sqrt(sum(errors**2))
    volerrors = pce.volumeerrors(solution, quadpoints)
    print "Volume Error / k^2: ", np.sqrt(sum(volerrors **2)) / (solution.computation.problem.k **2)
    if fileroot is not None:
        try:
            writeSolutionVTK(solution, bounds, npoints, fname = fileroot +'.vti')        
            import pypwdg.output.vtk_output as pov
            pov.VTKGrid(mesh, errors).write(fileroot + '.vtu')
        except ImportError as e:   
            print "Some or all output probably failed: ",e
    if mploutput:
        pom.output2dsoln(bounds, solution, npoints,plotmesh=False, **kwargs)
Exemplo n.º 3
0
def compare(problem, basisrule, mortardegree, nquad, system, plotdata = None):
    if plotdata:
        bounds, npoints = plotdata
    it = psi.ItTracker()
    solver = psi.GMRESSolver('ctor', it)
    sm = solveMortar(problem, basisrule, 0, nquad, system, solver)
    if plotdata: pom.output2dsoln(bounds, sm, npoints, show=False)
    itsm = np.array(it.reset())
    
    compinfo = psc.ComputationInfo(problem, basisrule, nquad)
    computation = psc.Computation(compinfo, system)

    sdbb = computation.solution(psi.DiagonalBlockOperator(problem.mesh), solver)
    if plotdata: pom.output2dsoln(bounds, sbd, npoints, show=False)
    itsbb = np.array(it.reset())

    sb = computation.solution(psi.BlockPrecondOperator(problem.mesh), solver)
    if plotdata: pom.output2dsoln(bounds, sb, npoints, show=False)
    itsb = np.array(it.reset())


    sdd = computation.solution(psd.DomainDecompOperator(problem.mesh), solver)
    if plotdata: pom.output2dsoln(bounds, sdd, npoints, show=False)
    itsdd = np.array(it.reset())
    
    
#    sb = computation.solution(psi.BlockPrecondOperator(problem.mesh), solver)
#    if plotdata: pom.output2dsoln(bounds, sb, npoints, show=False)
#    itsb = np.array(it.reset())
    
    mp.figure()
    mp.hold(True)
    mp.semilogy(itsm, 'b')
#    mp.figure()
    mp.semilogy(itsdd, 'r')
    mp.semilogy(itsbb, 'g')
    mp.semilogy(itsb, 'k')
#    mp.figure()
#    mp.semilogy(itsb, 'g')
    mp.show()
Exemplo n.º 4
0
    
#    basisrule = pcbr.ReferenceBasisRule(pcbr.Dubiner(0))
#    dovolumes = True
    nquad = 7
   
#    mesh = pmo.overlappingPartitions(pmo.overlappingPartitions(mesh))
    mesh = pmo.overlappingPartitions(mesh)
    
   
    problem = psp.Problem(mesh, k, bnddata)
    
    compinfo = psc.ComputationInfo(problem, basisrule, nquad)
    computation = psc.Computation(compinfo, pcp.HelmholtzSystem)
    sold = computation.solution(psc.DirectOperator(), psc.DirectSolver(), dovolumes=dovolumes)
    print "direct solution", sold.x
    pom.output2dsoln(bounds, sold, npoints, show = False)
    for p in [1]:#, 1, 1j, -0.1, -0.1j]:
        perturbation = GeneralRobinPerturbation(compinfo, p)
    
        w = PerturbedSchwarzWorker(perturbation, mesh)
        op = psd.GeneralSchwarzOperator(w)
#        op = psd.SchwarzOperator(mesh)
        
        sol = computation.solution(op, psi.GMRESSolver('ctor'), dovolumes=dovolumes)

        M, P, G = w.getData()
        sio.savemat('mpg.mat', {'M':M.tocsr(), 'P':P.tocsr(), 'G':G.tocsr().todense()})

        print "solution", sol.x

        xe = sol.x[op.extidxs]
Exemplo n.º 5
0
problem = psp.Problem(mesh, k, bnddata)
basisrule = pcb.planeWaveBases(2,k,11)
#basisrule = pcbr.ReferenceBasisRule(pcbr.Dubiner(0))
mortarrule = pcbr.ReferenceBasisRule(pcbr.Legendre1D(1))
s = -1j*k
#s = 0
#tracebc = [0,0]

mc = psm.MortarComputation(problem, basisrule, mortarrule, nquad, pcp.HelmholtzSystem, pcp.HelmholtzBoundary, s)
#sol = mc.solution(psi.BrutalSolver(np.complex), dovolumes=True)
sol = mc.solution(psi.GMRESSolver('ctor'), dovolumes=True)
#solfaked = mc.fakesolution(g, [s, 1])
#print sol.x
#pos.standardoutput(sol, 20, bounds, npoints, 'squaremortar')
pom.output2dsoln(bounds, sol, npoints, plotmesh = True, show = False)
#pom.output2dsoln(bounds, solfaked, npoints, plotmesh = True, show = False)
pom.output2dfn(bounds, g.values, npoints, show=False)

#rectmesh = tum.regularrectmesh([0,0.5], [0,1.0], n/2, n)
#rectbd = {1:ig, 2:ig, 3:ig, 4:ig}
#rectprob = psp.Problem(rectmesh, k, rectbd)
#rectcmp = psc.DirectComputation(rectprob, basisrule, nquad, pcp.HelmholtzSystem)
#rectsol = rectcmp.solution()
#pom.output2dsoln([[0,0.5],[0,1]],rectsol, npoints, plotmesh=True, show=False)

mp.show()
#
#sold = psc.DirectComputation(problem, basisrule, nquad, pcp.HelmholtzSystem).solution()
#pos.standardoutput(sold, 20, bounds, npoints, 'squaremortar', mploutput=True)
Exemplo n.º 6
0
import pypwdg.setup.problem as psp
import pypwdg.setup.computation as psc
import pypwdg.core.physics as pcp
import pypwdg.output.solution as pos
import pypwdg.raytrace.control as prc
import pypwdg.parallel.main
import pypwdg.output.mploutput as pom


from numpy import array,sqrt

k = 20
direction=array([[1.0,1.0]])/sqrt(2)
g = pcb.PlaneWaves(direction, k)
nq = 11

bnddata={11:pcbd.zero_dirichlet(),
         10:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g=g)}

bounds=array([[-2,2],[-2,2]],dtype='d')
npoints=array([500,500])

mesh = pmm.gmshMesh('squarescatt.msh',dim=2)
problem = psp.Problem(mesh, k, bnddata)
computation = psc.DirectComputation(problem, pcb.planeWaveBases(2,k,12), nq, pcp.HelmholtzSystem, alpha=0.5, beta=0.0, delta=0.0)
solution = computation.solution()
pos.standardoutput(solution, 20, bounds, npoints, 'soundsoft')
pom.outputMeshPartition(bounds, npoints, mesh, 3)
pom.output2dsoln(bounds, solution, npoints, plotmesh=False)