In [1]:
from HelmholtzSolver2D import *
from ExampleBoundaries import Square

c         = 344.0 # speed of sound [m/s]
rho       = 1.205 # density of air [kg/m^3]
frequency = 400.0 # frequency [Hz]


# Test Problem 1
# Dirichlet boundary condition with phi = sin(k/sqrt(2)*x) * sin(k/sqrt(2)*y)
#
solver = HelmholtzSolver2D(*(Square()))

boundaryCondition = BoundaryCondition(solver.aElement.shape[0])
boundaryCondition.alpha.fill(1.0)
boundaryCondition.beta.fill(0.0)

k = frequencyToWavenumber(frequency)

boundaryCondition.f[:] = np.sin(k/np.sqrt(2.0) * solver.aCenters[:,0]) \
                       * np.sin(k/np.sqrt(2.0) * solver.aCenters[:,1])

boundaryIncidence = BoundaryIncidence(solver.aElement.shape[0])
boundaryIncidence.phi.fill(0.0)
boundaryIncidence.v.fill(0.0)

interiorPoints = np.array([[0.0250, 0.0250],
                           [0.0750, 0.0250],
                           [0.0250, 0.0750],
                           [0.0750, 0.0750],
                           [0.0500, 0.0500]], dtype=np.float32)

interiorIncidentPhi = np.zeros(interiorPoints.shape[0], dtype=np.complex64)

boundarySolution = solver.solveInteriorBoundary(k, boundaryCondition, boundaryIncidence)
interiorPhi = solver.solveInterior(boundarySolution, interiorIncidentPhi, interiorPoints)
print "Test Problem 1"
print "==============\n"
print boundarySolution
printInteriorSolution(boundarySolution, interiorPhi)


# Test Problem 2
# von Neumann boundary condition such that phi = sin(k/sqrt(2) * x) * sin(k/sqrt(2) * y)
# Differentiate with respect to x and y to obtain outward normal:
# dPhi/dX = k/sqrt(2) * cos(k/sqrt(2) * x) * sin(k/sqrt(2) * y)
# dPhi/dY = k/sqrt(2) * sin(k/sqrt(2) * x) * cos(k/sqrt(2) * y)
boundaryCondition.alpha.fill(0.0)
boundaryCondition.beta.fill(1.0)
c = k / np.sqrt(2.0)
for i in range(solver.aCenters.shape[0]):
    x = solver.aCenters[i, 0]
    y = solver.aCenters[i, 1]
    if (x < 1e-7):
        boundaryCondition.f[i] = -c * np.cos(c * x) * np.sin(c * y)
    elif (x > 0.1 - 1e-7):
        boundaryCondition.f[i] =  c * np.cos(c * x) * np.sin(c * y)
    elif (y < 1e-7):
        boundaryCondition.f[i] = -c * np.sin(c * x) * np.cos(c * y)
    else:
        boundaryCondition.f[i] =  c * np.sin(c * x) * np.cos(c * y)        

boundarySolution = solver.solveInteriorBoundary(k, boundaryCondition, boundaryIncidence)
interiorPhi = solver.solveInterior(boundarySolution, interiorIncidentPhi, interiorPoints)
print "\n\nTest Problem 2"
print "==============\n"
print boundarySolution
printInteriorSolution(boundarySolution, interiorPhi)

   
# Test Problem 3
# The test problem computes the field produced by a unit source at
# the point (0.5,0.25) within the square with a rigid boundary.
# The rigid boundary implies the bondary condition v=0.
# The test problem computes the field produced by a unit source at
# the point (0.5,0.25) within the square with a rigid boundary.
# The incident velocity potential is given by {\phi}_inc=i*h0(kr)/4
# where r is the distance from the point (0.5,0.25)
boundaryCondition.alpha.fill(0.0)
boundaryCondition.beta.fill(1.0)
boundaryCondition.f.fill(0.0)

