GQCP
Loading...
Searching...
No Matches
CI.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
26
27#include <memory>
28
29
30namespace GQCP {
31namespace QCMethod {
32
33
40template <typename _Scalar, typename _ONVBasis>
41class CI {
42public:
43 // The scalar type of the expansion coefficients: real or complex.
44 using Scalar = _Scalar;
45
46 // The type of the ONV basis.
47 using ONVBasis = _ONVBasis;
48
49
50private:
51 // The number of states that are searched for (including the ground state).
52 size_t number_of_states;
53
54 // The ONV basis with respect to which the configuration interaction is expressed.
55 ONVBasis onv_basis;
56
57
58public:
59 /*
60 * MARK: Constructors
61 */
62
67 CI(const ONVBasis& onv_basis, const size_t number_of_states = 1) :
68 onv_basis {onv_basis},
69 number_of_states {number_of_states} {}
70
71
72 /*
73 * MARK: Optimization
74 */
75
83 template <typename Solver>
85
86 // The CI method's responsibility is to try to optimize the parameters of its method, given a solver and associated environment.
87 solver.perform(environment);
88
89
90 // Extract the requested number of eigenpairs from the environment and place them into the LinearExpansion wave function model.
91 const auto eigenpairs = environment.eigenpairs(this->number_of_states);
92
93 std::vector<LinearExpansion<Scalar, ONVBasis>> linear_expansions {};
94 linear_expansions.reserve(number_of_states);
95
96 std::vector<Scalar> energies {};
97 energies.reserve(this->number_of_states);
98
99 for (const auto& eigenpair : eigenpairs) {
100 linear_expansions.emplace_back(onv_basis, eigenpair.eigenvector());
101 energies.push_back(eigenpair.eigenvalue());
102 }
103
104
105 // Wrap all the requested number of states into a QCStructure.
106 // Since we have already created a list of LinearExpansions, we only have to create a list of the corresponding energies.
107 return QCStructure<LinearExpansion<Scalar, ONVBasis>, Scalar>(energies, linear_expansions);
108 }
109};
110
111
112} // namespace QCMethod
113} // namespace GQCP
Definition: EigenproblemEnvironment.hpp:35
std::vector< Eigenpair< double, Scalar > > eigenpairs(const size_t number_of_requested_eigenpairs=1) const
Definition: EigenproblemEnvironment.hpp:154
Definition: CI.hpp:41
QCStructure< LinearExpansion< Scalar, ONVBasis >, Scalar > optimize(Solver &solver, EigenproblemEnvironment< Scalar > &environment) const
Definition: CI.hpp:84
_Scalar Scalar
Definition: CI.hpp:44
_ONVBasis ONVBasis
Definition: CI.hpp:47
CI(const ONVBasis &onv_basis, const size_t number_of_states=1)
Definition: CI.hpp:67
Definition: QCStructure.hpp:36
Definition: BaseOneElectronIntegralBuffer.hpp:25