Esempio n. 1
0
def elementwiseconstant():
    npw = 12
    basisrule = pcbv.PlaneWaveVariableN(pcb.circleDirections(npw))  
    entityton = {11:1.0,12:1.5}
    
    problem = psp.VariableNProblem(entityton, mesh, k, bnddata)
    computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, quadpoints)
    solution = computation.solution(psc.DirectSolver().solve)
    
    pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'twocirclesEWC')
Esempio n. 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)
Esempio n. 3
0
def polysoln(problem, pdeg):
    k = problem.k
    poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg))                    
    h = 4.0/40
    p = 1 if pdeg < 1 else pdeg
    alpha = ((p*1.0)**2 )  / (k*h)
    beta = np.min([(k*h) / (p * 1.0),1]) 
    computation = psc.Computation(problem, poly, pcp.HelmholtzSystem, 15, alpha = alpha, beta = beta)
    
    solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
    bounds=array([[-2,2],[-2,2]],dtype='d')
    npoints=array([200,200])
    pos.standardoutput(computation, solution, 20, bounds, npoints, mploutput = True)
Esempio n. 4
0
def raytracesoln(problem, etods, pdeg = 2, npw = 15, radius = 0.5):
    quadpoints = 15
    k = problem.k
    rtpw = prb.OldRaytracedBasisRule(etods)
    
    fb = FourierBesselRule()
    shadow = RaytracedShadowRule(etods, fb)
    
    
    crt = SourceBasisRule()
        
    
    poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg))

#   unonpw = pcbu.UnionBasisRule([shadow, crt])                         
#    polynonpw = pcb.ProductBasisRule(poly, unonpw)
#    basisrule = pcbu.UnionBasisRule([polynonpw,rtpw])
    
#    unionall = pcbu.UnionBasisRule([shadow, rtpw, crt])
#    polyall = pcb.ProductBasisRule(poly, unionall)
#    basisrule = polyall
    
    rt = pcbu.UnionBasisRule([rtpw, shadow])
    polyrt = pcb.ProductBasisRule(poly, rt)
    basisrule = polyrt
    
    
#    pw = pcb.planeWaveBases(2, k, nplanewaves=npw)
#    basisrule = CornerMultiplexBasisRule(pw, basisrule, radius)    
    
#    polyrt2 = pcbu.UnionBasisRule([rt,pcb.ProductBasisRule(poly, crt)])
    
#    basisrule = polyrt2
    basisrule = pcbred.SVDBasisReduceRule(puq.trianglequadrature(quadpoints), basisrule, threshold=1E-5)
    
    p = 1 if pdeg < 1 else pdeg
    h = 4.0/40
    alpha = ((p*1.0)**2 )  / (k*h)
    beta = np.min([(k*h) / (p * 1.0),1]) 
    computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, quadpoints, alpha = alpha, beta = beta)
    
    solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
    bounds=array([[-2,2],[-2,2]],dtype='d')
    npoints=array([200,200])
    pos.standardoutput(computation, solution, 20, bounds, npoints, mploutput = True, cmap=pom.mp.cm.get_cmap('binary'))
Esempio n. 5
0
def fullyvariable():
    npw1 = 15 
    npw2 = 15
    b1 = pcb.ProductBasisRule(pcbv.PlaneWaveVariableN(pcb.circleDirections(npw1)),pcbr.ReferenceBasisRule(pcbr.Dubiner(2)))
    b2=  pcbv.PlaneWaveVariableN(pcb.circleDirections(npw2))
    
    basisDict={11:b2,12:b1}
    
    basisrule = pcb.GeomIdBasisRule(basisDict)
    
    #basisrule = pcbv.PlaneWaveVariableN(pcb.circleDirections(npw*3))  
    
    entityton = {11:1.0, 12:QuadBubble(1.0, 2.0)}
    problem = psp.VariableNProblem(entityton, mesh, k, bnddata)
    computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, quadpoints)
    solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
    
    pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'twocirclesFV')
Esempio n. 6
0
#average = (mesh.connectivity + mesh.internal)/2
#jump = mesh.internal - mesh.connectivity
#AD = average
#AN = jump / 2
#JD = jump
#JN = average * 2
#I = mesh.facepartition
#
#print mesh.connectivity.nnz, mesh.internal.nnz, AD.nnz, AN.nnz, JD.nnz, JN.nnz, I.nnz

npw = 12
quadpoints = 10

# Original basis:
pw = pcbv.PlaneWaveVariableN(pcb.uniformdirs(2,npw))
# Polynomials only:
#basisrule = pcbr.ReferenceBasisRule(pcbr.Dubiner(3))
# Product basis:
#basisrule = pcb.ProductBasisRule(pcb.planeWaveBases(2,k,npw), pcbr.ReferenceBasisRule(pcbr.Dubiner(1)))

#basisrule=pcb.ProductBasisRule(pw,pcbr.ReferenceBasisRule(pcbr.Dubiner(0)))
basisrule = pw
#basisrule = pcbred.SVDBasisReduceRule(puq.trianglequadrature(quadpoints), basisrule)

problem = psp.Problem(mesh, k, bnddata)
computation = psc.DirectComputation(problem, basisrule, quadpoints, pcp.HelmholtzSystem)
solution = computation.solution(dovolumes=True)

pos.comparetrue(bounds, npoints, g, solution)
pos.standardoutput(solution, quadpoints, bounds, npoints, 'square', mploutput = True)
Esempio n. 7
0
etob = [[pcb.PlaneWaves(ds, k)] if len(ds) else [] for ds in etods]
pob.vtkbasis(mesh,etob,'waveguide_rays.vtu',None)

b0=pcbv.PlaneWaveVariableN(pcb.circleDirections(10))
b=pcb.PlaneWaveFromDirectionsRule(etods)

