PSCF v1.3
rpc/solvers/Block.h
1#ifndef RPC_BLOCK_H
2#define RPC_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 <rpc/solvers/Propagator.h> // base class template argument
13
14#include <prdc/cpu/RField.h> // member
15#include <prdc/cpu/RFieldDft.h> // member
16#include <util/containers/DMatrix.h> // member template
17#include <util/containers/FSArray.h> // member template
18
19// Forward declarations
20namespace Pscf {
21 template <int D> class Mesh;
22 namespace Prdc{
23 template <int D> class UnitCell;
24 namespace Cpu {
25 template <int D> class FFT;
26 template <int D> class WaveList;
27 }
28 }
29 namespace Rpc{
30 template <int D> class FieldIo;
31 }
32}
33
34namespace Pscf {
35namespace Rpc {
36
37 using namespace Util;
38 using namespace Pscf::Prdc;
39 using namespace Pscf::Prdc::Cpu;
40
50 template <int D>
51 class Block : public BlockTmpl< Propagator<D> >
52 {
53
54 public:
55
56 // Public type name aliases
57
60
63
65 using FFTT = FFT<D>;
66
69
72
73 // Public member functions
74
78 Block();
79
83 ~Block();
84
97 void associate(Mesh<D> const& mesh,
98 FFT<D> const& fft,
99 UnitCell<D> const& cell,
100 WaveList<D>& wavelist);
101
127 void allocate(double ds);
128
137 void clearUnitCellData();
138
147 void setLength(double newLength);
148
154 void setKuhn(double kuhn);
155
165 void setupSolver(RField<D> const & w);
166
178 void stepThread(RField<D> const & qin, RField<D>& qout) const;
179
191 void stepBead(RField<D> const & qin, RField<D>& qout) const;
192
201 void stepFieldBead(RField<D> & q) const;
202
213 void stepBondBead(RField<D> const & qin, RField<D>& qout) const;
214
226 void stepHalfBondBead(RField<D> const & qin, RField<D>& qout) const;
227
252 void computeConcentrationThread(double prefactor);
253
277 void computeConcentrationBead(double prefactor);
278
288 void computeStressThread(double prefactor);
289
299 void computeStressBead(double prefactor);
300
309 double stress(int n) const;
310
314 double ds() const;
315
329 int ns() const;
330
331 // Inherited public member functions with non-dependent names
332
333 using Base::setKuhn;
334 using Base::propagator;
335 using Base::cField;
336 using Base::kuhn;
337
338 using Edge::setId;
339 using Edge::setVertexIds;
340 using Edge::setMonomerId;
341 using Edge::setLength;
342 using Edge::id;
343 using Edge::monomerId;
344 using Edge::vertexIds;
345 using Edge::vertexId;
346 using Edge::length;
347 using Edge::nBead;
348
349 private:
350
351 // Private member data
352
353 // In bead model, ds=1 by definition.
354
356 FSArray<double, 6> stress_;
357
359 RField<D> expKsq_;
360
362 RField<D> expW_;
363
365 RField<D> expKsq2_;
366
368 RField<D> expW2_;
369
371 RField<D> expWInv_;
372
374 mutable RField<D> qr_;
375
377 mutable RField<D> qr2_;
378
380 mutable RFieldDft<D> qk_;
381
383 mutable RFieldDft<D> qk2_;
384
386 Mesh<D> const * meshPtr_;
387
389 FFT<D> const * fftPtr_;
390
392 UnitCell<D> const * unitCellPtr_;
393
395 WaveList<D> * waveListPtr_;
396
398 IntVec<D> kMeshDimensions_;
399
401 int kSize_;
402
404 double ds_;
405
407 double dsTarget_;
408
410 int ns_;
411
413 bool isAllocated_;
414
416 bool hasExpKsq_;
417
419 UnitCell<D> const & unitCell() const
420 { return *unitCellPtr_; }
421
423 WaveList<D> const & wavelist() const
424 { return *waveListPtr_; }
425
427 int nParams_;
428
429 // Private member functions
430
434 Mesh<D> const & mesh() const;
435
439 FFT<D> const & fft() const;
440
444 void computeExpKsq();
445
446 };
447
448 // Inline member functions
449
450 // Get number of contour grid points, including end points.
451 template <int D>
452 inline int Block<D>::ns() const
453 { return ns_; }
454
455 // Get contour step size.
456 template <int D>
457 inline double Block<D>::ds() const
458 { return ds_; }
459
460 // Stress with respect to unit cell parameter n.
461 template <int D>
462 inline double Block<D>::stress(int n) const
463 { return stress_[n]; }
464
465 // Get associated Mesh<D> object by const reference.
466 template <int D>
467 inline Mesh<D> const & Block<D>::mesh() const
468 {
469 UTIL_CHECK(meshPtr_);
470 return *meshPtr_;
471 }
472
473 // Get associated FFT<D> object by const reference.
474 template <int D>
475 inline FFT<D> const & Block<D>::fft() const
476 {
477 UTIL_CHECK(fftPtr_);
478 return * fftPtr_;
479 }
480
481 #ifndef RPC_BLOCK_TPP
482 // Suppresse implicit instantiation
483 extern template class Block<1>;
484 extern template class Block<2>;
485 extern template class Block<3>;
486 #endif
487
488}
489}
490#endif
Propagator< D > & propagator(int directionId)
virtual void setKuhn(double kuhn)
Propagator< D >::FieldT & cField()
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.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
BlockTmpl< Propagator< D > > Base
Base class.
void stepBondBead(RField< D > const &qin, RField< D > &qout) const
Apply a bond operator for the bead model.
void setLength(double newLength)
Set or reset block length (only used in thread model).
void computeConcentrationBead(double prefactor)
Compute the concentration for this block, using the bead model.
double stress(int n) const
Get derivative of free energy w/ respect to a unit cell parameter.
void setKuhn(double kuhn)
Set or reset monomer statistical segment length.
void clearUnitCellData()
Clear all internal data that depends on the unit cell parameters.
void setupSolver(RField< D > const &w)
Set up the MDE solver for this block.
void allocate(double ds)
Allocate memory and set contour step size.
void computeStressBead(double prefactor)
Compute stress contribution for this block, using bead model.
void associate(Mesh< D > const &mesh, FFT< D > const &fft, UnitCell< D > const &cell, WaveList< D > &wavelist)
Create permanent associations with related objects.
double kuhn() const
Get monomer statistical segment length.
FFT< D > FFTT
Fast Fourier Transform type.
Propagator< D > PropagatorT
Propagator type.
void computeConcentrationThread(double prefactor)
Compute the concentration for this block, for the thread model.
void stepThread(RField< D > const &qin, RField< D > &qout) const
Compute one step of solution of MDE for the thread model.
void computeStressThread(double prefactor)
Compute stress contribution for this block, using thread model.
double ds() const
Get contour length step size.
int ns() const
Get the number of contour grid points, including end points.
void stepFieldBead(RField< D > &q) const
Apply the exponential field operator for the bead model.
void stepHalfBondBead(RField< D > const &qin, RField< D > &qout) const
Apply a half-bond operator for the bead model.
WaveList< D > WaveListT
WaveList type.
void stepBead(RField< D > const &qin, RField< D > &qout) const
Compute one step of solution of MDE for the bead model.
FieldIo< D > FieldIoT
FieldIo type.
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_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1