PSCF v1.1
pspc/solvers/Polymer.tpp
1#ifndef PSPC_POLYMER_TPP
2#define PSPC_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 Pspc {
15
16 template <int D>
18 { setClassName("Polymer");}
19
20 template <int D>
22 {}
23
24 template <int D>
25 void Polymer<D>::setPhi(double phi)
26 {
27 UTIL_CHECK(ensemble() == Species::Closed);
28 UTIL_CHECK(phi >= 0.0);
29 UTIL_CHECK(phi <= 1.0);
30 phi_ = phi;
31 }
32
33 template <int D>
34 void Polymer<D>::setMu(double mu)
35 {
36 UTIL_CHECK(ensemble() == Species::Open);
37 mu_ = mu;
38 }
39
40 /*
41 * Set unit cell dimensions in all solvers.
42 */
43 template <int D>
45 {
46 // Set association to unitCell
47 unitCellPtr_ = &unitCell;
48
49 for (int j = 0; j < nBlock(); ++j) {
50 block(j).setupUnitCell(unitCell);
51 }
52 }
53
54 /*
55 * Compute solution to MDE and block concentrations.
56 */
57 template <int D>
58 void Polymer<D>::compute(DArray< RField<D> > const & wFields,
59 double phiTot)
60 {
61 // Setup solvers for all blocks
62 int monomerId;
63 for (int j = 0; j < nBlock(); ++j) {
64 monomerId = block(j).monomerId();
65 block(j).setupSolver(wFields[monomerId]);
66 }
67
68 // Call base class PolymerTmpl solve() function
69 solve(phiTot);
70 }
71
72 /*
73 * Compute stress from a polymer chain.
74 */
75 template <int D>
77 {
78
79 // Initialize all stress_ elements zero
80 for (int i = 0; i < 6; ++i) {
81 stress_[i] = 0.0;
82 }
83
84 // Compute and accumulate stress contributions from all blocks
85 double prefactor = exp(mu_)/length();
86 for (int i = 0; i < nBlock(); ++i) {
87 block(i).computeStress(prefactor);
88 for (int j = 0; j < unitCellPtr_->nParameter() ; ++j){
89 stress_[j] += block(i).stress(j);
90 }
91 }
92
93 }
94
95}
96}
97#endif
void setPhi(double phi)
Set value of phi (volume fraction), if ensemble is closed.
void setupUnitCell(UnitCell< D > const &unitCell)
Set up the unit cell after a change in unit cell parameters.
void setMu(double mu)
Set value of mu (chemical potential), if ensemble is closed.
Polymer()
Default constructor.
void compute(DArray< RField< D > > const &wFields, double phiTot=1.0)
Compute solution to MDE and block concentrations.
void computeStress()
Compute stress contribution from this species.
Field of real double precision values on an FFT mesh.
Definition: RField.h:29
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition: UnitCell.h:44
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
C++ namespace for polymer self-consistent field theory (PSCF).