PSCF v1.4.0
rp/solvers/Mixture.h
1#ifndef RP_MIXTURE_H
2#define RP_MIXTURE_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 Rp {
28
29 using namespace Util;
30 using namespace Prdc;
31
58 template <int D, class T>
59 class Mixture : public
60 MixtureTmpl<typename T::Polymer, typename T::Solvent, double>
61 {
62
63 public:
64
65 // Public type name aliases
66
68 using PolymerT = typename T::Polymer;
69
71 using SolventT = typename T::Solvent;
72
74 using BlockT = typename T::Block;
75
77 using PropagatorT = typename T::Propagator;
78
80 using FieldT = typename T::RField;
81
83 using FFTT = typename T::FFT;
84
86 using WaveListT = typename T::WaveList;
87
89 using FieldIoT = typename T::FieldIo;
90
93
96
97 // Public member functions
98
101
111 virtual void readParameters(std::istream& in);
112
133 void associate(Mesh<D> const & mesh,
134 FFTT const & fft,
135 UnitCell<D> const & cell,
136 WaveListT& waveList);
137
146 void setFieldIo(FieldIoT const & fieldIo);
147
154 void allocate();
155
159
193 void compute(DArray<FieldT> const & wFields,
194 DArray<FieldT>& cFields,
195 double phiTot = 1.0);
196
206 void setIsSymmetric(bool isSymmetric);
207
219 void computeStress(double phiTot = 1.0);
220
224 bool hasStress() const;
225
234 double stress(int parameterId) const;
235
239
250 void setKuhn(int monomerId, double kuhn);
251
260 void clearUnitCellData();
261
265
286 void createBlockCRGrid(DArray<FieldT>& blockCFields) const;
287
301 void writeBlockCRGrid(std::string const & filename) const;
302
306
316 void writeQSlice(std::string const & filename,
317 int polymerId, int blockId,
318 int directionId, int segmentId) const;
319
328 void writeQTail(std::string const & filename, int polymerId,
329 int blockId, int directionId) const;
330
339 void writeQ(std::string const & filename, int polymerId,
340 int blockId, int directionId) const;
341
360 void writeQAll(std::string const & basename);
361
365
371 void writeStress(std::ostream& out) const;
372
374
375 // Inherited non-dependent public member functions
380 using MixtureBaseT::nMonomer;
381 using MixtureBaseT::monomer;
382 using MixtureBaseT::nPolymer;
383 using MixtureBaseT::nSolvent;
384 using MixtureBaseT::nBlock;
385 using MixtureBaseT::vMonomer;
386 using MixtureBaseT::isCanonical;
387
388 protected:
389
393 Mixture();
394
398 ~Mixture();
399
401 Mesh<D> const & mesh() const
402 { return *meshPtr_; }
403
405 UnitCell<D> const & unitCell() const
406 { return *unitCellPtr_; }
407
409 FieldIoT const & fieldIo() const
410 { return *fieldIoPtr_; }
411
413 double ds() const
414 { return ds_; }
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
449 virtual void allocateBlocks() = 0;
450
451 };
452
453 // Public inline member functions
454
455 /*
456 * Has the stress been computed for the current w fields?
457 */
458 template <int D, class T>
459 inline bool Mixture<D,T>::hasStress() const
460 { return hasStress_; }
461
462 /*
463 * Get derivative of free energy w/ respect to a unit cell parameter.
464 */
465 template <int D, class T>
466 inline double Mixture<D,T>::stress(int parameterId) const
467 {
468 UTIL_CHECK(hasStress_);
469 UTIL_CHECK(parameterId < nParam_);
470 return stress_[parameterId];
471 }
472
473} // namespace Rp
474} // namespace Pscf
475#endif
Description of a regular grid of points in a periodic domain.
Definition Mesh.h:61
SolventSpecies< double > const & solventSpecies(int id) const final
PolymerSpecies< double > const & polymerSpecies(int id) const final
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
typename T::RField FieldT
Field type, for data defined on a real-space grid.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the complete propagator for one block, in r-grid format.
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.
double stress(int parameterId) const
Get derivative of free energy w/ respect to a unit cell parameter.
void writeStress(std::ostream &out) const
Write stress values to output stream.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
MixtureTmpl< PolymerT, SolventT, double > MixtureTmplT
MixtureTmpl direct (parent) base class.
void allocate()
Allocate required internal memory for all solvers.
typename T::Polymer PolymerT
Polymer object type.
typename T::Propagator PropagatorT
Propagator type, for one direction within a block.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
typename T::Solvent SolventT
Solvent object type.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
typename T::WaveList WaveListT
WaveList type.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
void associate(Mesh< D > const &mesh, FFTT const &fft, UnitCell< D > const &cell, WaveListT &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
typename T::Block BlockT
Block type, for a block in a block polymer.
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
typename MixtureTmplT::MixtureBaseT MixtureBaseT
MixtureBase indirect (grandparent) base class.
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
double ds() const
Return target value for the contour step size ds.
typename T::FFT FFTT
WaveList type.
bool hasStress() const
Has the stress been computed since the last MDE solution?
UnitCell< D > const & unitCell() const
Return associated UnitCell<D> by const reference.
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
typename T::FieldIo FieldIoT
FieldIo type.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
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
Periodic fields and crystallography.
Definition complex.cpp:11
Class templates for real-valued periodic fields.
PSCF package top-level namespace.
Utility classes for scientific computation.