PSCF v1.5.0
Block_c.h
1#ifndef RP_BLOCK_C_H
2#define RP_BLOCK_C_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/cpp/CPT.h> // template argument
13
14#include <pscf/field/cpp/RField.h> // member
15#include <pscf/field/cpp/RFieldDft.h> // member
16#include <pscf/math/IntVec.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
45 template <int D>
46 class Block<D,CPT>
47 : public BlockTmpl< Rp::Propagator<D,CPT>, RField<D,CPT> >
48 {
49
50 public:
51
52 // Public type name aliases
53
56
58 using typename BlockTmplT::PropagatorT;
59
61 using typename BlockTmplT::FieldT;
62
63 // Public member functions
64
68 Block();
69
73 ~Block();
74
77
90 void associate(Mesh<D> const& mesh,
91 FFT<D,CPT> const& fft,
92 UnitCell<D> const& cell,
93 WaveList<D,CPT>& waveList);
94
124 void allocate(double ds, bool useBatchedFFT = false);
125
134 void clearUnitCellData();
135
144 void setLength(double newLength);
145
154 void setNBead(int nBead);
155
161 void setKuhn(double kuhn);
162
172 void setupSolver(RField<D,CPT> const & w);
173
177
189 void stepThread(RField<D,CPT> const & qin, RField<D,CPT>& qout) const;
190
202 void stepBead(RField<D,CPT> const & qin, RField<D,CPT>& qout) const;
203
212 void stepFieldBead(RField<D,CPT> & q) const;
213
224 void stepBondBead(RField<D,CPT> const & qin, RField<D,CPT>& qout) const;
225
237 void stepHalfBondBead(RField<D,CPT> const & qin, RField<D,CPT>& qout) const;
238
242
267 void computeConcentrationThread(double prefactor);
268
292 void computeConcentrationBead(double prefactor);
293
297
307 void computeStressThread(double prefactor);
308
318 void computeStressBead(double prefactor);
319
328 double stress(int n) const;
329
333
337 double ds() const;
338
352 int ns() const;
353
354 // Inherited inherited functions with non-dependent names (selected)
356 using BlockTmplT::cField;
357
358 private:
359
360 // Private member data
361
363 FSArray<double, 6> stress_;
364
366 RField<D,CPT> expKsq_;
367
369 RField<D,CPT> expW_;
370
372 RField<D,CPT> expKsq2_;
373
375 RField<D,CPT> expW2_;
376
378 RField<D,CPT> expWInv_;
379
381 mutable RField<D,CPT> qr_;
382
384 mutable RField<D,CPT> qr2_;
385
387 mutable RFieldDft<D,CPT> qk_;
388
390 mutable RFieldDft<D,CPT> qk2_;
391
393 Mesh<D> const * meshPtr_;
394
396 FFT<D,CPT> const * fftPtr_;
397
399 UnitCell<D> const * unitCellPtr_;
400
402 WaveList<D,CPT> * 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
429 // Private member functions
430
432 Mesh<D> const & mesh() const;
433
435 FFT<D,CPT> const & fft() const;
436
438 UnitCell<D> const & unitCell() const;
439
441 WaveList<D,CPT> & waveList();
442
446 void computeExpKsq();
447
448 };
449
450 // Inline member functions
451
452 // Get number of contour grid points, including end points.
453 template <int D>
454 inline int Block<D,CPT>::ns() const
455 { return ns_; }
456
457 // Get contour step size.
458 template <int D>
459 inline double Block<D,CPT>::ds() const
460 { return ds_; }
461
462 // Stress with respect to unit cell parameter n.
463 template <int D>
464 inline double Block<D,CPT>::stress(int n) const
465 { return stress_[n]; }
466
467 // Private inline member function definitions
468
469 // Get associated Mesh<D> object by const reference (private).
470 template <int D>
471 inline Mesh<D> const & Block<D,CPT>::mesh() const
472 {
473 UTIL_CHECK(meshPtr_);
474 return *meshPtr_;
475 }
476
477 // Get associated FFT<D,CPT> object by const reference (private).
478 template <int D>
479 inline FFT<D,CPT> const & Block<D,CPT>::fft() const
480 {
481 UTIL_CHECK(fftPtr_);
482 return * fftPtr_;
483 }
484
485 // Get associated UnitCell<D> by const reference (private).
486 template <int D>
487 UnitCell<D> const & Block<D,CPT>::unitCell() const
488 {
489 UTIL_CHECK(unitCellPtr_);
490 return *unitCellPtr_;
491 }
492
493 // Get associated WaveList<D,CPT> by reference (private).
494 template <int D>
495 WaveList<D,CPT>& Block<D,CPT>::waveList()
496 {
497 UTIL_CHECK(waveListPtr_);
498 return *waveListPtr_;
499 }
500
501} // namespace Rp
502} // namespace Pscf
503
504// Explicit instantiation declarations
505namespace Pscf {
506
507 extern template
509 extern template
511 extern template
513
514 namespace Rp {
515 extern template class Block<1,CPT>;
516 extern template class Block<2,CPT>;
517 extern template class Block<3,CPT>;
518 }
519
520}
521#endif
Class template for a block solver in a block copolymer.
Definition BlockTmpl.h:107
Rp::Propagator< D, CPT > & propagator(int directionId)
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
int nBead() const
Get the number of beads in this block, in the bead model.
Definition Edge.h:305
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
BlockTmpl< Rp::Propagator< D, CPT >, RField< D, CPT > > BlockTmplT
Direct (parent) base class.
Definition Block_c.h:55
double ds() const
Get contour length step size.
Definition Block_c.h:459
void allocate(double ds, bool useBatchedFFT=false)
Allocate memory and set contour step size.
int ns() const
Get the number of contour grid points, including end points.
Definition Block_c.h:454
void stepBondBead(RField< D, CPT > const &qin, RField< D, CPT > &qout) const
Apply a bond operator for the bead model.
double stress(int n) const
Get derivative of free energy w/ respect to a unit cell parameter.
Definition Block_c.h:464
void computeStressBead(double prefactor)
Compute stress contribution for this block, using bead model.
void computeConcentrationBead(double prefactor)
Compute the concentration for this block, using the bead model.
void setNBead(int nBead)
Set or reset the number of beads (only used in bead model).
void computeStressThread(double prefactor)
Compute stress contribution for this block, using thread model.
void clearUnitCellData()
Clear all internal data that depends on the unit cell parameters.
void stepBead(RField< D, CPT > const &qin, RField< D, CPT > &qout) const
Compute one step of solution of MDE for the bead model.
void stepThread(RField< D, CPT > const &qin, RField< D, CPT > &qout) const
Compute one step of solution of MDE for the thread model.
void setLength(double newLength)
Set or reset block length (only used in thread model).
void associate(Mesh< D > const &mesh, FFT< D, CPT > const &fft, UnitCell< D > const &cell, WaveList< D, CPT > &waveList)
Create permanent associations with related objects.
void setupSolver(RField< D, CPT > const &w)
Set up the MDE solver for this block.
void stepHalfBondBead(RField< D, CPT > const &qin, RField< D, CPT > &qout) const
Apply a half-bond operator for the bead model.
void computeConcentrationThread(double prefactor)
Compute the concentration for this block, for the thread model.
void stepFieldBead(RField< D, CPT > &q) const
Apply the exponential field operator for the bead model.
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
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_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.