PSCF v1.3.3
rpg/scft/iterator/Iterator.tpp
1#ifndef RPG_ITERATOR_TPP
2#define RPG_ITERATOR_TPP
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 "Iterator.h"
12
13#include <prdc/environment/Environment.h>
14#include <rpg/system/System.h>
15#include <rpg/solvers/Mixture.h>
16#include <rpg/field/Domain.h>
17
18namespace Pscf {
19namespace Rpg {
20
21 template <int D> class System;
22
23 using namespace Util;
24 using namespace Prdc;
25
26 /*
27 * Default constructor.
28 */
29 template<int D>
31 : isSymmetric_(false),
32 isFlexible_(false),
33 sysPtr_(nullptr)
34 { setClassName("Iterator"); }
35
36 /*
37 * Constructor.
38 */
39 template<int D>
41 : isSymmetric_(false),
42 isFlexible_(false),
43 sysPtr_(&system)
44 { setClassName("Iterator"); }
45
46 /*
47 * Destructor.
48 */
49 template<int D>
52
53 /*
54 * Does this iterator use a symmetry-adapted Fourier basis?
55 */
56 template<int D>
57 inline bool Iterator<D>::isSymmetric() const
58 { return isSymmetric_; }
59
60 /*
61 * Is the unit cell flexible (true) or rigid (false) ?
62 */
63 template<int D>
64 inline bool Iterator<D>::isFlexible() const
65 { return isFlexible_; }
66
67 /*
68 * Get the array indicating which lattice parameters are flexible.
69 */
70 template<int D>
73
74 /*
75 * Get the number of flexible lattice parameters.
76 */
77 template <int D>
79 {
81 system().domain().unitCell().nParameter());
82 int nFlexParams = 0;
83 for (int i = 0; i < flexibleParams_.size(); i++) {
84 if (flexibleParams_[i]) nFlexParams++;
85 }
86 return nFlexParams;
87 }
88
89 /*
90 * Set the array indicating which lattice parameters are flexible.
91 */
92 template <int D>
94 {
95 flexibleParams_ = flexParams;
96 if (nFlexibleParams() == 0) {
97 isFlexible_ = false;
98 } else {
99 isFlexible_ = true;
100 }
101 }
102
103 /*
104 * Return the stress used by this Iterator, for one lattice parameter.
105 */
106 template <int D>
107 double Iterator<D>::stress(int paramId) const
108 {
109 // Parameter must be flexible to access the stress
110 UTIL_CHECK(flexibleParams_[paramId]);
111
112 if (system().hasEnvironment()) {
113 return system().environment().stress(paramId);
114 } else {
115 return system().mixture().stress(paramId);
116 }
117 }
118
119} // namespace Rpg
120} // namespace Pscf
121#endif
System< D > & system()
Return reference to parent system.
void setFlexibleParams(FSArray< bool, 6 > const &flexParams)
Set the array indicating which lattice parameters are flexible.
bool isFlexible() const
Is the unit cell flexible (true) or rigid (false).
int nFlexibleParams() const
Get the number of flexible lattice parameters.
bool isSymmetric() const
Does this iterator use a symmetry-adapted Fourier basis?
bool isFlexible_
Is the unit cell flexible during iteration?
virtual double stress(int paramId) const
Return the stress used by this Iterator, for one lattice parameter.
FSArray< bool, 6 > flexibleParams() const
Get the array indicating which lattice parameters are flexible.
FSArray< bool, 6 > flexibleParams_
Array of indices of the lattice parameters that are flexible.
bool isSymmetric_
Does this iterator use a symmetry-adapted basis?
Main class, representing a complete physical system.
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.