DFT-EFE
 
Loading...
Searching...
No Matches
MixingScheme.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Avirup Sircar
24 * @adapted from
25 * "https://github.com/dftfeDevelopers/dftfe/blob/publicGithubDevelop/include/MixingScheme.h"
26 */
27
28#ifndef dftefeMixingScheme_h
29#define dftefeMixingScheme_h
30
31#include <deque>
36
37namespace dftefe
38{
39 namespace ksdft
40 {
46 enum class mixingVariable
47 {
48 rho,
49 gradRho, // GGA — dependent (empty weights)
50 /*magZ, // spin-polarized / non-collinear
51 gradMagZ, // spin-polarized GGA / non-collinear GGA — dependent
52 magY, // non-collinear only
53 gradMagY, // non-collinear GGA — dependent
54 magX, // non-collinear only
55 gradMagX, // non-collinear GGA — dependent
56 tau, // meta-GGA — primary, full JxW weights
57 tauMagZ, // MGGA spin-polarized
58 tauMagY, // MGGA non-collinear
59 tauMagX, // MGGA non-collinear*/
60 };
61
70 template <typename ValueTypeMixingVariable, typename ValueTypeWeights>
72 {
73 public:
74 using ValueType =
76 ValueTypeMixingVariable>;
77
78 public:
79 MixingScheme(const utils::mpi::MPIComm &mpiComm);
80
81 ~MixingScheme() = default;
82
85
90 void
92 const std::vector<mixingVariable> mixingVariablesList,
94 &linAlgOpContextHost);
95
100 void
102
107 void
108 popOldHistory(size_type mixingHistory);
109
114 void
115 clearHistory();
116
125 void
127 const mixingVariable mixingVariableList,
129 & weightDotProducts,
130 const bool performMPIReduce,
131 const double mixingValue,
132 const bool isAdaptiveMixing);
133
138 template <utils::MemorySpace memorySpace>
139 void
140 addVariableToInHist(const mixingVariable mixingVariableName,
141 const ValueTypeMixingVariable *inputVariableToInHist,
142 const size_type length);
143
148 template <utils::MemorySpace memorySpace>
149 void
151 const mixingVariable mixingVariableName,
152 const ValueTypeMixingVariable *inputVariableToResidualHist,
153 const size_type length);
154
159 template <utils::MemorySpace memorySpace>
160 void
161 mixVariable(const mixingVariable mixingVariableName,
162 ValueTypeMixingVariable *outputVariable,
163 const size_type lenVar);
164
165 bool
166 hasVariable(mixingVariable var) const;
167
168 private:
174 void
176 const std::deque<std::vector<ValueTypeMixingVariable>> &inHist,
177 const std::deque<std::vector<ValueTypeMixingVariable>> &outHist,
179 & weightDotProducts,
180 const bool isPerformMixing,
181 const bool isMPIAllReduce,
182 std::vector<ValueType> &A,
183 std::vector<ValueType> &c);
184
185 std::vector<ValueType> d_A, d_c;
187
188 std::map<mixingVariable, std::deque<std::vector<ValueTypeMixingVariable>>>
190 std::map<mixingVariable,
193 std::map<mixingVariable, bool> d_performMPIReduce;
194
195 const MPI_Comm &d_mpiComm;
196
197 std::map<mixingVariable, double> d_mixingParameter;
198 std::map<mixingVariable, bool> d_isAdaptiveMixing;
204 std::map<mixingVariable, bool> d_performMixing;
206 };
207 } // namespace ksdft
208} // end of namespace dftefe
210#endif // dftefeMixingScheme_h
This class performs the anderson mixing in a variable agnostic way This class takes can take differen...
Definition: MixingScheme.h:72
std::vector< ValueType > d_A
Definition: MixingScheme.h:185
ValueType d_cFinal
Definition: MixingScheme.h:186
void computeAdaptiveAndersonMixingParameter()
Computes the adaptive mixing parameter.
Definition: MixingScheme.t.cpp:250
std::map< mixingVariable, bool > d_performMixing
Definition: MixingScheme.h:204
void addVariableToInHist(const mixingVariable mixingVariableName, const ValueTypeMixingVariable *inputVariableToInHist, const size_type length)
Adds to the input history.
Definition: MixingScheme.t.cpp:314
std::vector< ValueType > d_c
Definition: MixingScheme.h:185
std::map< mixingVariable, utils::MemoryStorage< ValueTypeWeights, utils::MemorySpace::HOST > > d_vectorDotProductWeights
Definition: MixingScheme.h:192
linearAlgebra::blasLapack::scalar_type< ValueTypeWeights, ValueTypeMixingVariable > ValueType
Definition: MixingScheme.h:76
size_type d_mixingHistory
Definition: MixingScheme.h:203
std::map< mixingVariable, bool > d_performMPIReduce
Definition: MixingScheme.h:193
void popOldHistory(size_type mixingHistory)
Deletes the old history if the length exceeds max length of history.
Definition: MixingScheme.t.cpp:425
void mixVariable(const mixingVariable mixingVariableName, ValueTypeMixingVariable *outputVariable, const size_type lenVar)
Computes the input for the next iteration based on the anderson coefficients.
Definition: MixingScheme.t.cpp:362
void clearHistory()
Clears all the the history.
Definition: MixingScheme.t.cpp:409
void computeMixingMatrices(const std::deque< std::vector< ValueTypeMixingVariable > > &inHist, const std::deque< std::vector< ValueTypeMixingVariable > > &outHist, const utils::MemoryStorage< ValueTypeWeights, utils::MemorySpace::HOST > &weightDotProducts, const bool isPerformMixing, const bool isMPIAllReduce, std::vector< ValueType > &A, std::vector< ValueType > &c)
Computes the matrix A and c vector that will be needed for anderson mixing. This function computes th...
Definition: MixingScheme.t.cpp:93
bool hasVariable(mixingVariable var) const
Definition: MixingScheme.t.cpp:439
std::map< mixingVariable, double > d_mixingParameter
Definition: MixingScheme.h:197
void addMixingVariable(const mixingVariable mixingVariableList, const utils::MemoryStorage< ValueTypeWeights, utils::MemorySpace::HOST > &weightDotProducts, const bool performMPIReduce, const double mixingValue, const bool isAdaptiveMixing)
This function is used to add the mixing variables and its corresponding JxW values For dependent vari...
Definition: MixingScheme.t.cpp:43
bool d_anyMixingParameterAdaptive
Definition: MixingScheme.h:199
bool d_adaptiveMixingParameterIncAllIterations
Definition: MixingScheme.h:202
const MPI_Comm & d_mpiComm
Definition: MixingScheme.h:195
std::map< mixingVariable, std::deque< std::vector< ValueTypeMixingVariable > > > d_variableHistoryResidual
Definition: MixingScheme.h:189
utils::ConditionalOStream d_rootCout
Definition: MixingScheme.h:205
bool d_adaptiveMixingParameterDecLastIteration
Definition: MixingScheme.h:200
size_type lengthOfHistory()
Definition: MixingScheme.t.cpp:196
void computeAndersonMixingCoeff(const std::vector< mixingVariable > mixingVariablesList, linearAlgebra::LinAlgOpContext< utils::MemorySpace::HOST > &linAlgOpContextHost)
Computes the mixing coefficients.
Definition: MixingScheme.t.cpp:206
void addVariableToResidualHist(const mixingVariable mixingVariableName, const ValueTypeMixingVariable *inputVariableToResidualHist, const size_type length)
Adds to the residual history.
Definition: MixingScheme.t.cpp:337
bool d_adaptiveMixingParameterDecAllIterations
Definition: MixingScheme.h:201
std::map< mixingVariable, std::deque< std::vector< ValueTypeMixingVariable > > > d_variableHistoryIn
Definition: MixingScheme.h:189
std::map< mixingVariable, bool > d_isAdaptiveMixing
Definition: MixingScheme.h:198
Definition: LinAlgOpContext.h:52
Provides an interface to print based on whether a certain condition is met or not....
Definition: ConditionalOStream.h:47
Definition: MemoryStorage.h:38
mixingVariable
Enum class that stores he list of variables that will can be used in the mixing scheme.
Definition: MixingScheme.h:47
typeInternal::scalar_type< ValueType1, ValueType2 > scalar_type
Definition: BlasLapackTypedef.h:183
int MPIComm
Definition: MPITypes.h:84
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
std::uint64_t size_type
Definition: TypeConfig.h:9