Skip to content

[WIP] Add a Radiation module #4523

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

Open
wants to merge 69 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9df2a10
first_step
tmsclark Dec 4, 2023
3fc03cb
update
tmsclark Dec 4, 2023
a9728a5
.
tmsclark Dec 5, 2023
2f3384e
.
tmsclark Dec 5, 2023
f52b7f6
.
tmsclark Dec 5, 2023
b6a3b1c
.
tmsclark Dec 6, 2023
abdde48
.
tmsclark Dec 6, 2023
03898e9
.
tmsclark Dec 6, 2023
0e82d55
.
tmsclark Dec 7, 2023
c3bf08a
.
tmsclark Dec 7, 2023
7db336a
.
tmsclark Dec 15, 2023
c84b257
.
tmsclark Dec 15, 2023
002e66e
.
tmsclark Dec 15, 2023
b8a2aa8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2023
be0ae47
use false insteand of 0 for bool
lucafedeli88 Dec 15, 2023
2e4b9f8
remove radiation flag from warpx class
lucafedeli88 Dec 15, 2023
091b68b
remove Utils/Math/Complex.H
lucafedeli88 Dec 15, 2023
4c4397f
move WarpX_Complex.H into ablastr
lucafedeli88 Dec 15, 2023
5ca0281
fix bugs
lucafedeli88 Dec 15, 2023
08b34f6
Merge pull request #2 from lucafedeli88/improve_radiation_module
tmsclark2 Dec 15, 2023
05eec99
remove unused function
lucafedeli88 Dec 15, 2023
8ca7b6a
removed comments
lucafedeli88 Dec 15, 2023
706ca3b
using forward declaration for radiation module
lucafedeli88 Dec 15, 2023
dc26412
remove unused includes
lucafedeli88 Dec 15, 2023
0c2f68e
remove text message
lucafedeli88 Dec 15, 2023
6e50dc4
refactoring
lucafedeli88 Dec 15, 2023
6e3dde3
fixed bug
lucafedeli88 Dec 15, 2023
f57bf3b
Merge pull request #3 from lucafedeli88/improve_radiation_module_2
tmsclark2 Dec 15, 2023
2282ebd
cleaning
lucafedeli88 Dec 18, 2023
99c42ab
continue cleaning
lucafedeli88 Dec 19, 2023
5f11973
refactoring
lucafedeli88 Dec 19, 2023
364ab03
Merge pull request #4 from lucafedeli88/improve_radiation_reaction_III
tmsclark2 Dec 20, 2023
31bb585
fix issue with headers
lucafedeli88 Dec 20, 2023
cd4db39
added missing include
lucafedeli88 Dec 20, 2023
9f6087a
fix bugs
lucafedeli88 Dec 20, 2023
3500334
fixed bugs
lucafedeli88 Dec 20, 2023
8465c79
fixed bugs
lucafedeli88 Dec 20, 2023
2e52122
fixed bugs
lucafedeli88 Dec 20, 2023
58f75bc
fix bugs
lucafedeli88 Dec 20, 2023
e9454cd
fix bugs
lucafedeli88 Dec 21, 2023
e9664b1
add missing line in Makefile
lucafedeli88 Dec 21, 2023
3d6cc21
fix misplaced using namespace directive
lucafedeli88 Dec 21, 2023
8572d2b
add missing include
lucafedeli88 Dec 21, 2023
48fc5a7
fix misspelled name
lucafedeli88 Dec 21, 2023
e42a20a
fixed bug
lucafedeli88 Dec 21, 2023
7475fd8
using parser to read inputfile
lucafedeli88 Dec 21, 2023
cbcef56
fix bug
lucafedeli88 Dec 21, 2023
7b94a13
make function public to allow its use on NVIDIA GPUs
lucafedeli88 Dec 21, 2023
53ea810
avoid implicit capture of this
lucafedeli88 Dec 21, 2023
6af40a0
make LinSpaceFill callable only from host code
lucafedeli88 Dec 21, 2023
ab65f9e
use pointers for data to be used on GPUs
lucafedeli88 Dec 21, 2023
753409f
missing include
lucafedeli88 Dec 21, 2023
4faf90e
removing include
lucafedeli88 Dec 21, 2023
9c25bbf
fix issue with constexpr
lucafedeli88 Dec 21, 2023
e53cb08
fix issues on GPU
lucafedeli88 Dec 21, 2023
b394e4e
Merge pull request #5 from lucafedeli88/improve_radiation_module_4
tmsclark2 Dec 27, 2023
06a5a11
Integral_over_time
tmsclark Jan 23, 2024
4723f04
Integral_over_time_mod
tmsclark Jan 23, 2024
039957c
debugging radiation module
lucafedeli88 Jan 23, 2024
56ee248
Merge pull request #6 from lucafedeli88/debugging_radiation_module
tmsclark2 Jan 23, 2024
1a68d9f
Nyquist limiter
tmsclark Jan 31, 2024
f3d4a29
Work in progress: spherical detector
Feb 7, 2024
5359092
Correction of spherical radiation and chose between spherical and car…
Feb 7, 2024
9def939
Corrections, need change of frame in spherical implementation
Feb 12, 2024
08dd0d5
use amrex::linspace
lucafedeli88 Feb 15, 2024
00ee4dd
Merge pull request #1 from lucafedeli88/use_amrex_linspace
Pierre-Bartoli Feb 15, 2024
43d82ec
Minor correction and adjustements
Feb 15, 2024
49d95b9
Merge
Feb 15, 2024
40df9a7
Merge pull request #8 from Pierre-Bartoli/radiation_spherical
tmsclark2 Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Source/Evolve/WarpXEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Utils/WarpXUtil.H"
#include "Utils/WarpXConst.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "Particles/Radiation/RadiationHandler.H"

