def createproblem(k, direction=array([[1,1]])/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)} with(puf.pushd("../../examples/2D")): mesh = pmm.gmshMesh('squarescatt.msh',dim=2) return psp.Problem(mesh, k, bnddata)
def solvesquare(N, pdeg, g, basisrule, solve, k=20, dovolumes = True): impbd = pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g) bdytag = "BDY" bnddata={bdytag:impbd} mesh = tum.regularsquaremesh(N, bdytag) p = 1 if pdeg < 1 else pdeg alpha = ((p*1.0)**2 * N) / k beta = k / (p * 1.0*N) problem=psp.Problem(mesh,k, bnddata) computation = psc.Computation(problem, basisrule, pcp.HelmholtzSystem, 15, alpha = alpha, beta = beta) solution = computation.solution(solve, dovolumes=dovolumes) return solution
def testEdge(self): N = 10 k = 10 D = 1 x,w = puq.legendrequadrature(3*N) x = np.hstack((x, np.zeros_like(x))) g = pcb.PlaneWaves(pcb.circleDirections(40)[15], k) bc = pcbd.generic_boundary_data([1j*k,1],[1j*k,1],g) # t1 = prp.findpw(prp.ImpedanceProd(bc, (x,w), [0,1], k), D, maxtheta = 1) t1 = prp.findpw(prp.L2Prod(bc.values, (x,w), k), D, maxtheta = 1) self.assertAlmostEqual(t1, (2 * math.pi * 15) / 40)
import pypwdg.core.bases.reduced as pcbred import pypwdg.utils.quadrature as puq import pypwdg.mesh.submesh as pmsm import pypwdg.parallel.main import numpy as np k = 40 direction=np.array([[1.0,1.0]])/np.sqrt(2) #g = pcb.PlaneWaves(direction, k) g = pcb.FourierHankel([-2,-2], [0], k) impbd = pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g) #bnddata={7:impbd, # 8:impbd} bnddata={7:pcbd.dirichlet(g), 8:pcbd.dirichlet(g)} bounds=np.array([[0,1],[0,1]],dtype='d') npoints=np.array([500,500]) mesh = pmm.gmshMesh('square.msh',dim=2) #mesh = pmsm.SubMesh(mesh, "INTERNAL") #average = (mesh.connectivity + mesh.internal)/2 #jump = mesh.internal - mesh.connectivity #AD = average #AN = jump / 2
def nfun(p): #return 1+.5*1./4*(p[:,0]-1) return np.exp(1./5*p[:,0]*(5-p[:,0])) import pypwdg.parallel.main k = 10 direction=array([[1.0,0]]) g = pcb.PlaneWaves(direction, k) bnddata={7:pcbd.dirichlet(g), 8:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g=g)} bnddata={7:pcbd.dirichlet(g), 8:pcbd.zero_impedance(k)} bounds=array([[0.001,4.999],[0,1]],dtype='d') npoints=array([500,100]) mesh = pmm.gmshMesh('waveguide.msh',dim=2) quadpoints = 30 p=3 t=p**2 g=2 h=.1
import pypwdg.setup as ps import pypwdg.core.bases as pcb import pypwdg.mesh.mesh as pmm import pypwdg.core.boundary_data as pcbd from numpy import array k = 20 direction=array([[1.0,0,0]]) def g(x): return pcb.PlaneWaves(direction, k).values(x) def gn(x,n): return pcb.PlaneWaves(direction, k).derivs(x,n) bnddata={59:pcbd.zero_dirichlet(), 58:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g=g,dg=gn), 60:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g=g,dg=gn), 61:pcbd.zero_dirichlet()} bounds=array([[0,4],[0,1],[0,.3]],dtype='d') npoints=array([100,20,20]) comp=ps.setup(pmm.gmshMesh('hole_extrusion.msh',dim=3),k=k,nquadpoints=10,nplanewaves=4,bnddata=bnddata,usecache=False) comp.solve() comp.writeSolution(bounds,npoints,fname='hole_extrusion.vti') comp.writeMesh(fname='hole_extrusion.vtu',scalars=comp.combinedError())
self.R = R self.a = a def __call__(self, p): r2 = np.sum(p**2, axis=-1) return self.a - r2 * (self.a-1.0) / self.R**2 import pypwdg.parallel.main from numpy import array k = 40 direction=array([[1.0,0]]) g = pcb.PlaneWaves(direction, k) bnddata={15:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1],g)} bounds=array([[-4,4],[-4,4]],dtype='d') npoints=array([600,600]) mesh = pmm.gmshMesh('two_circles.msh',dim=2) quadpoints = 30 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)
conds.append(np.linalg.cond(M)) params.append(q) gmresits.append(solver.callback.n) print conds print params print gmresits #sol = computation.solution(op, psi.BrutalSolver(np.complex)) if __name__=="__main__": # search() # exit() k = 5 n = 4 g = pcb.FourierHankel([-1,-1], [0], k) bdytag = "BDY" bnddata={bdytag:pcbd.generic_boundary_data([-1j*k,1],[-1j*k,1], g)} bounds=np.array([[0,1],[0,1]],dtype='d') npoints=np.array([200,200]) # mesh = tum.regularsquaremesh(n, bdytag) 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) # direction=np.array([[1.0,1.0]])/math.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)} #
np.set_printoptions(threshold='nan') from numpy import array,sqrt import matplotlib.pyplot as mp #nparts = 3 nquad = 5 k = 3 n = 2 g = pcb.FourierHankel([-1,-1], [0], k) #g = pcb.PlaneWaves([3.0/5,-4.0/5], k) c = pcb.ConstantBasis() dg = pcbd.dirichlet(g) ig = pcbd.generic_boundary_data([-1j*k, 1], [-1j*k, 1], g) ic = pcbd.generic_boundary_data([-1j*k, 1], [1, 0], c) bdytag = "BDY" bnddata={1:dg,2:dg,3:dg,4:dg} bounds=array([[0,1],[0,1]],dtype='d') npoints=array([200,200]) #mesh = tum.regularsquaremesh(n, bdytag) meshinfo = tum.regularrectmeshinfo([0,1], [0,1], n, n) topology = pmm.Topology(meshinfo) #def partitions(nparts): # ne = meshinfo.nelements # return [np.arange((i * ne) / nparts, ((i+1) * ne) / nparts) for i in range(nparts)] # #partition = pmm.BespokePartition(meshinfo, topology, partitions)
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())
# effectivek = omega * distance / vel.averagevel omega = effectivek * veldata.averagevel / (ymax - ymin) averagek = effectivek / (ymax - ymin) trueh = effectiveh / (ymax - ymin) print "omega = %s" % omega print "bounds %s" % veldata.bounds print veldata.averagevel npoints = np.array([veldata.nx, veldata.ny]) # pom.output2dfn(veldata.bounds, veldata, npoints) sourcexpos = (xmax + xmin) / 2 sourcek = veldata(np.array([[sourcexpos, 0]]))[0] * averagek g = pcb.FourierHankel([sourcexpos, 0], [0], sourcek) sourceimp = pcbd.generic_boundary_data([-1j * averagek, 1], [-1j * averagek, 1], g) zeroimp = pcbd.zero_impedance(averagek) entityton = {5: veldata} mesh = ptum.regularrectmesh( [xmin, xmax], [ymin, ymax], int(((xmax - xmin) / (ymax - ymin)) / effectiveh), int(1 / effectiveh) ) print mesh.nelements bnddata = {1: zeroimp, 2: sourceimp, 3: zeroimp, 4: zeroimp} # 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)