Loading [MathJax]/extensions/TeX/AMSsymbols.js
PSCF v1.2
AmbdInteraction.cpp
1/*
2* PSCF - Polymer Self-Consistent Field Theory
3*
4* Copyright 2016 - 2022, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "AmbdInteraction.h"
9#include <pscf/math/LuSolver.h>
10
11namespace Pscf
12{
13
14 using namespace Util;
15
16 /*
17 * Constructor.
18 */
20 : nMonomer_(0),
21 isAllocated_(false)
22 {}
23
24 /*
25 * Destructor.
26 */
29
30 /*
31 * Set the number of monomer types and allocate memory.
32 */
34 {
35 UTIL_CHECK(isAllocated_ == false);
36 UTIL_CHECK(nMonomer_ == 0);
38 nMonomer_ = nMonomer;
40 chiInverse_.allocate(nMonomer, nMonomer);
42 isAllocated_ = true;
43 }
44
45 void AmbdInteraction::update(Interaction const & interaction)
46 {
47
48 // Set nMonomer and allocate memory if not done previously
49 if (!isAllocated_) {
50 setNMonomer(interaction.nMonomer());
51 }
52 UTIL_CHECK(nMonomer_ == interaction.nMonomer());
53
54 // Copy all chi and chiInverse matrix values
55 int i, j;
56 for (i = 0; i < nMonomer_; ++i) {
57 for (j = 0; j < nMonomer_; ++j) {
58 chi_(i, j) = interaction.chi(i, j);
59 chiInverse_(i, j) = interaction.chiInverse(i, j);
60 }
61 }
62
63 // Compute p and sumChiInverse
64 int k;
65 double sum = 0.0;
66 for (i = 0; i < nMonomer_; ++i) {
67 p_(0,i) = 0.0;
68 for (j = 0; j < nMonomer_; ++j) {
69 p_(0,i) -= chiInverse_(j,i);
70 }
71 sum -= p_(0,i);
72 for (k = 0; k < nMonomer_; ++k) { //row
73 p_(k,i) = p_(0,i);
74 }
75 }
76
77 for (i = 0; i < nMonomer_; ++i) { //row
78 for (j = 0; j < nMonomer_; ++j) { //coloumn
79 p_(i,j) /= sum;
80 }
81 p_(i,i) += 1.0 ;
82 }
83 sumChiInverse_ = sum;
84
85 }
86
87} // namespace Pscf
int nMonomer() const
Get number of monomer types.
AmbdInteraction()
Constructor.
void setNMonomer(int nMonomer)
Set number of monomers and allocate required memory.
void update(Interaction const &interaction)
Update all computed quantities.
virtual ~AmbdInteraction()
Destructor.
Flory-Huggins excess free energy model.
Definition Interaction.h:26
double chiInverse(int i, int j) const
Return one element of the inverse chi matrix.
DMatrix< double > const & chi() const
Return the chi matrix by const reference.
int nMonomer() const
Get number of monomer types.
void allocate(int capacity1, int capacity2)
Allocate memory for a matrix.
Definition DMatrix.h:170
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.