From 64594d9798a94bd71d2eb163cabd16a3ed6bd1c8 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 6 Aug 2015 14:13:05 +0200 Subject: [PATCH 1/2] Particle Manipulators: Init Multi-Ion Species This commit adds new manipulators that can be used during the species init-pipeline. - `RatioWeightingImpl`: Useful to clone one ion species from an other ion species by still satisfying the densityRatio of the new created species. - `ProtonTimesWeightingImpl`: Useful to clone electron species from an ion species for pre-ionized plasmas. The weighting of the electrons is simply multiplied by the proton number of the initial ion species. --- .../manipulators/ProtonTimesWeightingImpl.def | 47 +++++++++++++ .../manipulators/ProtonTimesWeightingImpl.hpp | 65 +++++++++++++++++ .../manipulators/RatioWeightingImpl.def | 47 +++++++++++++ .../manipulators/RatioWeightingImpl.hpp | 69 +++++++++++++++++++ .../particles/manipulators/manipulators.def | 4 +- .../particles/manipulators/manipulators.hpp | 4 +- 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def create mode 100644 src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp create mode 100644 src/picongpu/include/particles/manipulators/RatioWeightingImpl.def create mode 100644 src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp diff --git a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def new file mode 100644 index 0000000000..6b4a865cf5 --- /dev/null +++ b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def @@ -0,0 +1,47 @@ +/** + * Copyright 2015 Axel Huebl + * + * 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 . + */ + + +#pragma once + +namespace picongpu +{ +namespace particles +{ +namespace manipulators +{ + +/* Re-scale the weighting of a cloned species by numberOfProtons + * + * When cloning species from each other, the new + * species "inherits" the macro-particle weighting + * of the first one. + * This functor can be used to manipulate the weighting + * of the new species' macro particles to be a multiplied by + * the number of protons on the initial species. + * + * note: needs the atomicNumbers flag on the initial species, + * used by the GetAtomicNumbers trait. + */ +struct ProtonTimesWeightingImpl; + +} //namespace manipulators +} //namespace particles +} //namespace picongpu diff --git a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp new file mode 100644 index 0000000000..0f476e21a4 --- /dev/null +++ b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp @@ -0,0 +1,65 @@ +/** + * Copyright 2015 Axel Huebl + * + * 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 . + */ + + +#pragma once + +#include "particles/manipulators/ProtonTimesWeightingImpl.def" +#include "particles/traits/GetAtomicNumbers.hpp" + +#include "simulation_defines.hpp" + +namespace picongpu +{ +namespace particles +{ +namespace manipulators +{ + +struct ProtonTimesWeightingImpl +{ + + template + struct apply + { + typedef ProtonTimesWeightingImpl type; + }; + + HINLINE ProtonTimesWeightingImpl(uint32_t currentStep) + { + + } + + template + DINLINE void operator()(const DataSpace&, + T_Particle1& particleSpecies1, T_Particle2&, + const bool isParticle1, const bool isParticle2) + { + if (isParticle1 && isParticle2) + { + const float_X protonNumber = traits::GetAtomicNumbers::type::numberOfProtons; + particleSpecies1[weighting_] *= protonNumber; + } + } +}; + +} //namespace manipulators +} //namespace particles +} //namespace picongpu diff --git a/src/picongpu/include/particles/manipulators/RatioWeightingImpl.def b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.def new file mode 100644 index 0000000000..00e96e0855 --- /dev/null +++ b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.def @@ -0,0 +1,47 @@ +/** + * Copyright 2015 Axel Huebl + * + * 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 . + */ + + +#pragma once + +namespace picongpu +{ +namespace particles +{ +namespace manipulators +{ + +/* Re-scale the weighting of a cloned species by densityRatio + * + * When cloning species from each other, the new + * species "inherits" the macro-particle weighting + * of the first one. + * This functor can be used to manipulate the weighting + * of the new species' macro particles to satisfy the + * input densityRatio of it. + * + * note: needs the densityRatio flag on both species, + * used by the GetDensityRatio trait. + */ +struct RatioWeighting; + +} //namespace manipulators +} //namespace particles +} //namespace picongpu diff --git a/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp new file mode 100644 index 0000000000..941060d975 --- /dev/null +++ b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp @@ -0,0 +1,69 @@ +/** + * Copyright 2015 Axel Huebl + * + * 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 . + */ + + +#pragma once + +#include "particles/manipulators/RatioWeightingImpl.def" +#include "particles/traits/GetDensityRatio.hpp" + +#include "simulation_defines.hpp" + +namespace picongpu +{ +namespace particles +{ +namespace manipulators +{ + +struct RatioWeightingImpl +{ + + template + struct apply + { + typedef RatioWeightingImpl type; + }; + + HINLINE RatioWeightingImpl(uint32_t currentStep) + { + + } + + template + DINLINE void operator()(const DataSpace&, + T_Particle1& particleSpecies1, T_Particle2&, + const bool isParticle1, const bool isParticle2) + { + if (isParticle1 && isParticle2) + { + const float_X densityRatioDes = + traits::GetDensityRatio::type::getDefaultValue(); + const float_X densityRatioSrc = + traits::GetDensityRatio::type::getDefaultValue(); + + particleSpecies1[weighting_] *= densityRatioDes / densityRatioSrc; + } + } +}; + +} //namespace manipulators +} //namespace particles +} //namespace picongpu diff --git a/src/picongpu/include/particles/manipulators/manipulators.def b/src/picongpu/include/particles/manipulators/manipulators.def index 199aa14208..0b8b676bd4 100644 --- a/src/picongpu/include/particles/manipulators/manipulators.def +++ b/src/picongpu/include/particles/manipulators/manipulators.def @@ -1,5 +1,5 @@ /** - * Copyright 2014 Rene Widera + * Copyright 2014-2015 Rene Widera, Axel Huebl * * This file is part of PIConGPU. * @@ -32,3 +32,5 @@ #include "particles/manipulators/FreeImpl.def" #include "particles/manipulators/SetAttributeImpl.def" #include "particles/manipulators/RandomPositionImpl.def" +#include "particles/manipulators/RatioWeightingImpl.def" +#include "particles/manipulators/ProtonTimesWeightingImpl.def" diff --git a/src/picongpu/include/particles/manipulators/manipulators.hpp b/src/picongpu/include/particles/manipulators/manipulators.hpp index f6cf50272e..68983c1dde 100644 --- a/src/picongpu/include/particles/manipulators/manipulators.hpp +++ b/src/picongpu/include/particles/manipulators/manipulators.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2014 Rene Widera + * Copyright 2014-2015 Rene Widera, Axel Huebl * * This file is part of PIConGPU. * @@ -31,3 +31,5 @@ #include "particles/manipulators/FreeImpl.hpp" #include "particles/manipulators/SetAttributeImpl.hpp" #include "particles/manipulators/RandomPositionImpl.hpp" +#include "particles/manipulators/RatioWeightingImpl.hpp" +#include "particles/manipulators/ProtonTimesWeightingImpl.hpp" From 57cb32af48289a882b5c47b6a4c56a2821965fbc Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Tue, 8 Dec 2015 17:12:26 +0100 Subject: [PATCH 2/2] Review Comments: Increase Documentation ... and remove unused parameters. --- .../particles/manipulators/AssignImpl.hpp | 2 +- .../particles/manipulators/DriftImpl.hpp | 5 ++- .../particles/manipulators/FreeImpl.hpp | 5 ++- .../particles/manipulators/NoneImpl.hpp | 2 +- .../manipulators/ProtonTimesWeightingImpl.def | 5 +++ .../manipulators/ProtonTimesWeightingImpl.hpp | 29 ++++++++++----- .../manipulators/RatioWeightingImpl.hpp | 36 ++++++++++++++----- .../manipulators/SetAttributeImpl.hpp | 5 ++- 8 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/picongpu/include/particles/manipulators/AssignImpl.hpp b/src/picongpu/include/particles/manipulators/AssignImpl.hpp index 12aa4c0ac1..1dba7f7196 100644 --- a/src/picongpu/include/particles/manipulators/AssignImpl.hpp +++ b/src/picongpu/include/particles/manipulators/AssignImpl.hpp @@ -40,7 +40,7 @@ struct AssignImpl typedef AssignImpl type; }; - HINLINE AssignImpl(uint32_t currentStep) + HINLINE AssignImpl(uint32_t) { } diff --git a/src/picongpu/include/particles/manipulators/DriftImpl.hpp b/src/picongpu/include/particles/manipulators/DriftImpl.hpp index 718f649c61..082d498d3c 100644 --- a/src/picongpu/include/particles/manipulators/DriftImpl.hpp +++ b/src/picongpu/include/particles/manipulators/DriftImpl.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2013-2014 Axel Huebl, Rene Widera + * Copyright 2013-2015 Axel Huebl, Rene Widera * * This file is part of PIConGPU. * @@ -40,9 +40,8 @@ struct DriftImpl : private T_ValueFunctor typedef T_ValueFunctor ValueFunctor; - HINLINE DriftImpl(uint32_t currentStep) + HINLINE DriftImpl(uint32_t) { - } template diff --git a/src/picongpu/include/particles/manipulators/FreeImpl.hpp b/src/picongpu/include/particles/manipulators/FreeImpl.hpp index 32bb9eae6e..984b5108a6 100644 --- a/src/picongpu/include/particles/manipulators/FreeImpl.hpp +++ b/src/picongpu/include/particles/manipulators/FreeImpl.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2013-2015 Rene Widera + * Copyright 2013-2015 Rene Widera, Axel Huebl * * This file is part of PIConGPU. * @@ -43,9 +43,8 @@ struct FreeImpl typedef FreeImpl type; }; - HINLINE FreeImpl(uint32_t currentStep) + HINLINE FreeImpl(uint32_t) { - } template diff --git a/src/picongpu/include/particles/manipulators/NoneImpl.hpp b/src/picongpu/include/particles/manipulators/NoneImpl.hpp index a76d33fd3f..bcccbd4117 100644 --- a/src/picongpu/include/particles/manipulators/NoneImpl.hpp +++ b/src/picongpu/include/particles/manipulators/NoneImpl.hpp @@ -38,7 +38,7 @@ struct NoneImpl typedef NoneImpl type; }; - HINLINE NoneImpl(uint32_t currentStep) + HINLINE NoneImpl(uint32_t) { } diff --git a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def index 6b4a865cf5..50a27dc70c 100644 --- a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def +++ b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.def @@ -37,6 +37,11 @@ namespace manipulators * of the new species' macro particles to be a multiplied by * the number of protons on the initial species. * + * As an example, this comes useful when initializing a quasi-neutral, + * pre-ionized plasma of ions and electrons. Electrons can be created + * from ions via cloning and increasing their weight to avoid simulating + * multiple macro electrons per macro ion (with Z>1). + * * note: needs the atomicNumbers flag on the initial species, * used by the GetAtomicNumbers trait. */ diff --git a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp index 0f476e21a4..52322c04ea 100644 --- a/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp +++ b/src/picongpu/include/particles/manipulators/ProtonTimesWeightingImpl.hpp @@ -42,20 +42,33 @@ struct ProtonTimesWeightingImpl typedef ProtonTimesWeightingImpl type; }; - HINLINE ProtonTimesWeightingImpl(uint32_t currentStep) + HINLINE ProtonTimesWeightingImpl(uint32_t) { - } - template + /* Increase weighting of particleDest by proton number of SrcParticle + * + * The frame's `atomicNumber` `numberOfProtons`of `T_SrcParticle` + * is used to increase the weighting of particleDest. + * Useful to increase the weighting of macro electrons when cloned from an + * ion with Z>1. Otherwise one would need Z macro electrons (each with the + * same weighting as the initial ion) to keep the charge of a pre-ionized + * atom neutral. + * + * \tparam T_DestParticle type of the particle species with weighting to manipulate + * \tparam T_SrcParticle type of the particle species with proton number Z + * + * \see picongpu::particles::ManipulateCloneSpecies , picongpu::kernelCloneParticles + */ + template DINLINE void operator()(const DataSpace&, - T_Particle1& particleSpecies1, T_Particle2&, - const bool isParticle1, const bool isParticle2) + T_DestParticle& particleDest, T_SrcParticle&, + const bool isDestParticle, const bool isSrcParticle) { - if (isParticle1 && isParticle2) + if (isDestParticle && isSrcParticle) { - const float_X protonNumber = traits::GetAtomicNumbers::type::numberOfProtons; - particleSpecies1[weighting_] *= protonNumber; + const float_X protonNumber = traits::GetAtomicNumbers::type::numberOfProtons; + particleDest[weighting_] *= protonNumber; } } }; diff --git a/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp index 941060d975..b5c7521bca 100644 --- a/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp +++ b/src/picongpu/include/particles/manipulators/RatioWeightingImpl.hpp @@ -42,24 +42,42 @@ struct RatioWeightingImpl typedef RatioWeightingImpl type; }; - HINLINE RatioWeightingImpl(uint32_t currentStep) + HINLINE RatioWeightingImpl(uint32_t) { - } - template + /* Adjust the weighting of particleDes by densityRatio of own & Src particle + * + * While cloning a particle (particleDes) from another (T_SrcParticle), one + * can afterward directly normalize the weighting back to the intended density: + * - divide weighting with the `T_SrcParticle`'s densityRatio + * (to get macro particle weighting according to reference GAS_DENSITY * profile + * at this specific point in space & time) + * - multiply weighting with own densityRatio (to get this species' + * densityRatio * GAS_DENSITY * profile) + * + * This is useful when the profile and number of macro particles for both species + * shall be the same and the initialization of another profile via `CreateGas` + * would be expensive (or one wants to keep the exact same position while cloning). + * + * \tparam T_DesParticle type of the particle species with weighting to manipulate + * \tparam T_SrcParticle type of the particle species one cloned from + * + * \see picongpu::particles::ManipulateCloneSpecies , picongpu::kernelCloneParticles + */ + template DINLINE void operator()(const DataSpace&, - T_Particle1& particleSpecies1, T_Particle2&, - const bool isParticle1, const bool isParticle2) + T_DesParticle& particleDes, T_SrcParticle&, + const bool isDesParticle, const bool isSrcParticle) { - if (isParticle1 && isParticle2) + if (isDesParticle && isSrcParticle) { const float_X densityRatioDes = - traits::GetDensityRatio::type::getDefaultValue(); + traits::GetDensityRatio::type::getDefaultValue(); const float_X densityRatioSrc = - traits::GetDensityRatio::type::getDefaultValue(); + traits::GetDensityRatio::type::getDefaultValue(); - particleSpecies1[weighting_] *= densityRatioDes / densityRatioSrc; + particleDes[weighting_] *= densityRatioDes / densityRatioSrc; } } }; diff --git a/src/picongpu/include/particles/manipulators/SetAttributeImpl.hpp b/src/picongpu/include/particles/manipulators/SetAttributeImpl.hpp index 201fc4826a..b09268b78a 100644 --- a/src/picongpu/include/particles/manipulators/SetAttributeImpl.hpp +++ b/src/picongpu/include/particles/manipulators/SetAttributeImpl.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2015 Marco Garten + * Copyright 2015 Marco Garten, Axel Huebl * * This file is part of PIConGPU. * @@ -39,9 +39,8 @@ struct SetAttributeImpl : private T_ValueFunctor typedef T_ValueFunctor ValueFunctor; - HINLINE SetAttributeImpl(uint32_t currentStep) + HINLINE SetAttributeImpl(uint32_t) { - } template