9#include <r1d/system/System.h>
10#include <r1d/solvers/Mixture.h>
11#include <r1d/solvers/Polymer.h>
12#include <r1d/solvers/Solvent.h>
13#include <pscf/chem/Ensemble.h>
14#include <pscf/iterator/NanException.h>
15#include <pscf/cpu/VecOp.h>
16#include <pscf/cpu/Reduce.h>
19#include <pscf/iterator/AmIteratorTmpl.tpp>
53 AmTmpl::readParameters(in);
54 AmTmpl::readErrorType(in);
55 AmTmpl::readMixingParameters(in);
57 const int nMonomer = system().mixture().nMonomer();
58 interaction_.setNMonomer(nMonomer);
69 interaction_.update(system().interaction());
75 int AmIterator::nElements()
77 const int nm = system().mixture().nMonomer();
78 const int nx = domain().nx();
82 bool AmIterator::hasInitialGuess()
91 const int nm = system().mixture().nMonomer();
92 const int nx = domain().nx();
96 for (
int i = 0; i < nm; i++) {
97 for (
int k = 0; k < nx; k++) {
98 curr[i*nx+k] = (*currSys)[i][k];
106 void AmIterator::evaluate()
107 { mixture().compute(system().wFields(), system().cFields()); }
112 bool AmIterator::isCanonical()
117 for (
int i = 0; i < mixture().nPolymer(); ++i) {
118 ensemble = mixture().polymer(i).ensemble();
119 if (ensemble == Ensemble::Open) {
122 if (ensemble == Ensemble::Unknown) {
128 for (
int i = 0; i < mixture().nSolvent(); ++i) {
129 ensemble = mixture().solvent(i).ensemble();
130 if (ensemble == Ensemble::Open) {
133 if (ensemble == Ensemble::Unknown) {
145 const int nm = system().mixture().nMonomer();
146 const int nx = domain().nx();
147 const int nr = nm*nx;
150 const double shift = -1.0/interaction_.sumChiInverse();
151 for (
int i = 0 ; i < nr; ++i) {
158 for (i = 0; i < nm; ++i) {
159 for (j = 0; j < nm; ++j) {
160 DArray<double>& cField = system().cField(j);
161 DArray<double>& wField = system().wField(j);
162 chi = interaction_.chi(i,j);
163 p = interaction_.p(i,j);
164 for (k = 0; k < nx; ++k) {
166 resid[idx] += chi*cField[k] - p*wField[k];
176 const int nm = mixture().nMonomer();
177 const int nx = domain().nx();
181 const double shift = newGuess[nm*nx - 1];
182 for (
int i = 0; i < nm; i++) {
183 DArray<double>& wField = system().wField(i);
185 for (
int k = 0; k < nx; k++) {
186 wField[k] = newGuess[i*nx + k] - shift;
189 for (
int k = 0; k < nx; k++) {
190 wField[k] = newGuess[i*nx + k];
197 void AmIterator::outputToLog()
Template for Anderson mixing iterator algorithm.
void readParameters(std::istream &in) override
Read all parameters and initialize.
AmIterator(System &system)
Constructor.
void setup(bool isContinuation) override
Setup iterator just before entering iteration loop.
Base class for iterative solvers for SCF equations.
Main class in SCFT simulation of one system.
Dynamically allocatable contiguous array template.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Ensemble
Statistical ensemble type for the number of molecules of one species.
SCFT with real 1D fields.
PSCF package top-level namespace.