PSCF v1.3.1
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// Header file includes
12#include <util/param/ParamComposite.h> // base class
13
14#include <prdc/crystal/UnitCell.h> // member
15#include <pscf/chem/PolymerModel.h> // member
16#include <util/misc/FileMaster.h> // member
17
18// Forward declarations
19namespace Util {
20 template <typename E, int N> class FSArray;
21}
22
23namespace Pscf {
24namespace Prdc {
25
26 // Namespace that may be used implicitly
27 using namespace Util;
28
99 template <int D, class T>
101 {
102
103 public:
104
105 // Public type name aliases
106 using MixtureT = typename T::Mixture;
107 using InteractionT = typename T::Interaction;
108 using DomainT = typename T::Domain;
109 using WFieldsT = typename T::WFields;
110 using CFieldsT = typename T::CFields;
111 using MaskT = typename T::Mask;
112 using RFieldT = typename T::RField;
113
116
133 SystemTmpl(typename T::System& system);
134
138 ~SystemTmpl();
139
140 // Suppress compiler-generated member functions
141 SystemTmpl() = delete;
142 SystemTmpl(SystemTmpl<D,T> const &) = delete;
143 SystemTmpl<D,T>& operator = (SystemTmpl<D,T> const & ) = delete;
144
148
160 void setOptions(int argc, char **argv);
161
167 virtual void readParam(std::istream& in);
168
175 void readParam();
176
182 virtual void readParameters(std::istream& in);
183
189 void readCommands(std::istream& in);
190
197 void readCommands();
198
202
226 void compute(bool needStress = false);
227
239 void computeStress();
240
262 int iterate(bool isContinuation = false);
263
276 void sweep();
277
293 void simulate(int nStep);
294
305 void clearCFields();
306
310
323 void setUnitCell(UnitCell<D> const & unitCell);
324
338 void setUnitCell(FSArray<double, 6> const & parameters);
339
348 void clearUnitCellData();
349
353
357 typename T::CFields const & c() const;
358
362 typename T::WFields& w();
363
367 typename T::WFields const & w() const;
368
372 typename T::WFields& h();
373
377 typename T::WFields const & h() const;
378
382 typename T::Mask& mask();
383
387 typename T::Mask const & mask() const;
388
392
396 typename T::Mixture const & mixture() const;
397
401 typename T::MixtureModifier& mixtureModifier();
402
406 typename T::Interaction& interaction();
407
411 typename T::Interaction const & interaction() const;
412
416 typename T::Domain const & domain() const;
417
421 bool hasEnvironment() const;
422
426 typename T::Environment& environment();
427
431 typename T::Environment const & environment() const;
432
436 typename T::ScftThermo& scft();
437
441 typename T::ScftThermo const & scft() const;
442
446 bool hasIterator() const;
447
451 typename T::Iterator& iterator();
452
456 typename T::Iterator const & iterator() const;
457
461 bool hasSweep() const;
462
466 bool hasSimulator() const;
467
471 typename T::Simulator& simulator();
472
476 typename T::Simulator const & simulator() const;
477
484
488 FileMaster const & fileMaster() const;
489
493
506 void writeParamNoSweep(std::ostream& out) const;
507
511
517 void writeTimers(std::ostream& out) const;
518
522 void clearTimers();
523
525
526 protected:
527
543 virtual void setThreadCount(int nThread)
544 {};
545
546 private:
547
548 // Component objects
549
553 typename T::Mixture mixture_;
554
558 typename T::Domain domain_;
559
563 FileMaster fileMaster_;
564
568 typename T::WFields w_;
569
573 typename T::CFields c_;
574
578 typename T::WFields h_;
579
583 typename T::Mask mask_;
584
585 // Pointers to dynamic objects owned by this SystemTmpl
586
590 typename T::MixtureModifier* mixtureModifierPtr_;
591
595 typename T::Interaction* interactionPtr_;
596
600 typename T::Environment* environmentPtr_;
601
605 typename T::EnvironmentFactory* environmentFactoryPtr_;
606
610 typename T::ScftThermo* scftPtr_;
611
615 typename T::Iterator* iteratorPtr_;
616
620 typename T::IteratorFactory* iteratorFactoryPtr_;
621
625 typename T::Sweep* sweepPtr_;
626
630 typename T::SweepFactory* sweepFactoryPtr_;
631
635 typename T::Simulator* simulatorPtr_;
636
640 typename T::SimulatorFactory* simulatorFactoryPtr_;
641
645 typename T::System* systemPtr_;
646
650 PolymerModel::Type polymerModel_;
651
652 // Boolean state variables
653
657 bool isAllocatedGrid_;
658
662 bool isAllocatedBasis_;
663
667 bool hasMixture_;
668
669 // Mutable work space
670
671 mutable UnitCell<D> tmpUnitCell_;
672
673 // Private member functions
674
678 void allocateFieldsGrid();
679
683 void allocateFieldsBasis();
684
693 void readEcho(std::istream& in, std::string& string) const;
694
703 void readEcho(std::istream& in, double& value) const;
704
705 };
706
707 // Inline member functions
708
709 // Get the Mixture (const).
710 template <int D, class T> inline
711 typename T::Mixture const & SystemTmpl<D,T>::mixture() const
712 { return mixture_; }
713
714 // Get the MixtureModifier (non-const).
715 template <int D, class T> inline
716 typename T::MixtureModifier& SystemTmpl<D,T>::mixtureModifier()
717 {
718 UTIL_ASSERT(mixtureModifierPtr_);
719 return *mixtureModifierPtr_;
720 }
721
722 // Get the %Interaction (non-const).
723 template <int D, class T> inline
724 typename T::Interaction& SystemTmpl<D,T>::interaction()
725 {
726 UTIL_ASSERT(interactionPtr_);
727 return *interactionPtr_;
728 }
729
730 // Get the %Interaction (const).
731 template <int D, class T> inline
732 typename T::Interaction const & SystemTmpl<D,T>::interaction() const
733 {
734 UTIL_ASSERT(interactionPtr_);
735 return *interactionPtr_;
736 }
737
738 // Get the Domain (const).
739 template <int D, class T> inline
740 typename T::Domain const & SystemTmpl<D,T>::domain() const
741 { return domain_; }
742
743 // Does this system have an %Environment?
744 template <int D, class T> inline
746 { return (environmentPtr_); }
747
748 // Get the %Environment (non-const).
749 template <int D, class T> inline
750 typename T::Environment & SystemTmpl<D,T>::environment()
751 {
752 UTIL_ASSERT(environmentPtr_);
753 return *environmentPtr_;
754 }
755
756 // Get the %Environment (const).
757 template <int D, class T> inline
758 typename T::Environment const & SystemTmpl<D,T>::environment() const
759 {
760 UTIL_ASSERT(environmentPtr_);
761 return *environmentPtr_;
762 }
763
764 // Get the Scft calculator (non-const).
765 template <int D, class T> inline
766 typename T::ScftThermo & SystemTmpl<D,T>::scft()
767 {
768 UTIL_ASSERT(scftPtr_);
769 return *scftPtr_;
770 }
771
772 // Get the Scft calculator (const).
773 template <int D, class T> inline
774 typename T::ScftThermo const & SystemTmpl<D,T>::scft() const
775 {
776 UTIL_ASSERT(scftPtr_);
777 return *scftPtr_;
778 }
779
780 // Does this system have an Iterator?
781 template <int D, class T> inline
783 { return (iteratorPtr_); }
784
785 // Get the Iterator (non-const).
786 template <int D, class T> inline
787 typename T::Iterator& SystemTmpl<D,T>::iterator()
788 {
789 UTIL_ASSERT(iteratorPtr_);
790 return *iteratorPtr_;
791 }
792
793 // Get the Iterator (const).
794 template <int D, class T> inline
795 typename T::Iterator const & SystemTmpl<D,T>::iterator() const
796 {
797 UTIL_ASSERT(iteratorPtr_);
798 return *iteratorPtr_;
799 }
800
801 // Does this system have a Sweep?
802 template <int D, class T> inline
804 { return (sweepPtr_); }
805
806 // Does this system have a Simulator?
807 template <int D, class T> inline
809 { return (simulatorPtr_); }
810
811 // Get the Simulator (non-const).
812 template <int D, class T> inline
813 typename T::Simulator& SystemTmpl<D,T>::simulator()
814 {
815 UTIL_ASSERT(simulatorPtr_);
816 return *simulatorPtr_;
817 }
818
819 // Get the Simulator (const).
820 template <int D, class T> inline
821 typename T::Simulator const & SystemTmpl<D,T>::simulator() const
822 {
823 UTIL_ASSERT(simulatorPtr_);
824 return *simulatorPtr_;
825 }
826
827 // Get the FileMaster (non-const).
828 template <int D, class T> inline
830 { return fileMaster_; }
831
832 // Get the FileMaster (const).
833 template <int D, class T> inline
835 { return fileMaster_; }
836
837 // Get the container of c fields (const).
838 template <int D, class T> inline
839 typename T::CFields const & SystemTmpl<D,T>::c() const
840 { return c_; }
841
842 // Get the container of w fields (non-const).
843 template <int D, class T> inline
844 typename T::WFields& SystemTmpl<D,T>::w()
845 { return w_; }
846
847 // Get the container of w fields (const).
848 template <int D, class T> inline
849 typename T::WFields const & SystemTmpl<D,T>::w() const
850 { return w_; }
851
852 // Get the container of external fields (non-const).
853 template <int D, class T> inline
854 typename T::WFields& SystemTmpl<D,T>::h()
855 { return h_; }
856
857 // Get the container of external fields (const).
858 template <int D, class T> inline
859 typename T::WFields const & SystemTmpl<D,T>::h() const
860 { return h_; }
861
862 // Get the mask field (non-const).
863 template <int D, class T> inline
864 typename T::Mask& SystemTmpl<D,T>::mask()
865 { return mask_; }
866
867 // Get the mask field (const).
868 template <int D, class T> inline
869 typename T::Mask const & SystemTmpl<D,T>::mask() const
870 { return mask_; }
871
872} // namespace Prdc
873} // namespace Pscf
874#endif
T::Domain const & domain() const
Get the Domain (const).
Definition SystemTmpl.h:740
T::Mask & mask()
Get the mask (non-const).
Definition SystemTmpl.h:864
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:782
T::Simulator & simulator()
Get the Simulator (non-const).
Definition SystemTmpl.h:813
T::Interaction & interaction()
Get the Interaction (non-const).
Definition SystemTmpl.h:724
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:750
T::ScftThermo & scft()
Get the ScftThermo object (non-const).
Definition SystemTmpl.h:766
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:844
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:716
bool hasSimulator() const
Does this system have a Simulator?
Definition SystemTmpl.h:808
bool hasSweep() const
Does this system have a Sweep?
Definition SystemTmpl.h:803
T::Mixture const & mixture() const
Get the Mixture (const).
Definition SystemTmpl.h:711
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
T::Iterator & iterator()
Get the Iterator (non-const).
Definition SystemTmpl.h:787
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:543
T::CFields const & c() const
Get the monomer concentration (c) fields (const).
Definition SystemTmpl.h:839
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:745
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:829
T::WFields & h()
Get the external potential (h) fields (non-const).
Definition SystemTmpl.h:854
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.
Definition param_pc.dox:1
Utility classes for scientific computation.