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