From 5e1b4f4f694396df21b32f09bbccc74235bf861a Mon Sep 17 00:00:00 2001 From: Lorenzo Giacomel <47607756+lgiacome@users.noreply.github.com> Date: Fri, 12 Nov 2021 22:02:03 +0100 Subject: 2D EM solver with EB (#2401) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding the FieldProbe * adding missing file * updating makefile * fixing host-device problem * Revert "fixing host-device problem" This reverts commit 801e6fc47f19cfc42ec46e5ef1a18dcf86be3e5a. * fixing host-device problem * making some variables const * adding a few comments * Adding the FieldProbe to the documentation * making the probe mpi-safe * added field probe to reduced diag test * added field probe to reduced diag analysis * using cell-centered fields in probe diag * removed a few typos * Interpolating to the point instead oof cell center * bug fix * improved a comment * updated documentation * Undone an outdated change * improving some variable names * improving the box extraction * making the interpolation order an input parameter * fix a typo * setting the field values to zero if the point is not in the domain * skipping the communication if probe proc is IO prcessor * Fixed typo in documentation Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com> * Updating an header * Added a comment on the probe position * tidying up the analysis script * fixed a comment * removing an unused include * improving the parsing of parameters * fixing some comments * making some variables const * changed some ParticleReal into Real * using better tags in MPI communication * Making field probe work in 2D * making a variable const * initializing y_probe only in 3D * tidying up a line which is common to 2D and 3D * making a variable constexpr * adding a _rt * checking that the probe location is in one of the processors * removing a useless if condition * Fixing the initialization in 2D * Avoiding scrape particles in 2D (it segfaults) * Adding a test for 2D EB * Fixed the areas initialization * Initializing to zero some multifabs * Modified the ECT solver to make it work in 2D * Modified the cell extensions to make them work in 2D * Improved 2D cube test * Added 2D rotated cube test * Adding the 2d analysis script and CI * Removed an unused import from the analysis script * Ignoring some unused variables * Fixing the number of dimensions in the 2d test * Added missing analysis for ECT * Enabled again 2d particles scraping * Fixing the test_name with the general logic * Fixing the test_name with the general logic * Removed some commented code * Modified several preprocessor directives to check consistency EB-dimension * Added missing semicolons * Fixed a preprocessor directivew * Fix typo: WARPX_DIM_XZ * Improving some comments Co-authored-by: Axel Huebl * Adding some more consistency checks * Adding some more consistency checks * Fixed a typo Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com> Co-authored-by: Axel Huebl --- .../embedded_boundary_cube/analysis_fields_2d.py | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 Examples/Modules/embedded_boundary_cube/analysis_fields_2d.py (limited to 'Examples/Modules/embedded_boundary_cube/analysis_fields_2d.py') diff --git a/Examples/Modules/embedded_boundary_cube/analysis_fields_2d.py b/Examples/Modules/embedded_boundary_cube/analysis_fields_2d.py new file mode 100755 index 000000000..ebf303601 --- /dev/null +++ b/Examples/Modules/embedded_boundary_cube/analysis_fields_2d.py @@ -0,0 +1,60 @@ +#! /usr/bin/env python + +import yt +import os +import 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_y = \mu \cos(k_x x)\cos(k_z z)\cos( \omega_p t)$$ +# with +# $$ k_x = \frac{m\pi}{L}$$ +# $$ k_y = \frac{n\pi}{L}$$ +# $$ k_z = \frac{p\pi}{L}$$ + +hi = [0.8, 0.8] +lo = [-0.8, -0.8] +ncells = [32, 32, 1] +dx = (hi[0] - lo[0]) / ncells[0] +dz = (hi[1] - lo[1]) / ncells[1] +m = 0 +n = 1 +Lx = 1 +Lz = 1 + +# 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) + +t = ds.current_time.to_value() + +# Compute the analytic solution +By_th = np.zeros(ncells) +for i in range(ncells[0]): + for j in range(ncells[1]): + x = (i+0.5) * dx + lo[0] + z = (j+0.5) * dz + lo[1] + + By_th[i, j, 0] = mu_0 * (np.cos(m * pi / Lx * (x - Lx / 2)) * + np.cos(n * pi / Lz * (z - Lz / 2)) * + (-Lx / 2 <= x < Lx / 2) * + (-Lz / 2 <= z < Lz / 2) * + np.cos(np.pi / Lx * c * t)) + +rel_tol_err = 1e-3 + +# 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) + +test_name = os.path.split(os.getcwd())[1] + +checksumAPI.evaluate_checksum(test_name, filename) -- cgit v1.2.3