PSCF v1.2
rpg/fts/compressor/LrAmCompressor.h
1#ifndef RPG_LR_POST_AM_COMPRESSOR_H
2#define RPG_LR_POST_AM_COMPRESSOR_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, 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 <prdc/cpu/RField.h>
13#include <prdc/cpu/RFieldDft.h>
14#include <pscf/cuda/DeviceArray.h>
15#include <pscf/iterator/AmIteratorTmpl.h>
16#include <rpg/fts/compressor/intra/IntraCorrelation.h>
17
18namespace Pscf {
19namespace Rpg
20{
21
22 template <int D> class System;
23 template <int D> class IntraCorrelation;
24
25 using namespace Util;
26 using namespace Pscf::Prdc;
27 using namespace Pscf::Prdc::Cuda;
28
40 template <int D>
42 : public AmIteratorTmpl<Compressor<D>, DeviceArray<cudaReal> >
43 {
44
45 public:
46
53
58
64 void readParameters(std::istream& in);
65
75 void setup(bool isContinuation);
76
82 int compress();
83
87 void outputTimers(std::ostream& out);
88
92 void clearTimers();
93
94 // Inherited public member functions
96
97 protected:
98
99 // Inherited protected members
101 using Compressor<D>::mdeCounter_;
102
103 private:
104
108 int itr_;
109
113 DArray< RField<D> > w0_;
114
118 DArray< RField<D> > wFieldTmp_;
119
123 RField<D> resid_;
124
128 RFieldDft<D> residK_;
129
133 RField<D> intraCorrelationK_;
134
138 IntVec<D> kMeshDimensions_;
139
143 int kSize_;
144
151 void setEqual(DeviceArray<cudaReal>& a, DeviceArray<cudaReal> const & b);
152
156 double dotProduct(DeviceArray<cudaReal> const & a, DeviceArray<cudaReal> const & b);
157
161 double maxAbs(DeviceArray<cudaReal> const & hist);
162
169 void updateBasis(RingBuffer<DeviceArray<cudaReal> > & basis,
170 RingBuffer<DeviceArray<cudaReal> > const & hists);
171
180 void addHistories(DeviceArray<cudaReal>& trial,
181 RingBuffer<DeviceArray<cudaReal> > const & basis,
182 DArray<double> coeffs,
183 int nHist);
184
192 void addPredictedError(DeviceArray<cudaReal>& fieldTrial,
193 DeviceArray<cudaReal> const & resTrial,
194 double lambda);
195
199 bool hasInitialGuess();
200
206 int nElements();
207
213 void getCurrent(DeviceArray<cudaReal>& curr);
214
221 void evaluate();
222
228 void getResidual(DeviceArray<cudaReal>& resid);
229
235 void update(DeviceArray<cudaReal>& newGuess);
236
240 void outputToLog();
241
245 double computeLambda(double r);
246
250 bool isIntraCalculated_;
251
255 IntraCorrelation<D> intra_;
256
260 bool isAllocated_;
261
262 // Inherited private members
263 using Compressor<D>::system;
264
265 };
266
267 #ifndef RPG_LR_POST_AM_COMPRESSOR_TPP
268 // Suppress implicit instantiation
269 extern template class LrAmCompressor<1>;
270 extern template class LrAmCompressor<2>;
271 extern template class LrAmCompressor<3>;
272 #endif
273
274} // namespace Rpg
275} // namespace Pscf
276#endif
Template for Anderson mixing iterator algorithm.
Dynamic array on the GPU device with aligned data.
Definition rpg/System.h:32
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.
Base class for iterators that impose incompressibility.
Base class for iterators that impose incompressibility.
Anderson Mixing compressor with linear-response mixing step.
void readParameters(std::istream &in)
Read all parameters and initialize.
int compress()
Compress to obtain partial saddle point w+.
void clearTimers()
Clear all timers (reset accumulated time to zero).
void setup(bool isContinuation)
Initialize just before entry to iterative loop.
LrAmCompressor(System< D > &system)
Constructor.
void outputTimers(std::ostream &out)
Return compressor times contributions.
Main class for calculations that represent one system.
Definition rpg/System.h:107
Dynamically allocatable contiguous array template.
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, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition CField.cu:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.