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