PSCF v1.2
LrAmPreCompressor.h
1#ifndef RPG_LR_AM_COMPRESSOR_H
2#define RPG_LR_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/cuda/RField.h>
13#include <prdc/cuda/RFieldDft.h>
14#include <pscf/math/IntVec.h>
15#include <pscf/cuda/DeviceArray.h>
16#include <pscf/iterator/AmIteratorTmpl.h>
17#include <rpg/fts/compressor/intra/IntraCorrelation.h>
18
19namespace Pscf {
20namespace Rpg
21{
22
23 template <int D> class System;
24 template <int D> class IntraCorrelation;
25
26 using namespace Util;
27 using namespace Pscf::Prdc;
28 using namespace Pscf::Prdc::Cuda;
29
46 template <int D>
48 : public AmIteratorTmpl<Compressor<D>, DeviceArray<cudaReal> >
49 {
50
51 public:
52
59
64
70 void readParameters(std::istream& in);
71
81 void setup(bool isContinuation);
82
83
89 int compress();
90
96 void outputTimers(std::ostream& out);
97
101 void clearTimers();
102
112 double computeError(DeviceArray<cudaReal>& residTrial,
113 DeviceArray<cudaReal>& fieldTrial,
114 std::string errorType,
115 int verbose);
116
117 // Inherited public member functions
118
120
121 protected:
122
123 // Inherited protected members
125 using Compressor<D>::system;
126 using Compressor<D>::mdeCounter_;
127
128 private:
129
133 std::string errorType_;
134
138 int itr_;
139
143 DArray< RField<D> > w0_;
144
148 RField<D> error_;
149
153 RField<D> resid_;
154
158 RFieldDft<D> residK_;
159
163 RField<D> intraCorrelation_;
164
168 IntVec<D> kMeshDimensions_;
169
173 int kSize_;
174
179 DArray< RField<D> > wFieldTmp_;
180
187 void setEqual(DeviceArray<cudaReal>& a, DeviceArray<cudaReal> const & b);
188
192 double dotProduct(DeviceArray<cudaReal> const & a, DeviceArray<cudaReal> const & b);
193
197 double maxAbs(DeviceArray<cudaReal> const & hist);
198
205 void updateBasis(RingBuffer<DeviceArray<cudaReal> > & basis,
206 RingBuffer<DeviceArray<cudaReal> > const & hists);
207
216 void addHistories(DeviceArray<cudaReal>& trial,
217 RingBuffer<DeviceArray<cudaReal> > const & basis,
218 DArray<double> coeffs,
219 int nHist);
220
228 void addPredictedError(DeviceArray<cudaReal>& fieldTrial,
229 DeviceArray<cudaReal> const & resTrial,
230 double lambda);
231
235 bool hasInitialGuess();
236
242 int nElements();
243
249 void getCurrent(DeviceArray<cudaReal>& curr);
250
257 void evaluate();
258
264 void getResidual(DeviceArray<cudaReal>& resid);
265
271 void update(DeviceArray<cudaReal>& newGuess);
272
276 void outputToLog();
277
281 double computeLambda(double r);
282
286 IntraCorrelation<D> intra_;
287
291 bool isIntraCalculated_;
292
296 bool isAllocated_;
297
298 };
299
300 #ifndef RPG_LR_AM_COMPRESSOR_TPP
301 // Suppress implicit instantiation
302 extern template class LrAmPreCompressor<1>;
303 extern template class LrAmPreCompressor<2>;
304 extern template class LrAmPreCompressor<3>;
305 #endif
306
307} // namespace Rpg
308} // namespace Pscf
309#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 preconditioning.
LrAmPreCompressor(System< D > &system)
Constructor.
double computeError(DeviceArray< cudaReal > &residTrial, DeviceArray< cudaReal > &fieldTrial, std::string errorType, int verbose)
Compute and return error used to test for convergence.
void readParameters(std::istream &in)
Read all parameters and initialize.
void setup(bool isContinuation)
Initialize just before entry to iterative loop.
void clearTimers()
Reset / clear all timers.
int compress()
Compress to obtain partial saddle point w+.
void outputTimers(std::ostream &out)
Write a report of time contributions used by this algorithm.
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.