PSCF v1.3
rpc/fts/compressor/LrCompressor.h
1#ifndef RPC_LR_COMPRESSOR_H
2#define RPC_LR_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"
12#include <rpc/fts/compressor/IntraCorrelation.h>
13#include <prdc/cpu/RField.h>
14#include <prdc/cpu/RFieldDft.h>
15#include <util/containers/DArray.h>
16#include <util/misc/Timer.h>
17
18namespace Pscf {
19namespace Rpc {
20
21 template <int D> class System;
22
23 using namespace Util;
24 using namespace Pscf::Prdc::Cpu;
25
36 template <int D>
37 class LrCompressor : public Compressor<D>
38 {
39
40 public:
41
48
53
59 void readParameters(std::istream& in);
60
68 void setup();
69
75 int compress();
76
77 double subspacePercent(){return 0;};
78
79 double correctionPercent(){return 0;};
80
84 void outputTimers(std::ostream& out) const;
85
86 void clearTimers();
87
88 protected:
89
90 // Inherited protected members
95
96 private:
97
98 // Error tolerance.
99 double epsilon_;
100
101 // Current iteration counter.
102 int itr_;
103
104 // Maximum number of iterations.
105 int maxItr_;
106
107 // Total iteration counter.
108 int totalItr_;
109
110 // Timers for analyzing performance.
111 Timer timerTotal_;
112 Timer timerMDE_;
113
114 // Type of error criterion used to test convergence
115 std::string errorType_;
116
117 // Verbosity level.
118 int verbose_;
119
123 IntVec<D> kMeshDimensions_;
124
128 RField<D> intraCorrelationK_;
129
133 RField<D> resid_;
134
138 RFieldDft<D> residK_;
139
143 DArray< RField<D> > w0_;
144
148 DArray< RField<D> > wFieldTmp_;
149
155 void getResidual();
156
160 void updateWFields();
161
168 double computeError(int verbose);
169
173 double maxAbs(RField<D> const & a);
174
181 double dotProduct(RField<D> const & a, RField<D> const & b);
182
186 double norm(RField<D> const & a);
187
191 void outputToLog();
192
196 IntraCorrelation<D> intra_;
197
198 // Has the IntraCorrelation been calculated?
199 bool isIntraCalculated_;
200
201 // Has required memory been allocated.
202 bool isAllocated_;
203
204 // Private inherited members
205 using Compressor<D>::system;
206
207 };
208
209 #ifndef RPC_LR_COMPRESSOR_TPP
210 // Suppress implicit instantiation
211 extern template class LrCompressor<1>;
212 extern template class LrCompressor<2>;
213 extern template class LrCompressor<3>;
214 #endif
215
216} // namespace Rpc
217} // namespace Pscf
218#endif
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
System< D > const & system() const
Return const reference to parent system.
Compressor(System< D > &system)
Constructor.
int mdeCounter_
Count how many times MDE has been solved.
Intramolecular correlation analysis for LR compressors.
LrCompressor(System< D > &system)
Constructor.
int compress()
Iterate pressure field to obtain partial saddle point.
void readParameters(std::istream &in)
Read all parameters and initialize.
void setup()
Initialize just before entry to iterative loop.
void outputTimers(std::ostream &out) const
Return compressor times contributions.
Main class, representing one complete system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
Wall clock timer.
Definition Timer.h:35
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1