コード例 #1
0
ファイル: acoustic.py プロジェクト: rorypeck/tdbempp
    def evaluate_potential(self,wavenumber,density):

        from bempp import lib as bempplib
        
        op_found_in_cache = False
        if self._use_cache:
            try:
                potential = self._potential_operator_cache.get(wavenumber)
                op_found_in_cache = True
            except:
                pass
        
        if not op_found_in_cache:
            evalOps = _bempplib.createEvaluationOptions()
            #evalOps.setVerbosityLevel('low')
            acaOps = _bempplib.createAcaOptions()
            acaOps.eps = self._aca_epsilon
            evalOps.switchToAcaMode(acaOps)
 
        
            potential = _bempplib.createModifiedHelmholtz3dDoubleLayerPotentialOperator(self._context,wavenumber).assemble(self._spaces[0],
                                                                                                                           self._evaluation_points,
                                                                                                                           self._quad_strategy,
                                                                                                                           evalOps).discreteOperator()
        
            if self._use_cache: self._potential_operator_cache.insert(wavenumber,potential)
            
        n = len(density[0])
        return (potential*density[0].reshape(n,1)).ravel()
コード例 #2
0
ファイル: tools.py プロジェクト: UCL/bempp
def evaluatePotentialOnPlane(potential, gridfun, limits, dimensions, plane="xy",
                             origin=[0,0,0], evalOps=None):
    """evaluatePotentialOnPlane(potential, gridfun, limits, dimensions, plane="xy",
                                evalOps=None, quadStrategy=None)

       Evaluate a given potential operator on a plane

       Parameters:
       -----------
       potential    : Instance of a potential operator.
       gridfun      : grid function with which to evaluate the potential
       limits       : tuple (xmin,xmax,ymin,ymax) specifying the
                      extent of the plane.
       dimensions   : tuple (xdim,ydim) specifying the number of points in
                      the (x,y) dimensions of the plane.
       plane        : either "xy", "xz" or "yz", (default: "xy"); the orientation
                      of the plane in 3d space.
       origin       : origin of the plane (default: [0,0,0])
       evalOps      : Optional EvaluationOptions object. Use default options
                      if none is given.

       Returns:
       --------
       points     : Array [p_1,p_2,,,] of points in 3d space.
       values     : Array [v_1,v_2,..] of values v_i of the potential at points p_i.
    """

    if not plane in ["xy","xz","yz"]:
        raise ValueError("'plane' must by either 'xy', 'xz', or 'yz'")

    xmin, xmax, ymin, ymax = limits
    x, y = np.mgrid[xmin:xmax:dimensions[0]*1j,
                    ymin:ymax:dimensions[1]*1j]

    points_2d = np.array([x.T.ravel(),y.T.ravel()],dtype ='d')

    dims = dimensions

    if plane=="xy":
        points = np.array([points_2d[0]+origin[0],points_2d[1]+origin[1],np.zeros(dims[0]*dims[1],dtype='d')+origin[2]])
    elif plane=="xz":
        points = np.array([points_2d[0]+origin[0],np.zeros(dims[0]*dims[1],dtype='d')+origin[1],points_2d[1]+origin[2]])
    elif plane=="yz":
        points = np.array([np.zeros(dims[0]*dims[1],dtype='d')+origin[0],points_2d[0]+origin[1],points_2d[1]+origin[2]])

    if evalOps is None:
        evalOps = lib.createEvaluationOptions()
    values = potential.evaluateAtPoints(gridfun, points, evalOps)

    return (points, values)
コード例 #3
0
ファイル: tools.py プロジェクト: figotan/bempp
def evaluatePotentialInBox(potentials, gridfuns, coefficients, limits, dimensions, evalOps=None):
    """evaluatePotentialOnPlane(potential, gridfun, limits, dimensions, 
                                evalOps=None)

       Evaluate a linear combination of given potential operators in a box

       Parameters:
       -----------
       potentials   : List of instances of a potential operators.
       gridfuns     : List grid functions with which to evaluate the potentials
       coefficients : Scalar coefficients of the potentials
       limits       : tuple (xmin,xmax,ymin,ymax,zmin,zmax) specifying the
                      extent of the plane.
       dimensions   : tuple (xdim,ydim,zdim) specifying the number of points in
                      the (x,y) dimensions of the plane.
       evalOps      : Optional EvaluationOptions object. Use default options
                      if none is given.

       Returns:
       --------
       points     : A numpy.mgrid object defining the points in 3d space.
       values     : Array [v_1,v_2,...], where each v_i has the same shape as the
                    components of the mgrid object points. Each element v_i corresponds
                    to one dimension of the return value of the potential, e.g. for Maxwell
                    the values v_1,v_2, and v_3 correspond to the x, y and z component of the
                    potential field.
    """


    pointsArray, pointsMgrid = pointsInBox(limits,dimensions,mgridObj=True)

    if evalOps is None:
        evalOps = lib.createEvaluationOptions()

    values = coefficients[0]*potentials[0].evaluateAtPoints(gridfuns[0],pointsArray,evalOps)
    for i in range(1,len(potentials)):
        values +=coefficients[i]*potentials[i].evaluateAtPoints(gridfuns[i],pointsArray,evalOps)
    valsMgrid = np.array([v.reshape(dimensions[::-1][:]) for v in values])

    return (pointsMgrid, valsMgrid)
