PSCF v1.3
rpg/solvers/Polymer.tpp
1#ifndef RPG_POLYMER_TPP
2#define RPG_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 <rpg/solvers/Block.h>
13#include <prdc/cuda/RField.h>
14#include <pscf/chem/PolymerModel.h>
15
16namespace Pscf {
17namespace Rpg {
18
19 /*
20 * Constructor.
21 */
22 template <int D>
24 : nParams_(0)
25 { ParamComposite::setClassName("Polymer"); }
26
27 /*
28 * Destructor.
29 */
30 template <int D>
33
34 /*
35 * Store the number of lattice parameters in the unit cell.
36 */
37 template <int D>
38 void Polymer<D>::setNParams(int nParams)
39 { nParams_ = nParams; }
40
41 /*
42 * Clear all data that depends on unit cell dimensions.
43 */
44 template <int D>
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 concentrations.
55 */
56 template <int D>
57 void Polymer<D>::compute(DArray< RField<D> > const & wFields,
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>
92 {
93 UTIL_CHECK(nParams_ > 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 < nParams_; ++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 < nParams_; ++j){
118 stress_[j] += block(i).stress(j);
119 }
120 }
121
122 }
123
124}
125}
126#endif
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
void computeStress()
Compute SCFT stress contribution from this polymer species.
double phi() const
Get the overall volume fraction for this species.
Definition Species.h:149
void compute(DArray< RField< D > > const &wFields, double phiTot=1.0)
Compute MDE solutions and block concentrations.
void clearUnitCellData()
Clear all data that depends on unit cell parameters.
void setNParams(int nParams)
Set the number of unit cell parameters.
int nBead() const
Total number of beads in the polymer (bead model).
int nBlock() const
Number of blocks.
Block< D > & block(int id)
Get a specified Block (solver and descriptor).
double length() const
Sum of the lengths of all blocks in the polymer (thread model).
double q() const
Get the molecular partition function for this species.
Definition Species.h:161
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 ?
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1