sisi4s
Loading...
Searching...
No Matches
Mixer.hpp
Go to the documentation of this file.
1#ifndef MIXER_DEFINED
2#define MIXER_DEFINED
3
5#include <math/Complex.hpp>
6#include <math/FockVector.hpp>
8
9#include <string>
10
11namespace sisi4s {
12template <typename F>
13class Mixer {
14public:
16 virtual ~Mixer();
17
21 virtual std::string getName() = 0;
22
30 virtual void append(const PTR(FockVector<F>) &A,
31 const PTR(FockVector<F>) &R) = 0;
32
39 virtual PTR(const FockVector<F>) get() = 0;
40
48 virtual PTR(const FockVector<F>) getResiduum() = 0;
49
51};
52
53template <typename F>
55public:
56 // FIXME: find out why typedef doesn't work in this case
57 /*
58 typedef std::map<
59 std::string,
60 std::function<Mixer<F> *(Algorithm *)>
61 > MixerMap;
62 */
69 static PTR(Mixer<F>) create(std::string const &name, Algorithm *algorithm) {
70 auto iterator(getMixerMap()->find(name));
71 return iterator != getMixerMap()->end() ? iterator->second(algorithm)
72 : PTR(Mixer<F>)();
73 }
74
75protected:
76 static std::map<std::string,
77 std::function<PTR(Mixer<F>)(Algorithm *algorithm)>> *
79 return mixerMap
80 ? mixerMap
81 : (mixerMap =
82 new std::map<std::string,
83 std::function<PTR(Mixer<F>)(Algorithm *)>>);
84 }
85 static std::map<std::string, std::function<PTR(Mixer<F>)(Algorithm *)>>
87 /*
88 static MixerMap *getMixerMap() {
89 return mixerMap ? mixerMap : (mixerMap = new MixerMap);
90 }
91 static MixerMap *mixerMap;
92 */
93};
94
98template <typename F, typename MixerType>
100 return NEW(MixerType, algorithm);
101}
102
108template <typename F, typename MixerType>
109class MixerRegistrar : protected MixerFactory<F> {
110public:
116 MixerRegistrar(std::string const &name) {
117 (*MixerFactory<F>::getMixerMap())[name] = &createMixer<F, MixerType>;
118 }
119};
120
127#define MIXER_REGISTRAR_DECLARATION(NAME) \
128 virtual std::string getName() { return #NAME; } \
129 static MixerRegistrar<F, NAME<F>> registrar_
130
137#define MIXER_REGISTRAR_DEFINITION(NAME) \
138 template <typename F> \
139 MixerRegistrar<F, NAME<F>> NAME<F>::registrar_(#NAME)
140} // namespace sisi4s
141
142#endif
#define NEW(TYPE,...)
Definition SharedPointer.hpp:10
#define PTR(TYPE)
Definition SharedPointer.hpp:8
Definition Algorithm.hpp:26
Represents the direct sum of Tensors and provides the vector space operations of addition,...
Definition FockVector.hpp:26
Definition Mixer.hpp:54
static std::map< std::string, std::function< std::shared_ptr< Mixer< F > >(Algorithm *algorithm)> > * getMixerMap()
Definition Mixer.hpp:78
static std::shared_ptr< Mixer< F > > create(std::string const &name, Algorithm *algorithm)
Creates a mixer object of the mixer type specified by the given name. The instantiated mixer must be ...
Definition Mixer.hpp:69
static std::map< std::string, std::function< std::shared_ptr< Mixer< F > >(Algorithm *)> > * mixerMap
Definition Mixer.hpp:86
Class to be statically instantiated by a mixer to register it in the MixerFactory....
Definition Mixer.hpp:109
MixerRegistrar(std::string const &name)
Constructs the registrating instance. The mixer type must be given as template argument,...
Definition Mixer.hpp:116
Definition Mixer.hpp:13
virtual void append(const std::shared_ptr< FockVector< F > > &A, const std::shared_ptr< FockVector< F > > &R)=0
Appends the given pair (A,R) of FockVectors to the mixer, where R is the residuum when using the ampl...
Algorithm * algorithm
Definition Mixer.hpp:50
virtual ~Mixer()
Definition Mixer.cxx:11
virtual std::shared_ptr< const FockVector< F > > getResiduum()=0
Returns the estimated residuum of the current best estimate of the amplitdues according to previously...
virtual std::shared_ptr< const FockVector< F > > get()=0
Returns the current best estimate of the amplitudes according to previously given pairs of amplitudes...
virtual std::string getName()=0
Returns the name of the implenting mixer.
Definition Algorithm.hpp:10
std::shared_ptr< Mixer< F > > createMixer(Algorithm *algorithm)
template function creating an instance of the given class.
Definition Mixer.hpp:99