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 <pscf/mesh/MeshIterator.h>
30 isIntraCalculated_(false),
68 const int nMonomer = system().mixture().nMonomer();
69 const int meshSize = system().domain().mesh().size();
70 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
73 for (
int i = 0; i < D; ++i) {
75 kMeshDimensions_[i] = dimensions[i];
77 kMeshDimensions_[i] = dimensions[i]/2 + 1;
83 newBasis_.allocate(meshSize);
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) {
105 for (
int j = 0; j< meshSize; ++j){
106 w0_[i][j] = system().w().rgrid(i)[j];
129 out <<
"LrAmCompressor time contributions:\n";
157 const int n = fieldTrial.
capacity();
158 const double vMonomer = system().mixture().vMonomer();
162 for (
int i = 0 ; i < n; ++i) {
163 resid_[i] = resTrial[i];
167 system().domain().fft().forwardTransform(resid_, residK_);
174 factor = 1.0 / (vMonomer * intraCorrelationK_[iter.
rank()]);
175 residK_[iter.
rank()][0] *= factor;
176 residK_[iter.
rank()][1] *= factor;
182 system().domain().fft().inverseTransformUnsafe(residK_, resid_);
185 for (
int i = 0; i < n; i++) {
186 fieldTrial[i] += resid_[i];
196 int LrAmCompressor<D>::nElements()
197 {
return system().domain().mesh().size(); }
203 bool LrAmCompressor<D>::hasInitialGuess()
204 {
return system().w().hasData(); }
216 const int meshSize = system().domain().mesh().size();
225 for (
int i = 0; i < meshSize; i++){
226 curr[i] = (*currSys)[0][i] - w0_[0][i];
235 void LrAmCompressor<D>::evaluate()
247 const int n = nElements();
248 const int nMonomer = system().mixture().nMonomer();
249 const int meshSize = system().domain().mesh().size();
252 for (
int i = 0 ; i < n; ++i) {
257 for (
int j = 0; j < nMonomer; ++j) {
258 for (
int k = 0; k < meshSize; ++k) {
259 resid[k] += system().c().rgrid(j)[k];
272 const int nMonomer = system().mixture().nMonomer();
273 const int meshSize = system().domain().mesh().size();
277 for (
int i = 0; i < nMonomer; i++){
278 for (
int k = 0; k < meshSize; k++){
279 wFieldTmp_[i][k] = w0_[i][k] + newGuess[k];
284 system().w().setRGrid(wFieldTmp_);
291 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.