Example #1
0
slPotOp = createLaplace3dSingleLayerPotentialOperator(context)
dlPotOp = createLaplace3dDoubleLayerPotentialOperator(context)

# Define points at which the solution should be evaluated

rCount = 51;
thetaCount = 361;
r, theta, z = np.mgrid[1:2:rCount*1j, 0:2*np.pi:thetaCount*1j, 0:0:1j]
x = r * np.cos(theta)
y = r * np.sin(theta)
# put the x, y and z coordinates in successive rows of a matrix
evaluationPoints = np.vstack((x.ravel(), y.ravel(), z.ravel()))

# Use the Green's representation formula to evaluate the solution

evaluationOptions = createEvaluationOptions()
field = (-slPotOp.evaluateAtPoints(solFun, evaluationPoints,
                                   evaluationOptions) +
          dlPotOp.evaluateAtPoints(dirichletData, evaluationPoints,
                                   evaluationOptions))

# Plot data

from bempp import visualization2 as vis
annulus = vis.tvtkStructuredGridData(
    evaluationPoints, field, (rCount, thetaCount))
sphere = vis.tvtkGridFunction(dirichletData)
vis.plotScalarData(tvtkGridFunctions=sphere,
                   tvtkStructuredGridData=annulus)
Example #2
0
           + dlPotExt.evaluateAtPoints(uSc, points[:,outside], evalOptions)
           + uIncData(points[:,outside]))
valsInt = (  slPotInt.evaluateAtPoints(uIntDeriv, points[:,inside], evalOptions)
           - dlPotInt.evaluateAtPoints(uInt, points[:,inside], evalOptions))

# Combine the results obtained for points inside and outside the scatterer
# in a single array

vals = np.empty(nPointsX * nPointsY, dtype=complex)
np.place(vals, outside, valsExt.ravel())
np.place(vals, inside, valsInt.ravel())

# Display the field plot

from bempp import visualization2 as vis
tvtkU = vis.tvtkStructuredGridData(
        points, vals, (nPointsX, nPointsY))
tvtkGrid = vis.tvtkGrid(grid)
vis.plotScalarData(tvtkGrid, None, tvtkU)

# Export the results into a VTK file

from tvtk.api import write_data
write_data(tvtkU, "u.vts")

# PART 6: Evaluate the far-field pattern of the scattered field ################

# Create the necessary potential operators

slFfPot = lib.createHelmholtz3dFarFieldSingleLayerPotentialOperator(context, kExt)
dlFfPot = lib.createHelmholtz3dFarFieldDoubleLayerPotentialOperator(context, kExt)
nPointsZ = nPointsX
x, y, z = np.mgrid[-5:5:nPointsX*1j, 0:0:1j, -5:5:nPointsZ*1j]
points = np.vstack((x.ravel(), y.ravel(), z.ravel()))

# Use Green's representation formula to evaluate the total field

evaluationOptions = createEvaluationOptions()
scatteredField = -(slPotOp.evaluateAtPoints(neumannData, points,
                                            evaluationOptions))
incidentField = evalIncField(points)
field = scatteredField + incidentField

# Display the field plot

from bempp import visualization2 as vis
tvtkField = vis.tvtkStructuredGridData(points, field, (nPointsX, nPointsZ))
tvtkGrid = vis.tvtkGrid(grid)
vis.plotVectorData(tvtkGrids=tvtkGrid, tvtkStructuredGridData=tvtkField)

# from bempp import visualization as vis
# uActor = vis.scalarDataOnRegularGridActor(
#         points, fieldMagnitude, (nPointsX, nPointsZ),
#         colorRange=(0, 2))
# legendActor = vis.legendActor(uActor)
# gridActor = vis.gridActor(grid)
# vis.plotTvtkActors([uActor, gridActor, legendActor])

# Export the results into a VTK file

from tvtk.api import write_data
write_data(tvtkField, "u.vts")