PSCF v1.4.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 - 2025, The Regents of the University of Minnesota
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
14// Forward declarations
15namespace Util {
16 class FileMaster;
17 template <typename E, int N> class FSArray;
18}
19namespace Pscf {
20 namespace Prdc {
21 template <int D> class UnitCell;
22 }
23}
24
25namespace Pscf {
26namespace Rp {
27
28 // Namespaces that may be used implicitly
29 using namespace Util;
30 using namespace Pscf::Prdc;
31
115 template <int D, class T>
116 class System : public ParamComposite
117 {
118
119 public:
120
121 // Suppress several compiler-generated member functions
122 System() = delete;
123 System(System<D,T> const &) = delete;
124 System<D,T>& operator = (System<D,T> const & ) = delete;
125
128
140 void setOptions(int argc, char **argv);
141
147 virtual void readParam(std::istream& in);
148
155 void readParam();
156
162 virtual void readParameters(std::istream& in);
163
169 void readCommands(std::istream& in);
170
177 void readCommands();
178
182
206 void compute(bool needStress = false);
207
219 void computeStress();
220
242 int iterate(bool isContinuation = false);
243
256 void sweep();
257
273 void simulate(int nStep);
274
285 void clearCFields();
286
290
303 void setUnitCell(UnitCell<D> const & unitCell);
304
318 void setUnitCell(FSArray<double, 6> const & parameters);
319
328 void clearUnitCellData();
329
333
337 typename T::CFields const & c() const;
338
342 typename T::WFields const & w() const;
343
347 typename T::WFields& w();
348
352 typename T::WFields const & h() const;
353
357 typename T::WFields& h();
358
362 typename T::Mask const & mask() const;
363
367 typename T::Mask& mask();
368
372
376 typename T::Mixture const & mixture() const;
377
381 typename T::MixtureModifier& mixtureModifier();
382
386 typename T::Interaction const & interaction() const;
387
391 typename T::Interaction& interaction();
392
396 typename T::Domain const & domain() const;
397
408 typename T::WaveList & waveList();
409
413 bool hasEnvironment() const;
414
418 typename T::Environment const & environment() const;
419
423 typename T::Environment& environment();
424
428 typename T::ScftThermo const & scft() const;
429
433 typename T::ScftThermo& scft();
434
438 bool hasIterator() const;
439
443 typename T::Iterator const & iterator() const;
444
448 typename T::Iterator& iterator();
449
453 bool hasSweep() const;
454
458 bool hasSimulator() const;
459
463 typename T::Simulator const & simulator() const;
464
468 typename T::Simulator& simulator();
469
473 FileMaster const & fileMaster() const;
474
481
485
498 void writeParamNoSweep(std::ostream& out) const;
499
503
509 void writeTimers(std::ostream& out) const;
510
514 void clearTimers();
515
517
518 protected:
519
522
540 System(typename T::System& system);
541
545 ~System();
546
548
563 virtual void setThreadCount(int nThread)
564 {};
565
566 private:
567
571 typename T::System* systemPtr_;
572
573 // Pointers to associated sub-objects (owned by System)
574
578 typename T::CFields* cPtr_;
579
583 typename T::WFields* wPtr_;
584
588 typename T::WFields* hPtr_;
589
593 typename T::Mask* maskPtr_;
594
598 typename T::Mixture* mixturePtr_;
599
603 typename T::MixtureModifier* mixtureModifierPtr_;
604
608 typename T::Domain* domainPtr_;
609
613 typename T::Interaction* interactionPtr_;
614
618 typename T::ScftThermo* scftPtr_;
619
623 typename T::Environment* environmentPtr_;
624
628 typename T::EnvironmentFactory* environmentFactoryPtr_;
629
633 typename T::Iterator* iteratorPtr_;
634
638 typename T::IteratorFactory* iteratorFactoryPtr_;
639
643 typename T::Sweep* sweepPtr_;
644
648 typename T::SweepFactory* sweepFactoryPtr_;
649
653 typename T::Simulator* simulatorPtr_;
654
658 typename T::SimulatorFactory* simulatorFactoryPtr_;
659
663 FileMaster* fileMasterPtr_;
664
668 UnitCell<D>* tmpUnitCellPtr_;
669
670 // Boolean and enum state variables
671
675 PolymerModel::Type polymerModel_;
676
680 bool isAllocatedGrid_;
681
685 bool isAllocatedBasis_;
686
690 bool hasMixture_;
691
692 // Private member functions
693
697 typename T::Mixture & mixture_();
698
702 typename T::Domain& domain_();
703
707 typename T::CFields& c_();
708
712 void allocateFieldsGrid();
713
717 void allocateFieldsBasis();
718
727 void readEcho(std::istream& in, std::string& string) const;
728
737 void readEcho(std::istream& in, double& value) const;
738
739 };
740
741 // Inline member functions
742
743 // Get the Mixture (const).
744 template <int D, class T> inline
745 typename T::Mixture const & System<D,T>::mixture() const
746 { return *mixturePtr_; }
747
748 // Get the MixtureModifier (non-const).
749 template <int D, class T> inline
750 typename T::MixtureModifier& System<D,T>::mixtureModifier()
751 {
752 UTIL_ASSERT(mixtureModifierPtr_);
753 return *mixtureModifierPtr_;
754 }
755
756 // Get the %Interaction (const).
757 template <int D, class T> inline
758 typename T::Interaction const & System<D,T>::interaction() const
759 {
760 UTIL_ASSERT(interactionPtr_);
761 return *interactionPtr_;
762 }
763
764 // Get the %Interaction (non-const).
765 template <int D, class T> inline
766 typename T::Interaction& System<D,T>::interaction()
767 {
768 UTIL_ASSERT(interactionPtr_);
769 return *interactionPtr_;
770 }
771
772 // Get the Domain (const).
773 template <int D, class T> inline
774 typename T::Domain const & System<D,T>::domain() const
775 { return *domainPtr_; }
776
777 // Get the WaveList (non-const).
778 template <int D, class T> inline
779 typename T::WaveList& System<D,T>::waveList()
780 { return domainPtr_->waveList(); }
781
782 // Accessors for field containers
783
784 // Get the container of c fields (const).
785 template <int D, class T> inline
786 typename T::CFields const & System<D,T>::c() const
787 { return *cPtr_; }
788
789 // Get the container of w fields (const).
790 template <int D, class T> inline
791 typename T::WFields const & System<D,T>::w() const
792 { return *wPtr_; }
793
794 // Get the container of w fields (non-const).
795 template <int D, class T> inline
796 typename T::WFields& System<D,T>::w()
797 { return *wPtr_; }
798
799 // Get the container of external fields (const).
800 template <int D, class T> inline
801 typename T::WFields const & System<D,T>::h() const
802 { return *hPtr_; }
803
804 // Get the container of external fields (non-const).
805 template <int D, class T> inline
806 typename T::WFields& System<D,T>::h()
807 { return *hPtr_; }
808
809 // Get the mask field (const).
810 template <int D, class T> inline
811 typename T::Mask const & System<D,T>::mask() const
812 { return *maskPtr_; }
813
814 // Get the mask field (non-const).
815 template <int D, class T> inline
816 typename T::Mask& System<D,T>::mask()
817 { return *maskPtr_; }
818
819 // Accessors for optional elements
820
821 // Does this system have an %Environment?
822 template <int D, class T> inline
824 { return (environmentPtr_); }
825
826 // Get the %Environment (const).
827 template <int D, class T> inline
828 typename T::Environment const & System<D,T>::environment() const
829 {
830 UTIL_ASSERT(environmentPtr_);
831 return *environmentPtr_;
832 }
833
834 // Get the %Environment (non-const).
835 template <int D, class T> inline
836 typename T::Environment & System<D,T>::environment()
837 {
838 UTIL_ASSERT(environmentPtr_);
839 return *environmentPtr_;
840 }
841
842 // Get the Scft calculator (const).
843 template <int D, class T> inline
844 typename T::ScftThermo const & System<D,T>::scft() const
845 {
846 UTIL_ASSERT(scftPtr_);
847 return *scftPtr_;
848 }
849
850 // Get the Scft calculator (non-const).
851 template <int D, class T> inline
852 typename T::ScftThermo & System<D,T>::scft()
853 {
854 UTIL_ASSERT(scftPtr_);
855 return *scftPtr_;
856 }
857
858 // Does this system have an Iterator?
859 template <int D, class T> inline
861 { return (iteratorPtr_); }
862
863 // Get the Iterator (const).
864 template <int D, class T> inline
865 typename T::Iterator const & System<D,T>::iterator() const
866 {
867 UTIL_ASSERT(iteratorPtr_);
868 return *iteratorPtr_;
869 }
870
871 // Get the Iterator (non-const).
872 template <int D, class T> inline
873 typename T::Iterator& System<D,T>::iterator()
874 {
875 UTIL_ASSERT(iteratorPtr_);
876 return *iteratorPtr_;
877 }
878
879 // Does this system have a Sweep?
880 template <int D, class T> inline
882 { return (sweepPtr_); }
883
884 // Does this system have a Simulator?
885 template <int D, class T> inline
887 { return (simulatorPtr_); }
888
889 // Get the Simulator (const).
890 template <int D, class T> inline
891 typename T::Simulator const & System<D,T>::simulator() const
892 {
893 UTIL_ASSERT(simulatorPtr_);
894 return *simulatorPtr_;
895 }
896
897 // Get the Simulator (non-const).
898 template <int D, class T> inline
899 typename T::Simulator& System<D,T>::simulator()
900 {
901 UTIL_ASSERT(simulatorPtr_);
902 return *simulatorPtr_;
903 }
904
905 // Get the FileMaster (const).
906 template <int D, class T> inline
908 { return *fileMasterPtr_; }
909
910 // Get the FileMaster (non-const).
911 template <int D, class T> inline
913 { return *fileMasterPtr_; }
914
915 // Private inline functions:
916
917 // Get the Mixture (non-const).
918 template <int D, class T> inline
919 typename T::Mixture & System<D,T>::mixture_()
920 { return *mixturePtr_; }
921
922 // Get the Domain (non-const).
923 template <int D, class T> inline
924 typename T::Domain & System<D,T>::domain_()
925 { return *domainPtr_; }
926
927 // Get the CFields container (non-const).
928 template <int D, class T> inline
929 typename T::CFields & System<D,T>::c_()
930 { return *cPtr_; }
931
932} // namespace Rp
933} // namespace Pscf
934#endif
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
T::Simulator const & simulator() const
Get the Simulator (const).
void simulate(int nStep)
Perform a field theoretic simulation (PS-FTS).
T::Mixture const & mixture() const
Get the Mixture (const).
T::WFields const & w() const
Get the chemical potential (w) fields (const).
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
T::Interaction const & interaction() const
Get the Interaction (const).
T::Domain const & domain() const
Get the Domain (const).
bool hasSimulator() const
Does this system have a Simulator?
void computeStress()
Compute SCFT stress.
T::CFields const & c() const
Get the monomer concentration (c) fields (const).
T::WaveList & waveList()
Get the WaveList (non-const).
bool hasEnvironment() const
Does this system have an Environment?
FileMaster const & fileMaster() const
Get the FileMaster (const).
virtual void setThreadCount(int nThread)
Set the number of threads given as a command line argument.
bool hasSweep() const
Does this system have a Sweep?
void readCommands()
Read and process commands from the default command file.
T::ScftThermo const & scft() const
Get the ScftThermo object (const).
T::Iterator const & iterator() const
Get the Iterator (const).
void clearUnitCellData()
Notify System members that unit cell parameters have been modified.
void clearCFields()
Mark c-fields and free energy as outdated or invalid.
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
T::Environment const & environment() const
Get the Environment (const).
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
void readParam()
Read input parameters from default param file.
void clearTimers()
Clear all timers.
T::Mask const & mask() const
Get the mask (const).
T::MixtureModifier & mixtureModifier()
Get the MixtureModifier (non-const).
bool hasIterator() const
Does this system have an Iterator?
void writeParamNoSweep(std::ostream &out) const
Write partial parameter file to an ostream.
void writeTimers(std::ostream &out) const
Write timer information to an output stream.
T::WFields const & h() const
Get the external potential (h) fields (const).
void setOptions(int argc, char **argv)
Process command line options.
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.
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.