PSCF v1.3.3
rpg/fts/compressor/LrAmCompressor.h
1#ifndef RPG_LR_AM_COMPRESSOR_H
2#define RPG_LR_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" // base class argument
12#include <pscf/cuda/DeviceArray.h> // base class argument
13#include <pscf/iterator/AmIteratorTmpl.h> // base class template
14
15#include <rpg/fts/compressor/IntraCorrelation.h> // member
16#include <prdc/cpu/RField.h> // member
17#include <prdc/cpu/RFieldDft.h> // member
18#include <util/containers/DArray.h> // member
19
20#include <iostream>
21
22namespace Pscf {
23namespace Rpg {
24
25 // Forward declaration
26 template <int D> class System;
27
28 using namespace Util;
29 using namespace Pscf::Prdc;
30 using namespace Pscf::Prdc::Cuda;
31
43 template <int D>
45 : public AmIteratorTmpl<Compressor<D>, DeviceArray<cudaReal> >
46 {
47
48 public:
49
52
59
64
70 void readParameters(std::istream& in);
71
81 void setup(bool isContinuation);
82
88 int compress();
89
93 void outputTimers(std::ostream& out) const;
94
98 void clearTimers();
99
100 private:
101
105 int itr_;
106
110 DArray< RField<D> > w0_;
111
115 DArray< RField<D> > wFieldTmp_;
116
120 RField<D> resid_;
121
125 RFieldDft<D> residK_;
126
130 RField<D> intraCorrelationK_;
131
135 IntVec<D> kMeshDimensions_;
136
140 int kSize_;
141
145 bool isIntraCalculated_;
146
150 IntraCorrelation<D> intra_;
151
155 bool isAllocated_;
156
157 // AM algorithm operations
158
165 void addCorrection(VectorT& fieldTrial,
166 VectorT const & resTrial) override;
167
168
169 // Private virtual that interact with the parent System
170
176 int nElements() override;
177
181 bool hasInitialGuess() override;
182
188 void getCurrent(VectorT& curr) override;
189
196 void evaluate() override;
197
203 void getResidual(VectorT& resid) override;
204
210 void update(VectorT& newGuess) override;
211
215 void outputToLog() override;
216
217 // Private virtual functions for vector math
218
225 void setEqual(VectorT& a,
226 VectorT const & b) override;
227
234 double dotProduct(VectorT const & a,
235 VectorT const & b) override;
236
240 double maxAbs(VectorT const & hist) override;
241
249 void subVV(VectorT& a,
250 VectorT const & b,
251 VectorT const & c) override;
252
260 void addEqVc(VectorT& a,
261 VectorT const & b,
262 double c) override;
263
264 // Inherited private member
265 using Compressor<D>::system;
266
269 };
270
271 // Explicit instantiation declarations
272 extern template class LrAmCompressor<1>;
273 extern template class LrAmCompressor<2>;
274 extern template class LrAmCompressor<3>;
275
276} // namespace Rpg
277} // namespace Pscf
278#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.
DeviceArray< cudaReal > VectorT
Typename for field and residual vectors.
Main class, representing a complete physical system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition CField.cu:12
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.