group_particles
Loading...
Searching...
No Matches
callback_utils_prt_action.hpp
Go to the documentation of this file.
1
7#ifndef CALLBACK_UTILS_PRT_ACTION_HPP
8#define CALLBACK_UTILS_PRT_ACTION_HPP
9
10#include "callback.hpp"
12
13namespace CallbackUtils {
14
17namespace prt_action {
18
34 template<typename AFields, typename Tdata>
36 virtual public Callback<AFields>,
37 private grp_action::MultiGrpAction<AFields, StorePrtHomogeneous<AFields, Tdata>>
38 {// {{{
42
43 // some functionality to figure out whether Tdata has the method
44 // void prt_insert (size_t grp_idx, const GrpProperties &grp,
45 // const PrtProperties &prt, coord_t Rsq)
46 // from https://stackoverflow.com/questions/87372/check-if-a-class-has-a-member-function-of-a-given-signature
47 template<typename, typename T>
48 struct has_prt_insert { static_assert(std::integral_constant<T, false>::value); };
49
50 template<typename C, typename Ret, typename... Args>
51 class has_prt_insert<C, Ret(Args...)>
52 {
53 template<typename T>
54 static constexpr auto check (T *)
55 -> typename std::is_same<
56 decltype(std::declval<T>().prt_insert(std::declval<Args>()...)),
57 Ret
58 >::type;
59
60 template<typename>
61 static constexpr std::false_type check(...);
62
63 using type = decltype(check<C>(0));
64 public :
65 static constexpr bool value = type::value;
66 };
67
68
69 std::vector<Tdata> &data;
70
71 void this_grp_action (const GrpProperties &grp) override final
72 {
73 if constexpr (std::is_constructible_v<Tdata, const GrpProperties &>)
74 {
75 static_assert(!std::is_default_constructible_v<Tdata>);
76 data.emplace_back(grp);
77 }
78 else
79 data.emplace_back();
80 }
81 protected :
106 virtual void prt_insert (size_t grp_idx, const GrpProperties &grp,
107 const PrtProperties &prt, coord_t Rsq,
108 Tdata &data_item)
109 {
110 assert(("Need to override CallbackUtils::StorePrtHomogeneous<AFields,Tdata>::prt_insert if Tdata does not implement prt_insert method.", false));
111 }
112
113 public :
121 StorePrtHomogeneous (std::vector<Tdata> &data_) :
122 data(data_)
123 { }
124
125 void prt_action (size_t grp_idx, const GrpProperties &grp,
126 const PrtProperties &prt, coord_t Rsq) override final
127 {
128 if constexpr (has_prt_insert<Tdata, void(size_t, const GrpProperties &,
129 const PrtProperties &, coord_t)>::value)
130 data[grp_idx].prt_insert(grp_idx, grp, prt, Rsq);
131 else
132 prt_insert(grp_idx, grp, prt, Rsq, data[grp_idx]);
133 }
134 };// }}}
135
136} // namespace prt_action
137
138
139} // namespace CallbackUtils
140
141#endif // CALLBACK_UTILS_PRT_ACTION_HPP
Contains the abstract base class that the user should subclass from in order to define the desired fu...
Some common ways to override Callback::grp_action.
Specialization of the Callback::BaseProperties type to groups.
Definition callback.hpp:85
interface class to add an action to be performed during Callback::grp_action
Definition callback_utils_grp_action.hpp:64
implements the common case that each group gets an item of identical type into which the particles be...
Definition callback_utils_prt_action.hpp:38
StorePrtHomogeneous(std::vector< Tdata > &data_)
Definition callback_utils_prt_action.hpp:121
virtual void prt_insert(size_t grp_idx, const GrpProperties &grp, const PrtProperties &prt, coord_t Rsq, Tdata &data_item)
Definition callback_utils_prt_action.hpp:106
float coord_t
Internal coordinate type.
Definition fields.hpp:28
contains classes that implement parts of the Callback base.
Definition callback_utils.hpp:35
Specialization of the Callback::BaseProperties type to particles.
Definition callback.hpp:95
The abstract base class the user should inherit from.
Definition callback.hpp:32