def analytichconvergence(maxN, k = 20, scale = 4.0): fileroot = "hconv.k%s.scale%s"%(k,scale) bounds=np.array([[0,1],[0,1]],dtype='d') npoints=np.array([k * scale * 10,k * scale * 10], dtype=int) S = harmonic1(scale) g = HarmonicDerived(k, S) nfn = NormOfGradient(S) bdycond = pcbd.dirichlet(g) npw = 15 pdeg = 2 Ns = genNs(math.pow(2,1.0/3),1,maxN+1) pw = pcbv.PlaneWaveVariableN(pcb.circleDirections(npw)) fo = pof.ErrorFileOutput(fileroot + 'uniformpw%s'%npw, str(Ns), g, bounds, npoints) variableNhConvergence(Ns, nfn, bdycond, pw, fo.process, k, scale) poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(pdeg)) fo = pof.ErrorFileOutput(fileroot + 'poly%s'%pdeg, str(Ns), g, bounds, npoints) variableNhConvergence(Ns, nfn, bdycond, poly, fo.process, k, scale, pdeg) for err in [0, 0.02, 0.2]: rt = PlaneWaveFromDirectionsRule(S, err) fo = pof.ErrorFileOutput(fileroot + 'rt-err%s'%err, str(Ns), g, bounds, npoints) variableNhConvergence(Ns, nfn, bdycond, rt, fo.process, k, scale) for p in [1,2,3,4]: poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(p)) polyrt = pcb.ProductBasisRule(poly, rt) fo = pof.ErrorFileOutput(fileroot + 'poly%srt-err%s'%(p,err), str(Ns), g, bounds, npoints) variableNhConvergence(Ns, nfn, bdycond, polyrt, fo.process, k, scale, p)
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
def analyticconvergencepwprod(maxN, k = 20, scale = 4.0): fileroot = "hconv.k%s.scale%s"%(k,scale) bounds=np.array([[0,1],[0,1]],dtype='d') npoints=np.array([k * scale * 10,k * scale * 10], dtype=int) S = harmonic1(scale) g = HarmonicDerived(k, S) nfn = NormOfGradient(S) bdycond = pcbd.dirichlet(g) npw = 15 Ns = genNs(math.pow(2,1.0/2),1,maxN+1) pw = pcbv.PlaneWaveVariableN(pcb.circleDirections(npw)) for p in [1,2,3,4]: poly = pcbr.ReferenceBasisRule(pcbr.Dubiner(p)) polypw = pcb.ProductBasisRule(poly, pw) fo = FileOutput(fileroot + 'pw%spoly%s'%(npw,p), str(Ns), g, bounds, npoints) variableNhConvergence(Ns, nfn, bdycond, polypw, fo.process, k, scale, p)
import pypwdg.core.physics as pcp import pypwdg.output.solution as pos import pypwdg.test.utils.mesh as tum import numpy as np np.set_printoptions(threshold='nan') import pypwdg.parallel.main 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()))
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 #JD = jump #JN = average * 2 #I = mesh.facepartition #
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
Nq = 16 Np = 3 dirs = cubeRotations(cubeDirections(Np)) quad=trianglequadrature(Nq) elttobasis = [[PlaneWaves(dirs, k)]] * mesh.nelements params={'alpha':.5, 'beta':.5,'delta':.5} l_coeffs=[-1j*k, 1] r_coeffs=[-1j*k, 1] bnddata={82:zero_impedance(k), 83:dirichlet(g) } mqs = MeshQuadratures(mesh, quad) lv = LocalVandermondes(mesh, elttobasis, mqs, usecache=False) bndvs=[] for data in bnddata.values(): bndv = LocalVandermondes(mesh, [[data]] * mesh.nelements, mqs) bndvs.append(bndv) S, f = assemble(mesh, k, lv, bndvs, mqs, elttobasis, bnddata, params) print "Solving system"
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")
import numpy as np 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)] #
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())
#mesh.partition(4) #print cubemesh.nodes boundaryentities = [10,11] #SM = StructureMatrices(mesh, boundaryentities) Nq = 20 Np = 15 dirs = circleDirections(Np) elttobasis = [[PlaneWaves(dirs, k)]] * mesh.nelements params={'alpha':.5, 'beta':.5,'delta':.5} bnddata={11:dirichlet(g), 10:zero_impedance(k)} quad=legendrequadrature(Nq) mqs = MeshQuadratures(mesh, quad) lv = LocalVandermondes(mesh, elttobasis, mqs, usecache=True) bndvs=[] for data in bnddata.values(): bndv = LocalVandermondes(mesh, [[data]] * mesh.nelements, mqs) bndvs.append(bndv) quad=legendrequadrature(Nq) S, f = assemble(mesh, k, lv, bndvs, mqs, elttobasis, bnddata, params)