Grid 0.7.0
ActionSet.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/ActionSet.h
6
7Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10Author: neo <cossu@post.kek.jp>
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along
23with this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26See the full license in the file "LICENSE" in the top level distribution
27directory
28*************************************************************************************/
29 /* END LEGAL */
30#ifndef ACTION_SET_H
31#define ACTION_SET_H
32
34
36// Indexing of tuple types
38
39template <class T, class Tuple>
40struct Index;
41
42template <class T, class... Types>
43struct Index<T, std::tuple<T, Types...>> {
44 static const std::size_t value = 0;
45};
46
47template <class T, class U, class... Types>
48struct Index<T, std::tuple<U, Types...>> {
49 static const std::size_t value = 1 + Index<T, std::tuple<Types...>>::value;
50};
51
52
54// Action Level
55// Action collection
56// in a integration level
57// (for multilevel integration schemes)
59
60template <class Field, class Repr = NoHirep >
62public:
63 unsigned int multiplier;
64
65 // Fundamental repr actions separated because of the smearing
67
68 // construct a tuple of vectors of the actions for the corresponding higher
69 // representation fields
72
74 std::vector<ActPtr>& actions;
75
76 explicit ActionLevel(unsigned int mul = 1) :
77 actions(std::get<0>(actions_hirep)), multiplier(mul) {
78 // initialize the hirep vectors to zero.
79 // apply(this->resize, actions_hirep, 0); //need a working resize
80 assert(mul >= 1);
81 }
82
83 template < class GenField >
85 // insert only in the correct vector
86 std::get< Index < GenField, action_hirep_types>::value >(actions_hirep).push_back(ptr);
87 }
88
89 template <class ActPtr>
90 static void resize(ActPtr ap, unsigned int n) {
91 ap->resize(n);
92 }
93
94 // Loop on tuple for a callable function
95 template <std::size_t I = 1, typename Callable, typename ...Args>
96 inline typename std::enable_if<I == std::tuple_size<action_collection>::value, void>::type apply(Callable, Repr& R,Args&...) const {}
97
98 template <std::size_t I = 1, typename Callable, typename ...Args>
99 inline typename std::enable_if<I < std::tuple_size<action_collection>::value, void>::type apply(Callable fn, Repr& R, Args&... arguments) const {
100 fn(std::get<I>(actions_hirep), std::get<I>(R.rep), arguments...);
101 apply<I + 1>(fn, R, arguments...);
102 }
103
104};
105
106// Define the ActionSet
107template <class GaugeField, class R>
108using ActionSet = std::vector<ActionLevel<GaugeField, R> >;
109
111
112#endif // ACTION_SET_H
std::vector< ActionLevel< GaugeField, R > > ActionSet
Definition ActionSet.h:108
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
Base class for all actions.
Definition ActionBase.h:64
AccessTypes< Action, Repr >::VectorCollection action_collection
Definition ActionSet.h:70
std::enable_if< I==std::tuple_size< action_collection >::value, void >::type apply(Callable, Repr &R, Args &...) const
Definition ActionSet.h:96
unsigned int multiplier
Definition ActionSet.h:63
AccessTypes< Action, Repr >::FieldTypeCollection action_hirep_types
Definition ActionSet.h:71
ActionLevel(unsigned int mul=1)
Definition ActionSet.h:76
action_collection actions_hirep
Definition ActionSet.h:73
std::vector< ActPtr > & actions
Definition ActionSet.h:74
void push_back(Action< GenField > *ptr)
Definition ActionSet.h:84
Action< Field > * ActPtr
Definition ActionSet.h:66
static void resize(ActPtr ap, unsigned int n)
Definition ActionSet.h:90
static const std::size_t value
Definition ActionSet.h:44
static const std::size_t value
Definition ActionSet.h:49