PSCF v1.5.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 - 2026, David Morse (morse012@um.edu) and co-authors
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
13
14#include <pscf/backend/TmplDeclare.h>
15#include <iostream>
16
17// Forward declarations
18namespace Util {
19 template <typename T> class DArray;
20}
21namespace Pscf {
22 template <int D> class Mesh;
23 template <int D> class UnitCell;
24 template <int D, class T> class WaveList;
25 template <int D, class T> class FFT;
26 template <int D, class T> class RField;
27 namespace Rp {
28 template <int D, class T> class Polymer;
29 template <int D, class T> class Solvent;
30 template <int D, class T> class Block;
31 template <int D, class T> class Propagator;
32 template <int D, class T> class FieldIo;
33 }
34}
35
36namespace Pscf {
37namespace Rp {
38
39 using namespace Util;
40
66 template <int D, class T>
67 class Mixture
68 : public MixtureTmpl<Polymer<D,T>, Solvent<D,T>, double>
69 {
70
71 public:
72
73 // Public type name aliases
74
77
80
83
86
89
92
95
96 // Public member functions
97
100
104 Mixture();
105
109 ~Mixture();
110
120 virtual void readParameters(std::istream& in);
121
142 void associate(Mesh<D> const & mesh,
143 FFT<D,T> const & fft,
144 UnitCell<D> const & cell,
145 WaveList<D,T>& waveList);
146
155 void setFieldIo(FieldIo<D,T> const & fieldIo);
156
163 void allocate();
164
168
202 void compute(DArray<FieldT> const & wFields,
203 DArray<FieldT>& cFields,
204 double phiTot = 1.0);
205
215 void setIsSymmetric(bool isSymmetric);
216
228 void computeStress(double phiTot = 1.0);
229
233 bool hasStress() const;
234
243 double stress(int parameterId) const;
244
248
259 void setKuhn(int monomerId, double kuhn);
260
269 void clearUnitCellData();
270
274
295 void createBlockCRGrid(DArray<FieldT>& blockCFields) const;
296
310 void writeBlockCRGrid(std::string const & filename) const;
311
315
325 void writeQSlice(std::string const & filename,
326 int polymerId, int blockId,
327 int directionId, int segmentId) const;
328
337 void writeQTail(std::string const & filename, int polymerId,
338 int blockId, int directionId) const;
339
348 void writeQ(std::string const & filename, int polymerId,
349 int blockId, int directionId) const;
350
369 void writeQAll(std::string const & basename);
370
374
380 void writeStress(std::ostream& out) const;
381
383
384 // Inherited non-dependent public member functions
389 using CompositionT::nMonomer;
390 using CompositionT::monomer;
391 using CompositionT::nPolymer;
392 using CompositionT::nSolvent;
393 using CompositionT::nBlock;
394 using CompositionT::vMonomer;
395 using CompositionT::isCanonical;
396
397 protected:
398
400 Mesh<D> const & mesh() const
401 { return *meshPtr_; }
402
404 UnitCell<D> const & unitCell() const
405 { return *unitCellPtr_; }
406
408 FieldIo<D,T> const & fieldIo() const
409 { return *fieldIoPtr_; }
410
412 double ds() const
413 { return ds_; }
414
415 private:
416
417 // Private member data
418
420 FSArray<double, 6> stress_;
421
423 double ds_;
424
426 Mesh<D> const * meshPtr_;
427
428 // Pointer to associated UnitCell<D> object
429 UnitCell<D> const * unitCellPtr_;
430
431 // Pointer to associated FieldIo object
432 FieldIo<D,T> const * fieldIoPtr_;
433
435 int nParam_;
436
438 bool hasStress_;
439
440 // Set true iff the w fields used in the MDE are symmetric
441 bool isSymmetric_;
442
444 bool useBatchedFFT_;
445
446 // Private member function
447
451 void allocateBlocks();
452
453 };
454
455 // Public inline member functions
456
457 /*
458 * Has the stress been computed for the current w fields?
459 */
460 template <int D, class T>
461 inline bool Mixture<D,T>::hasStress() const
462 { return hasStress_; }
463
464 /*
465 * Get derivative of free energy w/ respect to a unit cell parameter.
466 */
467 template <int D, class T>
468 inline double Mixture<D,T>::stress(int parameterId) const
469 {
470 UTIL_CHECK(hasStress_);
471 UTIL_CHECK(parameterId < nParam_);
472 return stress_[parameterId];
473 }
474
475 // Explicit instantiation declarations
476 PSCF_TMPL_DECLARE(Mixture)
477
478} // namespace Rp
479} // namespace Pscf
480
481// Explicit instantiation declarations for base class specializations
482namespace Pscf {
483 #ifdef PSCF_CPP
484 class CPT;
485 extern template
486 class MixtureTmpl< Rp::Polymer<1,CPT>, Rp::Solvent<1,CPT> >;
487 extern template
488 class MixtureTmpl< Rp::Polymer<2,CPT>, Rp::Solvent<2,CPT> >;
489 extern template
490 class MixtureTmpl< Rp::Polymer<3,CPT>, Rp::Solvent<3,CPT> >;
491 #endif
492 #ifdef PSCF_CUDA
493 class CUT;
494 extern template
495 class MixtureTmpl< Rp::Polymer<1,CUT>, Rp::Solvent<1,CUT> >;
496 extern template
497 class MixtureTmpl< Rp::Polymer<2,CUT>, Rp::Solvent<2,CUT> >;
498 extern template
499 class MixtureTmpl< Rp::Polymer<3,CUT>, Rp::Solvent<3,CUT> >;
500 #endif
501}
502
503#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
File input/output, format conversions and other utilities for fields.
Solver and descriptor for a mixture of polymers and solvents.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
void writeQSlice(std::string const &filename, int polymerId, int blockId, int directionId, int segmentId) const
Polymer< D, T > PolymerT
Polymer object type.
double stress(int parameterId) const
Get derivative of free energy w/ respect to a unit cell parameter.
void writeStress(std::ostream &out) const
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
Solvent< D, T > SolventT
Solvent object type.
typename MixtureTmplT::CompositionT CompositionT
Composition indirect (grandparent) base class.
MixtureTmpl< PolymerT, SolventT, double > MixtureTmplT
MixtureTmpl direct (parent) base class.
void allocate()
Allocate required internal memory for all solvers.
void associate(Mesh< D > const &mesh, FFT< D, T > const &fft, UnitCell< D > const &cell, WaveList< D, T > &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
Block< D, T > BlockT
Block type, for a block in a block polymer.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
FieldIo< D, T > const & fieldIo() const
Return associated FieldIo by const reference.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
void writeBlockCRGrid(std::string const &filename) const
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Propagator< D, T > PropagatorT
Propagator type, for one direction within a block.
void setFieldIo(FieldIo< D, T > const &fieldIo)
Create an association with a FieldIo object.
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.
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)
void writeQAll(std::string const &basename)
RField< D, T > FieldT
Field type, for data defined on a real-space grid.
Mixture()
Default constructor.
Descriptor and MDE solver for one polymer species.
Solver and descriptor for a solvent species.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:55
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.