PSCF v1.3
rpc/fts/compressor/LrAmCompressor.h
1#ifndef RPC_LR_POST_AM_COMPRESSOR_H
2#define RPC_LR_POST_AM_COMPRESSOR_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Compressor.h"
12#include <rpc/fts/compressor/IntraCorrelation.h>
13#include <prdc/cpu/RField.h>
14#include <prdc/cpu/RFieldDft.h>
15#include <pscf/iterator/AmIteratorTmpl.h>
16
17namespace Pscf {
18namespace Rpc {
19
20 template <int D> class System;
21
22 using namespace Util;
23 using namespace Pscf::Prdc;
24 using namespace Pscf::Prdc::Cpu;
25
37 template <int D>
39 : public AmIteratorTmpl<Compressor<D>, DArray<double> >
40 {
41
42 public:
43
50
55
61 void readParameters(std::istream& in);
62
72 void setup(bool isContinuation);
73
74
80 int compress();
81
85 void outputTimers(std::ostream& out) const;
86
90 void clearTimers();
91
92 // Inherited public member functions
93 using AmIteratorTmpl<Compressor<D>, DArray<double> >::setClassName;
94
95 protected:
96
97 // Inherited protected members
99 using Compressor<D>::mdeCounter_;
100
101 private:
102
106 int itr_;
107
111 DArray< RField<D> > w0_;
112
116 DArray< RField<D> > wFieldTmp_;
117
121 DArray<double> newBasis_;
122
126 RField<D> resid_;
127
131 RFieldDft<D> residK_;
132
136 RField<D> intraCorrelationK_;
137
141 IntVec<D> kMeshDimensions_;
142
149 void setEqual(DArray<double>& a, DArray<double> const & b);
150
154 double dotProduct(DArray<double> const & a, DArray<double> const & b);
155
159 double maxAbs(DArray<double> const & hist);
160
167 void updateBasis(RingBuffer<DArray<double> > & basis,
168 RingBuffer<DArray<double> > const & hists);
169
178 void addHistories(DArray<double>& trial,
179 RingBuffer<DArray<double> > const & basis,
180 DArray<double> coeffs,
181 int nHist);
182
190 void addPredictedError(DArray<double>& fieldTrial,
191 DArray<double> const & resTrial,
192 double lambda);
193
197 bool hasInitialGuess();
198
204 int nElements();
205
211 void getCurrent(DArray<double>& curr);
212
219 void evaluate();
220
226 void getResidual(DArray<double>& resid);
227
233 void update(DArray<double>& newGuess);
234
238 void outputToLog();
239
243 double computeLambda(double r);;
244
248 IntraCorrelation<D> intra_;
249
253 bool isIntraCalculated_;
254
258 bool isAllocated_;
259
260 // Inherited private members
261 using Compressor<D>::system;
262
263 };
264
265 #ifndef RPC_LR_POST_AM_COMPRESSOR_TPP
266 // Suppress implicit instantiation
267 extern template class LrAmCompressor<1>;
268 extern template class LrAmCompressor<2>;
269 extern template class LrAmCompressor<3>;
270 #endif
271
272} // namespace Rpc
273} // namespace Pscf
274#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Fourier transform of a real field on an FFT mesh.
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
Base class for iterators that impose incompressibility.
Intramolecular correlation analysis for LR compressors.
Anderson Mixing compressor with linear-response mixing step.
void readParameters(std::istream &in)
Read all parameters and initialize.
LrAmCompressor(System< D > &system)
Constructor.
void outputTimers(std::ostream &out) const
Return compressor times contributions.
void clearTimers()
Clear all timers (reset accumulated time to zero).
void setup(bool isContinuation)
Initialize just before entry to iterative loop.
int compress()
Compress to obtain partial saddle point w+.
Main class, representing one complete system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
Class for storing history of previous values in an array.
Definition RingBuffer.h:27
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1