9#include <fd1d/System.h>
10#include <pscf/inter/Interaction.h>
11#include <pscf/iterator/NanException.h>
23 { setClassName(
"AmIterator"); }
36 const int nMonomer = system().mixture().nMonomer();
44 interaction_.
update(system().interaction());
58 for (
int i = 0; i < n; i++) {
60 if (std::isnan(a[i]) || std::isnan(b[i])) {
61 throw NanException(
"AmIterator::dotProduct",__FILE__,__LINE__,0);
74 for (
int i = 0; i < n; i++) {
76 if (std::isnan(value)) {
77 throw NanException(
"AmIterator::dotProduct",__FILE__,__LINE__,0);
79 if (fabs(value) > maxRes)
92 const int n = hists[0].capacity();
97 for (
int i = 0; i < n; i++) {
98 newbasis[i] = hists[0][i] - hists[1][i];
101 basis.append(newbasis);
111 for (
int i = 0; i < nHist; i++) {
112 for (
int j = 0; j < n; j++) {
113 trial[j] += coeffs[i] * -1 * basis[i][j];
123 for (
int i = 0; i < n; i++) {
124 fieldTrial[i] += lambda * resTrial[i];
128 bool AmIterator::hasInitialGuess()
135 int AmIterator::nElements()
137 const int nm = system().mixture().nMonomer();
138 const int nx = domain().nx();
145 const int nm = system().mixture().nMonomer();
146 const int nx = domain().nx();
150 for (
int i = 0; i < nm; i++) {
151 for (
int k = 0; k < nx; k++) {
152 curr[i*nx+k] = (*currSys)[i][k];
158 void AmIterator::evaluate()
160 mixture().compute(system().wFields(), system().cFields());
165 bool AmIterator::isCanonical()
170 for (
int i = 0; i < mixture().nPolymer(); ++i) {
171 ensemble = mixture().polymer(i).ensemble();
172 if (ensemble == Species::Open) {
175 if (ensemble == Species::Unknown) {
181 for (
int i = 0; i < mixture().nSolvent(); ++i) {
182 ensemble = mixture().solvent(i).ensemble();
183 if (ensemble == Species::Open) {
186 if (ensemble == Species::Unknown) {
198 const int nm = system().mixture().nMonomer();
199 const int nx = domain().nx();
200 const int nr = nm*nx;
204 for (
int i = 0 ; i < nr; ++i) {
211 for (i = 0; i < nm; ++i) {
212 for (j = 0; j < nm; ++j) {
215 chi = interaction_.
chi(i,j);
216 p = interaction_.
p(i,j);
217 for (k = 0; k < nx; ++k) {
219 resid[idx] += chi*cField[k] - p*wField[k];
229 const int nm = mixture().nMonomer();
230 const int nx = domain().nx();
234 const double shift = newGuess[nm*nx - 1];
235 for (
int i = 0; i < nm; i++) {
238 for (
int k = 0; k < nx; k++) {
239 wField[k] = newGuess[i*nx + k] - shift;
242 for (
int k = 0; k < nx; k++) {
243 wField[k] = newGuess[i*nx + k];
250 void AmIterator::outputToLog()
Template for Anderson mixing iterator algorithm.
void readErrorType(std::istream &in)
Read and validate the optional errorType string parameter.
double chi(int i, int j) const
Return one element of the chi matrix.
double sumChiInverse() const
Return sum of elements of the inverse chi matrix.
void setNMonomer(int nMonomer)
Set number of monomers and allocate required memory.
void update(Interaction const &interaction)
Update all computed quantities.
double p(int i, int j) const
Return one element of the potent matrix P.
void readParameters(std::istream &in)
Read all parameters and initialize.
void setup(bool isContinuation)
Setup iterator just before entering iteration loop.
AmIterator(System &system)
Constructor.
Base class for iterative solvers for SCF equations.
Main class in SCFT simulation of one system.
Exception thrown when not-a-number (NaN) is encountered.
Ensemble
Statistical ensemble for number of molecules.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
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.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
float product(float a, float b)
Product for float Data.