示例#1
0
 def __init__(self,context,grid,
              evaluation_options=None,
              evaluation_quadrature_strategy=None,
              gmres_tol=1E-10,
              gmres_max_iter=1000,
              use_aca_lu_preconditioner=True,
              aca_lu_delta=1E-3,
              operator_cache=False,
              operator_cache_tol=1E-13):
     super(MaxwellEfiePecIndirect,self).__init__()
     
     
     if isinstance(grid,str):
         self._grid = _bempplib.createGridFactory().importGmshGrid("triangular",grid)
     else:
         self._grid = grid
     
     self._context = context
     self._evaluation_options = evaluation_options
     self._evaluation_quadrature_strategy = evaluation_quadrature_strategy
     self._gmres_tol = gmres_tol
     self._gmres_max_iter = gmres_max_iter
     self._use_aca_lu_preconditioner = use_aca_lu_preconditioner
     self._aca_lu_delta = aca_lu_delta
     self._operator_cache = operator_cache
     self._operator_cache_tol = operator_cache_tol
     self._boundary_operator_cache = None
     self._potential_operator_cache = None
     self._evaluation_points = None
     self._residuals = {}
     self._space = None
示例#2
0
    def __init__(self,
                 mesh,
                 aca_epsilon=1E-5,
                 use_aca=True,
                 aca_lu_epsilon=1E-2,
                 gmres_tol = 1E-10,
                 gmres_max_iter = 1000,
                 relative_singular_quadrature_order=2,
                 relative_regular_quadrature_order=1,
                 operator_cache_tol=1E-13,
                 use_cache = False):
                                
        if isinstance(mesh,str):
            self._mesh = _bempplib.createGridFactory().importGmshGrid("triangular",mesh)
        else:
            self._mesh = mesh    
 
        
        self._aca_epsilon = aca_epsilon
        self._use_aca = use_aca
        self._aca_lu_epsilon = aca_lu_epsilon
        self._gmres_tol = gmres_tol
        self._gmres_max_iter = gmres_max_iter
        self._relative_singular_quadrature_order = relative_singular_quadrature_order
        self._relative_regular_quadrature_order = relative_regular_quadrature_order
        self._operator_cache_tol = operator_cache_tol
        self._use_cache = use_cache
示例#3
0
 def __init__(self,context,grid,
              eps_ext,eps_int,mu_ext,mu_int,
              evaluation_options=None,
              evaluation_quadrature_strategy=None,
              gmres_tol=1E-8,
              gmres_max_iter=1000,
              use_aca_lu_preconditioner=True,
              aca_lu_delta=1E-3,
              operator_cache=False,
              operator_cache_tol=1E-13):
     super(MaxwellEfiePenetrable,self).__init__()
     
     
     if isinstance(grid,str):
         self._grid = _bempplib.createGridFactory().importGmshGrid("triangular",grid)
     else:
         self._grid = grid
     
     self._mu_ext = mu_ext
     self._mu_int = mu_int
     self._eps_ext = eps_ext
     self._eps_int = eps_int
     
     self._context = context
     self._evaluation_options = evaluation_options
     self._evaluation_options.setVerbosityLevel('low')
     self._evaluation_quadrature_strategy = evaluation_quadrature_strategy
     self._gmres_tol = gmres_tol
     self._gmres_max_iter = gmres_max_iter
     self._use_aca_lu_preconditioner = use_aca_lu_preconditioner
     self._aca_lu_delta = aca_lu_delta
     self._operator_cache = operator_cache
     self._operator_cache_tol = operator_cache_tol
     self._boundary_operator_cache = None
     self._potential_operator_cache = None
     self._evaluation_points = None
     self._residuals = {}
     self._space = None
     self._inside = None
     self._outside = None
     self._inc_dirichlet_traces = {}
     self._inc_neumann_traces = {}
示例#4
0
quadStrategy = lib.createNumericalQuadratureStrategy(
    "float64", "complex128", accuracyOptions)

# Use ACA to accelerate the assembly

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())

# The context object combines these settings

context = lib.createContext(quadStrategy, options)

# Load a grid approximating a unit sphere