#include <ablastr/utils/SignalHandling.H>
#include <ablastr/warn_manager/WarnManager.H>
Expand Down Expand Up @@ -245,6 +246,7 @@ WarpX::Evolve (int numsteps)
*Bfield_aux[lev][0],*Bfield_aux[lev][1],
*Bfield_aux[lev][2]);
}
mypc->Dump_radiations();
is_synchronized = true;
}

Expand Down Expand Up @@ -426,8 +428,20 @@ WarpX::OneStep_nosub (Real cur_time)
ExecutePythonCallback("particlescraper");
ExecutePythonCallback("beforedeposition");

//Save particle old momentum in a attribute
mypc->keepoldmomentum();

PushParticlesandDeposit(cur_time);

//Radiation contribution at each timestep
//Only level 0 is supported
mypc->doRadiation(dt[0],cur_time);






ExecutePythonCallback("afterdeposition");

// Synchronize J and rho:
Expand Down
1 change: 1 addition & 0 deletions Source/Particles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ add_subdirectory(ElementaryProcess)
add_subdirectory(Gather)
add_subdirectory(ParticleCreation)
#add_subdirectory(Pusher)
add_subdirectory(Radiation)
add_subdirectory(Resampling)
add_subdirectory(Sorting)
1 change: 1 addition & 0 deletions Source/Particles/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include $(WARPX_HOME)/Source/Particles/Sorting/Make.package
include $(WARPX_HOME)/Source/Particles/ParticleCreation/Make.package
include $(WARPX_HOME)/Source/Particles/ElementaryProcess/Make.package
include $(WARPX_HOME)/Source/Particles/Collision/Make.package
include $(WARPX_HOME)/Source/Particles/Radiation/Make.package
include $(WARPX_HOME)/Source/Particles/Filter/Make.package
include $(WARPX_HOME)/Source/Particles/Resampling/Make.package

Expand Down
17 changes: 16 additions & 1 deletion Source/Particles/MultiParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# include "Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper_fwd.H"
#endif
#include "PhysicalParticleContainer.H"
#include "Particles/Radiation/RadiationHandler.H"
#include "Utils/TextMsg.H"
#include "Utils/WarpXConst.H"
#include "WarpXParticleContainer.H"
Expand Down Expand Up @@ -329,6 +330,12 @@ public:
const amrex::MultiFab& Bz);
#endif

void doRadiation(amrex::Real dt, amrex::Real cur_time);

void keepoldmomentum();
void keepoldmomentum_p(std::unique_ptr<WarpXParticleContainer>& pc);

void Dump_radiations();
[[nodiscard]] int getSpeciesID (std::string product_str) const;

protected:
Expand Down Expand Up @@ -480,6 +487,12 @@ protected:
amrex::Real m_qed_schwinger_zmin = std::numeric_limits<amrex::Real>::lowest();
amrex::Real m_qed_schwinger_zmax = std::numeric_limits<amrex::Real>::max();

/**
* For Radiation module
*/
bool m_at_least_one_particle_radiate = 0;
int m_nspecies_radiate;

#endif

private:
Expand Down Expand Up @@ -527,6 +540,8 @@ private:
void CheckQEDProductSpecies();
#endif


// Radiation Handler
std::unique_ptr<RadiationHandler> m_p_radiation_handler;
bool m_at_least_one_has_radiation = false;
};
#endif /*WARPX_ParticleContainer_H_*/
76 changes: 72 additions & 4 deletions Source/Particles/MultiParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core)

