PSCF v1.3.1
rpg/fts/compressor/AmCompressor.h
1#ifndef RPG_AM_COMPRESSOR_H
2#define RPG_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/cuda/RField.h>
13#include <pscf/cuda/DeviceArray.h>
14#include <pscf/iterator/AmIteratorTmpl.h>
15
16#include <util/containers/DArray.h>
17
18namespace Pscf {
19namespace Rpg {
20
21 template <int D> class System;
22
23 using namespace Util;
24 using namespace Pscf::Prdc;
25 using namespace Pscf::Prdc::Cuda;
26
32 template <int D>
33 class AmCompressor : public AmIteratorTmpl<Compressor<D>,
34 DeviceArray<cudaReal> >
35 {
36
37 public:
38
44 AmCompressor(System<D>& system);
45
50
56 void readParameters(std::istream& in);
57
67 void setup(bool isContinuation);
68
69
75 int compress();
76
80 double computeLambda(double r);
81
85 int mdeCounter();
86
90 void outputTimers(std::ostream& out) const;
91
95 void clearTimers();
96
97 // Inherited public member functions
99 DeviceArray<cudaReal> >::setClassName;
100
101 protected:
102
103 // Inherited protected members
105 using Compressor<D>::system;
106 using Compressor<D>::mdeCounter_;
107
108 private:
112 int counter_;
113
117 DArray< RField<D> > w0_;
118
122 bool isAllocated_;
123
127 DArray< RField<D> > wFieldTmp_;
128
135 void setEqual(DeviceArray<cudaReal>& a,
136 DeviceArray<cudaReal> const & b);
137
141 double dotProduct(DeviceArray<cudaReal> const & a,
142 DeviceArray<cudaReal> const & b);
143
147 double maxAbs(DeviceArray<cudaReal> const & hist);
148
155 void updateBasis(RingBuffer<DeviceArray<cudaReal> > & basis,
156 RingBuffer<DeviceArray<cudaReal> > const & hists);
157
166 void addHistories(DeviceArray<cudaReal>& trial,
167 RingBuffer<DeviceArray<cudaReal> > const & basis,
168 DArray<double> coeffs,
169 int nHist);
170
178 void addPredictedError(DeviceArray<cudaReal>& fieldTrial,
179 DeviceArray<cudaReal> const & resTrial,
180 double lambda);
181
185 bool hasInitialGuess();
186
192 int nElements();
193
199 void getCurrent(DeviceArray<cudaReal>& curr);
200
207 void evaluate();
208
214 void getResidual(DeviceArray<cudaReal>& resid);
215
221 void update(DeviceArray<cudaReal>& newGuess);
222
226 void outputToLog();
227
228
229 };
230
231 // Explicit instantiation declarations
232 extern template class AmCompressor<1>;
233 extern template class AmCompressor<2>;
234 extern template class AmCompressor<3>;
235
236} // namespace Rpg
237} // namespace Pscf
238#endif
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:43
Rpg implementation of the Anderson Mixing compressor.
int compress()
Compress to obtain partial saddle point w+.
int mdeCounter()
Return how many times MDE has been solved.
AmCompressor(System< D > &system)
Constructor.
void setup(bool isContinuation)
Initialize just before entry to iterative loop.
double computeLambda(double r)
Compute mixing parameter lambda.
void clearTimers()
Clear all timers (reset accumulated time to zero).
void readParameters(std::istream &in)
Read all parameters and initialize.
void outputTimers(std::ostream &out) const
Return compressor times contributions.
Base class for iterators that impose incompressibility.
Main class, representing a complete physical 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, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition Reduce.cpp:14
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1