b1=pcb.ProductBasisRule(b,pcbr.ReferenceBasisRule(pcbr.Dubiner(p)))
b2=pcbr.ReferenceBasisRule(pcbr.Dubiner(p))

origins=np.array([[0,0],[0,5],[5,1],[0,1]])
h=pcb.FourierHankelBasisRule(origins,[0])
h2=pcb.ProductBasisRule(h,pcbr.ReferenceBasisRule(pcbr.Dubiner(p)))
bh=pcb.UnionBasisRule([h2,b1])
b3=pcb.ProductBasisRule(b0,b2)


basisrule = b3 #cbred.SVDBasisReduceRule(puq.trianglequadrature(quadpoints), bh, threshold=1E-5)


computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, quadpoints,alpha=alpha,beta=beta,delta=delta)
solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)



pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'waveguide')
print solution.getError('Dirichlet')
print solution.getError('Neumann')
print solution.getError('Boundary')

Esempio n. 8
0
        return self.a - r2 * (self.a - 1.0) / self.R ** 2


def expBubble(x):

    return np.exp(-(1 - x ** 2))


entityton = {1: expBubble}

import pypwdg.parallel.main

from numpy import array, sqrt


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

bnddata = {10: pcbd.dirichlet(g), 11: pcbd.zero_impedance(k)}

bounds = array([[-1, 1]], dtype="d")
npoints = array([200])

mesh = pmm.lineMesh(points=[-1, 1], nelems=[1000], physIds=[1])
problem = psp.VariableNProblem(entityton, mesh, k, bnddata)
# computation = psc.Computation(problem, pcb.planeWaveBases(1,k), pcp.HelmholtzSystem, 15)
computation = psc.Computation(problem, pcbr.ReferenceBasisRule(pcbr.Legendre1D(2)), pcp.HelmholtzSystem, 15)
solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
pos.standardoutput(computation, solution, 20, bounds, npoints, "soundsoft")
Esempio n. 9
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)

Esempio n. 10
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')
Esempio n. 11
0
         12:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g=g)}

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

mesh = pmm.gmshMesh('circscatt.msh',dim=2)

quadpoints = 20
p=2

entityton ={11:1}
problem=psp.VariableNProblem(entityton, mesh,k, bnddata)
etods = prc.tracemesh(problem, {12:lambda x:direction})

etob = [[pcb.PlaneWaves(ds, k)] if len(ds) else [] for ds in etods]
pob.vtkbasis(mesh,etob,'circsoundsoftrays.vtu',None)

b0=pcbv.PlaneWaveVariableN(pcb.circleDirections(20))
b=pcb.PlaneWaveFromDirectionsRule(etods)
b1=pcb.ProductBasisRule(b,pcbr.ReferenceBasisRule(pcbr.Dubiner(p)))
b2=pcbr.ReferenceBasisRule(pcbr.Dubiner(p))

computation = psc.Computation(problem, b1, pcp.HelmholtzSystem, quadpoints)

solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'circsoundsoft_pol')
print solution.getError('Dirichlet')
print solution.getError('Neumann')
print solution.getError('Boundary')

Esempio n. 12
0
entityton ={9:1}
problem=psp.VariableNProblem(entityton, mesh,k, bnddata)
etods = prc.tracemesh(problem, {10:lambda x:direction})


etob = [[pcb.PlaneWaves(ds, k)] if len(ds) else [] for ds in etods]
pob.vtkbasis(mesh,etob,'soundsoftrays.vtu',None)

b0=pcbv.PlaneWaveVariableN(pcb.circleDirections(30))
b=pcb.PlaneWaveFromDirectionsRule(etods)
origins=np.array([[-.5,-.5],[-.5,.5],[.5,-.5],[.5,.5]])
h=pcb.FourierHankelBasisRule(origins,[0])
h2=pcb.ProductBasisRule(h,pcbr.ReferenceBasisRule(pcbr.Dubiner(p)))

b1=pcb.ProductBasisRule(b,pcbr.ReferenceBasisRule(pcbr.Dubiner(p)))
bh=pcb.UnionBasisRule([h2,b1])


b2=pcbr.ReferenceBasisRule(pcbr.Dubiner(p))

basisrule = pcbred.SVDBasisReduceRule(puq.trianglequadrature(quadpoints), bh, threshold=1E-5)


computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, quadpoints,alpha=alpha,beta=beta,delta=delta)
solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'soundsoft_pol', mploutput = True)
print solution.getError('Dirichlet')
print solution.getError('Neumann')
print solution.getError('Boundary')

Esempio n. 13
0
# bdndata = {0:impbd, 1:pcbd.zero_impedance}

problem = psp.VariableNProblem(entityton, mesh, averagek, bnddata)

alpha = ((pdeg * 1.0) ** 2 / trueh) / averagek
beta = averagek / (pdeg * 1.0 * trueh)

pw = pcbv.PlaneWaveVariableN(pcb.circleDirections(npw))
if usepoly:
    poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg))
    polypw = pcb.ProductBasisRule(poly, pw)
    basisrule = polypw
else:
    basisrule = pw

computation = psc.Computation(
    problem, basisrule, pcp.HelmholtzSystem, quadpoints, alpha=alpha, beta=beta, usecache=False
)
solution = computation.solution(psc.DirectSolver().solve, dovolumes=True)
pos.standardoutput(
    computation,
    solution,
    quadpoints,
    veldata.bounds,
    npoints,
    "marmousi%s-%s-%s-%s" % (effectivek, effectiveh, npw, pdeg if usepoly else 0),
    mploutput=True,
)
# pom.output2dsoln(veldata.bounds, solution, np.array([veldata.nx,veldata.ny]), plotmesh = False)
mp.show()