Skip to content

Commit 5a4a3ba

Browse files
committed
Fix review findings and add comprehensive EM test coverage
Address 6 findings from review-2.md: - Fix incorrect L1 convergence norm (|a|-|b| to |a-b|) in elliptic chapter and source - Fix brittle test pattern in test_docs_consistency.py using regex - Fix exact solution/BC mismatch in Laplace convergence test (x*y/Lx to x/Lx) - Fix PDF download link in index.qmd - Remove ghost bibliography entry (devito-compiler) Add EM module source and comprehensive test suite (502 tests total): - src/em/ modules: materials, waveguide, GPR, Maxwell 1D/2D, units, verification - test_elliptic_src.py: 41 tests for all elliptic solver functions - test_em_materials.py: 42 tests for material models and soil functions - test_em_waveguide.py: 24 tests for slab waveguide mode analysis - test_em_gpr.py: 22 tests for GPR wavelets, travel time, and simulation - test_maxwell1D_devito.py: 32 tests including lossy, dispersive, ABC, PMC, source - test_maxwell2D_devito.py: 23 tests for 2D FDTD with PML, lossy, dispersive media Fix SparseTimeFunction broadcast bug in maxwell1D source injection.
1 parent d04eb9a commit 5a4a3ba

23 files changed

Lines changed: 7181 additions & 26 deletions