grid_factory = lib.createGridFactory()
grid = grid_factory.importGmshGrid(
    "triangular", "../../meshes/sphere-h-0.1.msh")

# Create a space of piecewise constant basis functions over the grid.

pwiseConstants = lib.createPiecewiseConstantScalarSpace(context, grid)

# We now initialize the boundary operators.
# A boundary operator always takes three space arguments: a domain space,
# a range space, and the test space (dual to the range).
# Here, we just use L^2 projections. Hence, all spaces are identical.

slpOp = lib.createHelmholtz3dSingleLayerBoundaryOperator(
    context, pwiseConstants, pwiseConstants, pwiseConstants, k)
adlpOp = lib.createHelmholtz3dAdjointDoubleLayerBoundaryOperator(
               sphere_def)
s3_geo_f.write("rad = " + str(r3) + ";\nlc = " + str(element_size) + ";\n" +
               sphere_def)
s1_geo_f.close()
s2_geo_f.close()
s3_geo_f.close()

# Use Gmsh to create meshes

subprocess.check_call(gmsh_command + " -2 " + s1_geo_name, shell=True)
subprocess.check_call(gmsh_command + " -2 " + s2_geo_name, shell=True)
subprocess.check_call(gmsh_command + " -2 " + s3_geo_name, shell=True)

# Read the meshes into BEM++ Objects

sphere1 = blib.createGridFactory().importGmshGrid("triangular", s1_msh_name)
sphere2 = blib.createGridFactory().importGmshGrid("triangular", s2_msh_name)
sphere3 = blib.createGridFactory().importGmshGrid("triangular", s3_msh_name)

# Clean up the temporary files

os.remove(s1_geo_name)
os.remove(s2_geo_name)
os.remove(s3_geo_name)
os.remove(s1_msh_name)
os.remove(s2_msh_name)
os.remove(s3_msh_name)

# Create Context

accuracy_options = blib.createAccuracyOptions()
示例#6
0
import numpy as np
import bempp.lib as lib
import scipy.special as sc
import numpy.polynomial.legendre as leg
import time

accuracyOptions = lib.createAccuracyOptions()
accuracyOptions.doubleRegular.setRelativeQuadratureOrder(2)
accuracyOptions.singleRegular.setRelativeQuadratureOrder(2)
quadStrategy = lib.createNumericalQuadratureStrategy("float64", "complex128", accuracyOptions)

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())
context = lib.createContext(quadStrategy, options)

grid = lib.createGridFactory().importGmshGrid("triangular", "airplane.msh")
pconsts = lib.createPiecewiseConstantScalarSpace(context, grid)

k = 16
#k = 64; #16; #0.16

# ansatz: direction of incident plane wave: assume x here
lhsOp = lib.createHelmholtz3dSingleLayerBoundaryOperator(context, pconsts, pconsts, pconsts, k, "SLP")

# Create a grid function representing the Dirichlet trace of the incident wave
def uIncData(point):
	x, y, z = point
	return np.exp(1j * k * x)

def incident(point):
	x, y, z = point
示例#7
0
    "float64", "complex128", accuracyOptions)

# Set assembly options -- switch to ACA

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())

# Combine the quadrature strategy and assembly options into an assembly context

context = lib.createContext(quadStrategy, options)

# PART 3: Define the system of integral equations to be solved #################

# Import mesh

grid = lib.createGridFactory().importGmshGrid(
    "triangular", "../../examples/meshes/sphere-h-0.1.msh")

# Create a function space

pconsts = lib.createPiecewiseConstantScalarSpace(context, grid)

# Define material and wave parameters

rhoInt = 2.
rhoExt = 1.
kInt = 1.
kExt = 5.

# Create boundary operators

