PSCF v1.3
FilmFieldGenMaskBase.tpp
1#ifndef PRDC_MASK_GEN_FILM_BASE_TPP
2#define PRDC_MASK_GEN_FILM_BASE_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 "FilmFieldGenMaskBase.h"
12#include "prdc/crystal/SpaceGroup.h"
13#include "util/param/ScalarParam.h"
14#include <cmath>
15
16namespace Pscf {
17namespace Prdc
18{
19
20 using namespace Util;
21
22 /*
23 * Constructor
24 */
25 template <int D>
29 fBulk_(),
30 normalVecId_(-1),
31 interfaceThickness_(-1.0),
32 excludedThickness_(-1.0),
33 hasFBulk_(false)
34 {
35 type_ = Mask;
36 normalVecCurrent_.setToZero();
37 }
38
39 /*
40 * Destructor
41 */
42 template <int D>
45
46 /*
47 * Read parameters and initialize.
48 */
49 template <int D>
51 {
52 // Read required data defining the walls
53 read(in, "normalVecId", normalVecId_);
54 read(in, "interfaceThickness", interfaceThickness_);
55 read(in, "excludedThickness", excludedThickness_);
56 ScalarParam<double>& fBulkParam = readOptional(in, "fBulk", fBulk_);
57 if (fBulkParam.isActive()) { // if we read fBulk
58 hasFBulk_ = true;
59 }
60
61 // Make sure inputs are valid
62 if (normalVecId_ > D || normalVecId_ < 0) {
63 UTIL_THROW("bad value for normalVecId, must be in [0,D)");
64 }
65 if (interfaceThickness_ > excludedThickness_) {
66 UTIL_THROW("excludedThickness must be larger than interfaceThickness");
67 }
68 if ((excludedThickness_ <= 0) || (interfaceThickness_ <= 0)) {
69 UTIL_THROW("excludedThickness and interfaceThickness must be >0");
70 }
71 }
72
73 /*
74 * Check whether system has changed such that the field needs updating.
75 */
76 template <int D>
78 {
79 UTIL_CHECK(normalVecId_ >= 0); // Check that readParameters was called
80
81 // If normalVecCurrent_ has not yet been set, return true
82 RealVec<D> tmp;
83 tmp.setToZero();
84 if (normalVecCurrent_ == tmp) {
85 return true;
86 }
87
88 // Check if system normalVec differ from normalVecCurrent_
89 // Note: normalVecCurrent_ is set to array of zeros in constructor,
90 // so if generate() has not been called, it is still an array of
91 // zeros and this method will return true, as it should.
92 if (normalVecCurrent_ == systemLatticeVector(normalVecId_)) {
93 return false;
94 } else {
95 return true;
96 }
97 }
98
99 /*
100 * Check that the system is compatible with this field.
101 */
102 template <int D>
104 {
105 // If lattice parameters are flexible, determine which parameters
106 // are allowed to vary, store them in this object, and pass them
107 // into the Iterator. The flexibleParams_ member of the Iterator
108 // should always be matched to that of this class.
110
111 // Ensure that space group symmetry is compatible with the wall
113
114 // Ensure that unit cell is compatible with wall
116 }
117
118 /*
119 * Check that space group is compatible with the mask.
120 */
121 template <int D>
123 {
124 // Setup
125 std::string groupName = systemSpaceGroup();
126 SpaceGroup<D> group;
127 std::ifstream in;
128
129 // Open and read file containing space group's symmetry operations
130 readGroup(groupName, group);
131
132 // Make sure all symmetry operations are allowed
133 int nv = normalVecId();
134 std::string msg = "Space group contains forbidden symmetry operations";
135 for (int i = 0; i < group.size(); i++) {
136 for (int j = 0; j < D; j++) {
137 int r = group[i].R(nv,j);
138 if (j == nv) {
139 if ((r != 1) && (r != -1)) {
140 UTIL_THROW(msg.c_str());
141 }
142 } else { // j != nv
143 if (r != 0) {
144 UTIL_THROW(msg.c_str());
145 }
146 }
147 }
148 if (group[i].t(nv) != 0) {
149 UTIL_THROW(msg.c_str());
150 }
151 }
152 }
153
154 // Explicit Specializations for checkLatticeVectors and
155 // modifyFlexibleParams are in FilmFieldGenMaskBase.cpp
156}
157}
158#endif
Type type_
Type of field (Mask, External, or None).
RealVec< D > normalVecCurrent_
The lattice vector normal to the film used to generate these fields.
virtual std::string systemSpaceGroup() const =0
Get the space group name for this system.
int normalVecId() const
Get value of normalVecId.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
double fBulk_
Reference free energy used to calculate stress normal to the film.
void checkSpaceGroup() const
Check that space group is compatible with the mask.
void readParameters(std::istream &in)
Read parameter file block and initialize.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
void checkCompatibility()
Check that the system is compatible with this field.
bool needsUpdate() const
Check whether system has changed such that the field needs updating.
virtual RealVec< D > systemLatticeVector(int id) const =0
Get one of the lattice vectors for this system.
void checkLatticeVectors() const
Check that lattice vectors are compatible with thin film constraint.
virtual void setFlexibleParams() const =0
Sets iterator's flexibleParams array to be compatible with the mask.
Crystallographic space group.
Definition SpaceGroup.h:32
int size() const
Return number of elements in group (i.e., the order of the group).
A RealVec<D, T> is D-component vector with elements of floating type T.
Definition RealVec.h:28
Vec< D, T > & setToZero()
Set all elements to zero.
Definition Vec.h:381
bool isActive() const
Is this parameter active?
Template for a Parameter object associated with a scalar variable.
Definition ScalarParam.h:35
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1