chapters/elliptic/elliptic.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ while l1norm > l1norm_target:
304304
op(p=_p, pn=_pn)
305305
306306
# Compute L1 norm
307-
l1norm = (np.sum(np.abs(_p.data[:]) - np.abs(_pn.data[:])) /
307+
l1norm = (np.sum(np.abs(_p.data[:] - _pn.data[:])) /
308308
np.sum(np.abs(_pn.data[:])))
309309
counter += 1
310310
@@ -387,7 +387,7 @@ def solve_laplace_2d(nx, ny, extent, l1norm_target=1e-4):
387387
388388
op(p=_p, pn=_pn)
389389
390-
l1norm = (np.sum(np.abs(_p.data[:]) - np.abs(_pn.data[:])) /
390+
l1norm = (np.sum(np.abs(_p.data[:] - _pn.data[:])) /
391391
np.sum(np.abs(_pn.data[:])))
392392
counter += 1
393393
@@ -723,7 +723,7 @@ impractical for fine grids.
723723
724724
The L1 norm we use measures relative change:
725725
$$
726-
L_1^{(k)} = \frac{\sum_{i,j} |p_{i,j}^{(k+1)}| - |p_{i,j}^{(k)}|}{\sum_{i,j} |p_{i,j}^{(k)}|}
726+
L_1^{(k)} = \frac{\sum_{i,j} |p_{i,j}^{(k+1)} - p_{i,j}^{(k)}|}{\sum_{i,j} |p_{i,j}^{(k)}|}
727727
$$
728728
729729
A more rigorous metric is the residual norm:
@@ -794,7 +794,7 @@ def solve_laplace_with_history(nx, ny, max_iter=5000, l1norm_target=1e-6):
794794
795795
op(p=_p, pn=_pn)
796796
797-
l1norm = (np.sum(np.abs(_p.data[:]) - np.abs(_pn.data[:])) /
797+
l1norm = (np.sum(np.abs(_p.data[:] - _pn.data[:])) /
798798
np.sum(np.abs(_pn.data[:])))
799799
l1_history.append(l1norm)
800800
counter += 1

index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This book teaches finite difference methods for solving partial differential equations, featuring [Devito](https://www.devitoproject.org/) for high-performance PDE solvers.
44

55
::: {.content-visible when-format="html"}
6-
[**Download PDF version**](book.pdf){.btn .btn-primary}
6+
[**Download PDF version**](Finite-Difference-Computing-with-PDEs.pdf){.btn .btn-primary}
77
:::
88

99
## About this Edition {.unnumbered}

references.bib

Lines changed: 200 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,6 @@ @article{devito-api
563563
doi = {10.1145/3374916}
564564
}
565565

566-
@article{devito-compiler,
567-
author = {Fabio Luporini and Michael Lange and Mathias Louboutin and Navjot Kukreja and Jan H{\"u}ckelheim and Charles Yount and Philipp Witte and Paul H. J. Kelly and Gerard J. Gorman and Felix J. Herrmann},
568-
title = {{Architecture and Performance of Devito, a System for Automated Stencil Computation}},
569-
journal = {Geoscientific Model Development},
570-
year = {2019},
571-
volume = {12},
572-
pages = {1165--1187},
573-
doi = {10.5194/gmd-12-1165-2019}
574-
}
575-
576566
@misc{devito-github,
577567
author = {{Devito Development Team}},
578568
title = {{Devito}: Symbolic Finite Difference Computation},
@@ -589,3 +579,203 @@ @article{devito-seismic
589579
pages = {1165--1187},
590580
doi = {10.5194/gmd-12-1165-2019}
591581
}
582+
583+
% =============================================================================
584+
% Electromagnetics / FDTD References
585+
% =============================================================================
586+
587+
@article{yee1966,
588+
author = {K. S. Yee},
589+
title = {Numerical solution of initial boundary value problems involving {Maxwell's} equations in isotropic media},
590+
journal = {IEEE Transactions on Antennas and Propagation},
591+
year = {1966},
592+
volume = {14},
593+
number = {3},
594+
pages = {302--307},
595+
doi = {10.1109/TAP.1966.1138693}
596+
}
597+
598+
@article{taflove_brodwin1975,
599+
author = {A. Taflove and M. E. Brodwin},
600+
title = {Numerical solution of steady-state electromagnetic scattering problems using the time-dependent {Maxwell's} equations},
601+
journal = {IEEE Transactions on Microwave Theory and Techniques},
602+
year = {1975},
603+
volume = {23},
604+
number = {8},
605+
pages = {623--630},
606+
doi = {10.1109/TMTT.1975.1128640}
607+
}
608+
609+
@article{taflove1980,
610+
author = {A. Taflove},
611+
title = {Application of the finite-difference time-domain method to sinusoidal steady-state electromagnetic-penetration problems},
612+
journal = {IEEE Transactions on Electromagnetic Compatibility},
613+
year = {1980},
614+
volume = {22},
615+
number = {3},
616+
pages = {191--202},
617+
doi = {10.1109/TEMC.1980.303879}
618+
}
619+
620+
@book{taflove2005,
621+
author = {A. Taflove and S. C. Hagness},
622+
title = {Computational Electrodynamics: The Finite-Difference Time-Domain Method},
623+
publisher = {Artech House},
624+
year = {2005},
625+
edition = {third}
626+
}
627+
628+
@article{berenger1994,
629+
author = {J.-P. Berenger},
630+
title = {A perfectly matched layer for the absorption of electromagnetic waves},
631+
journal = {Journal of Computational Physics},
632+
year = {1994},
633+
volume = {114},
634+
pages = {185--200},
635+
doi = {10.1006/jcph.1994.1159}
636+
}
637+
638+
@article{roden_gedney2000,
639+
author = {J. A. Roden and S. D. Gedney},
640+
title = {Convolution {PML} ({CPML}): An efficient {FDTD} implementation of the {CFS-PML} for arbitrary media},
641+
journal = {Microwave and Optical Technology Letters},
642+
year = {2000},
643+
volume = {27},
644+
number = {5},
645+
pages = {334--339},
646+
doi = {10.1002/1098-2760(20001205)27:5<334::AID-MOP14>3.0.CO;2-A}
647+
}
648+
649+
@article{monk_suli1994,
650+
author = {P. Monk and E. S\"uli},
651+
title = {Error estimates for {Yee's} method on non-uniform grids},
652+
journal = {IEEE Transactions on Magnetics},
653+
year = {1994},
654+
volume = {30},
655+
number = {5},
656+
pages = {3200--3203},
657+
doi = {10.1109/20.312618}
658+
}
659+
660+
@article{trefethen1982,
661+
author = {L. N. Trefethen},
662+
title = {Group velocity in finite difference schemes},
663+
journal = {SIAM Review},
664+
year = {1982},
665+
volume = {24},
666+
number = {2},
667+
pages = {113--136},
668+
doi = {10.1137/1024038}
669+
}
670+
671+
@book{sullivan2020,
672+
author = {D. M. Sullivan},
673+
title = {Electromagnetic Simulation Using the {FDTD} Method with {Python}},
674+
publisher = {Wiley-IEEE Press},
675+
year = {2020},
676+
edition = {third}
677+
}
678+
679+
@book{inan_marshall2011,
680+
author = {U. S. Inan and R. A. Marshall},
681+
title = {Numerical Electromagnetics: The {FDTD} Method},
682+
publisher = {Cambridge University Press},
683+
year = {2011}
684+
}
685+
686+
@book{griffiths_electrodynamics,
687+
author = {D. J. Griffiths},
688+
title = {Introduction to Electrodynamics},
689+
publisher = {Cambridge University Press},
690+
year = {2017},
691+
edition = {fourth}
692+
}
693+
694+
@book{roache2009,
695+
author = {P. J. Roache},
696+
title = {Fundamentals of Verification and Validation},
697+
publisher = {Hermosa Publishers},
698+
year = {2009}
699+
}
700+
701+
@book{bohren_huffman1983,
702+
author = {C. F. Bohren and D. R. Huffman},
703+
title = {Absorption and Scattering of Light by Small Particles},
704+
publisher = {Wiley},
705+
year = {1983}
706+
}
707+
708+
@article{warren2016_gprmax,
709+
author = {C. Warren and A. Giannopoulos and I. Giannakis},
710+
title = {{gprMax}: Open source software to simulate electromagnetic wave propagation for Ground Penetrating Radar},
711+
journal = {Computer Physics Communications},
712+
year = {2016},
713+
volume = {209},
714+
pages = {163--170},
715+
doi = {10.1016/j.cpc.2016.08.020}
716+
}
717+
718+
@article{giannopoulos2005_gprmax,
719+
author = {A. Giannopoulos},
720+
title = {Modelling ground penetrating radar by {GprMax}},
721+
journal = {Construction and Building Materials},
722+
year = {2005},
723+
volume = {19},
724+
number = {10},
725+
pages = {755--762},
726+
doi = {10.1016/j.conbuildmat.2005.06.007}
727+
}
728+
729+
@article{yefet_petropoulos2001,
730+
author = {A. Yefet and P. G. Petropoulos},
731+
title = {A staggered fourth-order accurate explicit finite difference scheme for the time-domain {Maxwell's} equations},
732+
journal = {Journal of Computational Physics},
733+
year = {2001},
734+
volume = {168},
735+
number = {2},
736+
pages = {286--315},
737+
doi = {10.1006/jcph.2001.6691}
738+
}
739+
740+
% Clayton-Engquist and Higdon ABC references
741+
@article{clayton_engquist1977,
742+
author = {R. Clayton and B. Engquist},
743+
title = {Absorbing boundary conditions for acoustic and elastic wave equations},
744+
journal = {Bulletin of the Seismological Society of America},
745+
year = {1977},
746+
volume = {67},
747+
number = {6},
748+
pages = {1529--1540}
749+
}
750+
751+
@article{enquist_majda1977,
752+
author = {B. Engquist and A. Majda},
753+
title = {Absorbing boundary conditions for the numerical simulation of waves},
754+
journal = {Mathematics of Computation},
755+
year = {1977},
756+
volume = {31},
757+
pages = {629--651},
758+
doi = {10.1090/S0025-5718-1977-0436612-4}
759+
}
760+
761+
@article{higdon1986,
762+
author = {R. L. Higdon},
763+
title = {Absorbing boundary conditions for difference approximations to the multi-dimensional wave equation},
764+
journal = {Mathematics of Computation},
765+
year = {1986},
766+
volume = {47},
767+
number = {176},
768+
pages = {437--459},
769+
doi = {10.1090/S0025-5718-1986-0856696-4}
770+
}
771+
772+
@article{higdon1987,
773+
author = {R. L. Higdon},
774+
title = {Numerical absorbing boundary conditions for the wave equation},
775+
journal = {Mathematics of Computation},
776+
year = {1987},
777+
volume = {49},
778+
number = {179},
779+
pages = {65--90},
780+
doi = {10.1090/S0025-5718-1987-0890254-1}
781+
}

src/elliptic/laplace_devito.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ def solve_laplace_2d(
269269
# Compute L1 norm for convergence check
270270
denom = np.sum(np.abs(_pn.data[:]))
271271
if denom > 1e-15:
272-
l1norm = np.sum(np.abs(_p.data[:]) - np.abs(_pn.data[:])) / denom
272+
l1norm = np.sum(np.abs(_p.data[:] - _pn.data[:])) / denom
273273
else:
274-
l1norm = np.sum(np.abs(_p.data[:]) - np.abs(_pn.data[:]))
274+
l1norm = np.sum(np.abs(_p.data[:] - _pn.data[:]))
275275

276276
l1norm = abs(l1norm)
277277
iteration += 1
@@ -505,9 +505,9 @@ def solve_laplace_2d_with_copy(
505505
# Compute L1 norm
506506
denom = np.sum(np.abs(pn.data[:]))
507507
if denom > 1e-15:
508-
l1norm = np.sum(np.abs(p.data[:]) - np.abs(pn.data[:])) / denom
508+
l1norm = np.sum(np.abs(p.data[:] - pn.data[:])) / denom
509509
else:
510-
l1norm = np.sum(np.abs(p.data[:]) - np.abs(pn.data[:]))
510+
l1norm = np.sum(np.abs(p.data[:] - pn.data[:]))
511511

512512
l1norm = abs(l1norm)
513513
iteration += 1
@@ -534,10 +534,10 @@ def exact_laplace_linear(
534534
535535
For the boundary conditions:
536536
p = 0 at x = 0
537-
p = y at x = Lx
537+
p = 1 at x = Lx
538538
dp/dy = 0 at y = 0 and y = Ly
539539
540-
The exact solution is p(x, y) = x * y / Lx
540+
The exact solution is p(x, y) = x / Lx
541541
542542
Parameters
543543
----------
@@ -555,7 +555,7 @@ def exact_laplace_linear(
555555
np.ndarray
556556
Exact solution at (x, y)
557557
"""
558-
return X * Y / Lx
558+
return X / Lx
559559

560560

561561
def convergence_test_laplace_2d(
@@ -591,7 +591,7 @@ def convergence_test_laplace_2d(
591591
Lx=Lx, Ly=Ly,
592592
Nx=N, Ny=N,
593593
bc_left=0.0,
594-
bc_right=lambda y: y,
594+
bc_right=1.0,
595595
bc_bottom="neumann",
596596
bc_top="neumann",
597597
tol=tol,

0 commit comments

Comments
 (0)