forked from BLAST-WarpX/warpx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis.py
executable file
·38 lines (30 loc) · 1.18 KB
/
analysis.py
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
#!/usr/bin/env python3
# Copyright 2024, Remi Lehe
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL
# This script tests the conservation of energy for a thermal plasma with periodic boundary.
# Here, we use energy-converving gather and an electrostatic solver. The energy
# is not expected to be exactly conserved, but it is expected to be better conserved
# than other gathering scheme. This tests checks that the energy does not increase by
# more than 0.3% over the duration of the simulatoin.
import os
import sys
import numpy as np
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
# this will be the name of the plot file
fn = sys.argv[1]
# Get energy as a function of time, from reduced diagnostics
EFdata = np.genfromtxt('./diags/reducedfiles/EF.txt') # Field energy
EPdata = np.genfromtxt('./diags/reducedfiles/EP.txt') # Particle energy
field_energy = EFdata[:,2]
particle_energy = EPdata[:,2]
E = field_energy + particle_energy
print(abs(E-E[0])/E[0])
# Check that the energy is conserved to 0.3%
assert np.all( abs(E-E[0])/E[0] < 0.003 )
# Checksum test
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, fn)