PSCF v1.5.0
rp/system/System.h
1#ifndef RP_SYSTEM_H
2#define RP_SYSTEM_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 <util/param/ParamComposite.h> // base class
12#include <pscf/chem/PolymerModel.h> // member
13#include <pscf/backend/TmplDeclare.h> // declaration macros
14
15// Forward declarations
16namespace Util {
17 class FileMaster;
18 template <typename E, int N> class FSArray;
19}
20namespace Pscf {
21 class Interaction;
22 template <int D> class UnitCell;
23 template <int D, class T> class WaveList;
24 namespace Rp {
25 class Environment;
26 template <int D, class T> class WFields;
27 template <int D, class T> class CFields;
28 template <int D, class T> class Mask;
29 template <int D, class T> class Domain;
30 template <int D, class T> class Mixture;
31 template <int D, class T> class MixtureModifier;
32 template <int D, class T> class ScftThermo;
33 template <int D, class T> class EnvironmentFactory;
34 template <int D, class T> class Iterator;
35 template <int D, class T> class IteratorFactory;
36 template <int D, class T> class Sweep;
37 template <int D, class T> class SweepFactory;
38 template <int D, class T> class Simulator;
39 template <int D, class T> class SimulatorFactory;
40 }
41}
42
43namespace Pscf {
44namespace Rp {
45
46 // Namespaces that may be used implicitly
47 using namespace Util;
48
123 template <int D, class T>
124 class System : public ParamComposite
125 {
126
127 public:
128
131
135 System();
136
140 ~System();
141
142 // Suppress copying and assignment
143 System(System<D,T> const &) = delete;
144 System<D,T>& operator = (System<D,T> const & ) = delete;
145
147
150
162 void setOptions(int argc, char **argv);
163
169 virtual void readParam(std::istream& in);
170
177 void readParam();
178
184 virtual void readParameters(std::istream& in);
185
196 int readCommands(std::istream& in);
197
206 int readCommands();
207
211
235 void compute(bool needStress = false);
236
248 void computeStress();
249
271 int iterate(bool isContinuation = false);
272
285 void sweep();
286
302 void simulate(int nStep);
303
314 void clearCFields();
315
319
332 void setUnitCell(UnitCell<D> const & unitCell);
333
347 void setUnitCell(FSArray<double, 6> const & parameters);
348
357 void clearUnitCellData();
358
362
366 CFields<D,T> const & c() const;
367
371 WFields<D,T> const & w() const;
372
376 WFields<D,T>& w();
377
381 WFields<D,T> const & h() const;
382
386 WFields<D,T>& h();
387
391 Mask<D,T> const & mask() const;
392
396 Mask<D,T>& mask();
397
407
411
415 Mixture<D,T> const & mixture() const;
416
421
425 Interaction const & interaction() const;
426
431
435 Domain<D,T> const & domain() const;
436
448
452 bool hasEnvironment() const;
453
457 Environment const & environment() const;
458
463
467 ScftThermo<D,T> const & scft() const;
468
473
477 bool hasIterator() const;
478
482 Iterator<D,T> const & iterator() const;
483
488
492 bool hasSweep() const;
493
497 bool hasSimulator() const;
498
502 Simulator<D,T> const & simulator() const;
503
508
512 FileMaster const & fileMaster() const;
513
520
524
537 void writeParamNoSweep(std::ostream& out) const;
538
542
548 void writeTimers(std::ostream& out) const;
549
553 void clearTimers();
554
556
557 private:
558
559
560 // Pointers to associated sub-objects (owned by System)
561
565 CFields<D,T>* cPtr_;
566
570 WFields<D,T>* wPtr_;
571
575 WFields<D,T>* hPtr_;
576
580 Mask<D,T>* maskPtr_;
581
585 Mixture<D,T>* mixturePtr_;
586
590 MixtureModifier<D,T>* mixtureModifierPtr_;
591
595 Domain<D,T>* domainPtr_;
596
600 Interaction* interactionPtr_;
601
605 ScftThermo<D,T>* scftPtr_;
606
610 Environment* environmentPtr_;
611
615 EnvironmentFactory<D,T>* environmentFactoryPtr_;
616
620 Iterator<D,T>* iteratorPtr_;
621
625 IteratorFactory<D,T>* iteratorFactoryPtr_;
626
630 Sweep<D,T>* sweepPtr_;
631
635 SweepFactory<D,T>* sweepFactoryPtr_;
636
640 Simulator<D,T>* simulatorPtr_;
641
645 SimulatorFactory<D,T>* simulatorFactoryPtr_;
646
650 FileMaster* fileMasterPtr_;
651
655 UnitCell<D>* tmpUnitCellPtr_;
656
657 // Boolean and enum state variables
658
662 PolymerModel::Type polymerModel_;
663
667 bool isAllocatedGrid_;
668
672 bool isAllocatedBasis_;
673
677 bool hasMixture_;
678
679 // Private member functions
680
684 Mixture<D,T> & mixture_();
685
689 Domain<D,T>& domain_();
690
694 CFields<D,T>& c_();
695
699 void allocateFieldsGrid();
700
704 void allocateFieldsBasis();
705
714 void readEcho(std::istream& in, std::string& string) const;
715
724 void readEcho(std::istream& in, double& value) const;
725
726 };
727
728 // Inline member functions
729
730 // Get the Mixture (const).
731 template <int D, class T> inline
733 {
734 UTIL_ASSERT(mixturePtr_);
735 return *mixturePtr_;
736 }
737
738 // Get the MixtureModifier (non-const).
739 template <int D, class T> inline
741 {
742 UTIL_ASSERT(mixtureModifierPtr_);
743 return *mixtureModifierPtr_;
744 }
745
746 // Get the %Interaction (const).
747 template <int D, class T> inline
749 {
750 UTIL_ASSERT(interactionPtr_);
751 return *interactionPtr_;
752 }
753
754 // Get the %Interaction (non-const).
755 template <int D, class T> inline
757 {
758 UTIL_ASSERT(interactionPtr_);
759 return *interactionPtr_;
760 }
761
762 // Get the Domain (const).
763 template <int D, class T> inline
765 {
766 UTIL_ASSERT(domainPtr_);
767 return *domainPtr_;
768 }
769
770 // Get the WaveList (non-const).
771 template <int D, class T> inline
773 {
774 UTIL_ASSERT(domainPtr_);
775 return domainPtr_->waveList();
776 }
777
778 // Get the FileMaster (const).
779 template <int D, class T> inline
781 {
782 UTIL_ASSERT(fileMasterPtr_);
783 return *fileMasterPtr_;
784 }
785
786 // Get the FileMaster (non-const).
787 template <int D, class T> inline
789 {
790 UTIL_ASSERT(fileMasterPtr_);
791 return *fileMasterPtr_;
792 }
793
794 // Accessors for field containers
795
796 // Get the container of c fields (const).
797 template <int D, class T> inline
799 { return *cPtr_; }
800
801 // Get the container of w fields (const).
802 template <int D, class T> inline
804 { return *wPtr_; }
805
806 // Get the container of w fields (non-const).
807 template <int D, class T> inline
809 { return *wPtr_; }
810
811 // Get the container of external fields (const).
812 template <int D, class T> inline
814 { return *hPtr_; }
815
816 // Get the container of external fields (non-const).
817 template <int D, class T> inline
819 { return *hPtr_; }
820
821 // Get the mask field (const).
822 template <int D, class T> inline
824 { return *maskPtr_; }
825
826 // Get the mask field (non-const).
827 template <int D, class T> inline
829 { return *maskPtr_; }
830
831 // Accessors for optional elements
832
833 // Does this system have an %Environment?
834 template <int D, class T> inline
836 { return (environmentPtr_); }
837
838 // Get the %Environment (const).
839 template <int D, class T> inline
841 {
842 UTIL_ASSERT(environmentPtr_);
843 return *environmentPtr_;
844 }
845
846 // Get the %Environment (non-const).
847 template <int D, class T> inline
849 {
850 UTIL_ASSERT(environmentPtr_);
851 return *environmentPtr_;
852 }
853
854 // Get the Scft thermodynamics calculator (const).
855 template <int D, class T> inline
857 {
858 UTIL_ASSERT(scftPtr_);
859 return *scftPtr_;
860 }
861
862 // Get the Scft thermodynamics calculator (non-const).
863 template <int D, class T> inline
865 {
866 UTIL_ASSERT(scftPtr_);
867 return *scftPtr_;
868 }
869
870 // Does this system have an SCFT Iterator?
871 template <int D, class T> inline
873 { return (iteratorPtr_); }
874
875 // Get the SCFT Iterator (const).
876 template <int D, class T> inline
878 {
879 UTIL_ASSERT(iteratorPtr_);
880 return *iteratorPtr_;
881 }
882
883 // Get the SCFT Iterator (non-const).
884 template <int D, class T> inline
886 {
887 UTIL_ASSERT(iteratorPtr_);
888 return *iteratorPtr_;
889 }
890
891 // Does this system have an SCFT Sweep?
892 template <int D, class T> inline
894 { return (sweepPtr_); }
895
896 // Does this system have a Simulator?
897 template <int D, class T> inline
899 { return (simulatorPtr_); }
900
901 // Get the Simulator (const).
902 template <int D, class T> inline
904 {
905 UTIL_ASSERT(simulatorPtr_);
906 return *simulatorPtr_;
907 }
908
909 // Get the Simulator (non-const).
910 template <int D, class T> inline
912 {
913 UTIL_ASSERT(simulatorPtr_);
914 return *simulatorPtr_;
915 }
916
917 // Private inline functions:
918
919 // Get the Mixture (non-const).
920 template <int D, class T> inline
921 Mixture<D,T> & System<D,T>::mixture_()
922 { return *mixturePtr_; }
923
924 // Get the Domain (non-const).
925 template <int D, class T> inline
926 Domain<D,T> & System<D,T>::domain_()
927 { return *domainPtr_; }
928
929 // Get the CFields container (non-const).
930 template <int D, class T> inline
931 CFields<D,T> & System<D,T>::c_()
932 { return *cPtr_; }
933
934 // Explicit instantiation declarations
935 PSCF_TMPL_DECLARE(System)
936
937} // namespace Rp
938} // namespace Pscf
939#endif
Interaction model for complex Langevin FTS.
Definition Interaction.h:24
A list of c fields stored in both basis and r-grid format.
Definition CFields.h:58
Spatial domain for a periodic structure with real fields.
Factory for subclasses of Environment.
Environment generator for variable-cell SCFT.
Definition Environment.h:59
Factory for subclasses of Iterator.
Base class template for iterative solvers for SCF equations.
A field that specifies an inhomogeneous total monomer concentration.
Definition Mask.h:85
Modifier for parameters of an associated mixture.
Solver and descriptor for a mixture of polymers and solvents.
Base class for SCFT thermodynamic property calculators.
Definition ScftThermo.h:39
Factory for subclasses of Simulator.
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Default Factory for subclasses of Sweep.
Solve a sequence of SCFT problems along a line in parameter space.
Base class template for classes that represent a complete system.
void simulate(int nStep)
Perform a field theoretic simulation (PS-FTS).
Definition System.tpp:1062
Simulator< D, T > const & simulator() const
Get the Simulator (const).
Environment const & environment() const
Get the Environment (const).
Mask< D, T > const & mask() const
Get the mask (const).
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
Definition System.tpp:1040
bool hasSimulator() const
Does this system have a Simulator?
System()
Constructor.
Definition System.tpp:85
void computeStress()
Compute SCFT stress.
Definition System.tpp:961
CFields< D, T > const & c() const
Get the monomer concentration (c) fields (const).
bool hasEnvironment() const
Does this system have an Environment?
FileMaster const & fileMaster() const
Get the FileMaster (const).
bool hasSweep() const
Does this system have a Sweep?
WFields< D, T > const & h() const
Get the external potential (h) fields (const).
int readCommands(std::istream &in)
Read and process commands from an input stream.
Definition System.tpp:486
ScftThermo< D, T > const & scft() const
Get the ScftThermo object (const).
void clearUnitCellData()
Notify System members that unit cell parameters have been modified.
Definition System.tpp:1169
void clearCFields()
Mark c-fields, propagators and free energies as outdated.
Definition System.tpp:1075
virtual void readParam(std::istream &in)
Read input parameters (with opening and closing lines).
Definition System.tpp:468
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
Definition System.tpp:1110
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
Definition System.tpp:354
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
Definition System.tpp:921
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
Definition System.tpp:991
Interaction const & interaction() const
Get the Interaction (const).
Mixture< D, T > const & mixture() const
Get the Mixture (const).
WaveList< D, T > & waveList()
Get the WaveList (non-const).
bool hasIterator() const
Does this system have an Iterator?
MixtureModifier< D, T > & mixtureModifier()
Get the MixtureModifier (non-const).
void writeParamNoSweep(std::ostream &out) const
Definition System.tpp:1188
void writeTimers(std::ostream &out) const
Definition System.tpp:1214
Domain< D, T > const & domain() const
Get the Domain (const).
WFields< D, T > const & w() const
Get the chemical potential (w) fields (const).
void setOptions(int argc, char **argv)
Process command line options.
Definition System.tpp:248
Iterator< D, T > const & iterator() const
Get the Iterator (const).
A container of w fields stored in both basis and r-grid format.
Definition WFields.h:87
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:55
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
ParamComposite()
Constructor.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Type
Scoped enumeration of polymer model types.
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.