PSCF v1.2
rpc/solvers/Polymer.tpp
1#ifndef RPC_POLYMER_TPP
2#define RPC_POLYMER_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Polymer.h"
12
13namespace Pscf {
14namespace Rpc {
15
16 template <int D>
18 : stress_(),
19 nParam_(0)
20 { setClassName("Polymer");}
21
22 template <int D>
25
26 template <int D>
27 void Polymer<D>::setPhi(double phi)
28 {
29 UTIL_CHECK(ensemble() == Species::Closed);
30 UTIL_CHECK(phi >= 0.0);
31 UTIL_CHECK(phi <= 1.0);
32 phi_ = phi;
33 }
34
35 template <int D>
36 void Polymer<D>::setMu(double mu)
37 {
38 UTIL_CHECK(ensemble() == Species::Open);
39 mu_ = mu;
40 }
41
42 /*
43 * Set the number of unit cell parameters.
44 */
45 template <int D>
46 void Polymer<D>::setNParams(int nParam)
47 { nParam_ = nParam; }
48
49 /*
50 * Set unit cell dimensions in all solvers.
51 */
52 template <int D>
54 {
55 for (int j = 0; j < nBlock(); ++j) {
56 block(j).clearUnitCellData();
57 }
58 }
59
60 /*
61 * Compute solution to MDE and block concentrations.
62 */
63 template <int D>
64 void Polymer<D>::compute(DArray< RField<D> > const & wFields,
65 double phiTot)
66 {
67 // Setup solvers for all blocks
68 int monomerId;
69 for (int j = 0; j < nBlock(); ++j) {
70 monomerId = block(j).monomerId();
71 block(j).setupSolver(wFields[monomerId]);
72 }
73
74 // Call base class PolymerTmpl solve() function
75 solve(phiTot);
76 }
77
78 /*
79 * Compute stress from a polymer chain.
80 */
81 template <int D>
83 {
84
85 // Initialize all stress_ elements zero
86 for (int i = 0; i < 6; ++i) {
87 stress_[i] = 0.0;
88 }
89
90 // Compute and accumulate stress contributions from all blocks
91 double prefactor = exp(mu_)/length();
92 for (int i = 0; i < nBlock(); ++i) {
93 block(i).computeStress(prefactor);
94 for (int j = 0; j < nParam_ ; ++j){
95 stress_[j] += block(i).stress(j);
96 }
97 }
98
99 }
100
101}
102}
103#endif
Field of real double precision values on an FFT mesh.
void setClassName(const char *className)
Set class name string.
void compute(DArray< RField< D > > const &wFields, double phiTot=1.0)
Compute solution to MDE and block concentrations.
Polymer()
Default constructor.
void setMu(double mu)
Set value of mu (chemical potential), if ensemble is closed.
void computeStress()
Compute stress contribution from this species.
void setPhi(double phi)
Set value of phi (volume fraction), if ensemble is closed.
void clearUnitCellData()
Clear all data that depends on unit cell parameters.
void setNParams(int nParam)
Store the number of unit cell parameters.
Dynamically allocatable contiguous array template.
#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