Skip to content

Commit 91b1b3d

Browse files
committed
Add fusion implementation similar to: doi.org/10.1063/5.0051178
1 parent 3774b05 commit 91b1b3d

File tree

22 files changed

+2702
-1
lines changed

22 files changed

+2702
-1
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* Copyright 2025 Filip Optolowicz
2+
*
3+
* This file is part of PIConGPU.
4+
*
5+
* PIConGPU is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* PIConGPU is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with PIConGPU.
17+
* If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include "picongpu/param/particleFilters.param"
23+
#include "picongpu/particles/fusion/fusion.def"
24+
#include "picongpu/plugins/misc/SpeciesFilter.hpp"
25+
26+
#include <pmacc/meta/conversion/MakeSeq.hpp>
27+
28+
29+
#ifndef PARAM_DYNAMIC_LOG
30+
# define PARAM_DYNAMIC_LOG 0
31+
#endif
32+
33+
namespace picongpu
34+
{
35+
namespace particles
36+
{
37+
namespace fusion
38+
{
39+
namespace precision
40+
{
41+
using float_COLL = float_64;
42+
} // namespace precision
43+
44+
using namespace picongpu::plugins;
45+
46+
// Example of defining a fusion reaction
47+
// Deuterium-Tritium reaction: D + T -> n + He4
48+
struct DT
49+
{
50+
51+
using reactants = pmacc::mp_list<
52+
Pair<PIC_Tritons, PIC_Deuterons>
53+
>;
54+
55+
using products = pmacc::mp_list<
56+
Pair<PIC_Neutrons, PIC_He4>
57+
>;
58+
59+
struct Params
60+
{
61+
// B_g - Gamov constant: B_g = pi*alpha*Z1*Z2*sqrt(2*m_r*c^2) in keV^1/2
62+
static constexpr float_X BG = 34.3827_X;
63+
64+
// Coefficients for the Bosch-Hale parameterization of the DT fusion cross-section
65+
static constexpr float_X A1 = 6.927e4_X;
66+
static constexpr float_X A2 = 7.454e8_X;
67+
static constexpr float_X A3 = 2.050e6_X;
68+
static constexpr float_X A4 = 5.2002e4_X;
69+
static constexpr float_X A5 = 0.0_X;
70+
71+
static constexpr float_X B1 = 6.38e1_X;
72+
static constexpr float_X B2 = -9.95e-1_X;
73+
static constexpr float_X B3 = 6.981e-5_X;
74+
static constexpr float_X B4 = 1.728e-4_X;
75+
};
76+
77+
using CrossSectionInterpolator = relativistic::FusionFunctor<Params>;
78+
};
79+
80+
81+
/** FusionPipeline defines in which order species interact with each other
82+
*
83+
* the functors are called in order (from first to last functor)
84+
*/
85+
using FusionPipeline = pmacc::mp_list<
86+
Collider<DT::CrossSectionInterpolator, DT::reactants, DT::products, OneFilter<filter::All>>>;
87+
88+
// using FusionPipeline = pmacc::mp_list<ColliderFromStruct<DT>>;
89+
90+
/** Chunk size used for cell list allocations.
91+
*
92+
* To reduce the fragmentation of the heap memory on accelerators the collision algorithm is allocating a
93+
* multiple of this value to store a cell list of particle IDs. The value must be non zero.
94+
*/
95+
constexpr uint32_t cellListChunkSize = TYPICAL_PARTICLES_PER_CELL;
96+
// if weighting of the products were to be less or equal than productMinWeighting we set Fmult = std::max(1,productWeighting/productMinWeighting);
97+
constexpr float_X productMinWeighting = 16.1;
98+
constexpr uint32_t maxFmult = 1e6;
99+
constexpr bool debugFusion = false;
100+
constexpr bool alwaysFuseQ = false;
101+
} // namespace fusion
102+
} // namespace particles
103+
} // namespace picongpu
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Copyright 2019-2024 Rene Widera, Pawel Ordyna
2+
*
3+
* This file is part of PIConGPU.
4+
*
5+
* PIConGPU is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* PIConGPU is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with PIConGPU.
17+
* If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include "picongpu/particles/filter/All.hpp"
23+
24+
#include <pmacc/meta/Pair.hpp>
25+
26+
namespace picongpu::particles::fusion
27+
{
28+
/* A pair of colliding species.
29+
*
30+
* @tparam T_Species0
31+
* @tparam T_Species1
32+
*/
33+
template<typename T_Species0, typename T_Species1>
34+
using Pair = pmacc::meta::Pair<T_Species0, T_Species1>;
35+
36+
/* A set of particle filters for a pair of colliding species.
37+
*
38+
* @tparam T_Filter0 Filter applied on the 1st species in a pair.
39+
* @tparam T_Filter1 Filter applied on the 2nd species in a pair.
40+
*/
41+
template<typename T_Filter0, typename T_Filter1>
42+
using FilterPair = pmacc::meta::Pair<T_Filter0, T_Filter1>;
43+
44+
/* Sets the same particle filter for both species in a pair.
45+
*
46+
* @tparam T_Filter A common particle filter for both colliding species.
47+
*/
48+
template<typename T_Filter>
49+
using OneFilter = pmacc::meta::Pair<T_Filter, T_Filter>;
50+
51+
/* Defines a set of binary collisions with common parameters.
52+
*
53+
* @tparam T_CrossSectionInterpolator A binary particle functor defining a single
54+
* macro particle collision in the binary-collision algorithm.
55+
* @tparam T_SpeciesPairs A sequence of pairs of colliding species.
56+
* @tparam T_Params A struct defining `coulombLog` for the collisions.
57+
* @tparam T_FilterPair A pair of particle filters. Each for every species
58+
* in a pair of colliding species. This pair of filters will be
59+
* aplied to all pairs in T_SpeciesPairs.
60+
*/
61+
template<
62+
typename T_CrossSectionInterpolator,
63+
typename T_SpeciesPairsReactants,
64+
typename T_SpeciesPairsProducts,
65+
typename T_FilterPair = OneFilter<filter::All>>
66+
struct Collider
67+
{
68+
using Functor = T_CrossSectionInterpolator;
69+
using SpeciesPairsReactants = T_SpeciesPairsReactants;
70+
using SpeciesPairsProducts = T_SpeciesPairsProducts;
71+
using FilterPair = T_FilterPair;
72+
};
73+
74+
template<typename T_FusionStruct>
75+
struct ColliderFromStruct
76+
{
77+
using Functor = typename T_FusionStruct::CrossSectionInterpolator;
78+
using SpeciesPairsReactants = typename T_FusionStruct::reactants;
79+
using SpeciesPairsProducts = typename T_FusionStruct::products;
80+
using FilterPair = typename T_FusionStruct::FilterPair;
81+
};
82+
} // namespace picongpu::particles::fusion
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright 2019-2024 Rene Widera, Pawel Ordyna, Filip Optolowicz
2+
*
3+
* This file is part of PIConGPU.
4+
*
5+
* PIConGPU is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* PIConGPU is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with PIConGPU.
17+
* If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include "picongpu/defines.hpp"
23+
#include "picongpu/particles/fusion/Collider.def"
24+
#include "picongpu/particles/fusion/WithPeer.hpp"
25+
26+
#include <pmacc/meta/ForEach.hpp>
27+
#include <pmacc/meta/accessors/First.hpp>
28+
#include <pmacc/meta/accessors/Second.hpp>
29+
#include <pmacc/meta/conversion/ApplyGuard.hpp>
30+
#include <pmacc/meta/conversion/ToSeq.hpp>
31+
32+
namespace picongpu::particles::fusion
33+
{
34+
namespace detail
35+
{
36+
// "For each" implementation for calling a collider for each species pair in a list of reactants
37+
template<
38+
typename T_SpeciesPairListReactants,
39+
typename T_SpeciesPairListProducts,
40+
typename T_Collider,
41+
uint32_t colliderId>
42+
struct CallColliderForAPair
43+
{
44+
template<size_t... I>
45+
HINLINE void operator()(
46+
std::index_sequence<I...>,
47+
std::shared_ptr<DeviceHeap> const& deviceHeap,
48+
uint32_t currentStep)
49+
{
50+
(fusion::WithPeer<
51+
typename T_Collider::Functor,
52+
typename pmacc::mp_at_c<T_SpeciesPairListReactants, I>::first,
53+
typename pmacc::mp_at_c<T_SpeciesPairListReactants, I>::second,
54+
typename pmacc::mp_at_c<T_SpeciesPairListProducts, I>::first,
55+
typename pmacc::mp_at_c<T_SpeciesPairListProducts, I>::second,
56+
typename T_Collider::FilterPair,
57+
colliderId,
58+
I>{}(deviceHeap, currentStep),
59+
...);
60+
}
61+
};
62+
} // namespace detail
63+
64+
template<typename T_Collider, uint32_t colliderId>
65+
struct CallCollider
66+
{
67+
void operator()(std::shared_ptr<DeviceHeap> const& deviceHeap, uint32_t currentStep)
68+
{
69+
using SpeciesPairListReactants = pmacc::ToSeq<typename T_Collider::SpeciesPairsReactants>;
70+
using SpeciesPairListProducts = pmacc::ToSeq<typename T_Collider::SpeciesPairsProducts>;
71+
constexpr size_t numPairs = pmacc::mp_size<SpeciesPairListReactants>::value;
72+
std::make_index_sequence<numPairs> index{};
73+
detail::CallColliderForAPair<SpeciesPairListReactants, SpeciesPairListProducts, T_Collider, colliderId>{}(
74+
index,
75+
deviceHeap,
76+
currentStep);
77+
}
78+
};
79+
} // namespace picongpu::particles::fusion
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Copyright 2019-2024 Rene Widera, Pawel Ordyna
2+
*
3+
* This file is part of PIConGPU.
4+
*
5+
* PIConGPU is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* PIConGPU is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with PIConGPU.
17+
* If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include <pmacc/functor/Interface.hpp>
23+
24+
namespace picongpu
25+
{
26+
namespace particles
27+
{
28+
namespace fusion
29+
{
30+
namespace acc
31+
{
32+
template<typename T_BinaryFunctor>
33+
using IBinary = pmacc::functor::acc::Interface<T_BinaryFunctor, 2u, void>;
34+
} // namespace acc
35+
36+
/** interface for a binary particle functor
37+
*
38+
*
39+
* @tparam T_BinaryFunctor binary particle acc functor, must contain
40+
* `void operator()(P1 & particle1, P2 & particle2, ...)`
41+
* and support at least two particles
42+
*/
43+
template<typename T_BinaryFunctor>
44+
using IBinary = pmacc::functor::Interface<T_BinaryFunctor, 2u, void>;
45+
46+
} // namespace fusion
47+
} // namespace particles
48+
} // namespace picongpu

0 commit comments

Comments
 (0)