PSCF v1.4.0
Interaction.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Interaction.h"
9#include <cmath>
10
11namespace Pscf {
12
13 using namespace Util;
14
15 /*
16 * Constructor.
17 */
19 : chi_(),
20 zeta_(-1.0),
21 nMonomer_(0),
22 isCompressible_(isCompressible),
23 isInitialized_(false)
24 { setClassName("Interaction"); }
25
26 /*
27 * Destructor.
28 */
31
32 /*
33 * Set the number of monomer types.
34 */
36 {
37 UTIL_CHECK(nMonomer_ == 0);
38 UTIL_CHECK(!isInitialized_);
40 nMonomer_ = nMonomer;
41 chi_.allocate(nMonomer, nMonomer);
42 setChiZero();
43 }
44
45 /*
46 * Read parameters from file.
47 */
48 void Interaction::readParameters(std::istream& in)
49 {
50 UTIL_CHECK(nMonomer_ > 0);
51 UTIL_CHECK(!isInitialized_);
52 setChiZero();
53 readDSymmMatrix(in, "chi", chi_, nMonomer());
54 if (isCompressible_) {
55 //isCompressible_ = readOptional(in, "zeta", zeta_).isActive();
56 auto& param = readOptional(in, "zeta", zeta_);
57 isCompressible_ = param.isActive();
58 }
59 isInitialized_ = true;
60 }
61
62 /*
63 * Set a single Flory-Huggins chi parameter.
64 */
65 void Interaction::setChi(int i, int j, double chi)
66 {
67 UTIL_CHECK(nMonomer_ > 0);
68 UTIL_CHECK(isInitialized_);
69 UTIL_CHECK(i >= 0);
70 UTIL_CHECK(i < nMonomer_);
71 UTIL_CHECK(j >= 0);
72 UTIL_CHECK(j < nMonomer_);
73 chi_(i,j) = chi;
74 if (i != j) {
75 chi_(j,i) = chi;
76 }
77 }
78
79 /*
80 * Set all elements of the chi matrix to zero.
81 */
82 void Interaction::setChiZero()
83 {
84 UTIL_CHECK(nMonomer_ > 0);
85 int i, j;
86 for (i = 0; i < nMonomer_; ++i) {
87 for (j = 0; j < nMonomer_; ++j) {
88 chi_(i, j) = 0.0;
89 }
90 }
91 }
92
93} // namespace Pscf
Interaction(bool isCompressible=false)
Constructor.
virtual void readParameters(std::istream &in)
Read model parameters.
DMatrix< double > const & chi() const
Return the chi matrix by const reference.
void setChi(int i, int j, double chi)
Change one element of the chi matrix.
void setNMonomer(int nMonomer)
Set the number of monomer types.
virtual ~Interaction()
Destructor.
int nMonomer() const
Get number of monomer types.
bool isCompressible() const
Is the system compressible?
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.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.