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 };
50
59 template <typename ValueTypeMixingVariable, typename ValueTypeWeights>
61 {
62 public:
63 using ValueType =
65 ValueTypeMixingVariable>;
66
67 public:
68 MixingScheme(const utils::mpi::MPIComm &mpiComm);
69
72
77 void
79 const std::vector<mixingVariable> mixingVariablesList,
81 &linAlgOpContextHost);
82
87 void
89
94 void
95 popOldHistory(size_type mixingHistory);
96
101 void
102 clearHistory();
103
112 void
114 const mixingVariable mixingVariableList,
116 & weightDotProducts,
117 const bool performMPIReduce,
118 const double mixingValue,
119 const bool isAdaptiveMixing);
120
125 template <utils::MemorySpace memorySpace>
126 void
127 addVariableToInHist(const mixingVariable mixingVariableName,
128 const ValueTypeMixingVariable *inputVariableToInHist,
129 const size_type length);
130
135 template <utils::MemorySpace memorySpace>
136 void
138 const mixingVariable mixingVariableName,
139 const ValueTypeMixingVariable *inputVariableToResidualHist,
140 const size_type length);
141
146 template <utils::MemorySpace memorySpace>
147 void
148 mixVariable(const mixingVariable mixingVariableName,
149 ValueTypeMixingVariable *outputVariable,
150 const size_type lenVar);
151
152
153 private:
159 void
161 const std::deque<std::vector<ValueTypeMixingVariable>> &inHist,
162 const std::deque<std::vector<ValueTypeMixingVariable>> &outHist,
164 & weightDotProducts,
165 const bool isPerformMixing,
166 const bool isMPIAllReduce,
167 std::vector<ValueType> &A,
168 std::vector<ValueType> &c);
169
170 std::vector<ValueType> d_A, d_c;
172
173 std::map<mixingVariable, std::deque<std::vector<ValueTypeMixingVariable>>>
175 std::map<mixingVariable,
178 std::map<mixingVariable, bool> d_performMPIReduce;
179
180 const MPI_Comm &d_mpiComm;
181
182 std::map<mixingVariable, double> d_mixingParameter;
183 std::map<mixingVariable, bool> d_isAdaptiveMixing;
189 std::map<mixingVariable, bool> d_performMixing;
191 };
192 } // namespace ksdft
193} // end of namespace dftefe
195#endif // dftefeMixingScheme_h
This class performs the anderson mixing in a variable agnostic way This class takes can take differen...
Definition: MixingScheme.h:61
std::vector< ValueType > d_A
Definition: MixingScheme.h:170
ValueType d_cFinal
Definition: MixingScheme.h:171
void computeAdaptiveAndersonMixingParameter()
Computes the adaptive mixing parameter.
Definition: MixingScheme.t.cpp:251
std::map< mixingVariable, bool > d_performMixing
Definition: MixingScheme.h:189
void addVariableToInHist(const mixingVariable mixingVariableName, const ValueTypeMixingVariable *inputVariableToInHist, const size_type length)
Adds to the input history.
Definition: MixingScheme.t.cpp:315
std::vector< ValueType > d_c
Definition: MixingScheme.h:170
std::map< mixingVariable, utils::MemoryStorage< ValueTypeWeights, utils::MemorySpace::HOST > > d_vectorDotProductWeights
Definition: MixingScheme.h:177
linearAlgebra::blasLapack::scalar_type< ValueTypeWeights, ValueTypeMixingVariable > ValueType
Definition: MixingScheme.h:65
size_type d_mixingHistory
Definition: MixingScheme.h:188
std::map< mixingVariable, bool > d_performMPIReduce
Definition: MixingScheme.h:178
void popOldHistory(size_type mixingHistory)
Deletes the old history if the length exceeds max length of history.
Definition: MixingScheme.t.cpp:426
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:363
void clearHistory()
Clears all the the history.
Definition: MixingScheme.t.cpp:410
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
std::map< mixingVariable, double > d_mixingParameter
Definition: MixingScheme.h:182
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:184
bool d_adaptiveMixingParameterIncAllIterations
Definition: MixingScheme.h:187
const MPI_Comm & d_mpiComm
Definition: MixingScheme.h:180
std::map< mixingVariable, std::deque< std::vector< ValueTypeMixingVariable > > > d_variableHistoryResidual
Definition: MixingScheme.h:174
utils::ConditionalOStream d_rootCout
Definition: MixingScheme.h:190
bool d_adaptiveMixingParameterDecLastIteration
Definition: MixingScheme.h:185
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:338
bool d_adaptiveMixingParameterDecAllIterations
Definition: MixingScheme.h:186
std::map< mixingVariable, std::deque< std::vector< ValueTypeMixingVariable > > > d_variableHistoryIn
Definition: MixingScheme.h:174
std::map< mixingVariable, bool > d_isAdaptiveMixing
Definition: MixingScheme.h:183
Definition: LinAlgOpContext.h:38
Provides an interface to print based on whether a certain condition is met or not....
Definition: ConditionalOStream.h:45
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
blas::scalar_type< ValueType1, ValueType2 > scalar_type
Definition: BlasLapackTypedef.h:70
int MPIComm
Definition: MPITypes.h:83
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
unsigned int size_type
Definition: TypeConfig.h:8