p = np.array([0.05, 0.025], dtype=np.float32)
for i in range(solver.aCenters.shape[0]):
    r = solver.aCenters[i] - p
    R = norm(r)
    boundaryIncidence.phi[i] = 0.25j * hankel1(0, k * R)
    if solver.aCenters[i, 0] < 1e-7:
        boundaryIncidence.v[i] = -0.25j * k * hankel1(1, k * R) * (-r[0] / R)
    elif solver.aCenters[i, 0] > 0.1 - 1e-7:
        boundaryIncidence.v[i] = -0.25j * k * hankel1(1, k * R) * ( r[0] / R)
    elif solver.aCenters[i, 1] < 1e-7:
        boundaryIncidence.v[i] = -0.25j * k * hankel1(1, k * R) * (-r[1] / R)
    elif solver.aCenters[i, 1] > 0.1 - 1e-7:
        boundaryIncidence.v[i] = -0.25j * k * hankel1(1, k * R) * ( r[1] / R)
    else:
        assert False, "All cases must be handled above."
        
for i in range(interiorIncidentPhi.size):
    r = interiorPoints[i] - p
    R = norm(r)
    interiorIncidentPhi[i] = 0.25j * hankel1(0, k * R)
       
boundarySolution = solver.solveInteriorBoundary(k, boundaryCondition, boundaryIncidence)
interiorPhi = solver.solveInterior(boundarySolution, interiorIncidentPhi, interiorPoints)
print "\n\nTest Problem 3"
print "==============\n"
print boundarySolution
printInteriorSolution(boundarySolution, interiorPhi)


Test Problem 1
==============

Density of medium:      1.205 kg/m^3
Speed of sound:         344.0 m/s
Wavenumber (Frequency): 7.30602942695 (400.0 Hz)

index          Potential                   Pressure                    Velocity              Intensity
    1   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.6416e-01+  6.9307e-03i     0.0000e+00
    2   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -5.0028e-01+  8.1443e-03i     0.0000e+00
    3   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -8.3287e-01+  9.1791e-03i     0.0000e+00
    4   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.1622e+00+  1.0142e-02i     0.0000e+00
    5   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.4864e+00+  1.1011e-02i     0.0000e+00
    6   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.8032e+00+  1.1634e-02i     0.0000e+00
    7   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -2.1078e+00+  1.1451e-02i     0.0000e+00
    8   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -2.4897e+00+  2.4934e-03i     0.0000e+00
    9   1.5946e-02+  0.0000e+00i    0.0000e+00+  4.8292e+01i   -4.0429e-02+  2.0195e-02i     4.8762e-01
   10   4.7771e-02+  0.0000e+00i    0.0000e+00+  1.4467e+02i    4.2439e-01+  9.6985e-03i     7.0156e-01
   11   7.9397e-02+  0.0000e+00i    0.0000e+00+  2.4045e+02i    7.2599e-01+  2.3330e-03i     2.8048e-01
   12   1.1069e-01+  0.0000e+00i    0.0000e+00+  3.3523e+02i    1.0135e+00+ -3.4407e-03i    -5.7671e-01
   13   1.4152e-01+  0.0000e+00i    0.0000e+00+  4.2861e+02i    1.2947e+00+ -8.7741e-03i    -1.8803e+00
   14   1.7177e-01+  0.0000e+00i    0.0000e+00+  5.2020e+02i    1.5710e+00+ -1.4252e-02i    -3.7069e+00
   15   2.0130e-01+  0.0000e+00i    0.0000e+00+  6.0962e+02i    1.8457e+00+ -2.0460e-02i    -6.2366e+00
   16   2.2998e-01+  0.0000e+00i    0.0000e+00+  6.9651e+02i    2.3253e+00+ -2.2042e-02i    -7.6760e+00
   17   2.2998e-01+  0.0000e+00i    0.0000e+00+  6.9651e+02i    2.3253e+00+ -2.2044e-02i    -7.6770e+00
   18   2.0130e-01+  0.0000e+00i    0.0000e+00+  6.0962e+02i    1.8457e+00+ -2.0463e-02i    -6.2374e+00
   19   1.7177e-01+  0.0000e+00i    0.0000e+00+  5.2020e+02i    1.5710e+00+ -1.4254e-02i    -3.7076e+00
   20   1.4152e-01+  0.0000e+00i    0.0000e+00+  4.2861e+02i    1.2946e+00+ -8.7765e-03i    -1.8808e+00
   21   1.1069e-01+  0.0000e+00i    0.0000e+00+  3.3523e+02i    1.0135e+00+ -3.4452e-03i    -5.7746e-01
   22   7.9397e-02+  0.0000e+00i    0.0000e+00+  2.4045e+02i    7.2604e-01+  2.3265e-03i     2.7970e-01
   23   4.7771e-02+  0.0000e+00i    0.0000e+00+  1.4467e+02i    4.2440e-01+  9.6945e-03i     7.0127e-01
   24   1.5946e-02+  0.0000e+00i    0.0000e+00+  4.8292e+01i   -4.0426e-02+  2.0192e-02i     4.8755e-01
   25   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -2.4897e+00+  2.4945e-03i     0.0000e+00
   26   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -2.1078e+00+  1.1451e-02i     0.0000e+00
   27   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.8032e+00+  1.1633e-02i     0.0000e+00
   28   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.4864e+00+  1.1011e-02i     0.0000e+00
   29   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.1622e+00+  1.0141e-02i     0.0000e+00
   30   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -8.3287e-01+  9.1783e-03i     0.0000e+00
   31   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -5.0027e-01+  8.1434e-03i     0.0000e+00
   32   0.0000e+00+  0.0000e+00i    0.0000e+00+  0.0000e+00i   -1.6415e-01+  6.9296e-03i     0.0000e+00


