PSCF v1.4.0
rpg/solvers/Block.h
1#ifndef RPG_BLOCK_H
2#define RPG_BLOCK_H
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 <pscf/solvers/BlockTmpl.h> // base class template
12
13#include <prdc/cuda/RField.h> // member
14#include <prdc/cuda/RFieldDft.h> // member
15#include <prdc/cuda/FFTBatched.h> // member
16#include <pscf/cuda/DeviceArray.h> // member
17#include <util/containers/FSArray.h> // member
18
19#include <prdc/cuda/resources.h>
20
21// Forward declarations
22namespace Pscf {
23 template <int D> class Mesh;
24 namespace Prdc {
25 template <int D> class UnitCell;
26 namespace Cuda {
27 template <int D> class WaveList;
28 template <int D> class FFT;
29 }
30 }
31 namespace Rpg {
32 template <int D> class Propagator;
33 }
34}
35
36namespace Pscf {
37namespace Rpg {
38
39 using namespace Util;
40 using namespace Pscf::Prdc;
41 using namespace Pscf::Prdc::Cuda;
42
55 template <int D>
56 class Block : public BlockTmpl< Propagator<D>, RField<D> >
57 {
58
59 public:
60
61 // Public type name aliases
62
65
67 using typename BlockTmplT::PropagatorT;
68
70 using typename BlockTmplT::FieldT;
71
73 using FFTT = FFT<D>;
74
77
78 // Public member functions
79
83 Block();
84
88 ~Block();
89
92
105 void associate(Mesh<D> const & mesh,
106 FFT<D> const & fft,
107 UnitCell<D> const & cell,
108 WaveList<D>& waveList);
109
135 void allocate(double ds, bool useBatchedFFT = true);
136
144 void clearUnitCellData();
145
153 void setLength(double newLength);
154
160 void setKuhn(double kuhn);
161
172 void setupSolver(RField<D> const & w);
173
177
189 void stepThread(RField<D> const & qin, RField<D>& qout) const;
190
202 void stepBead(RField<D> const & qin, RField<D>& qout) const;
203
212 void stepFieldBead(RField<D> & q) const;
213
224 void stepBondBead(RField<D> const & qin, RField<D>& qout) const;
225
236 void stepHalfBondBead(RField<D> const & qin, RField<D>& qout) const;
237
241
258 void computeConcentrationThread(double prefactor);
259
277 void computeConcentrationBead(double prefactor);
278
282
291 void computeStressThread(double prefactor);
292
301 void computeStressBead(double prefactor);
302
308 double stress(int n) const;
309
313
317 double ds() const;
318
322 int ns() const;
323
325
326 // Inherited functions with non-dependent names (selected)
328 using BlockTmplT::cField;
329
330 private:
331
333 FFTBatched<D> fftBatchedAll_;
334
336 FFTBatched<D> fftBatchedPair_;
337
339 FSArray<double, 6> stress_;
340
343 RField<D> expKsq_;
344
347 RField<D> expW_;
348
350 RField<D> expKsq2_;
351
353 RField<D> expW2_;
354
356 RField<D> expWInv_;
357
365 mutable DeviceArray<cudaReal> qrPair_;
366
374 mutable DeviceArray<cudaComplex> qkPair_;
375
376 // R-grid work space (used in productAverage)
377 mutable RField<D> qr_;
378
379 // K-grid work space (used for FFT of q in stepBondBead)
380 mutable RFieldDft<D> qk_;
381
383 mutable DeviceArray<cudaComplex> q0kBatched_;
384
386 mutable DeviceArray<cudaComplex> q1kBatched_;
387
388 // Slices of forward and reverse propagator on a k-grid (for stress)
389 mutable RFieldDft<D> q0k_;
390 mutable RFieldDft<D> q1k_;
391
393 Mesh<D> const * meshPtr_;
394
396 FFT<D> const * fftPtr_;
397
399 UnitCell<D> const * unitCellPtr_;
400
402 WaveList<D> * waveListPtr_;
403
405 IntVec<D> kMeshDimensions_;
406
408 int kSize_;
409
411 double ds_;
412
414 double dsTarget_;
415
417 int ns_;
418
420 int nParams_;
421
423 bool isAllocated_;
424
426 bool hasExpKsq_;
427
429 bool useBatchedFFT_;
430
432 Mesh<D> const & mesh() const;
433
435 FFT<D> const & fft() const;
436
438 UnitCell<D> const & unitCell() const;
439
441 WaveList<D> & waveList();
442
444 void computeExpKsq();
445
446 };
447
448 // Inline member functions
449
450 // Get number of contour steps.
451 template <int D>
452 inline int Block<D>::ns() const
453 { return ns_; }
454
455 // Get contour length step size.
456 template <int D>
457 inline double Block<D>::ds() const
458 { return ds_; }
459
460 // Get derivative of free energy w/ respect to a unit cell parameter.
461 template <int D>
462 inline double Block<D>::stress(int n) const
463 { return stress_[n]; }
464
465 // Get Mesh by reference.
466 template <int D>
467 inline Mesh<D> const & Block<D>::mesh() const
468 {
469 UTIL_ASSERT(meshPtr_);
470 return *meshPtr_;
471 }
472
473 // Get FFT by reference.
474 template <int D>
475 inline FFT<D> const & Block<D>::fft() const
476 {
477 UTIL_ASSERT(fftPtr_);
478 return *fftPtr_;
479 }
480
481 // Get associated UnitCell<D> by const reference (private).
482 template <int D>
483 UnitCell<D> const & Block<D>::unitCell() const
484 { return *unitCellPtr_; }
485
486 // Get the WaveList by non-const reference (private).
487 template <int D>
488 WaveList<D> & Block<D>::waveList()
489 { return *waveListPtr_; }
490
491} // namespace Rpg
492} // namespace Pscf
493
494// Explicit instantiation declarations
495namespace Pscf {
496
497 extern template
499 extern template
501 extern template
503
504 namespace Rpg {
505 extern template class Block<1>;
506 extern template class Block<2>;
507 extern template class Block<3>;
508 }
509}
510#endif
Class template for a block solver in a block copolymer.
Definition BlockTmpl.h:107
Propagator< D > & propagator(int directionId)
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:96
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
Batched Fourier transform wrapper for real data.
Definition FFTBatched.h:33
Fourier transform wrapper for real or complex data.
Definition cuda/FFT.h:38
Discrete Fourier Transform (DFT) of a real field, allocated on a GPU.
Field of real values on a regular mesh, allocated on a GPU device.
Definition cuda/RField.h:33
Class to compute and store properties associated with wavevectors.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
Block within a branched polymer.
void setLength(double newLength)
Set or reset block length (only used in thread model).
double stress(int n) const
Get derivative of free energy w/ respect to a unit cell parameter.
BlockTmpl< Propagator< D >, RField< D > > BlockTmplT
Direct (parent) base class.
double ds() const
Contour length step size.
void allocate(double ds, bool useBatchedFFT=true)
Allocate memory and set contour step size for thread model.
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
int ns() const
Number of contour length steps.
WaveList< D > WaveListT
Wavelist type.
void stepBondBead(RField< D > const &qin, RField< D > &qout) const
Compute a bond operator for the bead model.
void computeStressBead(double prefactor)
Compute stress contribution for this block, using bead model.
void stepFieldBead(RField< D > &q) const
Apply the exponential field operator for the bead model.
void stepThread(RField< D > const &qin, RField< D > &qout) const
Compute step of integration loop, from i to i+1.
void setupSolver(RField< D > const &w)
Set solver for this block.
void associate(Mesh< D > const &mesh, FFT< D > const &fft, UnitCell< D > const &cell, WaveList< D > &waveList)
Create permanent associations with related objects.
void computeConcentrationBead(double prefactor)
Compute the concentration for this block, using the bead model.
void computeConcentrationThread(double prefactor)
Compute unnormalized concentration for block by integration.
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
FFT< D > FFTT
Fast Fourier Transform (FFT) type.
void stepHalfBondBead(RField< D > const &qin, RField< D > &qout) const
Compute a half-bond operator for the bead model.
void computeStressThread(double prefactor)
Compute stress contribution for this block, using thread model.
void stepBead(RField< D > const &qin, RField< D > &qout) const
Compute one step of solution of MDE for the bead model.
MDE solver for one direction of one block.
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Fields, FFTs, and utilities for periodic boundary conditions (CUDA).
Definition CField.cu:12
Periodic fields and crystallography.
Definition complex.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.