PSCF v1.3.3
SystemTmpl.h
1#ifndef PRDC_SYSTEM_TMPL_H
2#define PRDC_SYSTEM_TMPL_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 Prdc {
27
28 // Namespace that may be used implicitly
29 using namespace Util;
30
101 template <int D, class T>
103 {
104
105 public:
106
107 // Public type name aliases
108 using MixtureT = typename T::Mixture;
109 using InteractionT = typename T::Interaction;
110 using DomainT = typename T::Domain;
111 using WFieldsT = typename T::WFields;
112 using CFieldsT = typename T::CFields;
113 using MaskT = typename T::Mask;
114 using RFieldT = typename T::RField;
115
118
135 SystemTmpl(typename T::System& system);
136
140 ~SystemTmpl();
141
142 // Suppress compiler-generated member functions
143 SystemTmpl() = delete;
144 SystemTmpl(SystemTmpl<D,T> const &) = delete;
145 SystemTmpl<D,T>& operator = (SystemTmpl<D,T> const & ) = delete;
146
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
191 void readCommands(std::istream& in);
192
199 void readCommands();
200
204
228 void compute(bool needStress = false);
229
241 void computeStress();
242
264 int iterate(bool isContinuation = false);
265
278 void sweep();
279
295 void simulate(int nStep);
296
307 void clearCFields();
308
312
325 void setUnitCell(UnitCell<D> const & unitCell);
326
340 void setUnitCell(FSArray<double, 6> const & parameters);
341
350 void clearUnitCellData();
351
355
359 typename T::CFields const & c() const;
360
364 typename T::WFields& w();
365
369 typename T::WFields const & w() const;
370
374 typename T::WFields& h();
375
379 typename T::WFields const & h() const;
380
384 typename T::Mask& mask();
385
389 typename T::Mask const & mask() const;
390
394
398 typename T::Mixture const & mixture() const;
399
403 typename T::MixtureModifier& mixtureModifier();
404
408 typename T::Interaction& interaction();
409
413 typename T::Interaction const & interaction() const;
414
418 typename T::Domain const & domain() const;
419
423 bool hasEnvironment() const;
424
428 typename T::Environment& environment();
429
433 typename T::Environment const & environment() const;
434
438 typename T::ScftThermo& scft();
439
443 typename T::ScftThermo const & scft() const;
444
448 bool hasIterator() const;
449
453 typename T::Iterator& iterator();
454
458 typename T::Iterator const & iterator() const;
459
463 bool hasSweep() const;
464
468 bool hasSimulator() const;
469
473 typename T::Simulator& simulator();
474
478 typename T::Simulator const & simulator() const;
479
486
490 FileMaster const & fileMaster() const;
491
495
508 void writeParamNoSweep(std::ostream& out) const;
509
513
519 void writeTimers(std::ostream& out) const;
520
524 void clearTimers();
525
527
528 protected:
529
545 virtual void setThreadCount(int nThread)
546 {};
547
548 private:
549
550 // Component objects
551
555 typename T::WFields w_;
556
560 typename T::CFields c_;
561
565 typename T::WFields h_;
566
570 typename T::Mask mask_;
571
572 // Pointers to associated objects
573
577 typename T::System* systemPtr_;
578
582 typename T::Mixture* mixturePtr_;
583
587 typename T::MixtureModifier* mixtureModifierPtr_;
588
592 typename T::Domain* domainPtr_;
593
597 typename T::Interaction* interactionPtr_;
598
602 typename T::Environment* environmentPtr_;
603
607 typename T::EnvironmentFactory* environmentFactoryPtr_;
608
612 typename T::ScftThermo* scftPtr_;
613
617 typename T::Iterator* iteratorPtr_;
618
622 typename T::IteratorFactory* iteratorFactoryPtr_;
623
627 typename T::Sweep* sweepPtr_;
628
632 typename T::SweepFactory* sweepFactoryPtr_;
633
637 typename T::Simulator* simulatorPtr_;
638
642 typename T::SimulatorFactory* simulatorFactoryPtr_;
643
647 FileMaster* fileMasterPtr_;
648
652 UnitCell<D>* tmpUnitCellPtr_;
653
657 PolymerModel::Type polymerModel_;
658
659 // Boolean state variables
660
664 bool isAllocatedGrid_;
665
669 bool isAllocatedBasis_;
670
674 bool hasMixture_;
675
676 #if 0
677 // Mutable work space
678
679 mutable UnitCell<D> tmpUnitCell_;
680 #endif
681
682 // Private member functions
683
687 typename T::Mixture & mixture_();
688
692 typename T::Domain& domain_();
693
697 void allocateFieldsGrid();
698
702 void allocateFieldsBasis();
703
712 void readEcho(std::istream& in, std::string& string) const;
713
722 void readEcho(std::istream& in, double& value) const;
723
724 };
725
726 // Inline member functions
727
728 // Get the Mixture (const).
729 template <int D, class T> inline
730 typename T::Mixture const & SystemTmpl<D,T>::mixture() const
731 { return *mixturePtr_; }
732
733 // Get the MixtureModifier (non-const).
734 template <int D, class T> inline
735 typename T::MixtureModifier& SystemTmpl<D,T>::mixtureModifier()
736 {
737 UTIL_ASSERT(mixtureModifierPtr_);
738 return *mixtureModifierPtr_;
739 }
740
741 // Get the %Interaction (non-const).
742 template <int D, class T> inline
743 typename T::Interaction& SystemTmpl<D,T>::interaction()
744 {
745 UTIL_ASSERT(interactionPtr_);
746 return *interactionPtr_;
747 }
748
749 // Get the %Interaction (const).
750 template <int D, class T> inline
751 typename T::Interaction const & SystemTmpl<D,T>::interaction() const
752 {
753 UTIL_ASSERT(interactionPtr_);
754 return *interactionPtr_;
755 }
756
757 // Get the Domain (const).
758 template <int D, class T> inline
759 typename T::Domain const & SystemTmpl<D,T>::domain() const
760 { return *domainPtr_; }
761
762 // Does this system have an %Environment?
763 template <int D, class T> inline
765 { return (environmentPtr_); }
766
767 // Get the %Environment (non-const).
768 template <int D, class T> inline
769 typename T::Environment & SystemTmpl<D,T>::environment()
770 {
771 UTIL_ASSERT(environmentPtr_);
772 return *environmentPtr_;
773 }
774
775 // Get the %Environment (const).
776 template <int D, class T> inline
777 typename T::Environment const & SystemTmpl<D,T>::environment() const
778 {
779 UTIL_ASSERT(environmentPtr_);
780 return *environmentPtr_;
781 }
782
783 // Get the Scft calculator (non-const).
784 template <int D, class T> inline
785 typename T::ScftThermo & SystemTmpl<D,T>::scft()
786 {
787 UTIL_ASSERT(scftPtr_);
788 return *scftPtr_;
789 }
790
791 // Get the Scft calculator (const).
792 template <int D, class T> inline
793 typename T::ScftThermo const & SystemTmpl<D,T>::scft() const
794 {
795 UTIL_ASSERT(scftPtr_);
796 return *scftPtr_;
797 }
798
799 // Does this system have an Iterator?
800 template <int D, class T> inline
802 { return (iteratorPtr_); }
803
804 // Get the Iterator (non-const).
805 template <int D, class T> inline
806 typename T::Iterator& SystemTmpl<D,T>::iterator()
807 {
808 UTIL_ASSERT(iteratorPtr_);
809 return *iteratorPtr_;
810 }
811
812 // Get the Iterator (const).
813 template <int D, class T> inline
814 typename T::Iterator const & SystemTmpl<D,T>::iterator() const
815 {
816 UTIL_ASSERT(iteratorPtr_);
817 return *iteratorPtr_;
818 }
819
820 // Does this system have a Sweep?
821 template <int D, class T> inline
823 { return (sweepPtr_); }
824
825 // Does this system have a Simulator?
826 template <int D, class T> inline
828 { return (simulatorPtr_); }
829
830 // Get the Simulator (non-const).
831 template <int D, class T> inline
832 typename T::Simulator& SystemTmpl<D,T>::simulator()
833 {
834 UTIL_ASSERT(simulatorPtr_);
835 return *simulatorPtr_;
836 }
837
838 // Get the Simulator (const).
839 template <int D, class T> inline
840 typename T::Simulator const & SystemTmpl<D,T>::simulator() const
841 {
842 UTIL_ASSERT(simulatorPtr_);
843 return *simulatorPtr_;
844 }
845
846 // Get the FileMaster (non-const).
847 template <int D, class T> inline
849 { return *fileMasterPtr_; }
850
851 // Get the FileMaster (const).
852 template <int D, class T> inline
854 { return *fileMasterPtr_; }
855
856 // Get the container of c fields (const).
857 template <int D, class T> inline
858 typename T::CFields const & SystemTmpl<D,T>::c() const
859 { return c_; }
860
861 // Get the container of w fields (non-const).
862 template <int D, class T> inline
863 typename T::WFields& SystemTmpl<D,T>::w()
864 { return w_; }
865
866 // Get the container of w fields (const).
867 template <int D, class T> inline
868 typename T::WFields const & SystemTmpl<D,T>::w() const
869 { return w_; }
870
871 // Get the container of external fields (non-const).
872 template <int D, class T> inline
873 typename T::WFields& SystemTmpl<D,T>::h()
874 { return h_; }
875
876 // Get the container of external fields (const).
877 template <int D, class T> inline
878 typename T::WFields const & SystemTmpl<D,T>::h() const
879 { return h_; }
880
881 // Get the mask field (non-const).
882 template <int D, class T> inline
883 typename T::Mask& SystemTmpl<D,T>::mask()
884 { return mask_; }
885
886 // Get the mask field (const).
887 template <int D, class T> inline
888 typename T::Mask const & SystemTmpl<D,T>::mask() const
889 { return mask_; }
890
891 // Private inline functions:
892
893 // Get the Mixture (non-const).
894 template <int D, class T> inline
895 typename T::Mixture & SystemTmpl<D,T>::mixture_()
896 { return *mixturePtr_; }
897
898 // Get the Domain (non-const).
899 template <int D, class T> inline
900 typename T::Domain & SystemTmpl<D,T>::domain_()
901 { return *domainPtr_; }
902
903} // namespace Prdc
904} // namespace Pscf
905#endif
T::Domain const & domain() const
Get the Domain (const).
Definition SystemTmpl.h:759
T::Mask & mask()
Get the mask (non-const).
Definition SystemTmpl.h:883
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
void computeStress()
Compute SCFT stress.
bool hasIterator() const
Does this system have an Iterator?
Definition SystemTmpl.h:801
T::Simulator & simulator()
Get the Simulator (non-const).
Definition SystemTmpl.h:832
T::Interaction & interaction()
Get the Interaction (non-const).
Definition SystemTmpl.h:743
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
T::Environment & environment()
Get the Environment (non-const).
Definition SystemTmpl.h:769
T::ScftThermo & scft()
Get the ScftThermo object (non-const).
Definition SystemTmpl.h:785
void clearCFields()
Mark c-fields and free energy as outdated or invalid.
void readParam()
Read input parameters from default param file.
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
T::WFields & w()
Get the chemical potential (w) fields (non-const).
Definition SystemTmpl.h:863
void setOptions(int argc, char **argv)
Process command line options.
void simulate(int nStep)
Perform a field theoretic simulation (PS-FTS).
T::MixtureModifier & mixtureModifier()
Get the MixtureModifier (non-const).
Definition SystemTmpl.h:735
bool hasSimulator() const
Does this system have a Simulator?
Definition SystemTmpl.h:827
bool hasSweep() const
Does this system have a Sweep?
Definition SystemTmpl.h:822
T::Mixture const & mixture() const
Get the Mixture (const).
Definition SystemTmpl.h:730
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
T::Iterator & iterator()
Get the Iterator (non-const).
Definition SystemTmpl.h:806
void writeTimers(std::ostream &out) const
Write timer information to an output stream.
void clearTimers()
Clear timers.
void readCommands()
Read and process commands from the default command file.
virtual void setThreadCount(int nThread)
Set the number of threads given as a command line argument.
Definition SystemTmpl.h:545
T::CFields const & c() const
Get the monomer concentration (c) fields (const).
Definition SystemTmpl.h:858
void writeParamNoSweep(std::ostream &out) const
Write partial parameter file to an ostream.
bool hasEnvironment() const
Does this system have an Environment?
Definition SystemTmpl.h:764
void clearUnitCellData()
Notify System members that unit cell parameters have been modified.
SystemTmpl(typename T::System &system)
Constructor.
FileMaster & fileMaster()
Get the FileMaster (non-const).
Definition SystemTmpl.h:848
T::WFields & h()
Get the external potential (h) fields (non-const).
Definition SystemTmpl.h:873
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
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 CField.cpp:11
PSCF package top-level namespace.
Utility classes for scientific computation.