1#ifndef RPC_LR_AM_COMPRESSOR_TPP
2#define RPC_LR_AM_COMPRESSOR_TPP
11#include "LrAmCompressor.h"
12#include <rpc/system/System.h>
13#include <rpc/solvers/Mixture.h>
14#include <rpc/field/Domain.h>
15#include <pscf/mesh/MeshIterator.h>
32 isIntraCalculated_(false),
70 const int nMonomer = system().mixture().nMonomer();
71 const int meshSize = system().domain().mesh().size();
72 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
75 for (
int i = 0; i < D; ++i) {
77 kMeshDimensions_[i] = dimensions[i];
79 kMeshDimensions_[i] = dimensions[i]/2 + 1;
85 newBasis_.allocate(meshSize);
86 w0_.allocate(nMonomer);
87 wFieldTmp_.allocate(nMonomer);
88 resid_.allocate(dimensions);
89 residK_.allocate(dimensions);
90 intraCorrelationK_.allocate(kMeshDimensions_);
91 for (
int i = 0; i < nMonomer; ++i) {
92 w0_[i].allocate(dimensions);
93 wFieldTmp_[i].allocate(dimensions);
100 if (!isIntraCalculated_){
101 intra_.computeIntraCorrelations(intraCorrelationK_);
102 isIntraCalculated_ =
true;
106 for (
int i = 0; i < nMonomer; ++i) {
107 for (
int j = 0; j< meshSize; ++j){
108 w0_[i][j] = system().w().rgrid(i)[j];
131 out <<
"LrAmCompressor time contributions:\n";
159 const int n = fieldTrial.
capacity();
160 const double vMonomer = system().mixture().vMonomer();
164 for (
int i = 0 ; i < n; ++i) {
165 resid_[i] = resTrial[i];
169 system().domain().fft().forwardTransform(resid_, residK_);
176 factor = 1.0 / (vMonomer * intraCorrelationK_[iter.
rank()]);
177 residK_[iter.
rank()][0] *= factor;
178 residK_[iter.
rank()][1] *= factor;
184 system().domain().fft().inverseTransformUnsafe(residK_, resid_);
187 for (
int i = 0; i < n; i++) {
188 fieldTrial[i] += resid_[i];
198 int LrAmCompressor<D>::nElements()
199 {
return system().domain().mesh().size(); }
205 bool LrAmCompressor<D>::hasInitialGuess()
206 {
return system().w().hasData(); }
218 const int meshSize = system().domain().mesh().size();
227 for (
int i = 0; i < meshSize; i++){
228 curr[i] = (*currSys)[0][i] - w0_[0][i];
237 void LrAmCompressor<D>::evaluate()
249 const int n = nElements();
250 const int nMonomer = system().mixture().nMonomer();
251 const int meshSize = system().domain().mesh().size();
254 for (
int i = 0 ; i < n; ++i) {
259 for (
int j = 0; j < nMonomer; ++j) {
260 for (
int k = 0; k < meshSize; ++k) {
261 resid[k] += system().c().rgrid(j)[k];
274 const int nMonomer = system().mixture().nMonomer();
275 const int meshSize = system().domain().mesh().size();
279 for (
int i = 0; i < nMonomer; i++){
280 for (
int k = 0; k < meshSize; k++){
281 wFieldTmp_[i][k] = w0_[i][k] + newGuess[k];
286 system().w().setRGrid(wFieldTmp_);
293 void LrAmCompressor<D>::outputToLog()
Template for Anderson mixing iterator algorithm.
void outputTimers(std::ostream &out) const
void readErrorType(std::istream &in)
virtual void readParameters(std::istream &in)
int solve(bool isContinuation=false)
An IntVec<D, T> is a D-component vector of elements of integer type T.
Iterator over points in a Mesh<D>.
int rank() const
Get the rank of current element.
void begin()
Set iterator to the first point in the mesh.
bool atEnd() const
Is this the end (i.e., one past the last point)?
void setDimensions(const IntVec< D > &dimensions)
Set the grid dimensions in all directions.
Base class for iterators that impose incompressibility.
int mdeCounter_
Count how many times MDE has been solved.
void readParameters(std::istream &in) override
Read all parameters and initialize.
~LrAmCompressor()
Destructor.
LrAmCompressor(System< D > &system)
Constructor.
int compress() override
Compress to obtain partial saddle point w+.
void outputTimers(std::ostream &out) const override
Return compressor times contributions.
void setup(bool isContinuation) override
Initialize just before entry to iterative loop.
void clearTimers() override
Clear all timers (reset accumulated time to zero).
Main class, representing a complete physical system.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.