PSCF v1.5.0
Block_u.h
1#ifndef RP_BLOCK_U_H
2#define RP_BLOCK_U_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/solvers/BlockTmpl.h> // base class template
12#include <pscf/backend/cuda/CUT.h> // template argument
13#include <pscf/field/cuda/RField.h> // member
14#include <pscf/field/cuda/RFieldDft.h> // member
15#include <pscf/field/cuda/FFTBatched.h> // member
16#include <pscf/backend/cuda/BackendArray.h> // member
17#include <util/containers/FSArray.h> // member
18
19// Forward declarations
20namespace Pscf {
21 template <int D> class Mesh;
22 template <int D> class UnitCell;
23 template <int D, class T> class WaveList;
24 template <int D, class T> class FFT;
25 namespace Rp {
26 template <int D, class T> class Propagator;
27 template <int D, class T> class Block;
28 }
29}
30
31namespace Pscf {
32namespace Rp {
33
34 using namespace Util;
35
44 template <int D>
45 class Block<D,CUT>
46 : public BlockTmpl< Rp::Propagator<D,CUT>, RField<D,CUT> >
47 {
48
49 public:
50
51 // Public type name aliases
52
55
57 using typename BlockTmplT::PropagatorT;
58
60 using typename BlockTmplT::FieldT;
61
64
67
68 // Public member functions
69
73 Block();
74
78 ~Block();
79
82
95 void associate(Mesh<D> const & mesh,
96 FFT<D,CUT> const & fft,
97 UnitCell<D> const & cell,
98 WaveList<D,CUT>& waveList);
99
125 void allocate(double ds, bool useBatchedFFT = true);
126
134 void clearUnitCellData();
135
143 void setLength(double newLength);
144
153 void setNBead(int nBead);
154
160 void setKuhn(double kuhn);
161
172 void setupSolver(RField<D,CUT> const & w);
173
177
189 void stepThread(RField<D,CUT> const & qin, RField<D,CUT>& qout) const;
190
202 void stepBead(RField<D,CUT> const & qin, RField<D,CUT>& qout) const;
203
212 void stepFieldBead(RField<D,CUT> & q) const;
213
224 void stepBondBead(RField<D,CUT> const & qin, RField<D,CUT>& qout) const;
225
236 void stepHalfBondBead(RField<D,CUT> const & qin, RField<D,CUT>& 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,CUT> expKsq_;
344
347 RField<D,CUT> expW_;
348
350 RField<D,CUT> expKsq2_;
351
353 RField<D,CUT> expW2_;
354
356 RField<D,CUT> expWInv_;
357
365 mutable BackendArray<cudaReal,CUT> qrPair_;
366
374 mutable BackendArray<cudaComplex,CUT> qkPair_;
375
376 // R-grid work space (used in productAverage)
377 mutable RField<D,CUT> qr_;
378
379 // K-grid work space (used for FFT of q in stepBondBead)
380 mutable RFieldDft<D,CUT> qk_;
381
383 mutable BackendArray<cudaComplex,CUT> q0kBatched_;
384
386 mutable BackendArray<cudaComplex,CUT> q1kBatched_;
387
388 // Slices of forward and reverse propagator on a k-grid (for stress)
389 mutable RFieldDft<D,CUT> q0k_;
390 mutable RFieldDft<D,CUT> q1k_;
391
393 Mesh<D> const * meshPtr_;
394
396 FFT<D,CUT> const * fftPtr_;
397
399 UnitCell<D> const * unitCellPtr_;
400
402 WaveList<D,CUT> * waveListPtr_;
403
405 IntVec<D> kMeshDimensions_;
406
408 int kSize_;
409
411 // In bead model, ds=1 by definition.
412 double ds_;
413
415 double dsTarget_;
416
418 int ns_;
419
421 int nParams_;
422
424 bool isAllocated_;
425
427 bool hasExpKsq_;
428
430 bool useBatchedFFT_;
431
433 Mesh<D> const & mesh() const;
434
436 FFT<D,CUT> const & fft() const;
437
439 UnitCell<D> const & unitCell() const;
440
442 WaveList<D,CUT> & waveList();
443
445 void computeExpKsq();
446
447 };
448
449 // Inline member functions
450
451 // Get number of contour steps.
452 template <int D> inline
454 { return ns_; }
455
456 // Get contour length step size.
457 template <int D> inline
458 double Block<D,CUT>::ds() const
459 { return ds_; }
460
461 // Get derivative of free energy w/ respect to a unit cell parameter.
462 template <int D> inline
463 double Block<D,CUT>::stress(int n) const
464 { return stress_[n]; }
465
466 // Get Mesh by reference.
467 template <int D> inline
468 Mesh<D> const & Block<D,CUT>::mesh() const
469 {
470 UTIL_ASSERT(meshPtr_);
471 return *meshPtr_;
472 }
473
474 // Get FFT by reference.
475 template <int D> inline
476 FFT<D,CUT> const & Block<D,CUT>::fft() const
477 {
478 UTIL_ASSERT(fftPtr_);
479 return *fftPtr_;
480 }
481
482 // Get associated UnitCell<D> by const reference (private).
483 template <int D> inline
484 UnitCell<D> const & Block<D,CUT>::unitCell() const
485 { return *unitCellPtr_; }
486
487 // Get the WaveList by non-const reference (private).
488 template <int D> inline
489 WaveList<D,CUT> & Block<D,CUT>::waveList()
490 { return *waveListPtr_; }
491
492} // namespace Rp
493} // namespace Pscf
494
495// Explicit instantiation declarations
496namespace Pscf {
497
498 extern template
500 extern template
502 extern template
504
505 namespace Rp {
506 extern template class Block<1,CUT>;
507 extern template class Block<2,CUT>;
508 extern template class Block<3,CUT>;
509 }
510}
511#endif
Class template for a block solver in a block copolymer.
Definition BlockTmpl.h:107
Rp::Propagator< D, CUT > & propagator(int directionId)
Backend identifier class for the GPU-enabled CUDA backend.
Definition CUT.h:31
int nBead() const
Get the number of beads in this block, in the bead model.
Definition Edge.h:305
Batched Fourier transform wrapper for real data.
Definition FFTBatched.h:29
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
void setNBead(int nBead)
Set or reset the number of beads (only used in bead model).
Definition Block.cu:390
void stepBondBead(RField< D, CUT > const &qin, RField< D, CUT > &qout) const
Compute a bond operator for the bead model.
Definition Block.cu:566
Block()
Constructor.
Definition Block.cu:218
int ns() const
Number of contour length steps.
Definition Block_u.h:453
void computeConcentrationBead(double prefactor)
Compute the concentration for this block, using the bead model.
Definition Block.cu:651
void computeConcentrationThread(double prefactor)
Compute unnormalized concentration for block by integration.
Definition Block.cu:615
double stress(int n) const
Get derivative of free energy w/ respect to a unit cell parameter.
Definition Block_u.h:463
void associate(Mesh< D > const &mesh, FFT< D, CUT > const &fft, UnitCell< D > const &cell, WaveList< D, CUT > &waveList)
Create permanent associations with related objects.
Definition Block.cu:245
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
Definition Block.cu:416
WaveList< D, CUT > WaveListT
Wavelist type.
Definition Block_u.h:66
void stepBead(RField< D, CUT > const &qin, RField< D, CUT > &qout) const
Compute one step of solution of MDE for the bead model.
Definition Block.cu:542
void stepThread(RField< D, CUT > const &qin, RField< D, CUT > &qout) const
Compute step of integration loop, from i to i+1.
Definition Block.cu:494
void computeStressThread(double prefactor)
Compute stress contribution for this block, using thread model.
Definition Block.cu:681
void setLength(double newLength)
Set or reset block length (only used in thread model).
Definition Block.cu:345
double ds() const
Contour length step size.
Definition Block_u.h:458
void computeStressBead(double prefactor)
Compute stress contribution for this block, using bead model.
Definition Block.cu:800
BlockTmpl< Rp::Propagator< D, CUT >, RField< D, CUT > > BlockTmplT
Direct (parent) base class.
Definition Block_u.h:54
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
Definition Block.cu:426
void allocate(double ds, bool useBatchedFFT=true)
Allocate memory and set contour step size for thread model.
Definition Block.cu:268
FFT< D, CUT > FFTT
Fast Fourier Transform (FFT) type.
Definition Block_u.h:63
void setupSolver(RField< D, CUT > const &w)
Set solver for this block.
Definition Block.cu:467
void stepFieldBead(RField< D, CUT > &q) const
Apply the exponential field operator for the bead model.
Definition Block.cu:552
void stepHalfBondBead(RField< D, CUT > const &qin, RField< D, CUT > &qout) const
Compute a half-bond operator for the bead model.
Definition Block.cu:592
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:55
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.