PSCF v1.3
MixtureReal.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
49 template <int D, class PT, class ST>
50 class MixtureReal : public MixtureTmpl<PT, ST>
51 {
52
53 public:
54
55 // Public type name aliases
56
59
61 using typename MixtureTmplT::SolventT;
62
64 using typename MixtureTmplT::PolymerT;
65
67 using typename MixtureTmplT::BlockT;
68
70 using typename MixtureTmplT::PropagatorT;
71
73 using FieldT = typename PropagatorT::FieldT;
74
76 using FFTT = typename BlockT::FFTT;
77
79 using WaveListT = typename BlockT::WaveListT;
80
82 using FieldIoT = typename BlockT::FieldIoT;
83
84 // Public member functions
85
88
93
98
108 virtual void readParameters(std::istream& in);
109
130 void associate(Mesh<D> const & mesh,
131 FFTT const & fft,
132 UnitCell<D> const & cell,
133 WaveListT& waveList);
134
143 void setFieldIo(FieldIoT const & fieldIo);
144
151 void allocate();
152
156
190 void compute(DArray<FieldT> const & wFields,
191 DArray<FieldT>& cFields,
192 double phiTot = 1.0);
193
203 void setIsSymmetric(bool isSymmetric);
204
216 void computeStress(double phiTot = 1.0);
217
221 bool hasStress() const;
222
231 double stress(int parameterId) const;
232
236
247 void setKuhn(int monomerId, double kuhn);
248
257 void clearUnitCellData();
258
262
283 void createBlockCRGrid(DArray<FieldT>& blockCFields) const;
284
298 void writeBlockCRGrid(std::string const & filename) const;
299
303
313 void writeQSlice(std::string const & filename,
314 int polymerId, int blockId,
315 int directionId, int segmentId) const;
316
325 void writeQTail(std::string const & filename, int polymerId,
326 int blockId, int directionId) const;
327
336 void writeQ(std::string const & filename, int polymerId,
337 int blockId, int directionId) const;
338
357 void writeQAll(std::string const & basename);
358
362
368 void writeStress(std::ostream& out) const;
369
371
372 // Inherited public member functions
384
385 protected:
386
388 Mesh<D> const & mesh() const
389 { return *meshPtr_; }
390
392 UnitCell<D> const & unitCell() const
393 { return *unitCellPtr_; }
394
396 FieldIoT const & fieldIo() const
397 { return *fieldIoPtr_; }
398
400 double ds() const
401 { return ds_; }
402
403 // Inherited protected member functions
407
408 private:
409
410 // Private member data
411
413 FSArray<double, 6> stress_;
414
416 double ds_;
417
419 Mesh<D> const * meshPtr_;
420
421 // Pointer to associated UnitCell<D> object
422 UnitCell<D> const * unitCellPtr_;
423
424 // Pointer to associated FieldIoT object
425 FieldIoT const * fieldIoPtr_;
426
428 int nParam_;
429
431 bool hasStress_;
432
433 // Set true iff the w fields used in the MDE are symmetric
434 bool isSymmetric_;
435
436 // Private member functions
437
444 virtual void eqS(FieldT& A, double s) const = 0;
445
452 virtual void addEqV(FieldT& A, FieldT const & B) const = 0;
453
457 virtual void allocateBlocks() = 0;
458
459 };
460
461 // Public inline member functions
462
463 /*
464 * Get derivative of free energy w/ respect to a unit cell parameter.
465 */
466 template <int D, class PT, class ST>
467 inline double MixtureReal<D,PT,ST>::stress(int parameterId) const
468 {
469 UTIL_CHECK(hasStress_);
470 UTIL_CHECK(parameterId < nParam_);
471 return stress_[parameterId];
472 }
473
474 /*
475 * Has the stress been computed for the current w fields?
476 */
477 template <int D, class PT, class ST>
479 { return hasStress_; }
480
481} // namespace Prdc
482} // namespace Pscf
483#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
typename BlockT::FieldIoT FieldIoT
FieldIo type.
Definition MixtureReal.h:82
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 writeStress(std::ostream &out) const
Write stress values to output stream.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
MixtureTmpl< PT, ST > MixtureTmplT
MixtureTmplT class.
Definition MixtureReal.h:58
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
double ds() const
Return target value for the contour step size ds.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
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 compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
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.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
MixtureReal()
Constructor.
double stress(int parameterId) const
Get derivative of free energy w/ respect to a unit cell parameter.
typename BlockT::FFTT FFTT
WaveList type.
Definition MixtureReal.h:76
UnitCell< D > const & unitCell() const
Return associated UnitCell<D> by const reference.
typename BlockT::WaveListT WaveListT
WaveList type.
Definition MixtureReal.h:79
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the complete propagator for one block, in r-grid format.
typename PropagatorT::FieldT FieldT
Field type, for data defined on a real-space grid.
Definition MixtureReal.h:73
void allocate()
Allocate required internal memory for all solvers.
bool hasStress() const
Has the stress been computed since the last MDE solution?
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.