PSCF v1.3
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#include "Propagator.h" // base class argument
13
14#include <prdc/cuda/RField.h> // member
15#include <prdc/cuda/RFieldDft.h> // member
16#include <prdc/cuda/FFTBatched.h> // member
17#include <pscf/cuda/DeviceArray.h> // member
18#include <util/containers/FSArray.h> // member
19
20#include <prdc/cuda/resources.h>
21
22// Forward declarations
23namespace Pscf {
24 template <int D> class Mesh;
25 namespace Prdc {
26 template <int D> class UnitCell;
27 namespace Cuda {
28 template <int D> class WaveList;
29 template <int D> class FFT;
30 }
31 }
32 namespace Rpg {
33 template <int D> class FieldIo;
34 }
35}
36
37namespace Pscf {
38namespace Rpg {
39
40
41 using namespace Util;
42 using namespace Pscf::Prdc;
43 using namespace Pscf::Prdc::Cuda;
44
53 template <int D>
54 class Block : public BlockTmpl< Propagator<D> >
55 {
56
57 public:
58
59 // Public type name aliases
60
63
66
68 using FFTT = FFT<D>;
69
72
75
76 // Public member functions
77
81 Block();
82
86 ~Block();
87
100 void associate(Mesh<D> const & mesh,
101 FFT<D> const & fft,
102 UnitCell<D> const & cell,
103 WaveList<D>& wavelist);
104
130 void allocate(double ds, bool useBatchedFFT = true);
131
139 void clearUnitCellData();
140
148 void setLength(double newLength);
149
155 void setKuhn(double kuhn);
156
167 void setupSolver(RField<D> const & w);
168
180 void stepThread(RField<D> const & qin, RField<D>& qout);
181
193 void stepBead(RField<D> const & qin, RField<D>& qout);
194
203 void stepFieldBead(RField<D> & q);
204
215 void stepBondBead(RField<D> const & qin, RField<D>& qout);
216
227 void stepHalfBondBead(RField<D> const & qin, RField<D>& qout);
228
245 void computeConcentrationThread(double prefactor);
246
264 void computeConcentrationBead(double prefactor);
265
273 double averageProduct(RField<D> const& q0, RField<D> const& q1);
274
284 double averageProductBead(RField<D> const& q0, RField<D> const& q1);
285
294 void computeStressThread(double prefactor);
295
304 void computeStressBead(double prefactor);
305
311 double stress(int n);
312
316 Mesh<D> const & mesh() const;
317
321 FFT<D> const & fft() const;
322
326 double ds() const;
327
331 int ns() const;
332
333 // Functions with non-dependent names from BlockTmpl<Propagator<D>>
338
339 // Functions with non-dependent names from Edge
340 using Edge::setId;
341 using Edge::setVertexIds;
342 using Edge::setMonomerId;
343 using Edge::setLength;
344 using Edge::id;
345 using Edge::monomerId;
346 using Edge::vertexIds;
347 using Edge::vertexId;
348 using Edge::length;
349 using Edge::nBead;
350
351 private:
352
354 FFTBatched<D> fftBatchedAll_;
355
357 FFTBatched<D> fftBatchedPair_;
358
360 FSArray<double, 6> stress_;
361
364 RField<D> expKsq_;
365
368 RField<D> expW_;
369
371 RField<D> expKsq2_;
372
374 RField<D> expW2_;
375
377 RField<D> expWInv_;
378
386 DeviceArray<cudaReal> qrPair_;
387
396
397 // R-grid work space (used in productAverage)
398 RField<D> qr_;
399
400 // K-grid work space (used for FFT of q in stepBondBead)
401 RFieldDft<D> qk_;
402
404 DeviceArray<cudaComplex> q0kBatched_;
405
407 DeviceArray<cudaComplex> q1kBatched_;
408
409 // Slices of forward and reverse propagator on a k-grid (for stress)
410 RFieldDft<D> q0k_;
411 RFieldDft<D> q1k_;
412
414 Mesh<D> const * meshPtr_;
415
417 FFT<D> const * fftPtr_;
418
420 UnitCell<D> const * unitCellPtr_;
421
423 WaveList<D> * waveListPtr_;
424
426 IntVec<D> kMeshDimensions_;
427
429 int kSize_;
430
432 double ds_;
433
435 double dsTarget_;
436
438 int ns_;
439
441 bool isAllocated_;
442
444 bool hasExpKsq_;
445
447 bool useBatchedFFT_;
448
450 UnitCell<D> const & unitCell() const
451 { return *unitCellPtr_; }
452
454 WaveList<D> const & wavelist() const
455 { return *waveListPtr_; }
456
458 int nParams_;
459
461 void computeExpKsq();
462
463 };
464
465 // Inline member functions
466
467 // Get number of contour steps.
468 template <int D>
469 inline int Block<D>::ns() const
470 { return ns_; }
471
472 // Get contour length step size.
473 template <int D>
474 inline double Block<D>::ds() const
475 { return ds_; }
476
477 // Get derivative of free energy w/ respect to a unit cell parameter.
478 template <int D>
479 inline double Block<D>::stress(int n)
480 { return stress_[n]; }
481
482 // Get Mesh by reference.
483 template <int D>
484 inline Mesh<D> const & Block<D>::mesh() const
485 {
486 UTIL_ASSERT(meshPtr_);
487 return *meshPtr_;
488 }
489
490 // Get FFT by reference.
491 template <int D>
492 inline FFT<D> const & Block<D>::fft() const
493 {
494 UTIL_ASSERT(fftPtr_);
495 return *fftPtr_;
496 }
497
498 #ifndef RPG_BLOCK_TPP
499 // Suppress implicit instantiation
500 extern template class Block<1>;
501 extern template class Block<2>;
502 extern template class Block<3>;
503 #endif
504
505}
506}
507#endif
Propagator< D > & propagator(int directionId)
Propagator< D >::FieldT & cField()
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:43
int id() const
Get the id of this block (unique within the polymer).
Definition Edge.h:278
void setVertexIds(int vertexId0, int vertexId1)
Set indices of associated vertices.
Definition Edge.cpp:50
const Pair< int > & vertexIds() const
Get the pair of associated vertex ids.
Definition Edge.h:290
int nBead() const
Get the number of beads in this block, in the bead model.
Definition Edge.h:302
virtual void setLength(double length)
Set the length of this block (only valid for thread model).
Definition Edge.cpp:68
int monomerId() const
Get the monomer type id for this block.
Definition Edge.h:284
int vertexId(int i) const
Get the id of one associated vertex.
Definition Edge.h:296
void setMonomerId(int monomerId)
Set the monomer type id.
Definition Edge.cpp:44
void setId(int id)
Set the id for this block.
Definition Edge.cpp:38
double length() const
Get the length of this block, in the thread model.
Definition Edge.h:311
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
Fourier transform wrapper.
Definition cpu/FFT.h:38
Fourier transform of a real field on an FFT mesh.
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
Class to calculate and store properties of wavevectors.
Batched Fourier transform wrapper for real data.
Definition FFTBatched.h:32
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 ds() const
Contour length step size.
void allocate(double ds, bool useBatchedFFT=true)
Allocate memory and set contour step size for thread model.
BlockTmpl< Propagator< D > > Base
Base class.
void stepHalfBondBead(RField< D > const &qin, RField< D > &qout)
Compute a half-bond operator for the bead model.
Mesh< D > const & mesh() const
Return associated spatial Mesh by const reference.
void stepBondBead(RField< D > const &qin, RField< D > &qout)
Compute a bond operator for the bead 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 associate(Mesh< D > const &mesh, FFT< D > const &fft, UnitCell< D > const &cell, WaveList< D > &wavelist)
Create permanent associations with related objects.
void computeStressBead(double prefactor)
Compute stress contribution for this block, using bead model.
FieldIo< D > FieldIoT
FieldIo type.
void setupSolver(RField< D > const &w)
Set solver for this block.
double stress(int n)
Get derivative of free energy w/ respect to a unit cell parameter.
void computeConcentrationBead(double prefactor)
Compute the concentration for this block, using the bead model.
double averageProduct(RField< D > const &q0, RField< D > const &q1)
Compute the spatial average of the product used to compute Q.
void computeConcentrationThread(double prefactor)
Compute unnormalized concentration for block by integration.
void stepFieldBead(RField< D > &q)
Apply the exponential field operator for the bead model.
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
Propagator< D > PropagatorT
Propagator type.
FFT< D > FFTT
Fast Fourier Transform (FFT) type.
FFT< D > const & fft() const
Return associated FFT<D> object by const reference.
void computeStressThread(double prefactor)
Compute stress contribution for this block, using thread model.
void stepBead(RField< D > const &qin, RField< D > &qout)
Compute one step of solution of MDE for the bead model.
double averageProductBead(RField< D > const &q0, RField< D > const &q1)
Compute the spatial average of the product used to compute Q.
void stepThread(RField< D > const &qin, RField< D > &qout)
Compute step of integration loop, from i to i+1.
File input/output operations and format conversions for fields.
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 Reduce.cpp:14
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1