SIRIUS 7.5.0
Electronic structure library and applications
mixer_factory.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 mixer_factory.hpp
21 *
22 * \brief Contains the mixer facttory for creating different types of mixers.
23 */
24
25#ifndef __MIXER_FACTORY_HPP__
26#define __MIXER_FACTORY_HPP__
27
28#include "mixer/mixer.hpp"
34
35namespace sirius {
36namespace mixer {
37
38/// Select and create a new mixer.
39/** \param [in] mix_cfg Parameters for mixer selection and creation.
40 * \param [in] comm Communicator passed to the mixer.
41 */
42template <typename... FUNCS>
43inline std::unique_ptr<Mixer<FUNCS...>> Mixer_factory(config_t::mixer_t const& mix_cfg)
44{
45 std::unique_ptr<Mixer<FUNCS...>> mixer;
46
47 if (mix_cfg.type() == "linear") {
48 mixer.reset(new Linear<FUNCS...>(mix_cfg.beta()));
49 }
50 // broyden1 is a misnomer, but keep it for backward compatibility
51 else if (mix_cfg.type() == "broyden1" || mix_cfg.type() == "anderson") {
52 mixer.reset(new Anderson<FUNCS...>(mix_cfg.max_history(), mix_cfg.beta(), mix_cfg.beta0(),
53 mix_cfg.beta_scaling_factor()));
54 } else if (mix_cfg.type() == "anderson_stable") {
55 mixer.reset(new Anderson_stable<FUNCS...>(mix_cfg.max_history(), mix_cfg.beta()));
56 } else if (mix_cfg.type() == "broyden2") {
57 mixer.reset(new Broyden2<FUNCS...>(mix_cfg.max_history(), mix_cfg.beta(), mix_cfg.beta0(),
58 mix_cfg.beta_scaling_factor(), mix_cfg.linear_mix_rms_tol()));
59 } else {
60 RTE_THROW("wrong type of mixer");
61 }
62 return mixer;
63}
64
65} // namespace mixer
66} // namespace sirius
67
68#endif // __MIXER_HPP__
Contains definition and implementation sirius::Anderson.
Contains definition and implementation sirius::Anderson_stable.
Contains definition and implementation of sirius::Broyden2.
Parameters of the mixer.
Definition: config.hpp:16
auto type() const
Type of the mixer.
Definition: config.hpp:23
auto linear_mix_rms_tol() const
RMS tolerance above which the linear mixing is triggered.
Definition: config.hpp:59
auto beta0() const
Mixing ratio in case of initial linear mixing.
Definition: config.hpp:47
auto beta() const
Mixing parameter.
Definition: config.hpp:35
auto beta_scaling_factor() const
Scaling factor for mixing parameter.
Definition: config.hpp:83
auto max_history() const
Number of history steps for Broyden-type mixers.
Definition: config.hpp:71
Abstract mixer for variadic number of Function objects, which are described by FunctionProperties.
Definition: mixer.hpp:279
Contains definition and implementation of sirius::Linear_mixer.
Contains definition and implementation of sirius::Mixer base class.
std::unique_ptr< Mixer< FUNCS... > > Mixer_factory(config_t::mixer_t const &mix_cfg)
Select and create a new mixer.
Namespace of the SIRIUS library.
Definition: sirius.f90:5
Contains definition and implementation of sirius::Simulation_parameters class.