-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5260 from PrometheusPi/add_binningPlugin_to_LWFAe…
…xample add binning plugin to LWFA example
- Loading branch information
Showing
3 changed files
with
239 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _LWFA-example: | ||
|
||
LaserWakefield: Laser Electron Acceleration | ||
=========================================== | ||
|
||
|
138 changes: 138 additions & 0 deletions
138
share/picongpu/examples/LaserWakefield/include/picongpu/param/binningSetup.param
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,138 @@ | ||
/* Copyright 2023-2024 Tapish Narwal | ||
* | ||
* This file is part of PIConGPU. | ||
* | ||
* PIConGPU is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* PIConGPU is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with PIConGPU. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "picongpu/defines.hpp" | ||
#include "picongpu/plugins/binning/binnerPlugin.hpp" | ||
|
||
namespace picongpu | ||
{ | ||
namespace plugins::binning | ||
{ | ||
void eSpec(BinningCreator& binningCreator); | ||
|
||
inline void getBinning(BinningCreator& binningCreator) | ||
{ | ||
// call electron spectromter (eSpec) defined below | ||
eSpec(binningCreator); | ||
} | ||
|
||
inline void eSpec(BinningCreator& binningCreator) | ||
{ | ||
/** | ||
* axes definitions below: | ||
*/ | ||
|
||
// axis 1: energy axis | ||
auto getEnergy | ||
= [] ALPAKA_FN_ACC(auto const& domainInfo, auto const& worker, auto const& particle) -> float_X | ||
{ | ||
float3_X const mom = particle[momentum_]; | ||
float_X const weighting = particle[weighting_]; | ||
float_X const mass = picongpu::traits::attribute::getMass(weighting, particle); | ||
|
||
// calculate kinetic energy of a single electron in the macro particle | ||
float_X energy = KinEnergy<>()(mom, mass) / weighting; | ||
|
||
return energy; | ||
}; | ||
|
||
// Define units of axis 1 | ||
std::array<double, numUnits> energyDimension{}; | ||
energyDimension[SIBaseUnits::length] = 2.0; | ||
energyDimension[SIBaseUnits::mass] = 1.0; | ||
energyDimension[SIBaseUnits::time] = -2.0; | ||
|
||
|
||
// Create Functor Description for axis 1 | ||
auto energyDescription = createFunctorDescription<float_X>(getEnergy, "Energy", energyDimension); | ||
|
||
// Create energy Axis (defined in SI units) | ||
float_X const minEnergy = 0.0_X; | ||
float_X const maxEnergy_MeV = 100.0_X; | ||
float_X const maxEnergy = sim.si.conv().eV2Joule(maxEnergy_MeV * 1e6); // [J] | ||
auto ax_energy | ||
= axis::createLinear(axis::AxisSplitting(axis::Range{minEnergy, maxEnergy}, 800), energyDescription); | ||
|
||
|
||
// axis 2: pointing axis | ||
auto getPointingXY | ||
= [] ALPAKA_FN_ACC(auto const& domainInfo, auto const& worker, auto const& particle) -> float_X | ||
{ | ||
auto theta = math::atan2(particle[momentum_][0], particle[momentum_][1]); | ||
return theta; | ||
}; | ||
|
||
// Define units of axis 2 | ||
std::array<double, numUnits> pointingXYDimension{}; | ||
pointingXYDimension[SIBaseUnits::length] = 0.0; | ||
pointingXYDimension[SIBaseUnits::mass] = 0.0; | ||
pointingXYDimension[SIBaseUnits::time] = 0.0; | ||
|
||
// Create Functor Description for axis 2 | ||
auto pointingXYDescription | ||
= createFunctorDescription<float_X>(getPointingXY, "pointingXY", pointingXYDimension); | ||
|
||
// Create pointing axis Axis | ||
float_X pointing_range = 250.0e-3; | ||
auto ax_pointing = axis::createLinear( | ||
axis::AxisSplitting(axis::Range{-1._X * pointing_range, +1._X * pointing_range}, 256), | ||
pointingXYDescription); | ||
|
||
|
||
// Bring the axes together in a tuple | ||
auto axisTuple = createTuple(ax_energy, ax_pointing); | ||
|
||
|
||
/** | ||
* Define the species to do binning over here | ||
* create object from type | ||
*/ | ||
auto electronsObj = PMACC_CSTRING("e"){}; | ||
|
||
// Bring the species together in a tuple | ||
auto speciesTuple = createSpeciesTuple(electronsObj); | ||
|
||
|
||
/** | ||
* Define deposited quantity here: charge per bin | ||
*/ | ||
auto getParticleCharge = [] ALPAKA_FN_ACC(auto const& worker, auto const& particle) -> float_X | ||
{ | ||
const float_X charge = picongpu::traits::attribute::getCharge(particle[weighting_], particle); | ||
return charge; | ||
}; | ||
|
||
std::array<double, numUnits> depositedUnits{}; // Tell user the 7 dimensional format | ||
depositedUnits[SIBaseUnits::length] = 0.0; | ||
depositedUnits[SIBaseUnits::electricCurrent] = 1.0; | ||
depositedUnits[SIBaseUnits::time] = 1.0; | ||
|
||
// @todo enforce functor return type is same as createFunctorDescription template type | ||
auto chargeDepositionData = createFunctorDescription<float_X>(getParticleCharge, "Charge", depositedUnits); | ||
|
||
binningCreator.addBinner("eSpec", axisTuple, speciesTuple, chargeDepositionData) | ||
.setNormalizeByBinVolume(true) | ||
.setNotifyPeriod("100") | ||
.setJsonCfg(R"({"hdf5":{"dataset":{"chunks":"auto"}}})") | ||
.setOpenPMDExtension("h5"); | ||
} | ||
} // namespace plugins::binning | ||
} // namespace picongpu |