PSCF v1.3.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
13#include <prdc/cpu/RField.h> // member
14#include <prdc/cpu/RFieldDft.h> // member
15#include <util/containers/FSArray.h> // member
16
17namespace Pscf {
18
19 // Forward declarations
20 template <int D> class Mesh;
21 namespace Prdc{
22 template <int D> class UnitCell;
23 namespace Cpu {
24 template <int D> class FFT;
25 template <int D> class WaveList;
26 }
27 }
28 namespace Rpc{
29 template <int D> class Propagator;
30 }
31
32 // Explicit instantiation declarations for base classes
33 extern template
35 extern template
37 extern template
39
40}
41
42namespace Pscf {
43namespace Rpc {
44
45 using namespace Util;
46 using namespace Pscf::Prdc;
47 using namespace Pscf::Prdc::Cpu;
48
58 template <int D>
59 class Block : public BlockTmpl< Propagator<D>, RField<D> >
60 {
61
62 public:
63
64 // Public type name aliases
65
68
70 using typename Base::PropagatorT;
71
73 using typename Base::FieldT;
74
75 // Public member functions
76
80 Block();
81
85 ~Block();
86
99 void associate(Mesh<D> const& mesh,
100 FFT<D> const& fft,
101 UnitCell<D> const& cell,
102 WaveList<D>& wavelist);
103
129 void allocate(double ds);
130
139 void clearUnitCellData();
140
149 void setLength(double newLength);
150
156 void setKuhn(double kuhn);
157
167 void setupSolver(RField<D> const & w);
168
180 void stepThread(RField<D> const & qin, RField<D>& qout) const;
181
193 void stepBead(RField<D> const & qin, RField<D>& qout) const;
194
203 void stepFieldBead(RField<D> & q) const;
204
215 void stepBondBead(RField<D> const & qin, RField<D>& qout) const;
216
228 void stepHalfBondBead(RField<D> const & qin, RField<D>& qout) const;
229
254 void computeConcentrationThread(double prefactor);
255
279 void computeConcentrationBead(double prefactor);
280
290 void computeStressThread(double prefactor);
291
301 void computeStressBead(double prefactor);
302
311 double stress(int n) const;
312
316 double ds() const;
317
331 int ns() const;
332
333 // Inherited public member functions with non-dependent names
334
335 using Base::setKuhn;
336 using Base::propagator;
337 using Base::cField;
338 using Base::kuhn;
339
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
353 // Private member data
354
355 // In bead model, ds=1 by definition.
356
358 FSArray<double, 6> stress_;
359
361 RField<D> expKsq_;
362
364 RField<D> expW_;
365
367 RField<D> expKsq2_;
368
370 RField<D> expW2_;
371
373 RField<D> expWInv_;
374
376 mutable RField<D> qr_;
377
379 mutable RField<D> qr2_;
380
382 mutable RFieldDft<D> qk_;
383
385 mutable RFieldDft<D> qk2_;
386
388 Mesh<D> const * meshPtr_;
389
391 FFT<D> const * fftPtr_;
392
394 UnitCell<D> const * unitCellPtr_;
395
397 WaveList<D> * waveListPtr_;
398
400 IntVec<D> kMeshDimensions_;
401
403 int kSize_;
404
406 double ds_;
407
409 double dsTarget_;
410
412 int ns_;
413
415 bool isAllocated_;
416
418 bool hasExpKsq_;
419
421 UnitCell<D> const & unitCell() const
422 { return *unitCellPtr_; }
423
425 WaveList<D> const & wavelist() const
426 { return *waveListPtr_; }
427
429 int nParams_;
430
431 // Private member functions
432
436 Mesh<D> const & mesh() const;
437
441 FFT<D> const & fft() const;
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>::ns() const
455 { return ns_; }
456
457 // Get contour step size.
458 template <int D>
459 inline double Block<D>::ds() const
460 { return ds_; }
461
462 // Stress with respect to unit cell parameter n.
463 template <int D>
464 inline double Block<D>::stress(int n) const
465 { return stress_[n]; }
466
467 // Get associated Mesh<D> object by const reference.
468 template <int D>
469 inline Mesh<D> const & Block<D>::mesh() const
470 {
471 UTIL_CHECK(meshPtr_);
472 return *meshPtr_;
473 }
474
475 // Get associated FFT<D> object by const reference.
476 template <int D>
477 inline FFT<D> const & Block<D>::fft() const
478 {
479 UTIL_CHECK(fftPtr_);
480 return * fftPtr_;
481 }
482
483 // Explicit instantiation declarations
484 extern template class Block<1>;
485 extern template class Block<2>;
486 extern template class Block<3>;
487
488} // R1d
489} // Pscf
490#endif
Class template for a block solver in a block copolymer.
Definition BlockTmpl.h:107
Propagator< D > & propagator(int directionId)
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
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.
BlockTmpl< Propagator< D >, RField< D > > Base
Base class.
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.
double kuhn() const
Get monomer statistical segment length.
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.
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.
void stepBead(RField< D > const &qin, RField< D > &qout) const
Compute one step of solution of MDE for the bead model.
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.