DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
cgPRPNonLinearSolver.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
18#ifndef CGPRPNonLinearSolver_h
19#define CGPRPNonLinearSolver_h
20
21
22#include "nonLinearSolver.h"
23
24namespace dftfe
25{
26 /**
27 * @brief Concrete class implementing Polak-Ribiere-Polyak Conjugate Gradient non-linear
28 * algebraic solver.
29 *
30 * @author Sambit Das
31 */
33 {
34 public:
35 /**
36 * @brief Constructor.
37 *
38 * @param maxNumberIterations Maximum number of iterations.
39 * @param debugLevel Debug output level:
40 * 0 - no debug output
41 * 1 - limited debug output
42 * 2 - all debug output.
43 * @param lineSearchTolerance Tolereance required for line search
44 * convergence.
45 * @param lineSearchMaxIterations Maximum number of iterations for the
46 * line search.
47 * @param lineSearchDampingParameter scales the initial line search step
48 */
50 const unsigned int maxNumberIterations,
51 const unsigned int debugLevel,
52 const MPI_Comm & mpi_comm_parent,
53 const double lineSearchTolerance = 1.0e-6,
54 const unsigned int lineSearchMaxIterations = 10,
55 const double lineSeachDampingParameter = 1.0,
56 const double maxIncrementSolLinf = 1e+6,
57 const bool isCurvatureOnlyLineSearchStoppingCondition = false);
58
59 /**
60 * @brief Destructor.
61 */
63
64 /**
65 * @brief Solve non-linear problem using Polak-Ribiere-Polyak nonlinar conjugate gradient method.
66 *
67 * @param problem[in] nonlinearSolverProblem object.
68 * @param checkpointFileName[in] if string is non-empty, creates checkpoint file
69 * named checkpointFileName for every nonlinear iteration. If restart is set
70 * to true, checkpointFileName must match the name of the checkpoint file.
71 * Empty string will throw an error.
72 * @param restart[in] boolean specifying whether this is a restart solve using the checkpoint file
73 * specified by checkpointFileName.
74 * @return Return value indicating success or failure.
75 */
78 const std::string checkpointFileName = "",
79 const bool restart = false);
80
81
82 /**
83 * @brief Create checkpoint file for current state of the cg solver.
84 *
85 */
86 void
87 save(const std::string &checkpointFileName);
88
89
90 private:
91 /**
92 * @brief Initialize direction.
93 */
94 void
96
97 /**
98 * @brief Perform line search.
99 *
100 * @param problem nonlinearSolverProblem object (functor) to compute energy and
101 * forces.
102 * @param tolerance Tolerance (relative) required for convergence.
103 * @param maxNumberIterations Maximum number of iterations.
104 * @param debugLevel Debug output level:
105 * 0 - no debug output
106 * 1 - limited debug output
107 * 2 - all debug output.
108 *
109 * @return Return value indicating success or failure.
110 */
113 const double tolerance,
114 const unsigned int maxNumberIterations,
115 const unsigned int debugLevel,
116 const std::string checkpointFileName = "",
117 const int startingIter = -1,
118 const bool isCheckpointRestart = false);
119
120 /**
121 * @brief Compute delta_d and eta_p.
122 *
123 * @return Pair containing delta_d and eta_p.
124 */
125 std::pair<double, double>
127
128 /**
129 * @brief Compute eta.
130 *
131 * @return Value of eta.
132 */
133 double
135
136 /**
137 * @brief Compute delta new and delta mid.
138 */
139 void
141
142 /**
143 * @brief Update direction.
144 */
145 void
147
148 /**
149 * @brief Compute residual L2-norm.
150 *
151 * @return Value of the residual L2-norm.
152 */
153 double
155
156 /**
157 * @brief Compute the total number of unknowns in all
158 * processors.
159 *
160 * @return Number of unknowns in all processors.
161 */
162 unsigned int
164
165 /**
166 * @brief Update solution x -> x + \alpha direction.
167 *
168 * @param alpha Scalar value.
169 * @param direction Direction vector.
170 * @param problem nonlinearSolverProblem object.
171 *
172 * @return bool true if valid update and false if increment bound exceeded
173 *
174 */
175 bool
176 updateSolution(const double alpha,
177 const std::vector<double> &direction,
178 nonlinearSolverProblem & problem);
179
180 /**
181 * @brief Load cg solver state from checkpoint file.
182 *
183 */
184 void
185 load(const std::string &checkpointFileName);
186
187 /// storage for conjugate direction
188 std::vector<double> d_conjugateDirection;
189
190 /// storage for the gradient of the nonlinear problem in the current cg step
191 std::vector<double> d_gradient;
192
193 /// storage for the steepest descent direction of the nonlinear problem in
194 /// the previous cg step
195 std::vector<double> d_steepestDirectionOld;
196
197 /// intermediate variable for beta computation
199
200 /// intermediate variable for beta computation
202
203 /// intermediate variable for beta computation
205
206 /// storage for beta- the parameter for updating the conjugate direction
207 /// d_beta = (d_deltaNew - d_deltaMid)/d_deltaOld
208 double d_beta;
209
210 ///
211 double d_gradMax;
212
213 /// storage for number of unknowns to be solved for in the nonlinear problem
214 unsigned int d_numberUnknowns;
215
216 /// storage for current nonlinear cg iteration count
217 unsigned int d_iter;
218
219 /**
220 * Storage for vector of flags (0 or 1) with size equal to the size of the
221 * solution vector of the nonlinear problem. If the flag value is 1 for an
222 * index in the vector, the corresponding entry in the solution vector is
223 * allowed to be updated and vice-versa if flag value is 0 for an index.
224 */
225 std::vector<unsigned int> d_unknownCountFlag;
226
227 /// line search stopping tolerance
229
230 /// maximum number of line search iterations
231 const unsigned int d_lineSearchMaxIterations;
232
233 /// damping parameter (0,1] to be multiplied with the steepest descent
234 /// direction, which controls the initial guess to the line search
235 /// iteration.
237
238 /// flag which restarts the CG if large increment to the solution vector
239 /// happens during line search
241
242 /// maximum allowed increment (measured as L_{inf}(delta x)) in solution
243 /// vector beyond which CG is restarted
245
246 /// line search data
248
249 /// line search data
250 double d_etaPChk;
251
252 /// line search data
253 double d_etaChk;
254
255 /// line search data
256 double d_eta;
257
258 /// line search data
260
261 /// line search data
263
264 /// line search data
266
267 /// line search iter
269
270 ///
272
273 //
275
276 // parallel objects
278 const unsigned int n_mpi_processes;
279 const unsigned int this_mpi_process;
280 dealii::ConditionalOStream pcout;
281 };
282
283} // namespace dftfe
284#endif // CGPRPNonLinearSolver_h
double computeResidualL2Norm() const
Compute residual L2-norm.
void save(const std::string &checkpointFileName)
Create checkpoint file for current state of the cg solver.
double d_etaAlphaZeroChk
line search data
Definition cgPRPNonLinearSolver.h:259
double d_gradMax
Definition cgPRPNonLinearSolver.h:211
std::vector< double > d_conjugateDirection
storage for conjugate direction
Definition cgPRPNonLinearSolver.h:188
double d_functionValueChk
line search data
Definition cgPRPNonLinearSolver.h:262
nonLinearSolver::ReturnValueType lineSearch(nonlinearSolverProblem &problem, const double tolerance, const unsigned int maxNumberIterations, const unsigned int debugLevel, const std::string checkpointFileName="", const int startingIter=-1, const bool isCheckpointRestart=false)
Perform line search.
void computeDeltas()
Compute delta new and delta mid.
double d_beta
Definition cgPRPNonLinearSolver.h:208
~cgPRPNonLinearSolver()
Destructor.
double d_deltaOld
intermediate variable for beta computation
Definition cgPRPNonLinearSolver.h:204
double d_etaChk
line search data
Definition cgPRPNonLinearSolver.h:253
double d_maxSolutionIncrementLinf
Definition cgPRPNonLinearSolver.h:244
const double d_lineSearchTolerance
line search stopping tolerance
Definition cgPRPNonLinearSolver.h:228
double d_functionalValueAfterAlphUpdateChk
line search data
Definition cgPRPNonLinearSolver.h:265
std::vector< double > d_steepestDirectionOld
Definition cgPRPNonLinearSolver.h:195
double d_alphaChk
line search data
Definition cgPRPNonLinearSolver.h:247
const unsigned int this_mpi_process
Definition cgPRPNonLinearSolver.h:279
unsigned int d_iter
storage for current nonlinear cg iteration count
Definition cgPRPNonLinearSolver.h:217
const unsigned int n_mpi_processes
Definition cgPRPNonLinearSolver.h:278
double d_eta
line search data
Definition cgPRPNonLinearSolver.h:256
bool d_useSingleAtomSolutionsInitialGuess
Definition cgPRPNonLinearSolver.h:271
unsigned int computeTotalNumberUnknowns() const
Compute the total number of unknowns in all processors.
std::pair< double, double > computeDeltaD()
Compute delta_d and eta_p.
const unsigned int d_lineSearchMaxIterations
maximum number of line search iterations
Definition cgPRPNonLinearSolver.h:231
double d_deltaNew
intermediate variable for beta computation
Definition cgPRPNonLinearSolver.h:198
int d_lineSearchRestartIterChk
line search iter
Definition cgPRPNonLinearSolver.h:268
bool d_isCurvatureOnlyLineSearchStoppingCondition
Definition cgPRPNonLinearSolver.h:274
MPI_Comm mpi_communicator
Definition cgPRPNonLinearSolver.h:277
nonLinearSolver::ReturnValueType solve(nonlinearSolverProblem &problem, const std::string checkpointFileName="", const bool restart=false)
Solve non-linear problem using Polak-Ribiere-Polyak nonlinar conjugate gradient method.
void initializeDirection()
Initialize direction.
dealii::ConditionalOStream pcout
Definition cgPRPNonLinearSolver.h:280
double d_deltaMid
intermediate variable for beta computation
Definition cgPRPNonLinearSolver.h:201
double d_lineSearchDampingParameter
Definition cgPRPNonLinearSolver.h:236
cgPRPNonLinearSolver(const unsigned int maxNumberIterations, const unsigned int debugLevel, const MPI_Comm &mpi_comm_parent, const double lineSearchTolerance=1.0e-6, const unsigned int lineSearchMaxIterations=10, const double lineSeachDampingParameter=1.0, const double maxIncrementSolLinf=1e+6, const bool isCurvatureOnlyLineSearchStoppingCondition=false)
Constructor.
void updateDirection()
Update direction.
bool d_isCGRestartDueToLargeIncrement
Definition cgPRPNonLinearSolver.h:240
bool updateSolution(const double alpha, const std::vector< double > &direction, nonlinearSolverProblem &problem)
Update solution x -> x + \alpha direction.
std::vector< unsigned int > d_unknownCountFlag
Definition cgPRPNonLinearSolver.h:225
std::vector< double > d_gradient
storage for the gradient of the nonlinear problem in the current cg step
Definition cgPRPNonLinearSolver.h:191
void load(const std::string &checkpointFileName)
Load cg solver state from checkpoint file.
double d_etaPChk
line search data
Definition cgPRPNonLinearSolver.h:250
double computeEta()
Compute eta.
unsigned int d_numberUnknowns
storage for number of unknowns to be solved for in the nonlinear problem
Definition cgPRPNonLinearSolver.h:214
nonLinearSolver(const unsigned int debugLevel, const unsigned int maxNumberIterations, const double tolerance=0)
Constructor.
ReturnValueType
Definition nonLinearSolver.h:45
Abstract class for solver functions.
Definition nonlinearSolverProblem.h:30
Definition pseudoPotentialToDftfeConverter.cc:34
@ e
Definition ExcSSDFunctionalBaseClass.h:52