PSCF v1.3.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
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
21namespace Pscf {
22
23 // Forward declarations
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 Propagator;
34 }
35
36 // Explicit instantiation declarations for base classes
37 extern template
39 extern template
41 extern template
43
44}
45
46namespace Pscf {
47namespace Rpg {
48
49 using namespace Util;
50 using namespace Pscf::Prdc;
51 using namespace Pscf::Prdc::Cuda;
52
61 template <int D>
62 class Block : public BlockTmpl< Propagator<D>, RField<D> >
63 {
64
65 public:
66
67 // Public type name aliases
68
71
73 using typename Base::PropagatorT;
74
76 using typename Base::FieldT;
77
79 using FFTT = FFT<D>;
80
83
84 // Public member functions
85
89 Block();
90
94 ~Block();
95
108 void associate(Mesh<D> const & mesh,
109 FFT<D> const & fft,
110 UnitCell<D> const & cell,
111 WaveList<D>& wavelist);
112
138 void allocate(double ds, bool useBatchedFFT = true);
139
147 void clearUnitCellData();
148
156 void setLength(double newLength);
157
163 void setKuhn(double kuhn);
164
175 void setupSolver(RField<D> const & w);
176
188 void stepThread(RField<D> const & qin, RField<D>& qout);
189
201 void stepBead(RField<D> const & qin, RField<D>& qout);
202
211 void stepFieldBead(RField<D> & q);
212
223 void stepBondBead(RField<D> const & qin, RField<D>& qout);
224
235 void stepHalfBondBead(RField<D> const & qin, RField<D>& qout);
236
253 void computeConcentrationThread(double prefactor);
254
272 void computeConcentrationBead(double prefactor);
273
281 double averageProduct(RField<D> const& q0, RField<D> const& q1);
282
292 double averageProductBead(RField<D> const& q0, RField<D> const& q1);
293
302 void computeStressThread(double prefactor);
303
312 void computeStressBead(double prefactor);
313
319 double stress(int n);
320
324 Mesh<D> const & mesh() const;
325
329 FFT<D> const & fft() const;
330
334 double ds() const;
335
339 int ns() const;
340
341 // Functions with non-dependent names from direct base.
342 using Base::setKuhn;
343 using Base::propagator;
344 using Base::cField;
345 using Base::kuhn;
346
347 // Functions with non-dependent names from Edge
348 using Edge::setId;
349 using Edge::setVertexIds;
350 using Edge::setMonomerId;
351 using Edge::setLength;
352 using Edge::id;
353 using Edge::monomerId;
354 using Edge::vertexIds;
355 using Edge::vertexId;
356 using Edge::length;
357 using Edge::nBead;
358
359 private:
360
362 FFTBatched<D> fftBatchedAll_;
363
365 FFTBatched<D> fftBatchedPair_;
366
368 FSArray<double, 6> stress_;
369
372 RField<D> expKsq_;
373
376 RField<D> expW_;
377
379 RField<D> expKsq2_;
380
382 RField<D> expW2_;
383
385 RField<D> expWInv_;
386
394 DeviceArray<cudaReal> qrPair_;
395
404
405 // R-grid work space (used in productAverage)
406 RField<D> qr_;
407
408 // K-grid work space (used for FFT of q in stepBondBead)
409 RFieldDft<D> qk_;
410
412 DeviceArray<cudaComplex> q0kBatched_;
413
415 DeviceArray<cudaComplex> q1kBatched_;
416
417 // Slices of forward and reverse propagator on a k-grid (for stress)
418 RFieldDft<D> q0k_;
419 RFieldDft<D> q1k_;
420
422 Mesh<D> const * meshPtr_;
423
425 FFT<D> const * fftPtr_;
426
428 UnitCell<D> const * unitCellPtr_;
429
431 WaveList<D> * waveListPtr_;
432
434 IntVec<D> kMeshDimensions_;
435
437 int kSize_;
438
440 double ds_;
441
443 double dsTarget_;
444
446 int ns_;
447
449 bool isAllocated_;
450
452 bool hasExpKsq_;
453
455 bool useBatchedFFT_;
456
458 UnitCell<D> const & unitCell() const
459 { return *unitCellPtr_; }
460
462 WaveList<D> const & wavelist() const
463 { return *waveListPtr_; }
464
466 int nParams_;
467
469 void computeExpKsq();
470
471 };
472
473 // Inline member functions
474
475 // Get number of contour steps.
476 template <int D>
477 inline int Block<D>::ns() const
478 { return ns_; }
479
480 // Get contour length step size.
481 template <int D>
482 inline double Block<D>::ds() const
483 { return ds_; }
484
485 // Get derivative of free energy w/ respect to a unit cell parameter.
486 template <int D>
487 inline double Block<D>::stress(int n)
488 { return stress_[n]; }
489
490 // Get Mesh by reference.
491 template <int D>
492 inline Mesh<D> const & Block<D>::mesh() const
493 {
494 UTIL_ASSERT(meshPtr_);
495 return *meshPtr_;
496 }
497
498 // Get FFT by reference.
499 template <int D>
500 inline FFT<D> const & Block<D>::fft() const
501 {
502 UTIL_ASSERT(fftPtr_);
503 return *fftPtr_;
504 }
505
506 // Explicit instantiation declarations
507 extern template class Block<1>;
508 extern template class Block<2>;
509 extern template class Block<3>;
510
511}
512}
513#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: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.
double kuhn() const
Get monomer statistical segment length.
BlockTmpl< Propagator< D >, RField< 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.
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.
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.
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 CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.