slpOpInt = lib.createHelmholtz3dSingleLayerBoundaryOperator(
示例#8
0
s1_geo_f.write("rad = "+str(r1)+";\nlc = "+str(element_size)+";\n"+sphere_def)
s2_geo_f.write("rad = "+str(r2)+";\nlc = "+str(element_size)+";\n"+sphere_def)
s3_geo_f.write("rad = "+str(r3)+";\nlc = "+str(element_size)+";\n"+sphere_def)
s1_geo_f.close()
s2_geo_f.close()
s3_geo_f.close()

# Use Gmsh to create meshes

subprocess.check_call(gmsh_command+" -2 "+s1_geo_name,shell=True)
subprocess.check_call(gmsh_command+" -2 "+s2_geo_name,shell=True)
subprocess.check_call(gmsh_command+" -2 "+s3_geo_name,shell=True)

# Read the meshes into BEM++ Objects

sphere1 = blib.createGridFactory().importGmshGrid("triangular",s1_msh_name)
sphere2 = blib.createGridFactory().importGmshGrid("triangular",s2_msh_name)
sphere3 = blib.createGridFactory().importGmshGrid("triangular",s3_msh_name)

# Clean up the temporary files

os.remove(s1_geo_name)
os.remove(s2_geo_name)
os.remove(s3_geo_name)
os.remove(s1_msh_name)
os.remove(s2_msh_name)
os.remove(s3_msh_name)

# Create Context

accuracy_options = blib.createAccuracyOptions()
示例#9
0
文件: shapes.py 项目: UCL/bempp
def __generate_grid_from_string(geo_string,grid=True,msh_file=False,parallel=True):
    """Helper routine that implements the grid generation
    """

    import os
    import subprocess

    def msh_from_string(geo_string):
        gmsh_command = findGmsh(gmsh_exe)
        f,geo_name,msh_name = getGmshFile()
        f.write(geo_string)
        f.close()

        fnull = open(os.devnull,'w')
        cmd = gmsh_command+" -2 "+geo_name
        try:
            print "Generating Gmsh grid..."
            subprocess.check_call(cmd,shell=True,stdout=fnull,stderr=fnull)
        except:
            print "The following command failed: "+cmd
            fnull.close()
            raise
        os.remove(geo_name)
        fnull.close()
        return msh_name
        
    if parallel:
        from PyTrilinos.Epetra import PyComm
        comm = PyComm()
        my_rank = comm.MyPID()
    else:
        my_rank = 0
        

    if parallel:
        if my_rank == 0:
            rank0_msh_name = msh_from_string(geo_string)
            nchar = np.array(len(rank0_msh_name),dtype='int')
            comm.Broadcast(nchar,0)
            msh_name_array=np.array(rank0_msh_name)
            comm.Broadcast(msh_name_array,0)
        else:
            nchar=np.array([0],dtype='int')
            comm.Broadcast(nchar,0)
            msh_name_array=''
            msh_name_array=np.array(msh_name_array.zfill(nchar))
            comm.Broadcast(msh_name_array,0)
        msh_name = msh_name_array.item()
    else:
        msh_name = msh_from_string(geo_string)
        
    grid_obj = None
    if grid:
        from bempp.lib import createGridFactory
        grid_obj = createGridFactory().importGmshGrid("triangular",msh_name)
        comm.Barrier()
    if not msh_file:
        if parallel:
            if my_rank==0:
                os.remove(msh_name)
            msh_name = None
        else:
            os.remove(msh_name)
            msh_name = None            
    if grid and not msh_name:
        return grid_obj
    elif msh_file and not grid:
        return msh_name
    elif msh_file and grid:
        return (grid_obj,msh_file)
    else:
        return None
示例#10
0
import bempp.lib as lib
import scipy.special as sc
import numpy.polynomial.legendre as leg
import time

accuracyOptions = lib.createAccuracyOptions()
accuracyOptions.doubleRegular.setRelativeQuadratureOrder(2)
accuracyOptions.singleRegular.setRelativeQuadratureOrder(2)
quadStrategy = lib.createNumericalQuadratureStrategy("float64", "complex128",
                                                     accuracyOptions)

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())
context = lib.createContext(quadStrategy, options)

grid = lib.createGridFactory().importGmshGrid("triangular", "airplane.msh")
pconsts = lib.createPiecewiseConstantScalarSpace(context, grid)

k = 16
#k = 64; #16; #0.16

# ansatz: direction of incident plane wave: assume x here
lhsOp = lib.createHelmholtz3dSingleLayerBoundaryOperator(
    context, pconsts, pconsts, pconsts, k, "SLP")