Sound pressure at the sample points

index          Potential                    Pressure               Magnitude         Phase

    1   1.5896e-02+  1.1894e-04i   -3.6019e-01+  4.8141e+01i     1.2763e+02 dB       1.5783
    2   4.8183e-02+  3.9962e-05i   -1.2102e-01+  1.4592e+02i     1.3726e+02 dB       1.5716
    3   4.8183e-02+  4.0005e-05i   -1.2116e-01+  1.4592e+02i     1.3726e+02 dB       1.5716
    4   1.4338e-01+ -2.5899e-04i    7.8433e-01+  4.3423e+02i     1.4673e+02 dB       1.5690
    5   6.4991e-02+ -1.4397e-05i    4.3603e-02+  1.9682e+02i     1.3986e+02 dB       1.5706


Test Problem 2
==============

Density of medium:      1.205 kg/m^3
Speed of sound:         344.0 m/s
Wavenumber (Frequency): 7.30602942695 (400.0 Hz)

index          Potential                   Pressure                    Velocity              Intensity
    1  -3.4277e-04+  7.7101e-04i   -2.3350e+00+ -1.0381e+00i   -1.6678e-01+  0.0000e+00i     1.9471e-01
    2  -2.9864e-04+  8.3379e-04i   -2.5251e+00+ -9.0444e-01i   -4.9964e-01+  0.0000e+00i     6.3083e-01
    3  -2.4640e-04+  8.9745e-04i   -2.7179e+00+ -7.4621e-01i   -8.3041e-01+  0.0000e+00i     1.1285e+00
    4  -1.4529e-04+  9.5503e-04i   -2.8923e+00+ -4.4002e-01i   -1.1577e+00+  0.0000e+00i     1.6743e+00
    5   5.3350e-05+  1.0012e-03i   -3.0321e+00+  1.6157e-01i   -1.4802e+00+  0.0000e+00i     2.2441e+00
    6   4.2715e-04+  1.0303e-03i   -3.1203e+00+  1.2936e+00i   -1.7965e+00+  0.0000e+00i     2.8029e+00
    7   1.1381e-03+  1.0371e-03i   -3.1408e+00+  3.4468e+00i   -2.1054e+00+  0.0000e+00i     3.3063e+00
    8   2.8794e-03+  1.0218e-03i   -3.0944e+00+  8.7203e+00i   -2.4054e+00+  0.0000e+00i     3.7216e+00
    9   1.9385e-02+  9.0112e-04i   -2.7290e+00+  5.8707e+01i    1.4501e-01+  0.0000e+00i    -1.9787e-01
   10   4.8831e-02+  1.1228e-03i   -3.4003e+00+  1.4789e+02i    4.3443e-01+  0.0000e+00i    -7.3859e-01
   11   7.9042e-02+  1.3995e-03i   -4.2383e+00+  2.3938e+02i    7.2204e-01+  0.0000e+00i    -1.5301e+00
   12   1.0918e-01+  1.6971e-03i   -5.1398e+00+  3.3064e+02i    1.0066e+00+  0.0000e+00i    -2.5870e+00
   13   1.3885e-01+  2.0031e-03i   -6.0662e+00+  4.2052e+02i    1.2870e+00+  0.0000e+00i    -3.9038e+00
   14   1.6775e-01+  2.3090e-03i   -6.9928e+00+  5.0803e+02i    1.5621e+00+  0.0000e+00i    -5.4617e+00
   15   1.9541e-01+  2.6040e-03i   -7.8861e+00+  5.9181e+02i    1.8306e+00+  0.0000e+00i    -7.2182e+00
   16   2.2053e-01+  2.8544e-03i   -8.6446e+00+  6.6789e+02i    2.0915e+00+  0.0000e+00i    -9.0401e+00
   17   2.2053e-01+  2.8544e-03i   -8.6446e+00+  6.6789e+02i    2.0915e+00+  0.0000e+00i    -9.0402e+00
   18   1.9541e-01+  2.6040e-03i   -7.8863e+00+  5.9181e+02i    1.8306e+00+  0.0000e+00i    -7.2183e+00
   19   1.6775e-01+  2.3091e-03i   -6.9931e+00+  5.0803e+02i    1.5621e+00+  0.0000e+00i    -5.4619e+00
   20   1.3885e-01+  2.0032e-03i   -6.0666e+00+  4.2052e+02i    1.2870e+00+  0.0000e+00i    -3.9040e+00
   21   1.0918e-01+  1.6973e-03i   -5.1403e+00+  3.3064e+02i    1.0066e+00+  0.0000e+00i    -2.5872e+00
   22   7.9042e-02+  1.3997e-03i   -4.2390e+00+  2.3938e+02i    7.2204e-01+  0.0000e+00i    -1.5304e+00
   23   4.8831e-02+  1.1229e-03i   -3.4008e+00+  1.4788e+02i    4.3443e-01+  0.0000e+00i    -7.3872e-01
   24   1.9385e-02+  9.0130e-04i   -2.7296e+00+  5.8706e+01i    1.4501e-01+  0.0000e+00i    -1.9791e-01
   25   2.8792e-03+  1.0219e-03i   -3.0948e+00+  8.7196e+00i   -2.4054e+00+  0.0000e+00i     3.7222e+00
   26   1.1379e-03+  1.0372e-03i   -3.1412e+00+  3.4462e+00i   -2.1054e+00+  0.0000e+00i     3.3067e+00
   27   4.2700e-04+  1.0304e-03i   -3.1206e+00+  1.2932e+00i   -1.7965e+00+  0.0000e+00i     2.8032e+00
   28   5.3238e-05+  1.0013e-03i   -3.0323e+00+  1.6123e-01i   -1.4802e+00+  0.0000e+00i     2.2442e+00
   29  -1.4537e-04+  9.5508e-04i   -2.8925e+00+ -4.4025e-01i   -1.1577e+00+  0.0000e+00i     1.6743e+00
   30  -2.4645e-04+  8.9748e-04i   -2.7180e+00+ -7.4636e-01i   -8.3041e-01+  0.0000e+00i     1.1285e+00
   31  -2.9867e-04+  8.3381e-04i   -2.5252e+00+ -9.0453e-01i   -4.9964e-01+  0.0000e+00i     6.3084e-01
   32  -3.4278e-04+  7.7102e-04i   -2.3350e+00+ -1.0381e+00i   -1.6678e-01+  0.0000e+00i     1.9471e-01


