SIRIUS 7.5.0
Electronic structure library and applications
linear_mixer.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2019 Simon Frasch, Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file linear_mixer.hpp
21 *
22 * \brief Contains definition and implementation of sirius::Linear_mixer.
23 */
24
25#ifndef __LINEAR_MIXER_HPP__
26#define __LINEAR_MIXER_HPP__
27
28#include <tuple>
29#include <functional>
30#include <utility>
31#include <vector>
32#include <limits>
33#include <memory>
34#include <exception>
35#include <cmath>
36#include <numeric>
37
38#include "mixer/mixer.hpp"
39
40namespace sirius {
41namespace mixer {
42template <typename... FUNCS>
43class Linear : public Mixer<FUNCS...>
44{
45 public:
46 explicit Linear(double beta)
47 : Mixer<FUNCS...>(2)
48 , beta_(beta)
49 {
50 }
51
52 void mix_impl() override
53 {
54 const auto idx = this->idx_hist(this->step_ + 1);
55
56 this->copy(this->input_, this->output_history_[idx]);
57 this->scale(beta_, this->output_history_[idx]);
58 this->axpy(1.0 - beta_, this->output_history_[this->idx_hist(this->step_)], this->output_history_[idx]);
59 }
60
61 private:
62 double beta_;
63};
64} // namespace mixer
65} // namespace sirius
66
67#endif // __MIXER_HPP__
Abstract mixer for variadic number of Function objects, which are described by FunctionProperties.
Definition: mixer.hpp:279
Contains definition and implementation of sirius::Mixer base class.
Namespace of the SIRIUS library.
Definition: sirius.f90:5