PSCF v1.1
pspg/solvers/Polymer.tpp
1#ifndef PSPG_POLYMER_TPP
2#define PSPG_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#include <pspg/math/GpuResources.h>
13
14namespace Pscf {
15namespace Pspg {
16
17 template <int D>
18 Polymer<D>::Polymer()
19 { setClassName("Polymer"); }
20
21 template <int D>
22 Polymer<D>::~Polymer()
23 {}
24
25 template <int D>
26 void Polymer<D>::setPhi(double phi)
27 {
28 UTIL_CHECK(ensemble() == Species::Closed);
29 UTIL_CHECK(phi >= 0.0);
30 UTIL_CHECK(phi <= 1.0);
31 phi_ = phi;
32 }
33
34 template <int D>
35 void Polymer<D>::setMu(double mu)
36 {
37 UTIL_CHECK(ensemble() == Species::Open);
38 mu_ = mu;
39 }
40
41 /*
42 * Set unit cell dimensions in all solvers.
43 */
44 template <int D>
45 void Polymer<D>::setupUnitCell(UnitCell<D> const & unitCell, const WaveList<D>& wavelist)
46 {
47 nParams_ = unitCell.nParameter();
48 for (int j = 0; j < nBlock(); ++j) {
49 block(j).setupUnitCell(unitCell, wavelist);
50 }
51 }
52
53 /*
54 * Compute solution to MDE and concentrations.
55 */
56 template <int D>
57 void Polymer<D>::compute(DArray< RDField<D> > const & wFields)
58 {
59 // Setup solvers for all blocks
60 int monomerId;
61 for (int j = 0; j < nBlock(); ++j) {
62 monomerId = block(j).monomerId();
63 block(j).setupSolver(wFields[monomerId]);
64 }
65
66 // Call generic solver() method base class template.
67 solve();
68 }
69
70 /*
71 * Compute stress from a polymer chain.
72 */
73
74 template <int D>
76 {
77 double prefactor;
78 prefactor = 0;
79
80 // Initialize stress_ to 0
81 for (int i = 0; i < nParams_; ++i) {
82 stress_ [i] = 0.0;
83 }
84
85 for (int i = 0; i < nBlock(); ++i) {
86 prefactor = exp(mu_)/length();
87 block(i).computeStress(wavelist, prefactor);
88
89 for (int j=0; j < nParams_; ++j){
90 stress_ [j] += block(i).stress(j);
91 //std::cout<<"stress_[j] "<<stress_[j]<<std::endl;
92 }
93 }
94 }
95
96}
97}
98#endif
void setupUnitCell(UnitCell< D > const &unitCell, WaveList< D > const &wavelist)
Compute solution to MDE and concentrations.
void compute(DArray< RDField< D > > const &wFields)
Compute solution to MDE and concentrations.
void computeStress(WaveList< D > const &wavelist)
Compute stress from a polymer chain, needs a pointer to basis.
Field of real single precision values on an FFT mesh on a device.
Definition: RDField.h:34
Container for wavevector data.
Definition: WaveList.h:31
int nParameter() const
Get the number of parameters in the unit cell.
Definition: UnitCellBase.h:243
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).