8#include "BinaryRelaxIterator.h"
10#include <r1d/solvers/Mixture.h>
11#include <r1d/solvers/Polymer.h>
12#include <pscf/inter/Interaction.h>
13#include <util/misc/Log.h>
14#include <util/misc/Timer.h>
41 read(in,
"epsilon", epsilon_);
42 read(in,
"maxIter", maxItr_);
43 read(in,
"lambdaPlus", lambdaPlus_);
44 read(in,
"lambdaMinus", lambdaMinus_);
50 void BinaryRelaxIterator::allocate()
52 if (isAllocated_)
return;
61 wFieldsNew_.allocate(nm);
62 cFieldsNew_.allocate(nm);
63 for (
int i = 0; i < nm; ++i) {
64 wFieldsNew_[i].allocate(nx);
65 cFieldsNew_[i].allocate(nx);
67 dWNew_[i].allocate(nx);
72 void BinaryRelaxIterator::computeDW(
Array<FieldT> const & wOld,
78 double dWm, dWp, c0, c1, w0, w1, wm;
84 for (
int i = 0; i < nx; ++i) {
91 dWm = 0.5*( c0 - c1 - wm/chi);
99 dWNorm = (dWpNorm + dWmNorm)/
double(nx);
100 dWNorm = sqrt(dWNorm);
103 void BinaryRelaxIterator::updateWFields(
Array<FieldT> const & wOld,
115 for (j = 0; j < nx; j++){
118 wNew[0][j] = w0 + dW[0][j];
119 wNew[1][j] = w1 + dW[1][j];
124 double shift = wNew[nm-1][nx-1];
125 for (i = 0; i < nm; ++i) {
126 for (j = 0; j < nx; ++j) {
150 for (
int i = 0; i < np; ++i) {
152 if (ensemble == Species::Unknown) {
155 if (ensemble == Species::Open) {
156 isCanonical_ =
false;
163 double shift =
wFields()[nm-1][nx-1];
165 for (i = 0; i < nm; ++i) {
166 for (j = 0; j < nx; ++j) {
178 for (i = 0; i < maxItr_; ++i) {
180 <<
" , error = " << dWNorm_
183 if (dWNorm_ < epsilon_) {
187 Log::file() <<
"The epsilon is " << epsilon_<< std::endl;
194 << timerTotal.
time() <<
" s " << std::endl;
195 Log::file() <<
"Average time cost of each iteration: "
196 << timerTotal.
time()/i <<
" s " << std::endl;
204 computeDW(wFieldsNew_, cFieldsNew_, dWNew_, dWNormNew_);
208 while (dWNormNew_ > dWNorm_ && j < 3) {
211 << dWNormNew_ <<
", decreasing increment" << std::endl;
216 << lambdaPlus_ << std::endl;
218 << lambdaMinus_<< std::endl;
227 if (dWNormNew_ < dWNorm_) {
229 for (j = 0; j < nm; ++j) {
230 for (k = 0; k < nx; ++k) {
233 dW_[j][k] = dWNew_[j][k];
235 dWNorm_ = dWNormNew_;
238 Log::file() <<
"Iteration failed, norm = "
239 << dWNormNew_ << std::endl;
DMatrix< double > const & chi() const
Return the chi matrix by const reference.
int nPolymer() const
Get number of polymer species.
int nMonomer() const
Get number of monomer types.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
virtual ~BinaryRelaxIterator()
Destructor.
int solve(bool isContinuation=false)
Iterate self-consistent field equations to solution.
void readParameters(std::istream &in)
Read all parameters and initialize.
BinaryRelaxIterator(System &system)
Constructor.
int nx() const
Get number of spatial grid points, including both endpoints.
Iterator()
Default constructor.
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields)
Compute concentrations.
const Domain & domain() const
Get spatial domain (including grid info) by reference.
DArray< System::CField > & cFields()
Get array of all chemical potential fields.
DArray< System::WField > & wFields()
Get array of all chemical potential fields.
const System & system() const
Get parent System by reference.
const Mixture & mixture() const
Get Mixture by reference.
Main class in SCFT simulation of one system.
Interaction & interaction()
Get interaction (i.e., excess free energy) by reference.
CField & cField(int monomerId)
Get chemical potential field for a specific monomer type.
void computeFreeEnergy()
Compute free energy density and pressure for current fields.
WField & wField(int monomerId)
Get chemical potential field for a specific monomer type.
Ensemble
Statistical ensemble for number of molecules.
Array container class template.
void allocate(int capacity)
Allocate the underlying C array.
static std::ostream & file()
Get log ostream by reference.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
void start(TimePoint begin)
Start timing from an externally supplied time.
double time() const
Return the accumulated time, in seconds.
void stop(TimePoint end)
Stop the clock at an externally supplied time.
#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.
SCFT with real 1D fields.
PSCF package top-level namespace.