// Setup particle collisions
collisionhandler = std::make_unique<CollisionHandler>(this);

amrex::Print() << "wEEEEEEEESSSSSSSHHHHH" << allcontainers.size() << "\n";
//Initialization of the radiation
for (auto& s : allcontainers) {
amrex::Print() << s->has_radiation() <<"jzfnfhjzbefhezbfhzebfzehb" << "\n";
if (s->has_radiation()) {
m_at_least_one_has_radiation = true;
amrex::Print() << "Hey ! I'm here" << "\n";
m_p_radiation_handler = std::make_unique<RadiationHandler>();
break;
}
}
}

void
Expand Down Expand Up @@ -367,8 +377,7 @@ MultiParticleContainer::ReadParameters ()
m_qed_schwinger_threshold_poisson_gaussian);
utils::parser::queryWithParser(
pp_qed_schwinger, "xmin", m_qed_schwinger_xmin);
utils::parser::queryWithParser(
pp_qed_schwinger, "xmax", m_qed_schwinger_xmax);

#if defined(WARPX_DIM_3D)
utils::parser::queryWithParser(
pp_qed_schwinger, "ymin", m_qed_schwinger_ymin);
Expand All @@ -384,7 +393,6 @@ MultiParticleContainer::ReadParameters ()
initialized = true;
}
}

WarpXParticleContainer&
MultiParticleContainer::GetParticleContainerFromName (const std::string& name) const
{
Expand Down Expand Up @@ -915,6 +923,47 @@ MultiParticleContainer::doFieldIonization (int lev,
}
}

void MultiParticleContainer::keepoldmomentum(){
for (auto& pc : allcontainers) {
if (pc->has_radiation()){
keepoldmomentum_p(pc);
}
}
}void MultiParticleContainer::keepoldmomentum_p
(std::unique_ptr<WarpXParticleContainer>& pc){
const auto level0=0;
for (WarpXParIter pti(*pc, level0); pti.isValid(); ++pti) {
auto index = std::make_pair(pti.index(), pti.LocalTileIndex());
auto& part=pc->GetParticles(level0)[index];
long const np = pti.numParticles();
auto& soa = part.GetStructOfArrays();

//Load the momentums
amrex::ParticleReal* ux = soa.GetRealData(PIdx::ux).data();
amrex::ParticleReal* uy = soa.GetRealData(PIdx::uy).data();
amrex::ParticleReal* uz = soa.GetRealData(PIdx::uz).data();

//Finding the good attribute index
int index_name_x=pc->GetRealCompIndex("prev_u_x");
int index_name_y=pc->GetRealCompIndex("prev_u_y");
int index_name_z=pc->GetRealCompIndex("prev_u_z");

auto* p_ux = soa.GetRealData(index_name_x).data();
auto* p_uy = soa.GetRealData(index_name_y).data();
auto* p_uz = soa.GetRealData(index_name_z).data();

amrex::ParallelFor(np,
[=] AMREX_GPU_DEVICE(int ip)
{
//Putting them in an attribute
p_ux[ip] = ux[ip];
p_uy[ip] = uy[ip];
p_uz[ip] = uz[ip];

});
}
}

