PSCF v1.1
pspg/solvers/Block.h
1#ifndef PSPG_BLOCK_H
2#define PSPG_BLOCK_H
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 "Propagator.h" // base class argument
12#include <pscf/solvers/BlockTmpl.h> // base class template
13#include <pspg/field/RDField.h> // member
14#include <pspg/field/RDFieldDft.h> // member
15#include <pspg/field/FFT.h> // member
16#include <pspg/field/FFTBatched.h> // member
17#include <util/containers/FArray.h>
18#include <pscf/crystal/UnitCell.h>
19#include <pspg/solvers/WaveList.h>
20
21
22namespace Pscf {
23
24 template <int D> class Mesh;
25
26namespace Pspg {
27
28 using namespace Util;
29
38 template <int D>
39 class Block : public BlockTmpl< Propagator<D> >
40 {
41
42 public:
43
47 Block();
48
52 ~Block();
53
60 void setDiscretization(double ds, const Mesh<D>& mesh);
61
68 void setupUnitCell(UnitCell<D> const & unitCell,
69 WaveList<D> const & waveList);
70
76 void setLength(double length);
77
83 void setKuhn(double kuhn);
84
90 void setupSolver(RDField<D> const & w);
91
95 void setupFFT();
96
103 void step(cudaReal const * q, cudaReal* qNew);
104
117 void computeConcentration(double prefactor);
118
127 void computeStress(WaveList<D> const & waveList, double prefactor);
128
134 double stress(int n);
135
139 Mesh<D> const & mesh() const;
140
144 double ds() const;
145
149 int ns() const;
150
151 // Functions with non-dependent names from BlockTmpl<Propagator<D>>
157
158 // Functions with non-dependent names from BlockDescriptor
168
169 private:
170
172 int nBlocks_;
173
175 int nThreads_;
176
178 FFT<D> fft_;
179
181 FFTBatched<D> fftBatched_;
182
184 FArray<double, 6> stress_;
185
186 // Array of elements containing exp(-K^2 b^2 ds/6) on k-grid
187 RDField<D> expKsq_;
188
189 // Array of elements containing exp(-K^2 b^2 ds/12) on k-grid
190 RDField<D> expKsq2_;
191
192 // Array of elements containing exp(-W[i] ds/2) on r-grid
193 RDField<D> expW_;
194
195 // Array of elements containing exp(-W[i] ds/4) on r-grid
196 RDField<D> expW2_;
197
198 // Work arrays for r-grid fields
199 RDField<D> qr_;
200 RDField<D> qr2_;
201
202 // Work arrays for wavevector space (k-grid) field
203 RDFieldDft<D> qk_;
204 RDFieldDft<D> qk2_;
205
206 // Batched FFTs of q
207 cudaComplex* qkBatched_;
208 cudaComplex* qk2Batched_;
209
210 // Propagators on r-grid
211 RDField<D> q1_;
212 RDField<D> q2_;
213
214 cudaReal* d_temp_;
215 cudaReal* temp_;
216
217 cudaReal* expKsq_host;
218 cudaReal* expKsq2_host;
219
221 Mesh<D> const * meshPtr_;
222
224 UnitCell<D> const* unitCellPtr_;
225
227 WaveList<D> const * waveListPtr_;
228
230 IntVec<D> kMeshDimensions_;
231
233 int kSize_;
234
236 double ds_;
237
239 int ns_;
240
242 bool isAllocated_;
243
245 bool hasExpKsq_;
246
248 UnitCell<D> const & unitCell() const
249 { return *unitCellPtr_; }
250
252 WaveList<D> const & wavelist() const
253 { return *waveListPtr_; }
254
256 int nParams_;
257
261 void computeExpKsq();
262
263 };
264
265 // Inline member functions
266
268 template <int D>
269 inline int Block<D>::ns() const
270 { return ns_; }
271
273 template <int D>
274 inline double Block<D>::ds() const
275 { return ds_; }
276
278 template <int D>
279 inline double Block<D>::stress(int n)
280 { return stress_[n]; }
281
283 template <int D>
284 inline Mesh<D> const & Block<D>::mesh() const
285 {
286 UTIL_ASSERT(meshPtr_);
287 return *meshPtr_;
288 }
289
290 #ifndef PSPG_BLOCK_TPP
291 // Suppress implicit instantiation
292 extern template class Block<1>;
293 extern template class Block<2>;
294 extern template class Block<3>;
295 #endif
296
297}
298}
299//#include "Block.tpp"
300#endif
double length() const
Get the length (number of monomers) in this block.
int vertexId(int i) const
Get id of an associated vertex.
void setId(int id)
Set the id for this block.
int monomerId() const
Get the monomer type id.
const Pair< int > & vertexIds() const
Get the pair of associated vertex ids.
virtual void setLength(double length)
Set the length of this block.
void setVertexIds(int vertexAId, int vertexBId)
Set indices of associated vertices.
int id() const
Get the id of this block.
void setMonomerId(int monomerId)
Set the monomer id.
Class template for a block in a block copolymer.
Definition: BlockTmpl.h:89
double kuhn() const
Get monomer statistical segment length.
Definition: BlockTmpl.h:205
Propagator< D > & propagator(int directionId)
Get a Propagator for a specified direction.
Definition: BlockTmpl.h:174
TP::CField & cField()
Get the associated monomer concentration field.
Definition: BlockTmpl.h:190
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition: IntVec.h:27
Description of a regular grid of points in a periodic domain.
Definition: Mesh.h:61
Block within a branched polymer.
double stress(int n)
Get derivative of free energy w/ respect to a unit cell parameter.
void computeConcentration(double prefactor)
Compute unnormalized concentration for block by integration.
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
double length() const
Get the length (number of monomers) in this block.
void computeStress(WaveList< D > const &waveList, double prefactor)
Compute derivatives of free energy w/ respect to cell parameters.
void setupSolver(RDField< D > const &w)
Set solver for this block.
void setDiscretization(double ds, const Mesh< D > &mesh)
Initialize discretization and allocate required memory.
double ds() const
Contour length step size.
Mesh< D > const & mesh() const
Return associated spatial Mesh by const reference.
void setupUnitCell(UnitCell< D > const &unitCell, WaveList< D > const &waveList)
Setup parameters that depend on the unit cell.
void setupFFT()
Initialize FFT and batch FFT classes.
void setLength(double length)
Set or reset block length.
void step(cudaReal const *q, cudaReal *qNew)
Compute step of integration loop, from i to i+1.
int ns() const
Number of contour length steps.
Fourier transform wrapper for real data.
Definition: FFTBatched.h:37
Fourier transform wrapper for real data.
MDE solver for one-direction of one block.
Discrete Fourier Transform (DFT) of a real field on an FFT mesh.
Definition: RDFieldDft.h:35
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
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition: UnitCell.h:44
A fixed size (static) contiguous array template.
Definition: FArray.h:47
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1