PSCF v1.2
rpc/solvers/Block.h
1#ifndef RPC_BLOCK_H
2#define RPC_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 <prdc/cpu/FFT.h> // member
13#include <prdc/cpu/RField.h> // member
14#include <prdc/cpu/RFieldDft.h> // member
15#include <prdc/crystal/UnitCell.h> // member
16#include <pscf/solvers/BlockTmpl.h> // base class template
17#include <pscf/mesh/Mesh.h> // member
18#include <util/containers/FArray.h> // member template
19#include <util/containers/DMatrix.h> // member template
20
21namespace Pscf {
22 template <int D> class Mesh;
23 namespace Prdc{
24 template <int D> class UnitCell;
25 }
26}
27
28namespace Pscf {
29namespace Rpc {
30
31 using namespace Util;
32 using namespace Pscf::Prdc;
33 using namespace Pscf::Prdc::Cpu;
34
44 template <int D>
45 class Block : public BlockTmpl< Propagator<D> >
46 {
47
48 public:
49
53 Block();
54
58 ~Block();
59
70 void associate(Mesh<D> const& mesh,
71 FFT<D> const& fft,
72 UnitCell<D> const& cell);
73
92 void allocate(double ds);
93
102 void clearUnitCellData();
103
109 void setLength(double newLength);
110
116 void setKuhn(double kuhn);
117
128 void setupSolver(RField<D> const & w);
129
141 void step(RField<D> const & q, RField<D>& qNew);
142
163 void computeConcentration(double prefactor);
164
174 void computeStress(double prefactor);
175
179 Mesh<D> const & mesh() const;
180
184 FFT<D> const & fft() const;
185
189 double ds() const;
190
194 int ns() const;
195
204 double stress(int n) const;
205
206 // Functions with non-dependent names from BlockTmpl< Propagator<D> >
207 using BlockTmpl< Propagator<D> >::setKuhn;
208 using BlockTmpl< Propagator<D> >::propagator;
209 using BlockTmpl< Propagator<D> >::cField;
210 using BlockTmpl< Propagator<D> >::length;
211 using BlockTmpl< Propagator<D> >::kuhn;
212
213 // Functions with non-dependent names from Edge
214 using Edge::setId;
215 using Edge::setVertexIds;
216 using Edge::setMonomerId;
217 using Edge::setLength;
218 using Edge::id;
219 using Edge::monomerId;
220 using Edge::vertexIds;
221 using Edge::vertexId;
222 using Edge::length;
223
224 private:
225
226 // Matrix to store derivatives of plane waves
227 DMatrix<double> dGsq_;
228
229 // Stress arising from this block
230 FSArray<double, 6> stress_;
231
232 // Fourier transform plan
233 // FFT<D> fft_;
234
235 // Array of elements containing exp(-K^2 b^2 ds/6)
236 RField<D> expKsq_;
237
238 // Array of elements containing exp(-W[i] ds/2)
239 RField<D> expW_;
240
241 // Array of elements containing exp(-K^2 b^2 ds/(6*2))
242 RField<D> expKsq2_;
243
244 // Array of elements containing exp(-W[i] (ds/2)*0.5)
245 RField<D> expW2_;
246
247 // Work array for real-space field (step size ds)
248 RField<D> qr_;
249
250 // Work array for real-space field (step size ds/2)
251 RField<D> qr2_;
252
253 // Work array for wavevector space field (step size ds)
254 RFieldDft<D> qk_;
255
256 // Work array for wavevector space field (step size ds/2)
257 RFieldDft<D> qk2_;
258
259 // Pointer to associated Mesh<D> object
260 Mesh<D> const* meshPtr_;
261
262 // Pointer to associated FFT<D> object
263 FFT<D> const* fftPtr_;
264
265 // Pointer to associated UnitCell<D> object
266 UnitCell<D> const* unitCellPtr_;
267
268 // Dimensions of wavevector mesh in real-to-complex transform
269 IntVec<D> kMeshDimensions_;
270
271 // Number of wavevectors in wavevector mesh
272 int kSize_;
273
274 // Contour length step size (actual step size for this block)
275 double ds_;
276
277 // Contour length step size (value input in param file)
278 double dsTarget_;
279
280 // Number of contour grid points = # of contour steps + 1
281 int ns_;
282
283 // Have arrays been allocated ?
284 bool isAllocated_;
285
286 // Are expKsq_ arrays up to date ? (initialize false)
287 bool hasExpKsq_;
288
292 UnitCell<D> const & unitCell() const
293 { return *unitCellPtr_; }
294
298 void computedGsq();
299
303 void computeExpKsq();
304
305 };
306
307 // Inline member functions
308
310 template <int D>
311 inline int Block<D>::ns() const
312 { return ns_; }
313
315 template <int D>
316 inline double Block<D>::ds() const
317 { return ds_; }
318
320 template <int D>
321 inline double Block<D>::stress(int n) const
322 { return stress_[n]; }
323
325 template <int D>
326 inline Mesh<D> const & Block<D>::mesh() const
327 {
328 UTIL_ASSERT(meshPtr_);
329 return *meshPtr_;
330 }
331
333 template <int D>
334 inline FFT<D> const & Block<D>::fft() const
335 {
336 UTIL_ASSERT(fftPtr_);
337 return *fftPtr_;
338 // return fft_;
339 }
340
341 #ifndef RPC_BLOCK_TPP
342 // Suppresse implicit instantiation
343 extern template class Block<1>;
344 extern template class Block<2>;
345 extern template class Block<3>;
346 #endif
347
348}
349}
350#endif
Class template for a block solver in a block copolymer.
Definition BlockTmpl.h:106
Propagator< D > & propagator(int directionId)
Definition BlockTmpl.h:191
Propagator< D >::CField & cField()
Definition BlockTmpl.h:207
void setVertexIds(int vertexAId, int vertexBId)
Set indices of associated vertices.
Definition Edge.cpp:43
int id() const
Get the id of this block.
Definition Edge.h:229
const Pair< int > & vertexIds() const
Get the pair of associated vertex ids.
Definition Edge.h:241
virtual void setLength(double length)
Set the length of this block.
Definition Edge.cpp:58
int monomerId() const
Get the monomer type id.
Definition Edge.h:235
int vertexId(int i) const
Get id of an associated vertex.
Definition Edge.h:247
void setMonomerId(int monomerId)
Set the monomer type id.
Definition Edge.cpp:52
void setId(int id)
Set the id for this block.
Definition Edge.cpp:37
double length() const
Get the length (number of monomers) in this block.
Definition Edge.h:253
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.
Fourier transform wrapper.
Fourier transform of a real field on an FFT mesh.
Field of real double precision values on an FFT mesh.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition rpg/System.h:34
Block within a branched polymer.
void computeStress(double prefactor)
Compute stress contribution for this block.
void setLength(double newLength)
Set or reset block length.
double stress(int n) const
Get derivative of free energy w/ respect to unit cell parameter n.
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
Mesh< D > const & mesh() const
Get associated spatial Mesh by const reference.
void clearUnitCellData()
Clear all internal data that depends on the unit cell parameters.
void setupSolver(RField< D > const &w)
Set solver for this block.
void allocate(double ds)
Allocate memory and set contour step size.
void associate(Mesh< D > const &mesh, FFT< D > const &fft, UnitCell< D > const &cell)
Initialize discretization and allocate required memory.
void step(RField< D > const &q, RField< D > &qNew)
Compute one step of solution of MDE, from step i to i+1.
double ds() const
Get contour length step size.
int ns() const
Get the number of contour length steps in this block.
FFT< D > const & fft() const
Get associated FFT object by const reference.
double length() const
Get the length (number of monomers) in this block.
Definition Edge.h:253
void computeConcentration(double prefactor)
Compute concentration (volume fraction) for block by integration.
Dynamically allocated Matrix.
Definition DMatrix.h:25
A fixed capacity (static) contiguous array with a variable logical size.
Definition rpg/System.h:28
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.