1#ifndef RPG_LR_POST_AM_COMPRESSOR_TPP
2#define RPG_LR_POST_AM_COMPRESSOR_TPP
11#include "LrAmCompressor.h"
12#include <rpg/System.h>
13#include <rpg/fts/compressor/intra/IntraCorrelation.h>
14#include <prdc/cuda/resources.h>
15#include <pscf/mesh/MeshIterator.h>
28 intraCorrelation_(system)
29 { setClassName(
"LrAmCompressor"); }
49 const int nMonomer = system().mixture().nMonomer();
50 const int meshSize = system().domain().mesh().size();
51 IntVec<D> const & dimensions = system().mesh().dimensions();
57 for (
int i = 0; i < D; ++i) {
59 kMeshDimensions_[i] = dimensions[i];
61 kMeshDimensions_[i] = dimensions[i]/2 + 1;
67 for (
int i = 0; i < D; ++i) {
68 kSize_ *= kMeshDimensions_[i];
73 w0_.allocate(nMonomer);
74 wFieldTmp_.allocate(nMonomer);
75 resid_.allocate(dimensions);
76 residK_.allocate(dimensions);
77 intraCorrelationK_.allocate(kMeshDimensions_);
78 for (
int i = 0; i < nMonomer; ++i) {
79 w0_[i].allocate(dimensions);
80 wFieldTmp_[i].allocate(dimensions);
87 for (
int i = 0; i < nMonomer; ++i) {
92 intraCorrelationK_ = intraCorrelation_.computeIntraCorrelations();
123 double LrAmCompressor<D>::maxAbs(DeviceArray<cudaReal>
const & a)
131 LrAmCompressor<D>::updateBasis(
RingBuffer< DeviceArray<cudaReal> > & basis,
132 RingBuffer< DeviceArray<cudaReal> >
const & hists)
138 if (basis[0].isAllocated()) {
139 UTIL_CHECK(basis[0].capacity() == hists[0].capacity());
141 basis[0].allocate(hists[0].capacity());
149 LrAmCompressor<D>::addHistories(DeviceArray<cudaReal>& trial,
150 RingBuffer<DeviceArray<cudaReal> >
const & basis,
154 for (
int i = 0; i < nHist; i++) {
160 double LrAmCompressor<D>::computeLambda(
double r)
166 void LrAmCompressor<D>::addPredictedError(DeviceArray<cudaReal>& fieldTrial,
167 DeviceArray<cudaReal>
const & resTrial,
170 int n = fieldTrial.capacity();
171 const double vMonomer = system().mixture().vMonomer();
177 system().fft().forwardTransform(resid_, residK_);
183 system().fft().inverseTransformUnsafe(residK_, resid_);
191 bool LrAmCompressor<D>::hasInitialGuess()
192 {
return system().w().hasData(); }
196 int LrAmCompressor<D>::nElements()
197 {
return system().domain().mesh().size(); }
201 void LrAmCompressor<D>::getCurrent(DeviceArray<cudaReal>& curr)
214 void LrAmCompressor<D>::evaluate()
222 void LrAmCompressor<D>::getResidual(DeviceArray<cudaReal>& resid)
224 const int nMonomer = system().mixture().nMonomer();
230 for (
int i = 1; i < nMonomer; i++) {
237 void LrAmCompressor<D>::update(DeviceArray<cudaReal>& newGuess)
240 const int nMonomer = system().mixture().nMonomer();
243 for (
int i = 0; i < nMonomer; i++) {
248 system().setWRGrid(wFieldTmp_);
252 void LrAmCompressor<D>::outputToLog()
260 out <<
"LrAmCompressor time contributions:\n";
Template for Anderson mixing iterator algorithm.
Dynamic array on the GPU device with aligned data.
int capacity() const
Return allocated capacity.
An IntVec<D, T> is a D-component vector of elements of integer type T.
Base class for iterators that impose incompressibility.
Anderson Mixing compressor with linear-response mixing step.
~LrAmCompressor()
Destructor.
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.
Dynamically allocatable contiguous array template.
Class for storing history of previous values in an array.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
cudaReal innerProduct(DeviceArray< cudaReal > const &a, DeviceArray< cudaReal > const &b)
Compute inner product of two real arrays (GPU kernel wrapper).
cudaReal maxAbs(DeviceArray< cudaReal > const &in)
Get maximum absolute magnitude of array elements (GPU kernel wrapper).
void addEqV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const int beginIdA, const int beginIdB, const int n)
Vector addition in-place, a[i] += b[i], kernel wrapper (cudaReal).
void eqV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i], kernel wrapper (cudaReal).
void subVS(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c, const int beginIdA, const int beginIdB, const int n)
Vector subtraction, a[i] = b[i] - c, kernel wrapper (cudaReal).
void addVV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, DeviceArray< cudaReal > const &c, const int beginIdA, const int beginIdB, const int beginIdC, const int n)
Vector addition, a[i] = b[i] + c[i], kernel wrapper (cudaReal).
void subVV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, DeviceArray< cudaReal > const &c, const int beginIdA, const int beginIdB, const int beginIdC, const int n)
Vector subtraction, a[i] = b[i] - c[i], kernel wrapper (cudaReal).
void divEqVc(DeviceArray< cudaComplex > &a, DeviceArray< cudaReal > const &b, cudaReal const c)
Vector division in-place w/ coeff., a[i] /= (b[i] * c), kernel wrapper.
void addEqVc(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c)
Vector addition in-place w/ coefficient, a[i] += b[i] * c, kernel wrapper.
PSCF package top-level namespace.
Utility classes for scientific computation.