TBTK
Need a break? Support the development by playing Polarity Puzzles
HartreeFock.h
1 /* Copyright 2019 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_HARTREE_FOCK_DIAGONALIZATION
25 #define COM_DAFER45_TBTK_HARTREE_FOCK_DIAGONALIZATION
26 
27 #include "TBTK/Atom.h"
28 #include "TBTK/Solver/Diagonalizer.h"
29 
30 namespace TBTK{
31 namespace Solver{
32 
34 class HartreeFock : public Diagonalizer{
35 public:
42  class Callbacks :
43  public HoppingAmplitude::AmplitudeCallback,
44  public OverlapAmplitude::AmplitudeCallback
45  {
46  public:
48  Callbacks();
49 
53  virtual std::complex<double> getHoppingAmplitude(
54  const Index &to,
55  const Index &from
56  ) const;
57 
61  virtual std::complex<double> getOverlapAmplitude(
62  const Index &bra,
63  const Index &ket
64  ) const;
65 
71  void setSolver(const HartreeFock &solver);
72  private:
75  const HartreeFock *solver;
76  };
77 
79  HartreeFock();
80 
82  virtual ~HartreeFock();
83 
87  void setOccupationNumber(unsigned int occupationNumber);
88 
92  double getTotalEnergy() const;
93 
98  void addNuclearCenter(const Atom &atom, const Vector3d &position);
99 
101  void run();
102 private:
104  class PositionedAtom : public Atom{
105  public:
110  PositionedAtom(const Atom &atom, const Vector3d &position);
111 
115  const Vector3d& getPosition() const;
116  private:
117  //Position
118  Vector3d position;
119  };
120 
122  std::vector<const AbstractState*> basisStates;
123 
125  Matrix<std::complex<double>> densityMatrix;
126 
128  std::vector<PositionedAtom> nuclearCenters;
129 
131  unsigned int occupationNumber;
132 
134  double totalEnergy;
135 
137  class SelfConsistencyCallback :
138  public Diagonalizer::SelfConsistencyCallback
139  {
140  public:
145  SelfConsistencyCallback(HartreeFock &solver);
146 
150  virtual bool selfConsistencyCallback(
151  Diagonalizer &diagonalizer
152  );
153  private:
155  HartreeFock &solver;
156  } selfConsistencyCallback;
157 
159  const Matrix<std::complex<double>>& getDensityMatrix() const;
160 
162  const std::vector<PositionedAtom>& getNuclearCenters() const;
163 
165  void calculateTotalEnergy();
166 };
167 
168 inline void HartreeFock::setOccupationNumber(unsigned int occupationNumber){
169  this->occupationNumber = occupationNumber;
170 }
171 
172 inline double HartreeFock::getTotalEnergy() const{
173  return totalEnergy;
174 }
175 
176 inline const Matrix<std::complex<double>>&
177 HartreeFock::getDensityMatrix() const{
178  return densityMatrix;
179 }
180 
181 inline void HartreeFock::addNuclearCenter(
182  const Atom &atom,
183  const Vector3d &position
184 ){
185  nuclearCenters.push_back(PositionedAtom(atom, position));
186 }
187 
188 inline const std::vector<HartreeFock::PositionedAtom>&
189 HartreeFock::getNuclearCenters() const{
190  return nuclearCenters;
191 }
192 
193 inline void HartreeFock::Callbacks::setSolver(const HartreeFock &solver){
194  this->solver = &solver;
195 }
196 
197 inline HartreeFock::PositionedAtom::PositionedAtom(
198  const Atom &atom,
199  const Vector3d &position
200 ) :
201  Atom(atom),
202  position(position)
203 {
204 }
205 
206 inline const Vector3d& HartreeFock::PositionedAtom::getPosition() const{
207  return position;
208 }
209 
210 }; //End of namespace Solver
211 }; //End of namespace TBTK
212 
213 #endif
214 
Definition: Boolean.h:32
Atom.h.