8#include "FhInteraction.h"
9#include <pscf/interaction/Interaction.h>
10#include <pscf/math/LuSolver.h>
113 void FhInteraction::updateMembers()
119 double det = chi_(0,0)*chi_(1, 1) - chi_(0,1)*chi_(1,0);
120 double norm = chi_(0,0)*chi_(0, 0) + chi_(1,1)*chi_(1,1)
121 + 2.0*chi_(0,1)*chi_(1,0);
122 if (fabs(det/norm) < 1.0E-8) {
125 chiInverse_(0,1) = -chi_(0,1)/det;
126 chiInverse_(1,0) = -chi_(1,0)/det;
127 chiInverse_(1,1) = chi_(0,0)/det;
128 chiInverse_(0,0) = chi_(1,1)/det;
133 solver.computeLU(chi_);
134 solver.inverse(chiInverse_);
147 double value1, value2, diff;
149 for (i = 0; i < nMonomer_; ++i) {
150 chi_(i, i) = other(i, i);
153 for (i = 0; i < nMonomer_; ++i) {
154 for (j = 0; j < i; ++j) {
155 value1 = other(i, j);
156 value2 = other(j, i);
157 diff = std::abs( value1 - value2 );
158 if (diff > 1.0E-10) {
159 Log::file() <<
"Diff = " << diff <<
"\n";
160 Log::file() <<
" i, j = " << i <<
" " << j <<
"\n";
161 Log::file() <<
"chi(i,j) = " << value1 <<
"\n";
162 Log::file() <<
"chi(j,i) = " << value2 <<
"\n";
195 void FhInteraction::setChiZero()
199 for (i = 0; i < nMonomer_; i++) {
200 for (j = 0; j < nMonomer_; j++) {
202 chiInverse_(i, j) = 0.0;
216 sum += chi_(i, j)* c[i]*c[j];
233 w[i] += chi_(i, j)* c[j];
251 sum1 += chiInverse_(i, j)*w[j];
252 sum2 += chiInverse_(i, j);
255 xi = (sum1 - 1.0)/sum2;
259 c[i] += chiInverse_(i, j)*( w[j] - xi );
276 sum1 += chiInverse_(i, j)*w[j];
277 sum2 += chiInverse_(i, j);
280 xi = (sum1 - 1.0)/sum2;
293 dWdC(i, j) = chi_(i, j);
Flory-Huggins interaction model.
void setNMonomer(int nMonomer)
Set the number of monomer types.
virtual void computeC(Array< double > const &w, Array< double > &c, double &xi) const
Compute concentration from chemical potential fields.
virtual void computeW(Array< double > const &c, Array< double > &w) const
Compute chemical potential from concentration.
virtual void computeXi(Array< double > const &w, double &xi) const
Compute Langrange multiplier xi from chemical potential fields.
FhInteraction & operator=(FhInteraction const &other)
Assignment.
virtual void readParameters(std::istream &in)
Read chi parameters.
int nMonomer() const
Get number of monomer types.
FhInteraction()
Constructor.
Matrix< double > const & chi() const
Return the chi matrix by const reference.
virtual void computeDwDc(Array< double > const &c, Matrix< double > &dWdC) const
Compute second derivatives of free energy.
virtual double fHelmholtz(Array< double > const &c) const
Compute excess Helmholtz free energy per monomer.
virtual ~FhInteraction()
Destructor.
void setChi(Matrix< double > const &chi)
Assign values for all elements of the chi matrix.
Interaction model for complex Langevin FTS.
DMatrix< double > const & chi() const
Return the chi matrix by const reference.
int nMonomer() const
Get number of monomer types.
Array container class template.
bool isAllocated() const
Return true if the DMatrix has been allocated, false otherwise.
static std::ostream & file()
Get log ostream by reference.
Two-dimensional array container template (abstract).
int capacity2() const
Get number of columns (range of the second array index).
int capacity1() const
Get number of rows (range of the first array index).
DSymmMatrixParam< Type > & readDSymmMatrix(std::istream &in, const char *label, DMatrix< Type > &matrix, int n)
Add and read a required symmetrix DMatrix.
void setClassName(const char *className)
Set class name string.
#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.
PSCF package top-level namespace.