PSCF v1.3
rpc/system/System.h
1#ifndef RPC_SYSTEM_H
2#define RPC_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// Header file includes
12#include <util/param/ParamComposite.h> // base class
13#include <rpc/solvers/Mixture.h> // member
14#include <rpc/field/Domain.h> // member
15#include <rpc/field/WFieldContainer.h> // member
16#include <rpc/field/CFieldContainer.h> // member
17#include <rpc/field/Mask.h> // member
18#include <prdc/crystal/UnitCell.h> // member
19#include <pscf/chem/PolymerModel.h> // member
20#include <util/misc/FileMaster.h> // member
21
22// Forward declarations
23namespace Util {
24 template <typename T, int N> class FSArray;
25}
26namespace Pscf {
27 class Interaction;
28 namespace Prdc {
29 class Environment;
30 namespace Cpu {
31 template <int D> class RField;
32 }
33 }
34 namespace Rpc {
35 template <int D> class MixtureModifier;
36 template <int D> class EnvironmentFactory;
37 template <int D> class ScftThermo;
38 template <int D> class Iterator;
39 template <int D> class IteratorFactory;
40 template <int D> class Sweep;
41 template <int D> class SweepFactory;
42 template <int D> class Simulator;
43 template <int D> class SimulatorFactory;
44 }
45}
46
47namespace Pscf {
48namespace Rpc {
49
50 // Namespaces that may be used implicitly
51 using namespace Util;
52 using namespace Prdc;
53 using namespace Prdc::Cpu;
54
102 template <int D>
103 class System : public ParamComposite
104 {
105
106 public:
107
108 // Public type name aliases
109 using MixtureT = Mixture<D>;
110 using InteractionT = Interaction;
111 using DomainT = Domain<D>;
112 using WFieldContainerT = WFieldContainer<D>;
113 using CFieldContainerT = CFieldContainer<D>;
114 using MaskT = Mask<D>;
115 using FieldT = RField<D>;
116
119
123 System();
124
128 ~System();
129
133
145 void setOptions(int argc, char **argv);
146
152 virtual void readParam(std::istream& in);
153
160 void readParam();
161
167 virtual void readParameters(std::istream& in);
168
174 void readCommands(std::istream& in);
175
182 void readCommands();
183
187
211 void compute(bool needStress = false);
212
223 void computeStress();
224
246 int iterate(bool isContinuation = false);
247
260 void sweep();
261
277 void simulate(int nStep);
278
289 void clearCFields();
290
294
308 void setUnitCell(UnitCell<D> const & unitCell);
309
323 void setUnitCell(FSArray<double, 6> const & parameters);
324
333 void clearUnitCellData();
334
338
342 CFieldContainer<D> const & c() const;
343
348
352 WFieldContainer<D> const & w() const;
353
358
362 WFieldContainer<D> const & h() const;
363
367 Mask<D>& mask();
368
372 Mask<D> const & mask() const;
373
377
381 Mixture<D> const & mixture() const;
382
387
392
396 Interaction const & interaction() const;
397
401 Domain<D> const & domain() const;
402
406 bool hasEnvironment() const;
407
412
416 Environment const & environment() const;
417
422
426 ScftThermo<D> const & scft() const;
427
431 bool hasIterator() const;
432
437
441 Iterator<D> const & iterator() const;
442
446 bool hasSweep() const;
447
451 bool hasSimulator() const;
452
457
461 Simulator<D> const & simulator() const;
462
469
473 FileMaster const & fileMaster() const;
474
478
491 void writeParamNoSweep(std::ostream& out) const;
492
496
502 void writeTimers(std::ostream& out) const;
503
507 void clearTimers();
508
510
511 private:
512
513 // Component objects
514
518 Mixture<D> mixture_;
519
523 Domain<D> domain_;
524
528 FileMaster fileMaster_;
529
534
539
544
548 Mask<D> mask_;
549
550 // Pointers to dynamic objects owned by this System
551
555 MixtureModifier<D>* mixtureModifierPtr_;
556
560 Interaction* interactionPtr_;
561
565 Environment* environmentPtr_;
566
570 EnvironmentFactory<D>* environmentFactoryPtr_;
571
575 ScftThermo<D>* scftPtr_;
576
580 Iterator<D>* iteratorPtr_;
581
585 IteratorFactory<D>* iteratorFactoryPtr_;
586
590 Sweep<D>* sweepPtr_;
591
595 SweepFactory<D>* sweepFactoryPtr_;
596
600 Simulator<D>* simulatorPtr_;
601
605 SimulatorFactory<D>* simulatorFactoryPtr_;
606
610 PolymerModel::Type polymerModel_;
611
612 // Boolean state variables
613
617 bool isAllocatedGrid_;
618
622 bool isAllocatedBasis_;
623
627 bool hasMixture_;
628
629 // Mutable work space
630
631 mutable UnitCell<D> tmpUnitCell_;
632
633 // Private member functions
634
638 void allocateFieldsGrid();
639
643 void allocateFieldsBasis();
644
653 void readEcho(std::istream& in, std::string& string) const;
654
663 void readEcho(std::istream& in, double& value) const;
664
665 };
666
667 // Inline member functions
668
669 // Get the Mixture (const).
670 template <int D>
671 inline Mixture<D> const & System<D>::mixture() const
672 { return mixture_; }
673
674 // Get the MixtureModifier (non-const).
675 template <int D>
677 {
678 UTIL_ASSERT(mixtureModifierPtr_);
679 return *mixtureModifierPtr_;
680 }
681
682 // Get the Interaction (non-const).
683 template <int D>
685 {
686 UTIL_ASSERT(interactionPtr_);
687 return *interactionPtr_;
688 }
689
690 // Get the Interaction (const).
691 template <int D>
692 inline Interaction const & System<D>::interaction() const
693 {
694 UTIL_ASSERT(interactionPtr_);
695 return *interactionPtr_;
696 }
697
698 // Get the Domain (const).
699 template <int D>
700 inline Domain<D> const & System<D>::domain() const
701 { return domain_; }
702
703 // Does this system have an Environment?
704 template <int D>
705 inline bool System<D>::hasEnvironment() const
706 { return (environmentPtr_); }
707
708 // Get the Environment (non-const).
709 template <int D>
711 {
712 UTIL_ASSERT(environmentPtr_);
713 return *environmentPtr_;
714 }
715
716 // Get the Environment (const).
717 template <int D>
718 inline Environment const & System<D>::environment() const
719 {
720 UTIL_ASSERT(environmentPtr_);
721 return *environmentPtr_;
722 }
723
724 // Get the Scft calculator (non-const).
725 template <int D>
727 {
728 UTIL_ASSERT(scftPtr_);
729 return *scftPtr_;
730 }
731
732 // Get the Scft calculator (const).
733 template <int D>
734 inline ScftThermo<D> const & System<D>::scft() const
735 {
736 UTIL_ASSERT(scftPtr_);
737 return *scftPtr_;
738 }
739
740 // Does this system have an Iterator?
741 template <int D>
742 inline bool System<D>::hasIterator() const
743 { return (iteratorPtr_); }
744
745 // Get the Iterator (non-const).
746 template <int D>
748 {
749 UTIL_ASSERT(iteratorPtr_);
750 return *iteratorPtr_;
751 }
752
753 // Get the Iterator (const).
754 template <int D>
755 inline Iterator<D> const & System<D>::iterator() const
756 {
757 UTIL_ASSERT(iteratorPtr_);
758 return *iteratorPtr_;
759 }
760
761 // Does this system have a Sweep?
762 template <int D>
763 inline bool System<D>::hasSweep() const
764 { return (sweepPtr_); }
765
766 // Does this system have a Simulator?
767 template <int D>
768 inline bool System<D>::hasSimulator() const
769 { return (simulatorPtr_); }
770
771 // Get the Simulator (non-const).
772 template <int D>
774 {
775 UTIL_ASSERT(simulatorPtr_);
776 return *simulatorPtr_;
777 }
778
779 // Get the Simulator (const).
780 template <int D>
781 inline Simulator<D> const & System<D>::simulator() const
782 {
783 UTIL_ASSERT(simulatorPtr_);
784 return *simulatorPtr_;
785 }
786
787 // Get the FileMaster (non-const).
788 template <int D>
790 { return fileMaster_; }
791
792 // Get the FileMaster (const).
793 template <int D>
794 inline FileMaster const & System<D>::fileMaster() const
795 { return fileMaster_; }
796
797 // Get the container of c fields (const).
798 template <int D>
799 inline
801 { return c_; }
802
803 // Get the container of w fields (non-const).
804 template <int D>
805 inline
807 { return w_; }
808
809 // Get the container of w fields (const).
810 template <int D>
811 inline
813 { return w_; }
814
815 // Get the container of external fields (non-const).
816 template <int D>
818 { return h_; }
819
820 // Get the container of external fields (const).
821 template <int D>
822 inline WFieldContainer<D> const & System<D>::h() const
823 { return h_; }
824
825 // Get the mask field (non-const).
826 template <int D>
828 { return mask_; }
829
830 // Get the mask field (const).
831 template <int D>
832 inline Mask<D> const & System<D>::mask() const
833 { return mask_; }
834
835 #ifndef RPC_SYSTEM_TPP
836 // Suppress implicit instantiation
837 extern template class System<1>;
838 extern template class System<2>;
839 extern template class System<3>;
840 #endif
841
842} // namespace Rpc
843} // namespace Pscf
844#endif
Flory-Huggins excess free energy model.
Definition Interaction.h:26
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
Base class mask and external field generator for variable-cell SCFT.
Definition Environment.h:59
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
A list of c fields stored in both basis and r-grid format.
Spatial domain for a periodic structure with real fields, on a CPU.
Factory for subclasses of Environment.
Factory for subclasses of Iterator.
Base class for iterative solvers for SCF equations.
A field to which the total density is constrained.
Parameter modifier for an associated Mixture.
Solver and descriptor for a mixture of polymers and solvents.
Computes SCFT free energies.
Factory for subclasses of Simulator.
Field theoretic simulator (base class).
Default Factory for subclasses of Sweep.
Solve a sequence of SCFT problems along a line in parameter space.
Main class, representing one complete system.
Mask< D > & mask()
Get the mask (non-const).
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
void clearCFields()
Mark c-fields and free energy as outdated or invalid.
void setOptions(int argc, char **argv)
Process command line options.
Simulator< D > & simulator()
Get the Simulator (non-const).
void writeTimers(std::ostream &out) const
Write timer information to an output stream.
void readCommands()
Read and process commands from the default command file.
void simulate(int nStep)
Perform a field theoretic simulation (PS-FTS).
MixtureModifier< D > & mixtureModifier()
Get the MixtureModifier (non-const).
Iterator< D > & iterator()
Get the Iterator (non-const).
FileMaster & fileMaster()
Get the FileMaster (non-const).
bool hasIterator() const
Does this system have an Iterator?
ScftThermo< D > & scft()
Get the ScftThermo object (non-const).
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
CFieldContainer< D > const & c() const
Get the monomer concentration (c) fields (const).
void clearTimers()
Clear timers.
bool hasSimulator() const
Does this system have a Simulator?
WFieldContainer< D > & w()
Get the chemical potential (w) fields (non-const).
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
void writeParamNoSweep(std::ostream &out) const
Write partial parameter file to an ostream.
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
void computeStress()
Compute SCFT stress.
bool hasSweep() const
Does this system have a Sweep?
void clearUnitCellData()
Notify System members that unit cell parameters have been modified.
bool hasEnvironment() const
Does this system have an Environment?
Environment & environment()
Get the Environment (non-const).
Domain< D > const & domain() const
Get the Domain (const).
void readParam()
Read input parameters from default param file.
WFieldContainer< D > & h()
Get the external potential (h) fields (non-const).
Interaction & interaction()
Get the Interaction (non-const).
Mixture< D > const & mixture() const
Get the Mixture (const).
A container of fields stored in both basis and r-grid format.
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.
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.