1#ifndef RPG_LR_POST_AM_COMPRESSOR_TPP
2#define RPG_LR_POST_AM_COMPRESSOR_TPP
11#include "LrAmCompressor.h"
12#include <rpg/system/System.h>
13#include <prdc/cuda/FFT.h>
14#include <prdc/cuda/resources.h>
15#include <pscf/mesh/MeshIterator.h>
30 isIntraCalculated_(false),
32 { setClassName(
"LrAmCompressor"); }
58 const int nMonomer = system().mixture().nMonomer();
59 const int meshSize = system().domain().mesh().size();
60 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
68 for (
int i = 0; i < D; ++i) {
70 kMeshDimensions_[i] = dimensions[i];
72 kMeshDimensions_[i] = dimensions[i]/2 + 1;
78 for (
int i = 0; i < D; ++i) {
79 kSize_ *= kMeshDimensions_[i];
84 w0_.allocate(nMonomer);
85 wFieldTmp_.allocate(nMonomer);
86 resid_.allocate(dimensions);
87 residK_.allocate(dimensions);
88 intraCorrelationK_.allocate(kMeshDimensions_);
89 for (
int i = 0; i < nMonomer; ++i) {
90 w0_[i].allocate(dimensions);
91 wFieldTmp_[i].allocate(dimensions);
98 if (!isIntraCalculated_){
99 intra_.computeIntraCorrelations(intraCorrelationK_);
100 isIntraCalculated_ =
true;
104 for (
int i = 0; i < nMonomer; ++i) {
136 return Reduce::innerProduct(a, b);
141 double LrAmCompressor<D>::maxAbs(DeviceArray<cudaReal>
const & a)
143 return Reduce::maxAbs(a);
156 if (basis[0].isAllocated()) {
157 UTIL_CHECK(basis[0].capacity() == hists[0].capacity());
159 basis[0].allocate(hists[0].capacity());
172 for (
int i = 0; i < nHist; i++) {
178 double LrAmCompressor<D>::computeLambda(
double r)
188 int n = fieldTrial.capacity();
189 const double vMonomer = system().mixture().vMonomer();
195 system().domain().fft().forwardTransform(resid_, residK_);
201 system().domain().fft().inverseTransformUnsafe(residK_, resid_);
209 bool LrAmCompressor<D>::hasInitialGuess()
210 {
return system().w().hasData(); }
214 int LrAmCompressor<D>::nElements()
215 {
return system().domain().mesh().size(); }
232 void LrAmCompressor<D>::evaluate()
242 const int nMonomer = system().mixture().nMonomer();
248 for (
int i = 1; i < nMonomer; i++) {
258 const int nMonomer = system().mixture().nMonomer();
261 for (
int i = 0; i < nMonomer; i++) {
266 system().w().setRGrid(wFieldTmp_);
270 void LrAmCompressor<D>::outputToLog()
278 out <<
"LrAmCompressor time contributions:\n";
void readErrorType(std::istream &in)
int solve(bool isContinuation=false)
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.
static void computeKMesh(IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
Compute dimensions and size of k-space mesh for DFT of real data.
Base class for iterators that impose incompressibility.
~LrAmCompressor()
Destructor.
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.
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.
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 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 subVS(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const cudaReal c, const int beginIdA, const int beginIdB, const int n)
Vector subtraction, a[i] = b[i] - c, 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.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.