PSCF v1.3.1
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 <rpg/system/System.h>
14#include <prdc/environment/Environment.h>
15
16namespace Pscf {
17namespace Rpg {
18
19 template <int D> class System;
20
21 using namespace Util;
22 using namespace Prdc;
23
24 /*
25 * Default constructor.
26 */
27 template<int D>
29 : isSymmetric_(false),
30 isFlexible_(false),
31 sysPtr_(nullptr)
32 { setClassName("Iterator"); }
33
34 /*
35 * Constructor.
36 */
37 template<int D>
39 : isSymmetric_(false),
40 isFlexible_(false),
41 sysPtr_(&system)
42 { setClassName("Iterator"); }
43
44 /*
45 * Destructor.
46 */
47 template<int D>
50
51 /*
52 * Does this iterator use a symmetry-adapted Fourier basis?
53 */
54 template<int D>
55 inline bool Iterator<D>::isSymmetric() const
56 { return isSymmetric_; }
57
58 /*
59 * Is the unit cell flexible (true) or rigid (false) ?
60 */
61 template<int D>
62 inline bool Iterator<D>::isFlexible() const
63 { return isFlexible_; }
64
65 /*
66 * Get the array indicating which lattice parameters are flexible.
67 */
68 template<int D>
71
72 /*
73 * Get the number of flexible lattice parameters.
74 */
75 template <int D>
77 {
79 system().domain().unitCell().nParameter());
80 int nFlexParams = 0;
81 for (int i = 0; i < flexibleParams_.size(); i++) {
82 if (flexibleParams_[i]) nFlexParams++;
83 }
84 return nFlexParams;
85 }
86
87 /*
88 * Set the array indicating which lattice parameters are flexible.
89 */
90 template <int D>
92 {
93 flexibleParams_ = flexParams;
94 if (nFlexibleParams() == 0) {
95 isFlexible_ = false;
96 } else {
97 isFlexible_ = true;
98 }
99 }
100
101 /*
102 * Return the stress used by this Iterator, for one lattice parameter.
103 */
104 template <int D>
105 double Iterator<D>::stress(int paramId) const
106 {
107 // Parameter must be flexible to access the stress
108 UTIL_CHECK(flexibleParams_[paramId]);
109
110 if (system().hasEnvironment()) {
111 return system().environment().stress(paramId);
112 } else {
113 return system().mixture().stress(paramId);
114 }
115 }
116
117} // namespace Rpg
118} // namespace Pscf
119#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.
Definition param_pc.dox:1