void
MultiParticleContainer::doCollisions ( Real cur_time, amrex::Real dt )
{
Expand Down Expand Up @@ -955,6 +1004,25 @@ void MultiParticleContainer::ScrapeParticles (const amrex::Vector<const amrex::M
#endif
}

void MultiParticleContainer::doRadiation (const amrex::Real dt, amrex::Real cur_time)
{
if (m_at_least_one_has_radiation){
for (auto& pc : allcontainers) {
if (pc->has_radiation()){

m_p_radiation_handler->add_radiation_contribution(dt,pc,cur_time);
}
}
}
}


void MultiParticleContainer::Dump_radiations(){
if (m_at_least_one_has_radiation){
m_p_radiation_handler->Integral_overtime();
m_p_radiation_handler->gather_and_write_radiation("Radiation");
}
}
#ifdef WARPX_QED
void MultiParticleContainer::InitQED ()
{
Expand Down
17 changes: 17 additions & 0 deletions Source/Particles/NamedComponentParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ public:
/** Return the name-to-index map for the runtime-time integer components */
[[nodiscard]] std::map<std::string, int> getParticleRuntimeiComps () const noexcept { return particle_runtime_icomps;}

/** Get the index of a real component
*
* @param name Name of the new component
*/
int GetRealCompIndex (const std::string& name)
{
return particle_comps.at(name);
}
/** Initialize value at a component
*
* @param name Name of the new component
*/
// void InitializeComp (const std::string& name)
//{
// particle_runtime_comps.at(name);
//}

protected:
std::map<std::string, int> particle_comps;
std::map<std::string, int> particle_icomps;
Expand Down
3 changes: 3 additions & 0 deletions Source/Particles/PhysicalParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ public:
PairGenerationFilterFunc getPairGenerationFilterFunc ();
#endif

bool has_radiation() const override {return m_do_radiation;}

protected:
std::string species_name;
std::vector<std::unique_ptr<PlasmaInjector>> plasma_injectors;
Expand Down Expand Up @@ -386,6 +388,7 @@ protected:
//When true PhysicalParticleContainer tries to use a pusher including
//radiation reaction
bool do_classical_radiation_reaction = false;
bool m_do_radiation = false;

// A flag to enable saving of the previous timestep positions
bool m_save_previous_position = false;
Expand Down
9 changes: 9 additions & 0 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp

//check if Radiation Reaction is enabled and do consistency checks
pp_species_name.query("do_classical_radiation_reaction", do_classical_radiation_reaction);
//check if Radiations are enables for species and add previous momentum attribute
pp_species_name.query("do_radiation", m_do_radiation);
if (m_do_radiation==1){
amrex::Print() << "i'm here";
//enable the radiations in the evolve loop
AddRealComp("prev_u_x");
AddRealComp("prev_u_y");
AddRealComp("prev_u_z");
}
//if the species is not a lepton, do_classical_radiation_reaction
//should be false
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
Expand Down
7 changes: 7 additions & 0 deletions Source/Particles/Radiation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foreach(D IN LISTS WarpX_DIMS)
warpx_set_suffix_dims(SD ${D})
target_sources(lib_${SD}
PRIVATE
RadiationHandler.cpp
)
endforeach()
1 change: 1 addition & 0 deletions Source/Particles/Radiation/Make.package
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CEXE_sources += RadiationHandler.cpp
86 changes: 86 additions & 0 deletions Source/Particles/Radiation/RadiationHandler.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

/* Copyright 2023 Thomas Clark, Luca Fedeli
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/

#ifndef WARPX_PARTICLES_RADIATION_H_
#define WARPX_PARTICLES_RADIATION_H_
#include "Utils/Math/Complex.H"
#include "Particles/Pusher/GetAndSetPosition.H"


#include <AMReX_REAL.H>
#include <AMReX_Vector.H>
#include <AMReX_Box.H>
#include <AMReX_Vector.H>
#include <AMReX_FArrayBox.H>
#include <AMReX_Geometry.H>

#include "WarpX.H"
#include "Particles/Sorting/SortingUtils.H"
#include <memory>
#include <string>

/* \brief CollisionHandler is a light weight class that contains the
* calculation of radiation for particles at each frequencies and angles.
*/
class RadiationHandler
{
public:
RadiationHandler ();

/* Perform the calculation of the radiation */
//void doRadiation (amrex::Real dt, MultiParticleContainer* mypc);
void add_radiation_contribution(const amrex::Real dt, std::unique_ptr<WarpXParticleContainer>& pc, amrex::Real current_time);
void add_detector();
void gather_and_write_radiation(const std::string& filename);
void Integral_overtime();


private:

// Frequency range
amrex::Vector<amrex::Real> m_omega_range;

// Dimensions of the detector
amrex::Vector<amrex::Real> m_theta_range;

int m_omega_points;

//put a detector
int m_get_a_detector;
// Resolution of the detector
amrex::Vector<amrex::Real> m_d_theta;
double m_d_omega;
//The vector with the resolution of the detector
amrex::Vector<amrex::Real> m_d_det;
amrex::Real m_det_distance;

//Define the Fab with the datas
int ncomp;

amrex::Vector<int> m_det_pts;
amrex::Vector<int> m_det_direction;
amrex::Vector<amrex::Real> m_pos_det;
amrex::Vector<amrex::Real> n;

//resolution of the grid of the detectir
amrex::Vector<amrex::Real> m_d_d;

//
amrex::Gpu::DeviceVector<amrex::Real> m_radiation_data;
amrex::Gpu::DeviceVector<amrex::Real> m_radiation_calculation;

//
amrex::Real dephas;

//
amrex::Vector<amrex::Vector<amrex::Real>> det_bornes;
amrex::Vector<amrex::Vector<amrex::Real>> det_pos;
amrex::Vector<amrex::Real> omega_calc;

};
#endif // WARPX_PARTICLES_RADIATION_H_
Loading