Sound pressure at the sample points

index          Potential                    Pressure               Magnitude         Phase

    1   1.5612e-02+  1.1364e-03i   -3.4415e+00+  4.7282e+01i     1.2750e+02 dB       1.6435
    2   4.8070e-02+  1.3404e-03i   -4.0592e+00+  1.4558e+02i     1.3724e+02 dB       1.5987
    3   4.8070e-02+  1.3403e-03i   -4.0591e+00+  1.4558e+02i     1.3724e+02 dB       1.5987
    4   1.3979e-01+  1.8714e-03i   -5.6677e+00+  4.2335e+02i     1.4651e+02 dB       1.5842
    5   6.3939e-02+  1.4465e-03i   -4.3807e+00+  1.9364e+02i     1.3972e+02 dB       1.5934


Test Problem 3
==============

Density of medium:      1.205 kg/m^3
Speed of sound:         344.0 m/s
Wavenumber (Frequency): 7.30602942695 (400.0 Hz)

index          Potential                   Pressure                    Velocity              Intensity
    1  -1.8138e+00+  7.9567e-04i   -2.4097e+00+ -5.4929e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    2  -1.8275e+00+  7.4568e-04i   -2.2583e+00+ -5.5346e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    3  -1.8556e+00+  7.5399e-04i   -2.2835e+00+ -5.6198e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    4  -1.8950e+00+  8.0267e-04i   -2.4309e+00+ -5.7389e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    5  -1.9379e+00+  8.6302e-04i   -2.6137e+00+ -5.8688e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    6  -1.9762e+00+  9.1275e-04i   -2.7643e+00+ -5.9849e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    7  -2.0044e+00+  9.4877e-04i   -2.8733e+00+ -6.0703e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    8  -2.0193e+00+  9.6760e-04i   -2.9304e+00+ -6.1153e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
    9  -2.0204e+00+  9.2985e-04i   -2.8161e+00+ -6.1187e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   10  -2.0186e+00+  8.8954e-04i   -2.6940e+00+ -6.1133e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   11  -2.0161e+00+  8.5965e-04i   -2.6034e+00+ -6.1058e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   12  -2.0144e+00+  8.3928e-04i   -2.5418e+00+ -6.1005e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   13  -2.0143e+00+  8.3059e-04i   -2.5154e+00+ -6.1004e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   14  -2.0160e+00+  8.3388e-04i   -2.5254e+00+ -6.1055e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   15  -2.0185e+00+  8.5333e-04i   -2.5843e+00+ -6.1129e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   16  -2.0202e+00+  8.8823e-04i   -2.6900e+00+ -6.1182e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   17  -2.0192e+00+  9.2868e-04i   -2.8125e+00+ -6.1151e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   18  -2.0043e+00+  9.1315e-04i   -2.7655e+00+ -6.0701e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   19  -1.9761e+00+  8.7927e-04i   -2.6629e+00+ -5.9848e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   20  -1.9378e+00+  8.3053e-04i   -2.5153e+00+ -5.8686e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   21  -1.8949e+00+  7.6983e-04i   -2.3314e+00+ -5.7387e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   22  -1.8556e+00+  7.1998e-04i   -2.1805e+00+ -5.6196e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   23  -1.8274e+00+  7.1074e-04i   -2.1525e+00+ -5.5344e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   24  -1.8137e+00+  7.5863e-04i   -2.2975e+00+ -5.4927e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   25  -1.8102e+00+  8.6940e-04i   -2.6330e+00+ -5.4823e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   26  -1.7821e+00+  8.3670e-04i   -2.5339e+00+ -5.3969e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   27  -1.7313e+00+  7.0239e-04i   -2.1272e+00+ -5.2433e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   28  -1.6816e+00+  4.9580e-04i   -1.5015e+00+ -5.0927e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   29  -1.6816e+00+  5.0315e-04i   -1.5238e+00+ -5.0928e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   30  -1.7314e+00+  7.2462e-04i   -2.1945e+00+ -5.2436e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   31  -1.7822e+00+  8.6929e-04i   -2.6326e+00+ -5.3973e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00
   32  -1.8104e+00+  9.0778e-04i   -2.7492e+00+ -5.4827e+03i    0.0000e+00+  0.0000e+00i    -0.0000e+00


Sound pressure at the sample points

index          Potential                    Pressure               Magnitude         Phase

    1  -1.7777e+00+  8.2638e-04i   -2.5027e+00+ -5.3838e+03i     1.6860e+02 dB       -1.5713
    2  -1.7777e+00+  8.1342e-04i   -2.4634e+00+ -5.3837e+03i     1.6860e+02 dB       -1.5713
    3  -1.9841e+00+  8.7267e-04i   -2.6429e+00+ -6.0089e+03i     1.6956e+02 dB       -1.5712
    4  -1.9841e+00+  8.5916e-04i   -2.6020e+00+ -6.0088e+03i     1.6956e+02 dB       -1.5712
    5  -1.8452e+00+  8.5066e-04i   -2.5762e+00+ -5.5882e+03i     1.6892e+02 dB       -1.5713

Copyright (C) 2017 Frank Jargstorff

This file is part of the AcousticBEM library.

AcousticBEM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

AcousticBEM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with AcousticBEM. If not, see http://www.gnu.org/licenses/.