PSCF v1.4.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 - 2025, 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#include <pscf/solvers/PolymerTmpl.tpp>
13#include <pscf/chem/PolymerModel.h>
14
15namespace Pscf {
16namespace Rp {
17
18 /*
19 * Constructor.
20 */
21 template <int D, class T>
23 : stress_(),
24 nParam_(0)
25 { ParamComposite::setClassName("Polymer"); }
26
27 /*
28 * Destructor.
29 */
30 template <int D, class T>
33
34 /*
35 * Set the number of unit cell parameters.
36 */
37 template <int D, class T>
38 void Polymer<D,T>::setNParams(int nParam)
39 { nParam_ = nParam; }
40
41 /*
42 * Clear all data that depends on unit cell parameters.
43 */
44 template <int D, class T>
46 {
47 for (int j = 0; j < nBlock(); ++j) {
48 block(j).clearUnitCellData();
49 }
50 stress_.clear();
51 }
52
53 /*
54 * Compute solution to MDE and block concentrations.
55 */
56 template <int D, class T>
58 double phiTot)
59 {
60 // Setup solvers for all blocks
61 int monomerId;
62 for (int j = 0; j < nBlock(); ++j) {
63 monomerId = block(j).monomerId();
64 block(j).setupSolver(wFields[monomerId]);
65 }
66
67 // Call base class PolymerTmpl solve() function
68 // This solves the MDE for all propagators in a precalculated order
69 solve(phiTot);
70
71 // Compute block concentration fields
72 double prefactor;
74 prefactor = phi() / ( q() * length() );
75 for (int i = 0; i < nBlock(); ++i) {
76 block(i).computeConcentrationThread(prefactor);
77 }
78 } else {
79 prefactor = phi() / ( q() * (double)nBead() );
80 for (int i = 0; i < nBlock(); ++i) {
81 block(i).computeConcentrationBead(prefactor);
82 }
83 }
84
85 }
86
87 /*
88 * Compute stress contribution from a polymer species.
89 */
90 template <int D, class T>
92 {
93 UTIL_CHECK(nParam_ > 0);
94
95 // Compute stress contributions for all blocks
96 double prefactor;
98 prefactor = phi() / ( q() * length() );
99 for (int i = 0; i < nBlock(); ++i) {
100 block(i).computeStressThread(prefactor);
101 }
102 } else {
103 prefactor = phi() / ( q() * (double)nBead() );
104 for (int i = 0; i < nBlock(); ++i) {
105 block(i).computeStressBead(prefactor);
106 }
107 }
108
109 // Initialize all stress_ elements to zero
110 stress_.clear();
111 for (int i = 0; i < nParam_; ++i) {
112 stress_.append(0.0);
113 }
114
115 // Sum over all block stress contributions
116 for (int i = 0; i < nBlock(); ++i) {
117 for (int j = 0; j < nParam_; ++j){
118 stress_[j] += block(i).stress(j);
119 }
120 }
121
122 }
123
124}
125}
126#endif
void setNParams(int nParam)
Set the number of unit cell parameters.
BlockT & block(int id)
Get a specified Block (solver and descriptor).
void compute(DArray< typename T::RField > const &wFields, double phiTot=1.0)
Compute MDE solutions and block concentrations.
void clearUnitCellData()
Clear all data that depends on unit cell parameters.
void computeStress()
Compute SCFT stress contribution from this polymer species.
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 ?
Class templates for real-valued periodic fields.
PSCF package top-level namespace.