PSCF v1.4.0
Iterator.tpp
1#ifndef RP_ITERATOR_TPP
2#define RP_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
13namespace Pscf {
14namespace Rp {
15
16 using namespace Util;
17
18 // Public functions
19
20 /*
21 * Default constructor.
22 */
23 template <int D, class ST>
25 : isSymmetric_(false),
26 isFlexible_(false),
27 sysPtr_(nullptr)
28 { setClassName("Iterator"); }
29
30 /*
31 * Constructor.
32 */
33 template <int D, class ST>
35 : isSymmetric_(false),
36 isFlexible_(false),
37 sysPtr_(&system)
38 { setClassName("Iterator"); }
39
40 /*
41 * Destructor.
42 */
43 template <int D, class ST>
46
47 /*
48 * Get the number of flexible lattice parameters.
49 */
50 template <int D, class ST>
52 {
53 UTIL_CHECK(sysPtr_);
55 system().domain().unitCell().nParameter());
56 int nFlexParams = 0;
57 for (int i = 0; i < flexibleParams_.size(); i++) {
58 if (flexibleParams_[i]) nFlexParams++;
59 }
60 return nFlexParams;
61 }
62
63 /*
64 * Set the array indicating which lattice parameters are flexible.
65 */
66 template <int D, class ST>
68 {
69 UTIL_CHECK(sysPtr_);
70 flexibleParams_ = flexParams;
71 if (nFlexibleParams() == 0) {
72 isFlexible_ = false;
73 } else {
74 isFlexible_ = true;
75 }
76 }
77
78 /*
79 * Return the stress used by this Iterator, for one lattice parameter.
80 */
81 template <int D, class ST>
82 double Iterator<D,ST>::stress(int paramId) const
83 {
84 // Parameter must be flexible to access the stress
85 UTIL_CHECK(sysPtr_);
87
88 if (system().hasEnvironment()) {
89 return system().environment().stress(paramId);
90 } else {
91 return system().mixture().stress(paramId);
92 }
93 }
94
95 // Protected function
96
97 /*
98 * Set system.
99 */
100 template <int D, class ST>
102 {
103 UTIL_CHECK(!sysPtr_);
104 sysPtr_ = &system;
105 }
106
107} // namespace Rp
108} // namespace Pscf
109#endif
void setFlexibleParams(FSArray< bool, 6 > const &flexParams)
Set the array indicating which lattice parameters are flexible.
Definition Iterator.tpp:67
ST const & system() const
Get parent system by const reference.
Iterator()
Default constructor.
Definition Iterator.tpp:24
void setSystem(ST &system)
Set parent system.
Definition Iterator.tpp:101
bool isSymmetric_
Does this iterator use a symmetry-adapted basis?
int nFlexibleParams() const
Get the number of flexible lattice parameters.
Definition Iterator.tpp:51
virtual double stress(int paramId) const
Return the stress used by this Iterator, for one lattice parameter.
Definition Iterator.tpp:82
~Iterator()
Destructor.
Definition Iterator.tpp:44
bool isFlexible_
Are any lattice parameters flexible during iteration?
FSArray< bool, 6 > flexibleParams_
Array of indices of the lattice parameters that are flexible.
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
Class templates for real-valued periodic fields.
PSCF package top-level namespace.