-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reduced diagnostic: 2d differential luminosity #5545
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
22ed239
add diff lumi diag 2d
aeriforme d6b92de
add test
aeriforme 0115971
moved device vector, rm openpmd setUnitsSI
aeriforme 46d51a2
changed units and test
aeriforme c656457
add docs
aeriforme bfc77fb
update test
aeriforme 95aedcf
cleanup docs
aeriforme a5be100
clean up and adjust tolerances
aeriforme c180e20
Merge branch 'development' of github.com:ECP-WarpX/WarpX into 2d_lumi…
aeriforme 88bc562
Merge branch 'development' into 2d_luminosity
RemiLehe d789516
Made stronger test
RemiLehe 5a8963e
Clean up Python file
RemiLehe 381619c
Increase tolerance
RemiLehe 7648c77
Increase tolerance
RemiLehe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,20 @@ | |
# In that case, the differential luminosity can be calculated analytically. | ||
|
||
import os | ||
import re | ||
|
||
import numpy as np | ||
from read_raw_data import read_reduced_diags_histogram | ||
from openpmd_viewer import OpenPMDTimeSeries | ||
|
||
# Extract the differential luminosity from the file | ||
_, _, E_bin, bin_data = read_reduced_diags_histogram( | ||
"./diags/reducedfiles/DifferentialLuminosity_beam1_beam2.txt" | ||
) | ||
dL_dE_sim = bin_data[-1] # Differential luminosity at the end of the simulation | ||
# Extract the 1D differential luminosity from the file | ||
filename = "./diags/reducedfiles/DifferentialLuminosity_beam1_beam2.txt" | ||
with open(filename) as f: | ||
# First line: header, contains the energies | ||
line = f.readline() | ||
E_bin = np.array(list(map(float, re.findall("=(.*?)\(", line)))) | ||
data = np.loadtxt(filename) | ||
dE_bin = E_bin[1] - E_bin[0] | ||
dL_dE_sim = data[-1, 2:] # Differential luminosity at the end of the simulation | ||
|
||
# Beam parameters | ||
N = 1.2e10 | ||
|
@@ -33,21 +38,37 @@ | |
* np.exp(-((E_bin - 2 * E_beam) ** 2) / (2 * sigma_E**2)) | ||
) | ||
|
||
# Extract the 2D differential luminosity from the file | ||
series = OpenPMDTimeSeries("./diags/reducedfiles/DifferentialLuminosity2d_beam1_beam2/") | ||
d2L_dE1_dE2, info = series.get_field("d2L_dE1_dE2", iteration=80) | ||
dE1, dE2 = info.dE1, info.dE2 | ||
|
||
|
||
# Extract test name from path | ||
test_name = os.path.split(os.getcwd())[1] | ||
print("test_name", test_name) | ||
|
||
# Pick tolerance | ||
if "leptons" in test_name: | ||
tol = 1e-2 | ||
tol1 = 0.02 | ||
tol2 = 0.003 | ||
elif "photons" in test_name: | ||
# In the photons case, the particles are | ||
# initialized from a density distribution ; | ||
# tolerance is larger due to lower particle statistics | ||
tol = 6e-2 | ||
tol1 = 0.02 | ||
tol2 = 0.003 | ||
|
||
# Check that the 1D diagnostic and analytical result match | ||
error1 = abs(dL_dE_sim - dL_dE_th).max() / abs(dL_dE_th).max() | ||
print("Relative error: ", error1) | ||
print("Tolerance: ", tol1) | ||
|
||
# Check that the 2D and 1D diagnostics match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, a stronger test would be to compute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. |
||
error2 = abs(np.sum(d2L_dE1_dE2) * dE2 * dE1 - np.sum(dL_dE_sim) * dE_bin) / abs( | ||
np.sum(dL_dE_sim) * dE_bin | ||
) | ||
print("Relative error: ", error2) | ||
print("Tolerance: ", tol2) | ||
|
||
# Check that the simulation result and analytical result match | ||
error = abs(dL_dE_sim - dL_dE_th).max() / abs(dL_dE_th).max() | ||
print("Relative error: ", error) | ||
print("Tolerance: ", tol) | ||
assert error < tol | ||
assert error1 < tol1 | ||
assert error2 < tol2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Source/Diagnostics/ReducedDiags/DifferentialLuminosity2D.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* Copyright 2023 The WarpX Community | ||
* | ||
* This file is part of WarpX. | ||
* | ||
* Authors: Arianna Formenti, Remi Lehe | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
|
||
#ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY2D_H_ | ||
#define WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY2D_H_ | ||
|
||
#include "ReducedDiags.H" | ||
#include <AMReX_GpuContainers.H> | ||
#include <AMReX_TableData.H> | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
/** | ||
* This class contains the differential luminosity diagnostics. | ||
*/ | ||
class DifferentialLuminosity2D : public ReducedDiags | ||
{ | ||
public: | ||
|
||
/** | ||
* constructor | ||
* @param[in] rd_name reduced diags names | ||
*/ | ||
DifferentialLuminosity2D(const std::string& rd_name); | ||
|
||
/// File type | ||
std::string m_openpmd_backend {"default"}; | ||
|
||
/// minimum number of digits for file suffix (file-based only supported for now) */ | ||
int m_file_min_digits = 6; | ||
|
||
/// name of the two colliding species | ||
std::vector<std::string> m_beam_name; | ||
|
||
/// number of bins for the c.o.m. energy of the 2 species | ||
int m_bin_num_1; | ||
int m_bin_num_2; | ||
|
||
/// max and min bin values | ||
amrex::Real m_bin_max_1; | ||
amrex::Real m_bin_min_1; | ||
amrex::Real m_bin_max_2; | ||
amrex::Real m_bin_min_2; | ||
|
||
/// bin size | ||
amrex::Real m_bin_size_1; | ||
amrex::Real m_bin_size_2; | ||
|
||
/// output data | ||
amrex::TableData<amrex::Real,2> m_h_data_2D; | ||
|
||
void ComputeDiags(int step) final; | ||
|
||
void WriteToFile (int step) const final; | ||
|
||
private: | ||
|
||
/// output table in which to accumulate the luminosity across timesteps | ||
amrex::TableData<amrex::Real,2> m_d_data_2D; | ||
|
||
}; | ||
|
||
#endif // WARPX_DIAGNOSTICS_REDUCEDDIAGS_DIFFERENTIALLUMINOSITY2D_H_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change intentional? It seems unrelated to the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intentional.
This example requires the compilation flag
-DWarpX_FFT=ON
.Without this, the related
ctest
would fail.Note that this has not been a problem in CI so far because the FFT compilation flag is on.