コード例 #4
0
ファイル: airplaneTest.py プロジェクト: popsomer/bempp
# PART 4: Discretize and solve the equations ###################################
solver = lib.createDefaultIterativeSolver(lhsOp)
params = lib.defaultGmresParameterList(1e-8)
solver.initializeSolver(params)
# Solve the equation
solution = solver.solve(rhs)
print solution.solverMessage()

# PART 5: Extract the solution #################################################
sol = solution.gridFunction()
print "************** k = ", k, " **********************"


slPot = lib.createHelmholtz3dSingleLayerPotentialOperator(context, k)
dlPot = lib.createHelmholtz3dDoubleLayerPotentialOperator(context, k)
evalOptions = lib.createEvaluationOptions()

endpl = 0.5;
radpl = 0.1;
hwwing = 0.05;
angl = 0.3;
wings = 0.3;

xe = radpl*np.cos(angl)+wings;
ye = 0.0; #radpl*Sin(angl);
ze = 0.0; # : Middle of wing plane
potRes = slPot.evaluateAtPoints(sol, [[xe],[ye],[ze]], evalOptions)
negInci = -uIncData([xe,ye,ze])
print [[xe],[ye],[ze]], negInci, " = pt and neg of inc wave, approx and potential =", potRes, ", error = ", np.abs(potRes-negInci)

コード例 #5
0
def evaluatePotentialOnPlane(potential,
                             gridfun,
                             limits,
                             dimensions,
                             plane="xy",
                             origin=[0, 0, 0],
                             evalOps=None):
    """evaluatePotentialOnPlane(potential, gridfun, limits, dimensions, plane="xy",
                                evalOps=None, quadStrategy=None)

       Evaluate a given potential operator on a plane

       Parameters:
       -----------
       potential    : Instance of a potential operator.
       gridfun      : grid function with which to evaluate the potential
       limits       : tuple (xmin,xmax,ymin,ymax) specifying the
                      extent of the plane.
       dimensions   : tuple (xdim,ydim) specifying the number of points in
                      the (x,y) dimensions of the plane.
       plane        : either "xy", "xz" or "yz", (default: "xy"); the orientation
                      of the plane in 3d space.
       origin       : origin of the plane (default: [0,0,0])
       evalOps      : Optional EvaluationOptions object. Use default options
                      if none is given.

       Returns:
       --------
       points     : Array [p_1,p_2,,,] of points in 3d space.
       values     : Array [v_1,v_2,..] of values v_i of the potential at points p_i.
    """

    if not plane in ["xy", "xz", "yz"]:
        raise ValueError("'plane' must by either 'xy', 'xz', or 'yz'")

    xmin, xmax, ymin, ymax = limits
    x, y = np.mgrid[xmin:xmax:dimensions[0] * 1j, ymin:ymax:dimensions[1] * 1j]

    points_2d = np.array([x.T.ravel(), y.T.ravel()], dtype='d')

    dims = dimensions

    if plane == "xy":
        points = np.array([
            points_2d[0] + origin[0], points_2d[1] + origin[1],
            np.zeros(dims[0] * dims[1], dtype='d') + origin[2]
        ])
    elif plane == "xz":
        points = np.array([
            points_2d[0] + origin[0],
            np.zeros(dims[0] * dims[1], dtype='d') + origin[1],
            points_2d[1] + origin[2]
        ])
    elif plane == "yz":
        points = np.array([
            np.zeros(dims[0] * dims[1], dtype='d') + origin[0],
            points_2d[0] + origin[1], points_2d[1] + origin[2]
        ])

    if evalOps is None:
        evalOps = lib.createEvaluationOptions()
    values = potential.evaluateAtPoints(gridfun, points, evalOps)

    return (points, values)
