PSCF v1.3
rpc/fts/compressor/AmCompressor.h
1#ifndef RPC_AM_COMPRESSOR_H
2#define RPC_AM_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 <prdc/cpu/RField.h>
13#include <pscf/iterator/AmIteratorTmpl.h>
14
15namespace Pscf {
16namespace Rpc
17{
18
19 template <int D>
20 class System;
21
22 using namespace Util;
23 using namespace Pscf::Prdc::Cpu;
24
30 template <int D>
32 : public AmIteratorTmpl<Compressor<D>, DArray<double> >
33 {
34
35 public:
36
42 AmCompressor(System<D>& system);
43
48
54 void readParameters(std::istream& in);
55
65 void setup(bool isContinuation);
66
72 int compress();
73
77 double computeLambda(double r);
78
82 void outputTimers(std::ostream& out) const;
83
87 void clearTimers();
88
89 // Inherited public member functions
90 using AmIteratorTmpl<Compressor<D>, DArray<double> >::setClassName;
91
92 protected:
93
94 // Inherited protected members
96 using Compressor<D>::mdeCounter_;
97
98 private:
99
103 int itr_;
104
108 DArray< RField<D> > w0_;
109
113 bool isAllocated_;
114
118 DArray< RField<D> > wFieldTmp_;
119
123 DArray<double> newBasis_;
124
131 void setEqual(DArray<double>& a, DArray<double> const & b);
132
136 double dotProduct(DArray<double> const & a, DArray<double> const & b);
137
141 double maxAbs(DArray<double> const & hist);
142
149 void updateBasis(RingBuffer<DArray<double> > & basis,
150 RingBuffer<DArray<double> > const & hists);
151
160 void addHistories(DArray<double>& trial,
161 RingBuffer<DArray<double> > const & basis,
162 DArray<double> coeffs,
163 int nHist);
164
172 void addPredictedError(DArray<double>& fieldTrial,
173 DArray<double> const & resTrial,
174 double lambda);
175
179 bool hasInitialGuess();
180
186 int nElements();
187
193 void getCurrent(DArray<double>& curr);
194
201 void evaluate();
202
208 void getResidual(DArray<double>& resid);
209
215 void update(DArray<double>& newGuess);
216
220 void outputToLog();
221
222 // Inherited private members
223 using Compressor<D>::system;
224
225 };
226
227 #ifndef RPC_AM_COMPRESSOR_TPP
228 // Suppress implicit instantiation
229 extern template class AmCompressor<1>;
230 extern template class AmCompressor<2>;
231 extern template class AmCompressor<3>;
232 #endif
233
234} // namespace Rpc
235} // namespace Pscf
236#endif
void setup(bool isContinuation)
Initialize just before entry to iterative loop.
int compress()
Compress to obtain partial saddle point w+.
double computeLambda(double r)
Compute mixing parameter lambda.
AmCompressor(System< D > &system)
Constructor.
void readParameters(std::istream &in)
Read all parameters and initialize.
void outputTimers(std::ostream &out) const
Return compressor times contributions.
void clearTimers()
Clear all timers (reset accumulated time to zero).
Base class for iterators that impose incompressibility.
Main class, representing one complete system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
Class for storing history of previous values in an array.
Definition RingBuffer.h:27
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