PSCF v1.3
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
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 <rpg/fts/compressor/IntraCorrelation.h>
13#include <prdc/cpu/RField.h>
14#include <prdc/cpu/RFieldDft.h>
15#include <pscf/cuda/DeviceArray.h>
16#include <pscf/iterator/AmIteratorTmpl.h>
17
18namespace Pscf {
19namespace Rpg {
20
21 template <int D> class System;
22
23 using namespace Util;
24 using namespace Pscf::Prdc;
25 using namespace Pscf::Prdc::Cuda;
26
38 template <int D>
40 : public AmIteratorTmpl<Compressor<D>, DeviceArray<cudaReal> >
41 {
42
43 public:
44
51
56
62 void readParameters(std::istream& in);
63
73 void setup(bool isContinuation);
74
80 int compress();
81
85 void outputTimers(std::ostream& out) const;
86
90 void clearTimers();
91
92 // Inherited public member functions
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 RField<D> resid_;
122
126 RFieldDft<D> residK_;
127
131 RField<D> intraCorrelationK_;
132
136 IntVec<D> kMeshDimensions_;
137
141 int kSize_;
142
149 void setEqual(DeviceArray<cudaReal>& a, DeviceArray<cudaReal> const & b);
150
154 double dotProduct(DeviceArray<cudaReal> const & a, DeviceArray<cudaReal> const & b);
155
159 double maxAbs(DeviceArray<cudaReal> const & hist);
160
167 void updateBasis(RingBuffer<DeviceArray<cudaReal> > & basis,
168 RingBuffer<DeviceArray<cudaReal> > const & hists);
169
178 void addHistories(DeviceArray<cudaReal>& trial,
179 RingBuffer<DeviceArray<cudaReal> > const & basis,
180 DArray<double> coeffs,
181 int nHist);
182
190 void addPredictedError(DeviceArray<cudaReal>& fieldTrial,
191 DeviceArray<cudaReal> const & resTrial,
192 double lambda);
193
197 bool hasInitialGuess();
198
204 int nElements();
205
211 void getCurrent(DeviceArray<cudaReal>& curr);
212
219 void evaluate();
220
226 void getResidual(DeviceArray<cudaReal>& resid);
227
233 void update(DeviceArray<cudaReal>& newGuess);
234
238 void outputToLog();
239
243 double computeLambda(double r);
244
248 bool isIntraCalculated_;
249
253 IntraCorrelation<D> intra_;
254
258 bool isAllocated_;
259
260 // Inherited private members
261 using Compressor<D>::system;
262
263 };
264
265 #ifndef RPG_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 Rpg
273} // namespace Pscf
274#endif
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:43
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.
Linear response function for response to pressure.
Anderson Mixing compressor with linear-response mixing step.
void outputTimers(std::ostream &out) const
Return compressor times contributions.
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.
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, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition Reduce.cpp:14
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1