Skip to content

Commit b0d4e2a

Browse files
committed
Add test for dyadic Green's formula
1 parent 1cd5951 commit b0d4e2a

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

test/test_maxwell_green.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
__copyright__ = "Copyright (C) 2022 University of Illinois Board of Trustees"
2+
3+
__license__ = """
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
"""
22+
23+
24+
from typing import Tuple
25+
26+
import numpy as np
27+
from pytools.obj_array import make_obj_array # noqa: F401
28+
from pytential import bind, sym, norm
29+
from sumpy.kernel import HelmholtzKernel, AxisSourceDerivative
30+
31+
from meshmode import _acf
32+
from arraycontext import pytest_generate_tests_for_array_contexts
33+
from meshmode.array_context import PytestPyOpenCLArrayContextFactory
34+
pytest_generate_tests = pytest_generate_tests_for_array_contexts([
35+
PytestPyOpenCLArrayContextFactory,
36+
])
37+
38+
def dyadic_layer_pot(helm_k, vec, *,
39+
transpose: bool, source_curl: bool = False) -> np.ndarray:
40+
k_sym = HelmholtzKernel(3)
41+
42+
if transpose:
43+
outer = lambda i, j: j
44+
inner = lambda i, j: i
45+
else:
46+
outer = lambda i, j: i
47+
inner = lambda i, j: j
48+
49+
def helmholtz_vec(source_derivative_axes: Tuple[int, ...]):
50+
knl = k_sym
51+
for axis in source_derivative_axes:
52+
knl = AxisSourceDerivative(axis, knl)
53+
54+
return sym.int_g_vec(knl, vec, qbx_forced_limit=None,
55+
kernel_arguments={"k": helm_k})
56+
57+
from pytools import levi_civita
58+
# FIXME Could/should use Schwarz's theorem to optimize, but probably
59+
# only off-surface where potential is smooth.
60+
if source_curl:
61+
return make_obj_array([
62+
sum(
63+
levi_civita((ell, m, n))
64+
* (helmholtz_vec((m,))[n]
65+
+ 1/helm_k**2 * sum(
66+
helmholtz_vec((m, outer(n, j), inner(n, j)))[j]
67+
for j in range(3)))
68+
for m in range(3)
69+
for n in range(3))
70+
for ell in range(3)
71+
])
72+
else:
73+
return make_obj_array([
74+
helmholtz_vec(())[i]
75+
+ 1/helm_k**2 * sum(
76+
helmholtz_vec((outer(i, j), inner(i, j)))[j]
77+
for j in range(3))
78+
for i in range(3)])
79+
80+
81+
def test_dyadic_green(actx_factory):
82+
actx = actx_factory()
83+
84+
helm_k = sym.var("k")
85+
trace_e = sym.make_sym_vector("trace_e", 3)
86+
trace_curl_e = sym.make_sym_vector("trace_curl_e", 3)
87+
88+
normal = sym.normal(3).as_vector()
89+
90+
nxe = sym.cross(normal, trace_e)
91+
nxcurl_e = sym.cross(normal, trace_curl_e)
92+
93+
# Monk, Finite element methods for Maxwell's equations (2003)
94+
# https://doi.org/10.1093/acprof:oso/9780198508885.001.0001
95+
# Theorem 12.2.
96+
zero_op = (dyadic_layer_pot(helm_k, nxe, transpose=True)
97+
+ dyadic_layer_pot(helm_k, nxcurl_e, transpose=True, source_curl=True)
98+
- trace_e)
99+
100+
print(sym.pretty(zero_op))
101+
102+
103+
104+
# You can test individual routines by typing
105+
# $ python test_maxwell_green.py 'test_routine()'
106+
107+
if __name__ == "__main__":
108+
import sys
109+
if len(sys.argv) > 1:
110+
exec(sys.argv[1])
111+
else:
112+
from pytest import main
113+
main([__file__])
114+
115+
# vim: fdm=marker

0 commit comments

Comments
 (0)