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 showdirs(): k = 10 #direction=array([[1.0,1.0]])/sqrt(2) direction=array([[1,1]])/sqrt(2) # direction = array([[1,0]]) mesh = pmm.gmshMesh('squarescatt.msh',dim=2) problem = psp.Problem(mesh, k, None) etods = prc.tracemesh(problem, {10:lambda x:direction}) pom.showdirections2(problem.mesh, etods) pom.showmesh(problem.mesh)
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 # #print mesh.connectivity.nnz, mesh.internal.nnz, AD.nnz, AN.nnz, JD.nnz, JN.nnz, I.nnz npw = 12 quadpoints = 10 # Original basis:
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 beta=p**2*h*k alpha=k*p**2*1./h delta=.5 alpha=.5 beta=.5 delta=.5
import pypwdg.raytrace.control as prc import pypwdg.parallel.main from numpy import array,sqrt k = 45 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]) mesh = pmm.gmshMesh('squarescatt.msh',dim=2) quadpoints = 15 problem=psp.Problem(mesh,k, bnddata) etods = prc.tracemesh(problem, {10:lambda x:direction}) controller = paa.BasisController(mesh, quadpoints, etods, k, nfb=5) computation = paa.AdaptiveComputation(problem, controller, pcp.HelmholtzSystem, quadpoints) computation.solve(psc.DirectSolver().solve, 6, pos.AdaptiveOutput1(computation, quadpoints, bounds, npoints, "squarescatt").output) #problem=psp.Problem(mesh,k, bnddata) #ibc = paa.InitialPWFBCreator(mesh,k,3,7) #computation = paa.AdaptiveComputation(problem, ibc, pcp.HelmholtzSystem, quadpoints, 1) #computation.solve(psc.DirectSolver().solve, 6, pos.AdaptiveOutput1(computation, quadpoints, bounds, npoints, "squarescatt").output)
from pypwdg.mesh.gmsh_reader import gmsh_reader from pypwdg.mesh.mesh import gmshMesh from pypwdg.core.physics import assemble from pypwdg.core.boundary_data import zero_impedance, dirichlet from pypwdg.utils.quadrature import trianglequadrature from pypwdg.utils.timing import print_timing from pypwdg.core.evaluation import Evaluator, EvalElementError from pypwdg.output.vtk_output import VTKStructuredPoints from pypwdg.output.vtk_output import VTKGrid from pypwdg.mesh.meshutils import MeshQuadratures from pypwdg.core.vandermonde import LocalVandermondes mesh_dict=gmsh_reader('../../examples/3D/scattmesh.msh') mesh=gmshMesh(mesh_dict,dim=3) boundaryentities = [82, 83] 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]
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())
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) solution = computation.solution(psc.DirectSolver().solve) pos.standardoutput(computation, solution, quadpoints, bounds, npoints, 'twocirclesEWC') def fullyvariable():
import pypwdg.core.bases as pcb import pypwdg.mesh.mesh as pmm import pypwdg.core.boundary_data as pcbd import pypwdg.adaptivity.adaptivity as paa import pypwdg.output.basis as pob import pypwdg.utils.geometry as pug import pypwdg.adaptivity.scripts as pas import pypwdg.parallel.main import numpy as np k = 60 direction = np.array([[1.0, 1.0]]) / np.sqrt(2) # g = pcb.PlaneWaves(direction, k) g = pcb.FourierHankel([-1, -1], [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([250, 250]) mesh = pmm.gmshMesh("square.msh", dim=2) problem = ps.Problem(mesh, k, 16, bnddata) ibc = paa.InitialPWFBCreator(mesh, k, 3, 9) pas.runadaptive(problem, ibc, "square", 20, bounds, npoints, g)
import pypwdg.raytrace.control as prc import pypwdg.parallel.main from numpy import array,sqrt k = 15 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([200,200]) mesh = pmm.gmshMesh('circscatt.msh',dim=2) quadpoints = 10 problem=psp.Problem(mesh,k, bnddata) etods = prc.tracemesh(problem, {12:lambda x:direction}) controller = paa.BasisController(mesh, quadpoints, etods, k, nfb=5) computation = paa.AdaptiveComputation(problem, controller, pcp.HelmholtzSystem, quadpoints, 1) computation.solve(psc.DirectSolver().solve, 6, pos.AdaptiveOutput1(computation, quadpoints, bounds, npoints, "circscatt").output) #problem=psp.Problem(mesh,k, bnddata) #ibc = paa.InitialPWFBCreator(mesh,k,3,7) #computation = paa.AdaptiveComputation(problem, ibc, pcp.HelmholtzSystem, quadpoints, 1) #computation.solve(psc.DirectSolver().solve, 6, pos.AdaptiveOutput1(computation, quadpoints, bounds, npoints, "squarescatt").output)
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())
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())
def examplemeshes2d(): """ Loads in a list of 2D unstructured meshes used in examples""" return [pmm.gmshMesh(examplepath[0] + "/2D/" + fname, 2) for fname in ["square.msh", "squarescatt.msh"]]
def examplemeshes3d(): """ Loads in a list of 3D unstructured meshes used in examples""" return [pmm.gmshMesh(examplepath[0] + "/3D/" + fname, 3) for fname in ["cube.msh", "cube_coarse.msh"]]