diff options
author | 2021-04-27 20:18:11 +0200 | |
---|---|---|
committer | 2021-04-27 11:18:11 -0700 | |
commit | e92cb5cdd62e65e502945cd8205d399ef274edfc (patch) | |
tree | 8c39d623e9a5907f08294d9dd488d85cbe240d44 /Examples/Modules/embedded_boundary_cube/analysis_fields.py | |
parent | 5035351505823a0f2ba4070434453746064589cc (diff) | |
download | WarpX-e92cb5cdd62e65e502945cd8205d399ef274edfc.tar.gz WarpX-e92cb5cdd62e65e502945cd8205d399ef274edfc.tar.zst WarpX-e92cb5cdd62e65e502945cd8205d399ef274edfc.zip |
Staircased embedded boundaries in the YEE solver (#1881)
* Added staircased embedded boundaris to the YEE solver
* adding spherical resonating cavity test
* adding functions for fields initialization
* style adjustments
* fixing tabs
* fixed name of analysis script
* fixed name of analysis script
* fixed a few wrong preprocessor directives
* workaround for missing boost
* Revert "workaround for missing boost"
This reverts commit 601f9eb2ec6f8c2100304379b2bea1c6cf9d1851.
* another workaround for missing boost
* getting rid of boost by depending on c++17
* Removed a few unused variables
* adding USE_EB to addToCompileString for EB testing
* removed tabs
* fixing the inputs name for EB sphere test
* shortened the test
* zero padding the names of the images
* adjusted two for loops
* removed some unused variables
* improving the fields initialization
* removed the sphere test and implemented the cube test
* fixed edges lengths computation and added comments
* Fixed the case of all_regular geometries
* fixing a bug that was breaking some tests
* adding test folder
* fixed the default values for the EB cube test
* simplified the analysis script
* fixed cubic resonator default results
* inputting the plot file name from command line
* fixing the diag name
* Fixed a bug in edges initialization
Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
* Adding comments to the staircased yee solver (thanks Remi)
Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
* fixed the cube resonator test
* removed an unused import
Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
Diffstat (limited to 'Examples/Modules/embedded_boundary_cube/analysis_fields.py')
-rw-r--r-- | Examples/Modules/embedded_boundary_cube/analysis_fields.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Examples/Modules/embedded_boundary_cube/analysis_fields.py b/Examples/Modules/embedded_boundary_cube/analysis_fields.py new file mode 100644 index 000000000..58dad1bb7 --- /dev/null +++ b/Examples/Modules/embedded_boundary_cube/analysis_fields.py @@ -0,0 +1,86 @@ +#! /usr/bin/env python + +import yt +import os, sys +from scipy.constants import mu_0, pi, c +import numpy as np +sys.path.insert(1, '../../../../warpx/Regression/Checksum/') +import checksumAPI + +# This is a script that analyses the simulation results from +# the script `inputs_3d`. This simulates a TMmnp mode in a PEC cubic resonator. +# The magnetic field in the simulation is given (in theory) by: +# $$ B_x = \frac{-2\mu}{h^2}\, k_x k_z \sin(k_x x)\cos(k_y y)\cos(k_z z)\cos( \omega_p t)$$ +# $$ B_y = \frac{-2\mu}{h^2}\, k_y k_z \cos(k_x x)\sin(k_y y)\cos(k_z z)\cos( \omega_p t)$$ +# $$ B_z = \cos(k_x x)\cos(k_y y)\sin(k_z z)\sin( \omega_p t)$$ +# with +# $$ h^2 = k_x^2 + k_y^2 + k_z^2$$ +# $$ k_x = \frac{m\pi}{L}$$ +# $$ k_y = \frac{n\pi}{L}$$ +# $$ k_z = \frac{p\pi}{L}$$ + +hi = [0.8, 0.8, 0.8] +lo = [-0.8, -0.8, -0.8] +ncells = [48, 48, 48] +dx = (hi[0] - lo[0])/ncells[0] +dy = (hi[1] - lo[1])/ncells[1] +dz = (hi[2] - lo[2])/ncells[2] +m = 0 +n = 1 +p = 1 +Lx = 1 +Ly = 1 +Lz = 1 +h_2 = (m * pi / Lx) ** 2 + (n * pi / Ly) ** 2 + (p * pi / Lz) ** 2 +t = 1.3342563807926085e-08 + +# Compute the analytic solution +Bx_th = np.zeros(ncells) +By_th = np.zeros(ncells) +Bz_th = np.zeros(ncells) +for i in range(ncells[0]): + for j in range(ncells[1]): + for k in range(ncells[2]): + x = i*dx + lo[0] + y = (j+0.5)*dy + lo[1] + z = k*dz + lo[2] + + By_th[i, j, k] = -2/h_2*mu_0*(n * pi/Ly)*(p * pi/Lz) * (np.cos(m * pi/Lx * (x - Lx/2)) * + np.sin(n * pi/Ly * (y - Ly/2)) * + np.cos(p * pi/Lz * (z - Lz/2)) * + (-Lx/2 <= x < Lx/2) * + (-Ly/2 <= y < Ly/2) * + (-Lz/2 <= z < Lz/2) * + np.cos(np.sqrt(2) * + np.pi / Lx * c * t)) + + x = i*dx + lo[0] + y = j*dy + lo[1] + z = (k+0.5)*dz + lo[2] + Bz_th[i, j, k] = mu_0*(np.cos(m * pi/Lx * (x - Lx/2)) * + np.cos(n * pi/Ly * (y - Ly/2)) * + np.sin(p * pi/Lz * (z - Lz/2)) * + (-Lx/2 <= x < Lx/2) * + (-Ly/2 <= y < Ly/2) * + (-Lz/2 <= z < Lz/2) * + np.cos(np.sqrt(2) * np.pi / Lx * c * t)) + +# Open the right plot file +filename = sys.argv[1] +ds = yt.load(filename) +data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) + +rel_tol_err = 1e-1 + +# Compute relative l^2 error on By +By_sim = data['By'].to_ndarray() +rel_err_y = np.sqrt( np.sum(np.square(By_sim - By_th)) / np.sum(np.square(By_th))) +assert(rel_err_y < rel_tol_err) +# Compute relative l^2 error on Bz +Bz_sim = data['Bz'].to_ndarray() +rel_err_z = np.sqrt( np.sum(np.square(Bz_sim - Bz_th)) / np.sum(np.square(Bz_th))) +assert(rel_err_z < rel_tol_err) + +test_name = os.path.split(os.getcwd())[1] + +checksumAPI.evaluate_checksum(test_name, filename) |