コード例 #6
0
# PART 4: Discretize and solve the equations ###################################
solver = lib.createDefaultIterativeSolver(lhsOp)
params = lib.defaultGmresParameterList(1e-8)
solver.initializeSolver(params)
# Solve the equation
solution = solver.solve(rhs)
print solution.solverMessage()

# PART 5: Extract the solution #################################################
sol = solution.gridFunction()
print "************** k = ", k, " **********************"

slPot = lib.createHelmholtz3dSingleLayerPotentialOperator(context, k)
dlPot = lib.createHelmholtz3dDoubleLayerPotentialOperator(context, k)
evalOptions = lib.createEvaluationOptions()

endpl = 0.5
radpl = 0.1
hwwing = 0.05
angl = 0.3
wings = 0.3

xe = radpl * np.cos(angl) + wings
ye = 0.0
#radpl*Sin(angl);
ze = 0.0
# : Middle of wing plane
potRes = slPot.evaluateAtPoints(sol, [[xe], [ye], [ze]], evalOptions)
negInci = -uIncData([xe, ye, ze])
print[
コード例 #7
0
ファイル: tools.py プロジェクト: rorypeck/tdbempp
def create_bempp_options(solver_use_aca = True,
                         evaluation_use_aca = True,
                         solver_aca_epsilon = 1E-6,
                         solver_aca_maximum_rank = 200,
                         solver_aca_maximum_block_size = 2000,
                         solver_aca_mode = 'hybrid_assembly',
                         solver_aca_eta = 1.2,
                         evaluation_aca_epsilon = 1E-3,
                         evaluation_aca_eta = 0.4,
                         evaluation_aca_maximum_rank = 30,
                         evaluation_aca_maximum_block_size = 2000,
                         evaluation_aca_mode = 'global_assembly',
                         relative_double_singular_quadrature_order = 2,
                         relative_double_regular_quadrature_order = 1,
                         relative_single_regular_quadrature_order = 1,
                         verbosity_level = 'low',
                         basis_function_type = 'float64',
                         result_type = 'complex128',
                         number_of_threads = None
                         ):
                         
    solver_assembly_options = _bempplib.createAssemblyOptions()
    
    if number_of_threads is not None:
        solver_assembly_options.setMaxThreadCount(number_of_threads)
    
        
    solver_assembly_options.setVerbosityLevel(verbosity_level)
    
    if solver_use_aca:
        solver_aca_options = _bempplib.createAcaOptions()
        solver_aca_options.mode = solver_aca_mode
        solver_aca_options.eps = solver_aca_epsilon
        solver_aca_options.eta = solver_aca_eta
        solver_aca_options.maximumBlockSize = solver_aca_maximum_block_size
        solver_aca_options.maximumRank = solver_aca_maximum_rank
        solver_assembly_options.switchToAca(solver_aca_options)
    
    
    solver_accuracy_options = _bempplib.createAccuracyOptions()
    solver_accuracy_options.doubleRegular.setRelativeQuadratureOrder(relative_double_regular_quadrature_order)
    solver_accuracy_options.doubleSingular.setRelativeQuadratureOrder(relative_double_singular_quadrature_order)
    
    quadrature_strategy = _bempplib.createNumericalQuadratureStrategy(basis_function_type,result_type,solver_accuracy_options)
    context = _bempplib.createContext(quadrature_strategy,solver_assembly_options)
    
    evaluation_options = _bempplib.createEvaluationOptions()
    evaluation_accuracy_options = _bempplib.createAccuracyOptions()
    evaluation_accuracy_options.singleRegular.setRelativeQuadratureOrder(relative_single_regular_quadrature_order)
    evaluation_quadrature_strategy = _bempplib.createNumericalQuadratureStrategy(basis_function_type,result_type,evaluation_accuracy_options)
    if evaluation_use_aca:
        evaluation_aca_options = _bempplib.createAcaOptions()
        evaluation_aca_options.eps = evaluation_aca_epsilon
        evaluation_aca_options.eta = evaluation_aca_eta
        evaluation_aca_options.mode = evaluation_aca_mode
        evaluation_aca_options.maximumBlockSize = evaluation_aca_maximum_block_size
        evaluation_aca_options.maximumRank = evaluation_aca_maximum_rank
        evaluation_options.switchToAcaMode(evaluation_aca_options)
    return (context,evaluation_options,evaluation_quadrature_strategy)