diff options
Diffstat (limited to 'Examples/Tests/ElectrostaticDirichletBC/analysis.py')
-rwxr-xr-x | Examples/Tests/ElectrostaticDirichletBC/analysis.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Examples/Tests/ElectrostaticDirichletBC/analysis.py b/Examples/Tests/ElectrostaticDirichletBC/analysis.py new file mode 100755 index 000000000..b08c993c9 --- /dev/null +++ b/Examples/Tests/ElectrostaticDirichletBC/analysis.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python + +# Copyright 2021 Roelof Groenewald + +# This script tests the time dependent Dirichlet boundary +# conditions in a 2D electrostatic simulation. An empty +# domain of 64 x 8 cells is simulated with periodic boundary +# conditions in the x directions and Dirichlet boundary +# conditions in the y direction with specified potentials +# of sine waves with different periods on the lo and hi side. +# One period of the hi side sine wave is simulated and the +# potentials at the boundaries compared to expectation. + +# Possible running time: ~ 19 s + +import numpy as np + +import yt +import glob + +files = sorted(glob.glob('dirichletbc_plt*'))[1:] + +times = np.ones(len(files)) +potentials_lo = np.zeros(len(files)) +potentials_hi = np.zeros(len(files)) + +for ii, file in enumerate(files): + ds = yt.load( file ) + times[ii] = ( + ds.current_time.item() - float(ds.parameters.get('warpx.const_dt')) + ) + data = ds.covering_grid( + level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions + ) + potentials_lo[ii] = np.mean(data['phi'].to_ndarray()[0]) + potentials_hi[ii] = np.mean(data['phi'].to_ndarray()[-1]) + +expected_potentials_lo = 150.0 * np.sin(2.0 * np.pi * 6.78e6 * times) +expected_potentials_hi = 450.0 * np.sin(2.0 * np.pi * 13.56e6 * times) + +assert np.allclose(potentials_lo, expected_potentials_lo, rtol=0.1) +assert np.allclose(potentials_hi, expected_potentials_hi, rtol=0.1) |