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 */
41
42 /**
43 * @brief This class performs the anderson mixing in a variable agnostic way
44 * This class takes can take different input variables as input in a
45 * std::vector format and computes the mixing coefficients These coefficients
46 * can then be used to compute the new variable at the start of the SCF.
47 * @author Vishal Subramanian
48 */
50 {
51 public:
52 MixingScheme(const MPI_Comm &mpi_comm_parent,
53 const MPI_Comm &mpi_comm_domain,
54 const dftfe::uInt verbosity);
55
58
59 /**
60 * @brief Computes the mixing coefficients.
61 *
62 */
63 void
65 const std::vector<mixingVariable> mixingVariablesList);
66
67 /**
68 * @brief Computes the adaptive mixing parameter.
69 *
70 */
71 void
73
74 /**
75 * @brief Deletes the old history if the length exceeds max length of history
76 *
77 */
78 void
79 popOldHistory(dftfe::uInt mixingHistory);
80
81 /**
82 * @brief Clears all the the history.
83 *
84 */
85 void
87
88 /**
89 * @brief This function is used to add the mixing variables and its corresponding
90 * JxW values
91 * For dependent variables which are not used in mixing, the
92 * weightDotProducts is set to a vector of size zero. Later the dependent
93 * variables can be mixed with the same mixing coefficients.
94 *
95 */
96 void
98 const mixingVariable mixingVariableList,
100 &weightDotProducts,
101 const bool performMPIReduce,
102 const double mixingValue,
103 const bool adaptMixingValue);
104
105 /**
106 * @brief Adds to the input history
107 *
108 */
109 void
110 addVariableToInHist(const mixingVariable mixingVariableName,
111 const double *inputVariableToInHist,
112 const dftfe::uInt length);
113
114 /**
115 * @brief Adds to the residual history
116 *
117 */
118 void
120 const double *inputVariableToResidualHist,
121 const dftfe::uInt length);
122
123 /**
124 * @brief Computes the input for the next iteration based on the anderson coefficients
125 *
126 */
127 void
128 mixVariable(const mixingVariable mixingVariableName,
129 double *outputVariable,
130 const dftfe::uInt lenVar);
131
132
133 void
134 getOptimizedResidual(const mixingVariable mixingVariableName,
135 double *outputVariable,
136 const dftfe::uInt lenVar);
137
138
139 void
141 double *inputVariable,
142 double *outputVariable,
143 const dftfe::uInt lenVar);
144
145
146 private:
147 /**
148 * @brief Computes the matrix A and c vector that will be needed for anderson mixing.
149 * This function computes the A and c values for each variable which will be
150 * then added up in computeAndersonMixingCoeff()
151 */
152 void
154 const std::deque<
156 &inHist,
157 const std::deque<
159 &outHist,
161 &weightDotProducts,
162 const bool isPerformMixing,
163 const bool isMPIAllReduce,
164 std::vector<double> &A,
165 std::vector<double> &c);
166
167 std::vector<double> d_A, d_c;
168 double d_cFinal;
169
170 public:
171 std::map<
173 std::deque<
176
177 private:
178 std::map<
182 std::map<mixingVariable, bool> d_performMPIReduce;
183
185
186 std::map<mixingVariable, double> d_mixingParameter;
187 std::map<mixingVariable, bool> d_adaptMixingParameter;
193 std::map<mixingVariable, bool> d_performMixing;
195
196
197 /// conditional stream object
198 dealii::ConditionalOStream pcout;
199 };
200} // end of namespace dftfe
201#endif // DFTFE_MIXINGCLASS_H
void clearHistory()
Clears all the the history.
std::vector< double > d_A
Definition mixingClass.h:167
const MPI_Comm d_mpi_comm_domain
Definition mixingClass.h:184
bool d_anyMixingParameterAdaptive
Definition mixingClass.h:188
void getOptimizedResidual(const mixingVariable mixingVariableName, double *outputVariable, const dftfe::uInt lenVar)
std::map< mixingVariable, bool > d_adaptMixingParameter
Definition mixingClass.h:187
void addVariableToInHist(const mixingVariable mixingVariableName, const double *inputVariableToInHist, const dftfe::uInt length)
Adds to the input history.
const MPI_Comm d_mpi_comm_parent
Definition mixingClass.h:184
void computeAndersonMixingCoeff(const std::vector< mixingVariable > mixingVariablesList)
Computes the mixing coefficients.
MixingScheme(const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const dftfe::uInt verbosity)
dftfe::uInt lengthOfHistory()
bool d_adaptiveMixingParameterDecAllIterations
Definition mixingClass.h:190
std::vector< double > d_c
Definition mixingClass.h:167
std::map< mixingVariable, std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > > d_variableHistoryResidual
Definition mixingClass.h:175
dealii::ConditionalOStream pcout
conditional stream object
Definition mixingClass.h:198
bool d_adaptiveMixingParameterDecLastIteration
Definition mixingClass.h:189
std::map< mixingVariable, std::deque< dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > > d_variableHistoryIn
Definition mixingClass.h:175
double d_cFinal
Definition mixingClass.h:168
void mixVariable(const mixingVariable mixingVariableName, double *outputVariable, const dftfe::uInt lenVar)
Computes the input for the next iteration based on the anderson coefficients.
dftfe::uInt d_mixingHistory
Definition mixingClass.h:192
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...
void popOldHistory(dftfe::uInt mixingHistory)
Deletes the old history if the length exceeds max length of history.
bool d_adaptiveMixingParameterIncAllIterations
Definition mixingClass.h:191
std::map< mixingVariable, bool > d_performMixing
Definition mixingClass.h:193
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...
void mixPreconditionedResidual(const mixingVariable mixingVariableName, double *inputVariable, double *outputVariable, const dftfe::uInt lenVar)
const dftfe::Int d_verbosity
Definition mixingClass.h:194
std::map< mixingVariable, dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > > d_vectorDotProductWeights
Definition mixingClass.h:181
void computeAdaptiveAndersonMixingParameter()
Computes the adaptive mixing parameter.
std::map< mixingVariable, bool > d_performMPIReduce
Definition mixingClass.h:182
std::map< mixingVariable, double > d_mixingParameter
Definition mixingClass.h:186
void addVariableToResidualHist(const mixingVariable mixingVariableName, const double *inputVariableToResidualHist, const dftfe::uInt length)
Adds to the residual history.
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
@ tau
Definition mixingClass.h:38
@ gradRho
Definition mixingClass.h:34
@ rho
Definition mixingClass.h:33
@ hubbardOccupation
Definition mixingClass.h:37
@ tauMagZ
Definition mixingClass.h:39
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11