PSCF v1.5.0
rp/solvers/Polymer.tpp
1#ifndef RP_POLYMER_TPP
2#define RP_POLYMER_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Polymer.h"
12#include <rp/solvers/Block.h>
13#include <rp/solvers/Propagator.h>
14#include <pscf/field/RField.h>
15#include <pscf/solvers/PolymerTmpl.tpp>
16#include <pscf/chem/PolymerModel.h>
17
18namespace Pscf {
19namespace Rp {
20
21 /*
22 * Constructor.
23 */
24 template <int D, class T>
26 : stress_(),
27 nParam_(0)
28 { ParamComposite::setClassName("Polymer"); }
29
30 /*
31 * Destructor.
32 */
33 template <int D, class T>
36
37 /*
38 * Set the number of unit cell parameters.
39 */
40 template <int D, class T>
41 void Polymer<D,T>::setNParams(int nParam)
42 { nParam_ = nParam; }
43
44 /*
45 * Clear all data that depends on unit cell parameters.
46 */
47 template <int D, class T>
49 {
50 for (int j = 0; j < nBlock(); ++j) {
51 block(j).clearUnitCellData();
52 }
53 stress_.clear();
54 }
55
56 /*
57 * Compute solution to MDE and block concentrations.
58 */
59 template <int D, class T>
60 void Polymer<D,T>::compute(DArray< RField<D,T> > const & wFields,
61 double phiTot)
62 {
63 // Setup solvers for all blocks
64 int monomerId;
65 for (int j = 0; j < nBlock(); ++j) {
66 monomerId = block(j).monomerId();
67 block(j).setupSolver(wFields[monomerId]);
68 }
69
70 // Call base class PolymerTmpl solve() function
71 // This solves the MDE for all propagators in a precalculated order
72 PolymerTmplT::solve(phiTot);
73
74 // Compute block concentration fields
75 double prefactor;
77 prefactor = phi() / ( q() * length() );
78 for (int i = 0; i < nBlock(); ++i) {
79 block(i).computeConcentrationThread(prefactor);
80 }
81 } else {
82 prefactor = phi() / ( q() * (double)nBead() );
83 for (int i = 0; i < nBlock(); ++i) {
84 block(i).computeConcentrationBead(prefactor);
85 }
86 }
87
88 }
89
90 /*
91 * Compute stress contribution from a polymer species.
92 */
93 template <int D, class T>
95 {
96 UTIL_CHECK(nParam_ > 0);
97
98 // Compute stress contributions for all blocks
99 double prefactor;
101 prefactor = phi() / ( q() * length() );
102 for (int i = 0; i < nBlock(); ++i) {
103 block(i).computeStressThread(prefactor);
104 }
105 } else {
106 prefactor = phi() / ( q() * (double)nBead() );
107 for (int i = 0; i < nBlock(); ++i) {
108 block(i).computeStressBead(prefactor);
109 }
110 }
111
112 // Initialize all stress_ elements to zero
113 stress_.clear();
114 for (int i = 0; i < nParam_; ++i) {
115 stress_.append(0.0);
116 }
117
118 // Sum over all block stress contributions
119 for (int i = 0; i < nBlock(); ++i) {
120 for (int j = 0; j < nParam_; ++j){
121 stress_[j] += block(i).stress(j);
122 }
123 }
124
125 }
126
127}
128}
129#endif
virtual void solve(double phiTot=1.0)
void setNParams(int nParam)
Set the number of unit cell parameters.
BlockT & block(int id)
Get a specified Block (solver and descriptor).
void clearUnitCellData()
Clear all data that depends on unit cell parameters.
void computeStress()
Compute SCFT stress contribution from this polymer species.
void compute(DArray< RField< D, T > > const &wFields, double phiTot=1.0)
Compute MDE solutions and block concentrations.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
bool isThread()
Is the thread model in use ?
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.