Example #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
Example #2
0
def planewavesoln(problem, npw):
    k = problem.k
    pw = pcb.planeWaveBases(2, k, nplanewaves=npw)
    h = 4.0/40
    alpha = 1 / (k*h)
    beta = np.min([(k*h), 1])  
    computation = psc.Computation(problem, pw, pcp.HelmholtzSystem, 15, alpha = alpha, beta = beta)
    
    solution = computation.solution(psc.DirectSolver().solve, dovolumes=False)
    bounds=array([[-2,2],[-2,2]],dtype='d')
    npoints=array([200,200])
    pos.standardoutput(computation, solution, 20, bounds, npoints, mploutput = True)
Example #3
0
def sourcesquareconvergence(Ns, Ps, NPWs, k = 20, polyonly = False):
    condfile = open("hankelcondition%s.txt"%k, 'a')
    fileroot="hankelsquare_k%s"%(k);
    bounds=np.array([[0,1],[0,1]],dtype='d')
    npoints=np.array([k * 10,k * 10], dtype=int)
    
    origin = np.array([-0.2,-0.2])
    
    g = pcb.FourierHankel(origin, [0], k)
    
    rt = PlaneWaveFromSourceRule(origin)
    condfile.write("Plane waves\n")
    for npw in NPWs:
        print "Number of plane waves ",npw
        pw = pcb.planeWaveBases(2, k, npw)
        fo = pof.ErrorFileOutput(fileroot + 'npw%s'%(npw), str(Ns), g, bounds, npoints)
        for N in Ns:
            solver = psc.DirectSolver(callback = lambda M: condfile.writelines("%s, %s, %s\n"%(npw, N, cond(M))))
            sol = solvesquare(N, 1, g, pw, solver.solve, k, dovolumes=False)
            fo.process(N, sol)

    if not polyonly:
        condfile.write("Polynomials + plane wave\n")    
        for pdeg in Ps:
            print "polynomial degree ",pdeg
            poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg))                    
            polyrt = pcb.ProductBasisRule(poly, rt)
            fo = pof.ErrorFileOutput(fileroot + 'poly%srt'%(pdeg), str(Ns), g, bounds, npoints)
            for N in Ns:
                solver = psc.DirectSolver(callback = lambda M: condfile.write("%s, %s, %s\n"%(pdeg, N, cond(M))))
                sol = solvesquare(N, pdeg, g, polyrt, solver.solve, k)
                fo.process(N, sol)   
                
    if polyonly:
        condfile.write("Polynomials only\n")    
        for pdeg in Ps:
            print "polynomial degree ",pdeg
            poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg))                    
            fo = pof.ErrorFileOutput(fileroot + 'poly%srt'%(pdeg), str(Ns), g, bounds, npoints)
            for N in Ns:
                solver = psc.DirectSolver(callback = lambda M: condfile.write("%s, %s, %s\n"%(pdeg, N, cond(M))))
                sol = solvesquare(N, pdeg, g, poly, solver.solve, k)
                fo.process(N, sol)   
        condfile.close()     
Example #4
0
from numpy import array,sqrt

k = 20
n = 6
g = pcb.FourierHankel([-1,-1], [0], k)
bdytag = "BDY"
bnddata={bdytag:pcbd.dirichlet(g)}

bounds=array([[0,1],[0,1]],dtype='d')
npoints=array([200,200])
mesh = tum.regularsquaremesh(n, bdytag)
#print mesh.nodes
#print mesh.elements
    
problem = psp.Problem(mesh, k, bnddata)
basisrule = pcb.planeWaveBases(2,k,9)
nquad = 10
system = pcp.HelmholtzSystem
compinfo = psc.ComputationInfo(problem, basisrule, 10)
computation = psc.Computation(compinfo, system)

solblockdiagonal = computation.solution(psi.DiagonalBlockOperator(mesh), psi.GMRESSolver('ctor', psi.ItCounter()))
soldomaindecomp = computation.solution(psd.SchwarzOperator(mesh), psi.GMRESSolver('ctor', psi.ItCounter()))
mortarrule = pcbr.ReferenceBasisRule(pcbr.Legendre1D(6))
s = -1j*k
mc = psm.MortarComputation(problem, basisrule, mortarrule, nquad, system, system.boundaryclass, s)
solmortar = mc.solution(psi.GMRESSolver('ctor'), psi.ItCounter(5))


