1#ifndef RPC_AM_COMPRESSOR_TPP
2#define RPC_AM_COMPRESSOR_TPP
11#include "AmCompressor.h"
12#include <rpc/system/System.h>
25 { setClassName(
"AmCompressor"); }
45 const int nMonomer = system().mixture().nMonomer();
46 const int meshSize = system().domain().mesh().size();
47 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
53 newBasis_.allocate(meshSize);
54 w0_.allocate(nMonomer);
55 wFieldTmp_.allocate(nMonomer);
56 for (
int i = 0; i < nMonomer; ++i) {
57 w0_[i].allocate(dimensions);
58 wFieldTmp_[i].allocate(dimensions);
64 for (
int i = 0; i < nMonomer; ++i) {
65 for (
int j = 0; j< meshSize; ++j){
66 w0_[i][j] = system().w().rgrid(i)[j];
92 for (
int i = 0; i < n; i++) {
94 if (std::isnan(a[i]) || std::isnan(b[i])) {
95 throw NanException(
"AmCompressor::dotProduct",__FILE__,__LINE__,0);
109 for (
int i = 0; i < n; i++) {
111 if (std::isnan(value)) {
112 throw NanException(
"AmCompressor::dotProduct",__FILE__,__LINE__,0);
114 if (fabs(value) > max) {
130 const int n = hists[0].capacity();
133 for (
int i = 0; i < n; i++) {
134 newBasis_[i] = hists[0][i] - hists[1][i];
137 basis.append(newBasis_);
148 for (
int i = 0; i < nHist; i++) {
149 for (
int j = 0; j < n; j++) {
151 trial[j] += coeffs[i] * -1 * basis[i][j];
157 void AmCompressor<D>::addPredictedError(
DArray<double>& fieldTrial,
162 for (
int i = 0; i < n; i++) {
163 fieldTrial[i] += lambda * resTrial[i];
169 bool AmCompressor<D>::hasInitialGuess()
170 {
return system().w().hasData(); }
174 int AmCompressor<D>::nElements()
175 {
return system().domain().mesh().size(); }
182 const int meshSize = system().domain().mesh().size();
190 for (
int i = 0; i < meshSize; i++){
191 curr[i] = (*currSys)[0][i] - w0_[0][i];
198 void AmCompressor<D>::evaluate()
208 const int n = nElements();
209 const int nMonomer = system().mixture().nMonomer();
210 const int meshSize = system().domain().mesh().size();
213 for (
int i = 0 ; i < n; ++i) {
218 for (
int j = 0; j < nMonomer; ++j) {
219 for (
int k = 0; k < meshSize; ++k) {
220 resid[k] += system().c().rgrid(j)[k];
231 const int nMonomer = system().mixture().nMonomer();
232 const int meshSize = system().domain().mesh().size();
235 for (
int i = 0; i < nMonomer; i++){
236 for (
int k = 0; k < meshSize; k++){
237 wFieldTmp_[i][k] = w0_[i][k] + newGuess[k];
240 system().w().setRGrid(wFieldTmp_);
250 void AmCompressor<D>::outputToLog()
258 out <<
"AmCompressor time contributions:\n";
void readErrorType(std::istream &in)
int solve(bool isContinuation=false)
An IntVec<D, T> is a D-component vector of elements of integer type T.
Exception thrown when not-a-number (NaN) is encountered.
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.
~AmCompressor()
Destructor.
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.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
Class for storing history of previous values in an array.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.
float product(float a, float b)
Product for float Data.