GQCP
Loading...
Searching...
No Matches
CompoundConvergenceCriterion.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
22
23#include <boost/format.hpp>
24
25#include <memory>
26#include <vector>
27
28
29namespace GQCP {
30
31
37template <typename _Environment>
39 public ConvergenceCriterion<_Environment> {
40
41public:
42 using Environment = _Environment;
44
45
46private:
47 std::vector<std::shared_ptr<ConvergenceCriterion<Environment>>> criteria;
48
49
50public:
51 /*
52 * CONSTRUCTORS
53 */
54
61 template <typename C1, typename C2>
62 CompoundConvergenceCriterion(const C1& criterion1, const C2& criterion2) :
63 criteria {std::make_shared<C1>(criterion1), std::make_shared<C2>(criterion2)} {}
64
65
73 std::string description() const override {
74
75 std::string description_string = (boost::format("A compound convergence criterion step consisting of %s combined criteria:\n") % this->count()).str();
76
77 for (size_t i = 0; i < this->count(); i++) {
78 const auto& criterion = this->criteria[i];
79 description_string += (boost::format("\t%s. %s\n") % std::to_string(i + 1) % criterion->description()).str();
80 }
81 return description_string;
82 }
83
84
90 bool isFulfilled(Environment& environment) override {
91
92 // Check if every criterion is fulfilled.
93 for (const auto& criterion : this->criteria) {
94 if (!criterion->isFulfilled(environment)) {
95 return false;
96 }
97 }
98 return true;
99 }
100
101
102 /*
103 * PUBLIC METHODS
104 */
105
113 template <typename C>
114 Self add(const C& criterion) {
115 this->criteria.push_back(std::make_shared<C>(criterion));
116 return *this;
117 }
118
119
123 size_t count() const { return this->criteria.size(); }
124};
125
126
127} // namespace GQCP
Definition: CompoundConvergenceCriterion.hpp:39
Self add(const C &criterion)
Definition: CompoundConvergenceCriterion.hpp:114
std::string description() const override
Definition: CompoundConvergenceCriterion.hpp:73
bool isFulfilled(Environment &environment) override
Definition: CompoundConvergenceCriterion.hpp:90
size_t count() const
Definition: CompoundConvergenceCriterion.hpp:123
CompoundConvergenceCriterion(const C1 &criterion1, const C2 &criterion2)
Definition: CompoundConvergenceCriterion.hpp:62
_Environment Environment
Definition: CompoundConvergenceCriterion.hpp:42
Definition: ConvergenceCriterion.hpp:33
Definition: BaseOneElectronIntegralBuffer.hpp:25