DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
mixingClass.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16
17#ifndef DFTFE_MIXINGCLASS_H
18#define DFTFE_MIXINGCLASS_H
19
20#include <deque>
21#include <headers.h>
22#include <dftParameters.h>
23
24namespace dftfe
25{
26 /**
27 * @brief Enum class that stores he list of variables that will can be
28 * used in the mixing scheme
29 *
30 */
39
40 /**
41 * @brief This class performs the anderson mixing in a variable agnostic way
42 * This class takes can take different input variables as input in a
43 * std::vector format and computes the mixing coefficients These coefficients
44 * can then be used to compute the new variable at the start of the SCF.
45 * @author Vishal Subramanian
46 */
48 {
49 public:
50 MixingScheme(const MPI_Comm & mpi_comm_parent,
51 const MPI_Comm & mpi_comm_domain,
52 const unsigned int verbosity);
53
54 unsigned int
56
57 /**
58 * @brief Computes the mixing coefficients.
59 *
60 */
61 void
63 const std::vector<mixingVariable> mixingVariablesList);
64
65 /**
66 * @brief Computes the adaptive mixing parameter.
67 *
68 */
69 void
71
72 /**
73 * @brief Deletes the old history if the length exceeds max length of history
74 *
75 */
76 void
77 popOldHistory(unsigned int mixingHistory);
78
79 /**
80 * @brief Clears all the the history.
81 *
82 */
83 void
85
86 /**
87 * @brief This function is used to add the mixing variables and its corresponding
88 * JxW values
89 * For dependent variables which are not used in mixing, the
90 * weightDotProducts is set to a vector of size zero. Later the dependent
91 * variables can be mixed with the same mixing coefficients.
92 *
93 */
94 void
96 const mixingVariable mixingVariableList,
98 & weightDotProducts,
99 const bool performMPIReduce,
100 const double mixingValue,
101 const bool adaptMixingValue);
102
103 /**
104 * @brief Adds to the input history
105 *
106 */
107 void
108 addVariableToInHist(const mixingVariable mixingVariableName,
109 const double * inputVariableToInHist,
110 const unsigned int length);
111
112 /**
113 * @brief Adds to the residual history
114 *
115 */
116 void
118 const double * inputVariableToResidualHist,
119 const unsigned int length);
120
121 /**
122 * @brief Computes the input for the next iteration based on the anderson coefficients
123 *
124 */
125 void
126 mixVariable(const mixingVariable mixingVariableName,
127 double * outputVariable,
128 const unsigned int lenVar);
129
130
131 void
132 getOptimizedResidual(const mixingVariable mixingVariableName,
133 double * outputVariable,
134 const unsigned int lenVar);
135
136
137 void
139 double * inputVariable,
140 double * outputVariable,
141 const unsigned int lenVar);
142
143
144 private:
145 /**
146 * @brief Computes the matrix A and c vector that will be needed for anderson mixing.
147 * This function computes the A and c values for each variable which will be
148 * then added up in computeAndersonMixingCoeff()
149 */
150 void
152 const std::deque<
154 &inHist,
155 const std::deque<
157 &outHist,
159 & weightDotProducts,
160 const bool isPerformMixing,
161 const bool isMPIAllReduce,
162 std::vector<double> &A,
163 std::vector<double> &c);
164
165 std::vector<double> d_A, d_c;
166 double d_cFinal;
167
168 std::map<
170 std::deque<
173 std::map<
177 std::map<mixingVariable, bool> d_performMPIReduce;
178
180
181 std::map<mixingVariable, double> d_mixingParameter;
182 std::map<mixingVariable, bool> d_adaptMixingParameter;
187 unsigned int d_mixingHistory;
188 std::map<mixingVariable, bool> d_performMixing;
189 const int d_verbosity;
190
191
192 /// conditional stream object
193 dealii::ConditionalOStream pcout;
194 };
195} // end of namespace dftfe
196#endif // DFTFE_MIXINGCLASS_H
void clearHistory()
Clears all the the history.
std::vector< double > d_A
Definition mixingClass.h:165
const MPI_Comm d_mpi_comm_domain
Definition mixingClass.h:179
bool d_anyMixingParameterAdaptive
Definition mixingClass.h:183
std::map< mixingVariable, bool > d_adaptMixingParameter
Definition mixingClass.h:182
void mixVariable(const mixingVariable mixingVariableName, double *outputVariable, const unsigned int lenVar)
Computes the input for the next iteration based on the anderson coefficients.
unsigned int lengthOfHistory()
void popOldHistory(unsigned int mixingHistory)
Deletes the old history if the length exceeds max length of history.
const MPI_Comm d_mpi_comm_parent
Definition mixingClass.h:179
void computeAndersonMixingCoeff(const std::vector< mixingVariable > mixingVariablesList)
Computes the mixing coefficients.
void addVariableToInHist(const mixingVariable mixingVariableName, const double *inputVariableToInHist, const unsigned int length)
Adds to the input history.
bool d_adaptiveMixingParameterDecAllIterations
Definition mixingClass.h:185
std::vector< double > d_c
Definition mixingClass.h:165
std::map< mixingVariable, std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > > d_variableHistoryResidual
Definition mixingClass.h:172
dealii::ConditionalOStream pcout
conditional stream object
Definition mixingClass.h:193
bool d_adaptiveMixingParameterDecLastIteration
Definition mixingClass.h:184
unsigned int d_mixingHistory
Definition mixingClass.h:187
std::map< mixingVariable, std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > > d_variableHistoryIn
Definition mixingClass.h:172
void addVariableToResidualHist(const mixingVariable mixingVariableName, const double *inputVariableToResidualHist, const unsigned int length)
Adds to the residual history.
double d_cFinal
Definition mixingClass.h:166
void getOptimizedResidual(const mixingVariable mixingVariableName, double *outputVariable, const unsigned int lenVar)
void addMixingVariable(const mixingVariable mixingVariableList, const dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > &weightDotProducts, const bool performMPIReduce, const double mixingValue, const bool adaptMixingValue)
This function is used to add the mixing variables and its corresponding JxW values For dependent vari...
bool d_adaptiveMixingParameterIncAllIterations
Definition mixingClass.h:186
std::map< mixingVariable, bool > d_performMixing
Definition mixingClass.h:188
void computeMixingMatrices(const std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > &inHist, const std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > &outHist, const dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > &weightDotProducts, const bool isPerformMixing, const bool isMPIAllReduce, std::vector< double > &A, std::vector< double > &c)
Computes the matrix A and c vector that will be needed for anderson mixing. This function computes th...
std::map< mixingVariable, dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > d_vectorDotProductWeights
Definition mixingClass.h:176
void computeAdaptiveAndersonMixingParameter()
Computes the adaptive mixing parameter.
std::map< mixingVariable, bool > d_performMPIReduce
Definition mixingClass.h:177
std::map< mixingVariable, double > d_mixingParameter
Definition mixingClass.h:181
void mixPreconditionedResidual(const mixingVariable mixingVariableName, double *inputVariable, double *outputVariable, const unsigned int lenVar)
MixingScheme(const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const unsigned int verbosity)
const int d_verbosity
Definition mixingClass.h:189
Definition MemoryStorage.h:33
Definition pseudoPotentialToDftfeConverter.cc:34
mixingVariable
Enum class that stores he list of variables that will can be used in the mixing scheme.
Definition mixingClass.h:32
@ magZ
Definition mixingClass.h:35
@ gradMagZ
Definition mixingClass.h:36
@ gradRho
Definition mixingClass.h:34
@ rho
Definition mixingClass.h:33
@ hubbardOccupation
Definition mixingClass.h:37