#solbrutal = computation.solution(psd.DomainDecompOperator(mesh), psi.GMRESSolver('ctor'))
#print "DD solve"
Example #5
0
from numpy import array,sqrt

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

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([200,200])
with puf.pushd('../../examples/2D'):
    mesh = pmm.gmshMesh('squarescatt.msh',dim=2)
    
problem = psp.Problem(mesh, k, bnddata)
compinfo = psc.ComputationInfo(problem, pcb.planeWaveBases(2,k,11), 5)
computation = psc.Computation(compinfo, pcp.HelmholtzSystem)

#solbrutal = computation.solution(psi.BrutalSolver(np.complex, psi.DomainDecompOperator(mesh)).solve)
soldd = computation.solution(psd.SchwarzOperator(mesh), psi.GMRESSolver(np.complex))
solindirect = computation.solution(psi.BlockPrecondOperator(mesh), psi.GMRESSolver(np.complex))
soldirect = computation.solution(psc.DirectOperator(), psc.DirectSolver())

#print np.max(np.abs(soldirect.x - solbrutal.x))
print np.max(np.abs(soldirect.x - solindirect.x))
print np.max(np.abs(soldirect.x - soldd.x))

#solindirect = computation.solution(psi.IndirectSolver().solve)
#print solindirect.x[0:20]

#pos.standardoutput(computation, soldirect, 20, bounds, npoints, 'soundsoft')
Example #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)

Example #7
0
import pypwdg.setup as ps
import pypwdg.core.bases as pcb
import pypwdg.mesh.mesh as pmm
import pypwdg.core.boundary_data as pcbd
import pypwdg.parallel.main

from numpy import array
import math

k = 10

g = pcb.PlaneWaves(array([[1,0,0]])/math.sqrt(1), k)

bnddata={82:pcbd.zero_impedance(k), 83:pcbd.dirichlet(g) }

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

mesh = pmm.gmshMesh('scattmesh.msh',dim=3)
bases = pcb.planeWaveBases(mesh, k, 3)

problem=ps.Problem(mesh,k,16, bnddata)
solution = ps.Computation(problem, bases).solve()
solution.writeSolution(bounds,npoints,fname='scattmesh.vti')
problem.writeMesh(fname='scattmesh.vtu',scalars=solution.combinedError())

Example #8
0
import pypwdg.core.bases as pcb
import pypwdg.mesh.mesh as pmm
import pypwdg.core.boundary_data as pcbd
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.parallel.main

from numpy import array,sqrt

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

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

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

mesh = pmm.gmshMesh('circscatt.msh',dim=2)
problem = psp.Problem(mesh, k, bnddata)

quadpoints = 30

computation = psc.Computation(problem, pcb.planeWaveBases(2,k,30), pcp.HelmholtzSystem, quadpoints)
#computation = psc.Computation(problem, pcb.FourierBesselBasisRule(range(-4,5)), pcp.HelmholtzSystem, quadpoints)
solution = computation.solution(psc.DirectSolver().solve)
pos.standardoutput(computation, solution, 30, bounds, npoints, 'circle')
Example #9
0
import pypwdg.setup as ps
import pypwdg.core.bases as pcb
import pypwdg.mesh.mesh as pmm
import pypwdg.core.boundary_data as pcbd
import pypwdg.parallel.main

from numpy import array

k = 10
direction = array([[1.0, 0]])
g = pcb.PlaneWaves(direction, k)

bnddata = {
    21: pcbd.zero_dirichlet(),
    18: pcbd.generic_boundary_data([-1j * k, 1], [-1j * k, 1], g),
    20: pcbd.generic_boundary_data([-1j * k, 1], [-1j * k, 1], g),
    19: pcbd.zero_dirichlet(),
}

bounds = array([[0, 5], [0, 1]], dtype="d")
npoints = array([501, 101])

mesh = pmm.gmshMesh("2dhole.msh", dim=2)
bases = pcb.planeWaveBases(mesh, k, nplanewaves=15)


problem = ps.Problem(mesh, k, 20, bnddata)
solution = ps.Computation(problem, bases).solve()
solution.writeSolution(bounds, npoints, fname="2dhole.vti")
problem.writeMesh(fname="2dhole.vtu", scalars=solution.combinedError())