PSCF v1.3.1
MixturePrdc.h
1#ifndef PRDC_MIXTURE_REAL_H
2#define PRDC_MIXTURE_REAL_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/MixtureTmpl.h> // base class template
12#include <util/containers/FSArray.h> // member template (stress_)
13#include <iostream>
14
15// Forward declarations
16namespace Util {
17 template <typename T> class DArray;
18}
19namespace Pscf {
20 template <int D> class Mesh;
21 namespace Prdc {
22 template <int D> class UnitCell;
23 }
24}
25
26namespace Pscf {
27namespace Prdc {
28
29 using namespace Util;
30
57 template <int D, class PT, class ST>
58 class MixturePrdc : public MixtureTmpl<PT, ST>
59 {
60
61 public:
62
63 // Public type name aliases
64
67
69 using typename MixtureTmplT::SolventT;
70
72 using typename MixtureTmplT::PolymerT;
73
75 using typename MixtureTmplT::BlockT;
76
78 using typename MixtureTmplT::PropagatorT;
79
81 using FieldT = typename PropagatorT::FieldT;
82
84 using FFTT = typename BlockT::FFTT;
85
87 using WaveListT = typename BlockT::WaveListT;
88
90 using FieldIoT = typename BlockT::FieldIoT;
91
92 // Public member functions
93
96
100 MixturePrdc();
101
105 ~MixturePrdc();
106
116 virtual void readParameters(std::istream& in);
117
138 void associate(Mesh<D> const & mesh,
139 FFTT const & fft,
140 UnitCell<D> const & cell,
141 WaveListT& waveList);
142
151 void setFieldIo(FieldIoT const & fieldIo);
152
159 void allocate();
160
164
198 void compute(DArray<FieldT> const & wFields,
199 DArray<FieldT>& cFields,
200 double phiTot = 1.0);
201
211 void setIsSymmetric(bool isSymmetric);
212
224 void computeStress(double phiTot = 1.0);
225
229 bool hasStress() const;
230
239 double stress(int parameterId) const;
240
244
255 void setKuhn(int monomerId, double kuhn);
256
265 void clearUnitCellData();
266
270
291 void createBlockCRGrid(DArray<FieldT>& blockCFields) const;
292
306 void writeBlockCRGrid(std::string const & filename) const;
307
311
321 void writeQSlice(std::string const & filename,
322 int polymerId, int blockId,
323 int directionId, int segmentId) const;
324
333 void writeQTail(std::string const & filename, int polymerId,
334 int blockId, int directionId) const;
335
344 void writeQ(std::string const & filename, int polymerId,
345 int blockId, int directionId) const;
346
365 void writeQAll(std::string const & basename);
366
370
376 void writeStress(std::ostream& out) const;
377
379
380 // Inherited public member functions
392
393 protected:
394
396 Mesh<D> const & mesh() const
397 { return *meshPtr_; }
398
400 UnitCell<D> const & unitCell() const
401 { return *unitCellPtr_; }
402
404 FieldIoT const & fieldIo() const
405 { return *fieldIoPtr_; }
406
408 double ds() const
409 { return ds_; }
410
411 // Inherited protected member functions
415
416 private:
417
418 // Private member data
419
421 FSArray<double, 6> stress_;
422
424 double ds_;
425
427 Mesh<D> const * meshPtr_;
428
429 // Pointer to associated UnitCell<D> object
430 UnitCell<D> const * unitCellPtr_;
431
432 // Pointer to associated FieldIoT object
433 FieldIoT const * fieldIoPtr_;
434
436 int nParam_;
437
439 bool hasStress_;
440
441 // Set true iff the w fields used in the MDE are symmetric
442 bool isSymmetric_;
443
444 // Private member functions (pure virtual)
445
452 virtual void eqS(FieldT& A, double s) const = 0;
453
460 virtual void addEqV(FieldT& A, FieldT const & B) const = 0;
461
465 virtual void allocateBlocks() = 0;
466
467 };
468
469 // Public inline member functions
470
471 /*
472 * Has the stress been computed for the current w fields?
473 */
474 template <int D, class PT, class ST>
476 { return hasStress_; }
477
478 /*
479 * Get derivative of free energy w/ respect to a unit cell parameter.
480 */
481 template <int D, class PT, class ST>
482 inline double MixturePrdc<D,PT,ST>::stress(int parameterId) const
483 {
484 UTIL_CHECK(hasStress_);
485 UTIL_CHECK(parameterId < nParam_);
486 return stress_[parameterId];
487 }
488
489} // namespace Prdc
490} // namespace Pscf
491#endif
Description of a regular grid of points in a periodic domain.
Definition Mesh.h:61
int nPolymer() const
Get number of polymer species.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
int nMonomer() const
Get number of monomer types.
int nBlock() const
Get total number blocks among all polymer species.
int nSolvent() const
Get number of solvent (point particle) species.
double vMonomer() const
Get monomer reference volume (set to 1.0 by default).
bool isCanonical() const
Is this mixture being treated in canonical ensemble?
PolymerSpecies const & polymerSpecies(int id) const final
typename PT::BlockT BlockT
Block polymer block type.
Definition MixtureTmpl.h:45
PT PolymerT
Polymer species solver type.
Definition MixtureTmpl.h:40
MixtureTmpl()
Constructor.
SolventSpecies const & solventSpecies(int id) const final
typename BlockT::PropagatorT PropagatorT
Polymer block propagator type.
Definition MixtureTmpl.h:50
ST SolventT
Solvent species solver type.
Definition MixtureTmpl.h:35
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the complete propagator for one block, in r-grid format.
MixtureTmpl< PT, ST > MixtureTmplT
MixtureTmplT class.
Definition MixturePrdc.h:66
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
UnitCell< D > const & unitCell() const
Return associated UnitCell<D> by const reference.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
typename BlockT::FFTT FFTT
WaveList type.
Definition MixturePrdc.h:84
void associate(Mesh< D > const &mesh, FFTT const &fft, UnitCell< D > const &cell, WaveListT &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
bool hasStress() const
Has the stress been computed since the last MDE solution?
typename BlockT::WaveListT WaveListT
WaveList type.
Definition MixturePrdc.h:87
double ds() const
Return target value for the contour step size ds.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
typename BlockT::FieldIoT FieldIoT
FieldIo type.
Definition MixturePrdc.h:90
void writeQSlice(std::string const &filename, int polymerId, int blockId, int directionId, int segmentId) const
Write one slice of a propagator at fixed s in r-grid format.
MixturePrdc()
Constructor.
typename PropagatorT::FieldT FieldT
Field type, for data defined on a real-space grid.
Definition MixturePrdc.h:81
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
void allocate()
Allocate required internal memory for all solvers.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
void writeStress(std::ostream &out) const
Write stress values to output stream.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
double stress(int parameterId) const
Get derivative of free energy w/ respect to a unit cell parameter.
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
Dynamically allocatable contiguous array template.
Definition DArray.h:32
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.