aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/electrostatic_dirichlet_bc/analysis.py
blob: eae2f17243c0784444497859ff697d7ce3ca01ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3

# 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 glob

import numpy as np
import yt

files = sorted(glob.glob('dirichletbc_plt*'))[1:]
if len(files) == 0:
    files = sorted(glob.glob('Python_dirichletbc_plt*'))[1:]
assert len(files) > 0

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()
    )
    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)