# Create a grid function representing the Dirichlet trace of the incident wave
def uIncData(point):
    x, y, z = point
    return np.exp(1j * k * x)
示例#11
0
quadStrategy = lib.createNumericalQuadratureStrategy(
    "float64", "complex128", accuracyOptions)

# Use ACA to accelerate the assembly

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())

# The context object combines these settings

context = lib.createContext(quadStrategy, options)

# Load a grid approximating a unit sphere

grid_factory = lib.createGridFactory()
grid = grid_factory.importGmshGrid(
    "triangular", "../../examples/meshes/sphere-h-0.1.msh")

# Create a space of piecewise constant basis functions over the grid.

pwiseConstants = lib.createPiecewiseConstantScalarSpace(context, grid)

# We now initialize the boundary operators.
# A boundary operator always takes three space arguments: a domain space,
# a range space, and the test space (dual to the range).
# Here, we just use L^2 projections. Hence, all spaces are identical.

slpOp = lib.createHelmholtz3dSingleLayerBoundaryOperator(
    context, pwiseConstants, pwiseConstants, pwiseConstants, k)
adlpOp = lib.createHelmholtz3dAdjointDoubleLayerBoundaryOperator(
示例#12
0
def __generate_grid_from_string(geo_string,
                                grid=True,
                                msh_file=False,
                                parallel=True):
    """Helper routine that implements the grid generation
    """

    import os
    import subprocess

    def msh_from_string(geo_string):
        gmsh_command = findGmsh(gmsh_exe)
        f, geo_name, msh_name = getGmshFile()
        f.write(geo_string)
        f.close()

        fnull = open(os.devnull, 'w')
        cmd = gmsh_command + " -2 " + geo_name
        try:
            print "Generating Gmsh grid..."
            subprocess.check_call(cmd, shell=True, stdout=fnull, stderr=fnull)
        except:
            print "The following command failed: " + cmd
            fnull.close()
            raise
        os.remove(geo_name)
        fnull.close()
        return msh_name

    if parallel:
        from PyTrilinos.Epetra import PyComm
        comm = PyComm()
        my_rank = comm.MyPID()
    else:
        my_rank = 0

    if parallel:
        if my_rank == 0:
            rank0_msh_name = msh_from_string(geo_string)
            nchar = np.array(len(rank0_msh_name), dtype='int')
            comm.Broadcast(nchar, 0)
            msh_name_array = np.array(rank0_msh_name)
            comm.Broadcast(msh_name_array, 0)
        else:
            nchar = np.array([0], dtype='int')
            comm.Broadcast(nchar, 0)
            msh_name_array = ''
            msh_name_array = np.array(msh_name_array.zfill(nchar))
            comm.Broadcast(msh_name_array, 0)
        msh_name = msh_name_array.item()
    else:
        msh_name = msh_from_string(geo_string)

    grid_obj = None
    if grid:
        from bempp.lib import createGridFactory
        grid_obj = createGridFactory().importGmshGrid("triangular", msh_name)
        comm.Barrier()
    if not msh_file:
        if parallel:
            if my_rank == 0:
                os.remove(msh_name)
            msh_name = None
        else:
            os.remove(msh_name)
            msh_name = None
    if grid and not msh_name:
        return grid_obj
    elif msh_file and not grid:
        return msh_name
    elif msh_file and grid:
        return (grid_obj, msh_file)
    else:
        return None
示例#13
0
    "float64", "complex128", accuracyOptions)

# Set assembly options -- switch to ACA

options = lib.createAssemblyOptions()
options.switchToAca(lib.createAcaOptions())

# Combine the quadrature strategy and assembly options into an assembly context

context = lib.createContext(quadStrategy, options)

# PART 3: Define the system of integral equations to be solved #################

# Import mesh

grid = lib.createGridFactory().importGmshGrid(
    "triangular", "../../examples/meshes/sphere-h-0.1.msh")

# Create a function space

pconsts = lib.createPiecewiseConstantScalarSpace(context, grid)

# Define material and wave parameters

rhoInt = 2.
rhoExt = 1.
kInt = 1.
kExt = 5.

# Create boundary operators

slpOpInt = lib.createHelmholtz3dSingleLayerBoundaryOperator(