PSCF v1.1
pspc/System.h
1#ifndef PSPC_SYSTEM_H
2#define PSPC_SYSTEM_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11
12#include <util/param/ParamComposite.h> // base class
13
14#include <pspc/solvers/Mixture.h> // member
15#include <pspc/field/Domain.h> // member
16#include <pspc/field/FieldIo.h> // member
17#include <pspc/field/WFieldContainer.h> // member
18#include <pspc/field/CFieldContainer.h> // member
19#include <pspc/field/Mask.h> // member
20#include <pspc/field/RField.h> // member
21#include <pspc/field/RFieldDft.h> // member
22
23#include <pscf/homogeneous/Mixture.h> // member
24
25#include <util/misc/FileMaster.h> // member
26#include <util/containers/DArray.h> // member template
27#include <util/containers/FSArray.h> // member template
28
29namespace Pscf {
30
31 class Interaction;
32
33namespace Pspc
34{
35
36 template <int D> class Iterator;
37 template <int D> class IteratorFactory;
38 template <int D> class Sweep;
39 template <int D> class SweepFactory;
40
41 using namespace Util;
42
74 template <int D>
75 class System : public ParamComposite
76 {
77
78 public:
79
82
86 System();
87
91 ~System();
92
96
108 void setOptions(int argc, char **argv);
109
115 virtual void readParam(std::istream& in);
116
123 void readParam();
124
130 virtual void readParameters(std::istream& in);
131
137 void readCommands(std::istream& in);
138
145 void readCommands();
146
150
165 void readWBasis(const std::string & filename);
166
181 void readWRGrid(const std::string & filename);
182
193 void setWBasis(DArray< DArray<double> > const & fields);
194
205 void setWRGrid(DArray< RField<D> > const & fields);
206
220 void estimateWfromC(const std::string& filename);
221
225
234 void setUnitCell(UnitCell<D> const & unitCell);
235
245 void setUnitCell(typename UnitCell<D>::LatticeSystem lattice,
246 FSArray<double, 6> const & parameters);
247
256 void setUnitCell(FSArray<double, 6> const & parameters);
257
261
285 void compute(bool needStress = false);
286
307 int iterate(bool isContinuation = false);
308
323 void sweep();
324
328
337 void computeFreeEnergy();
338
345 double fHelmholtz() const;
346
353 double pressure() const;
354
358
369 void writeParamNoSweep(std::ostream& out) const;
370
387 void writeThermo(std::ostream& out);
388
392
398 void writeWBasis(const std::string & filename) const;
399
405 void writeWRGrid(const std::string & filename) const;
406
412 void writeCBasis(const std::string & filename) const;
413
419 void writeCRGrid(const std::string & filename) const;
420
432 void writeBlockCRGrid(const std::string & filename) const;
433
437
447 void writeQSlice(std::string const & filename,
448 int polymerId, int blockId,
449 int directionId, int segmentId) const;
450
459 void writeQTail(std::string const & filename, int polymerId,
460 int blockId, int directionId) const;
461
470 void writeQ(std::string const & filename, int polymerId,
471 int blockId, int directionId) const;
472
491 void writeQAll(std::string const & basename);
492
496
505 void writeStars(std::string const & filename) const;
506
515 void writeWaves(std::string const & filename) const;
516
522 void writeGroup(std::string const & filename) const;
523
527
542 void basisToRGrid(const std::string & inFileName,
543 const std::string & outFileName);
544
559 void rGridToBasis(const std::string & inFileName,
560 const std::string & outFileName);
561
568 void kGridToRGrid(const std::string& inFileName,
569 const std::string& outFileName);
570
577 void rGridToKGrid(const std::string & inFileName,
578 const std::string & outFileName);
579
594 void kGridToBasis(const std::string& inFileName,
595 const std::string& outFileName);
596
603 void basisToKGrid(const std::string & inFileName,
604 const std::string & outFileName);
605
614 void compare(const DArray< DArray<double> > field1,
615 const DArray< DArray<double> > field2);
616
625 void compare(const DArray< RField<D> > field1,
626 const DArray< RField<D> > field2);
627
635 bool checkRGridFieldSymmetry(const std::string & inFileName,
636 double epsilon = 1.0E-8);
637
641
645 WFieldContainer<D> const & w() const;
646
650 CFieldContainer<D> const & c() const;
651
656
660 Mask<D>& mask();
661
665
670
674 Mixture<D> const & mixture() const;
675
680
684 Interaction const & interaction() const;
685
689 Domain<D> const & domain() const;
690
694 UnitCell<D> const & unitCell() const;
695
699 Mesh<D> const & mesh() const;
700
704 Basis<D> const & basis() const;
705
709 FFT<D> const & fft() const;
710
714 FieldIo<D> const & fieldIo() const;
715
720
724 Iterator<D> const & iterator() const;
725
730
734 Homogeneous::Mixture const & homogeneous() const;
735
742
746 FileMaster const & fileMaster() const;
747
751 std::string groupName() const;
752
756
760 bool hasCFields() const;
761
765 bool hasFreeEnergy() const;
766
770 bool hasExternalFields() const;
771
775 bool hasMask() const;
776
780 bool hasSweep() const;
781
783
784 private:
785
786 // Private member variables
787
791 Mixture<D> mixture_;
792
796 Domain<D> domain_;
797
801 FileMaster fileMaster_;
802
806 Homogeneous::Mixture homogeneous_;
807
811 Interaction* interactionPtr_;
812
816 Iterator<D>* iteratorPtr_;
817
821 IteratorFactory<D>* iteratorFactoryPtr_;
822
826 Sweep<D>* sweepPtr_;
827
831 SweepFactory<D>* sweepFactoryPtr_;
832
837
842
847
851 Mask<D> mask_;
852
858 mutable DArray< DArray<double> > tmpFieldsBasis_;
859
865 mutable DArray< RField<D> > tmpFieldsRGrid_;
866
872 mutable DArray< RFieldDft<D> > tmpFieldsKGrid_;
873
877 double fHelmholtz_;
878
886 double fIdeal_;
887
891 double fInter_;
892
896 double fExt_;
897
904 double pressure_;
905
909 bool hasMixture_;
910
914 bool isAllocatedRGrid_;
915
919 bool isAllocatedBasis_;
920
932 bool hasCFields_;
933
937 bool hasFreeEnergy_;
938
939 // Private member functions
940
944 void allocateFieldsGrid();
945
949 void allocateFieldsBasis();
950
959 void readFieldHeader(std::string filename);
960
969 void readEcho(std::istream& in, std::string& string) const;
970
979 void readEcho(std::istream& in, double& value) const;
980
984 void initHomogeneous();
985
986 };
987
988 // Inline member functions
989
990 // Get the Mixture object.
991 template <int D>
993 { return mixture_; }
994
995 // Get the Mixture by const reference.
996 template <int D>
997 inline Mixture<D> const & System<D>::mixture() const
998 { return mixture_; }
999
1000 // Get the Domain by const reference.
1001 template <int D>
1002 inline Domain<D> const & System<D>::domain() const
1003 { return domain_; }
1004
1005 // Get the UnitCell by const reference.
1006 template <int D>
1007 inline UnitCell<D> const & System<D>::unitCell() const
1008 { return domain_.unitCell(); }
1009
1010 // Get the Mesh by const reference.
1011 template <int D>
1012 inline Mesh<D> const & System<D>::mesh() const
1013 { return domain_.mesh(); }
1014
1015 // Get the Basis<D> object.
1016 template <int D>
1017 inline Basis<D> const & System<D>::basis() const
1018 { return domain_.basis(); }
1019
1020 // Get the FFT object by const reference.
1021 template <int D>
1022 inline FFT<D> const & System<D>::fft() const
1023 { return domain_.fft(); }
1024
1025 // Get the FieldIo<D> by const reference.
1026 template <int D>
1027 inline FieldIo<D> const & System<D>::fieldIo() const
1028 { return domain_.fieldIo(); }
1029
1030 // Get the groupName string by value.
1031 template <int D>
1032 inline std::string System<D>::groupName() const
1033 { return domain_.groupName(); }
1034
1035 // Get the FileMaster by non-const reference.
1036 template <int D>
1038 { return fileMaster_; }
1039
1040 // Get the FileMaster by const reference.
1041 template <int D>
1042 inline FileMaster const & System<D>::fileMaster() const
1043 { return fileMaster_; }
1044
1045 // Get the Homogeneous::Mixture object.
1046 template <int D>
1048 { return homogeneous_; }
1049
1050 // Get the const Homogeneous::Mixture object.
1051 template <int D>
1053 { return homogeneous_; }
1054
1055 // Get the Interaction (excess free energy model).
1056 template <int D>
1058 {
1059 UTIL_ASSERT(interactionPtr_);
1060 return *interactionPtr_;
1061 }
1062
1063 // Get the Interaction by const reference.
1064 template <int D>
1066 {
1067 UTIL_ASSERT(interactionPtr_);
1068 return *interactionPtr_;
1069 }
1070
1071 // Get the Iterator.
1072 template <int D>
1074 {
1075 UTIL_ASSERT(iteratorPtr_);
1076 return *iteratorPtr_;
1077 }
1078
1079 // Get the Iterator by const reference.
1080 template <int D>
1081 inline Iterator<D> const & System<D>::iterator() const
1082 {
1083 UTIL_ASSERT(iteratorPtr_);
1084 return *iteratorPtr_;
1085 }
1086
1087 // Get container of chemical potential fields (const reference)
1088 template <int D>
1089 inline
1091 { return w_; }
1092
1093 // Get container of monomer concentration fields (const reference)
1094 template <int D>
1095 inline
1097 { return c_; }
1098
1099 // Get container of external potential fields (reference)
1100 template <int D>
1102 { return h_; }
1103
1104 // Get mask field (reference)
1105 template <int D>
1107 { return mask_; }
1108
1109 // Does the system have a Sweep object?
1110 template <int D>
1111 inline bool System<D>::hasSweep() const
1112 { return (sweepPtr_ != 0); }
1113
1114 // Does this system have external potential fields?
1115 template <int D>
1117 { return h_.hasData(); }
1118
1119 // Does this system have a mask?
1120 template <int D>
1121 inline bool System<D>::hasMask() const
1122 { return mask_.hasData(); }
1123
1124 // Have the c fields been computed for the current w fields?
1125 template <int D>
1126 inline bool System<D>::hasCFields() const
1127 { return hasCFields_; }
1128
1129 // Get the precomputed Helmoltz free energy per monomer / kT.
1130 template <int D>
1131 inline double System<D>::fHelmholtz() const
1132 {
1133 UTIL_CHECK(hasFreeEnergy_);
1134 return fHelmholtz_;
1135 }
1136
1137 // Get the precomputed pressure (units of kT / monomer volume).
1138 template <int D>
1139 inline double System<D>::pressure() const
1140 {
1141 UTIL_CHECK(hasFreeEnergy_);
1142 return pressure_;
1143 }
1144
1145 // Has the free energy been computed for the current w fields?
1146 template <int D>
1147 inline bool System<D>::hasFreeEnergy() const
1148 { return hasFreeEnergy_; }
1149
1150 #ifndef PSPC_SYSTEM_TPP
1151 // Suppress implicit instantiation
1152 extern template class System<1>;
1153 extern template class System<2>;
1154 extern template class System<3>;
1155 #endif
1156
1157} // namespace Pspc
1158} // namespace Pscf
1159#endif
Symmetry-adapted Fourier basis for pseudo-spectral scft.
Definition: Basis.h:346
A spatially homogeneous mixture.
Flory-Huggins excess free energy model.
Definition: Interaction.h:26
Description of a regular grid of points in a periodic domain.
Definition: Mesh.h:61
A list of c fields stored in both basis and r-grid format.
Spatial domain and spatial discretization for a periodic structure.
Fourier transform wrapper for real data.
File input/output operations and format conversions for fields.
Factory for subclasses of Iterator.
Base class for iterative solvers for SCF equations.
A field to which the total density is constrained.
Definition: Mask.h:56
Solver for a mixture of polymers and solvents.
Field of real double precision values on an FFT mesh.
Definition: RField.h:29
Default Factory for subclasses of Sweep.
Solve a sequence of problems along a line in parameter space.
Main class for SCFT simulation of one system.
Definition: pspc/System.h:76
void setWBasis(DArray< DArray< double > > const &fields)
Set chemical potential fields, in symmetry-adapted basis format.
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
void setOptions(int argc, char **argv)
Process command line options.
double fHelmholtz() const
Get precomputed Helmoltz free energy per monomer / kT.
Definition: pspc/System.h:1131
double pressure() const
Get precomputed pressure x monomer volume kT.
Definition: pspc/System.h:1139
bool hasMask() const
Does this system have a mask (inhomogeneous density constraint)
Definition: pspc/System.h:1121
void writeCRGrid(const std::string &filename) const
Write concentration fields in real space grid (r-grid) format.
void writeGroup(std::string const &filename) const
Output all elements of the space group.
Domain< D > const & domain() const
Get Domain by const reference.
Definition: pspc/System.h:1002
void readParam()
Read input parameters from default param file.
bool hasFreeEnergy() const
Has the free energy been computed from the current w fields?
Definition: pspc/System.h:1147
bool hasExternalFields() const
Does this system have external potential fields?
Definition: pspc/System.h:1116
void kGridToBasis(const std::string &inFileName, const std::string &outFileName)
Convert fields from Fourier (k-grid) to symmetrized basis format.
Iterator< D > & iterator()
Get the iterator.
Definition: pspc/System.h:1073
Mixture< D > & mixture()
Get the Mixture by non-const reference.
Definition: pspc/System.h:992
void writeWRGrid(const std::string &filename) const
Write chemical potential fields in real space grid (r-grid) format.
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
WFieldContainer< D > & h()
Get all of the external potential fields (reference).
Definition: pspc/System.h:1101
CFieldContainer< D > const & c() const
Get all of the monomer concentration fields (const reference).
Definition: pspc/System.h:1096
System()
Constructor.
Definition: pspc/System.tpp:45
void compare(const DArray< DArray< double > > field1, const DArray< DArray< double > > field2)
Compare two field files in symmetrized basis format.
Basis< D > const & basis() const
Get the Basis by const reference.
Definition: pspc/System.h:1017
void writeBlockCRGrid(const std::string &filename) const
Write c-fields for all blocks and solvents in r-grid format.
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
Mask< D > & mask()
Get the mask (field to which total density is constrained).
Definition: pspc/System.h:1106
void writeParamNoSweep(std::ostream &out) const
Write parameter file to an ostream, omitting any sweep block.
void basisToRGrid(const std::string &inFileName, const std::string &outFileName)
Convert a field from symmetrized basis format to r-grid format.
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
std::string groupName() const
Get the group name string.
Definition: pspc/System.h:1032
void readWRGrid(const std::string &filename)
Read chemical potential fields in real space grid (r-grid) format.
~System()
Destructor.
Definition: pspc/System.tpp:85
void writeThermo(std::ostream &out)
Write thermodynamic properties to a file.
void writeCBasis(const std::string &filename) const
Write concentration fields in symmetrized basis format.
Mesh< D > const & mesh() const
Get the spatial discretization mesh by const reference.
Definition: pspc/System.h:1012
WFieldContainer< D > const & w() const
Get all of the chemical potential fields (const reference).
Definition: pspc/System.h:1090
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
bool hasSweep() const
Does this system have a Sweep object?
Definition: pspc/System.h:1111
Interaction & interaction()
Get Interaction (excess free energy model) by reference.
Definition: pspc/System.h:1057
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
UnitCell< D > const & unitCell() const
Get UnitCell (i.e., type and parameters) by const reference.
Definition: pspc/System.h:1007
void estimateWfromC(const std::string &filename)
Construct trial w-fields from c-fields.
Homogeneous::Mixture & homogeneous()
Get homogeneous mixture (for reference calculations).
Definition: pspc/System.h:1047
void writeStars(std::string const &filename) const
Output information about stars and symmetrized basis functions.
void kGridToRGrid(const std::string &inFileName, const std::string &outFileName)
Convert fields from Fourier (k-grid) to real-space (r-grid) format.
void writeWBasis(const std::string &filename) const
Write chemical potential fields in symmetrized basis format.
void readCommands()
Read commands from default command file.
void rGridToBasis(const std::string &inFileName, const std::string &outFileName)
Convert a field from real-space grid to symmetrized basis format.
FieldIo< D > const & fieldIo() const
Get associated FieldIo object by const reference.
Definition: pspc/System.h:1027
void readWBasis(const std::string &filename)
Read chemical potential fields in symmetry adapted basis format.
void writeQSlice(std::string const &filename, int polymerId, int blockId, int directionId, int segmentId) const
Write slice of a propagator at fixed s in r-grid format.
bool checkRGridFieldSymmetry(const std::string &inFileName, double epsilon=1.0E-8)
Check if r-grid fields have the declared space group symmetry.
void rGridToKGrid(const std::string &inFileName, const std::string &outFileName)
Convert fields from real-space (r-grid) to Fourier (k-grid) format.
void writeWaves(std::string const &filename) const
Output information about waves.
bool hasCFields() const
Have c fields been computed from the current w fields?
Definition: pspc/System.h:1126
void computeFreeEnergy()
Compute free energy density and pressure for current fields.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write one propagator for one block, in r-grid format.
FileMaster & fileMaster()
Get the FileMaster.
Definition: pspc/System.h:1037
void basisToKGrid(const std::string &inFileName, const std::string &outFileName)
Convert fields from symmetrized basis to Fourier (k-grid) format.
FFT< D > const & fft() const
Get associated FFT object by const reference.
Definition: pspc/System.h:1022
void setWRGrid(DArray< RField< D > > const &fields)
Set new w fields, in real-space (r-grid) format.
A list of fields stored in both basis and r-grid format.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition: UnitCell.h:44
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:38
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:143
An object that can read multiple parameters from file.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1