PSCF v1.3
Environment.h
1#ifndef PRDC_ENVIRONMENT_H
2#define PRDC_ENVIRONMENT_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#include <prdc/solvers/MixtureReal.h> // method parameter
12#include <pscf/environment/EnvironmentBase.h> // base class
13#include <util/containers/FSArray.h> // container
14#include <iostream>
15
16namespace Pscf {
17namespace Prdc {
18
19 using namespace Util;
20
59 {
60
61 public:
62
67
72
87 void reset();
88
104 template <int D, class PT, class ST>
105 void computeStress(MixtureReal<D, PT, ST> const & mixture,
106 FSArray<bool, 6> const & flexibleParams);
107
123 virtual double modifyStress(int paramId, double stress) const;
124
130 double stress(int paramId) const;
131
137 void writeStress(std::ostream& out) const;
138
142 bool hasStress() const;
143
151 void setNParams(int nParams);
152
153 private:
154
156 FSArray<double, 6> stress_;
157
159 FSArray<int, 6> stressIds_;
160
162 bool hasStress_;
163
165 int nParam_;
166
167 };
168
169 /*
170 * Compute and store the environment-modified SCFT stress.
171 *
172 * (Note: this definition is included in header file so that it can
173 * be implicitly instantiated by the compiler wherever needed)
174 */
175 template <int D, class PT, class ST>
177 FSArray<bool, 6> const & flexibleParams)
178 {
179 if (hasStress_) return;
180
182 UTIL_CHECK(mixture.hasStress());
183 UTIL_CHECK(nParam_ > 0);
184 UTIL_CHECK(stress_.size() == 0);
185 UTIL_CHECK(stressIds_.size() == 0);
186
187 double stress;
188 for (int i = 0; i < nParam_; ++i) {
189 if (flexibleParams[i]) {
190 // First, retrieve stress contribution from Mixture
191 stress = mixture.stress(i);
192
193 // Next, allow Environment to modify stress using virtual
194 // modifyStress method (defined by subclasses)
196
197 // Store stress and its index
198 stress_.append(stress);
199 stressIds_.append(i);
200 }
201 }
202
203 hasStress_ = true;
204 }
205
206} // namespace Prdc
207} // namespace Pscf
208#endif
bool needsUpdate() const
Does this Environment need to be updated?
EnvironmentBase()
Constructor.
void computeStress(MixtureReal< D, PT, ST > const &mixture, FSArray< bool, 6 > const &flexibleParams)
Compute and store the environment-modified SCFT stress.
virtual double modifyStress(int paramId, double stress) const
Modify stress to account for Environment, for one lattice parameter.
Environment()
Constructor.
void reset()
Sets needsUpdate() to true and hasStress() to false.
double stress(int paramId) const
Return the environment-modified SCFT stress for one parameter.
bool hasStress() const
Has the stress been calculated?
void writeStress(std::ostream &out) const
Write the environment-modified SCFT stress.
void setNParams(int nParams)
Set the number of lattice parameters.
Solver and descriptor for a mixture of polymers and solvents.
Definition MixtureReal.h:51
double stress(int parameterId) const
Get derivative of free energy w/ respect to a unit cell parameter.
bool hasStress() const
Has the stress been computed since the last MDE solution?
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
#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
PSCF package top-level namespace.
Definition param_pc.dox:1