PSCF v1.5.0
Environment.h
1#ifndef RP_ENVIRONMENT_H
2#define RP_ENVIRONMENT_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/environment/EnvironmentBase.h> // base class
12#include <rp/solvers/Mixture.h> // function parameter
13#include <util/containers/FSArray.h> // container
14#include <iostream>
15
16namespace Pscf {
17namespace Rp {
18
19 using namespace Util;
20
59 {
60
61 public:
62
67
72
87 void reset();
88
96 void clearStress();
97
113 template <int D, class TT>
114 void computeStress(Rp::Mixture<D, TT> const & mixture,
115 FSArray<bool, 6> const & flexibleParams);
116
132 virtual double modifyStress(int paramId, double stress) const;
133
139 double stress(int paramId) const;
140
146 void writeStress(std::ostream& out) const;
147
151 bool hasStress() const;
152
160 void setNParams(int nParams);
161
162 private:
163
165 FSArray<double, 6> stress_;
166
168 FSArray<int, 6> stressIds_;
169
171 bool hasStress_;
172
174 int nParam_;
175
176 };
177
178 /*
179 * Compute and store the environment-modified SCFT stress.
180 *
181 * (Note: this definition is included in header file so that it can
182 * be implicitly instantiated by the compiler wherever needed)
183 */
184 template <int D, class TT>
186 FSArray<bool, 6> const & flexibleParams)
187 {
188 if (hasStress_) return;
189
191 UTIL_CHECK(mixture.hasStress());
192 UTIL_CHECK(nParam_ > 0);
193 UTIL_CHECK(stress_.size() == 0);
194 UTIL_CHECK(stressIds_.size() == 0);
195
196 double stress;
197 for (int i = 0; i < nParam_; ++i) {
198 if (flexibleParams[i]) {
199 // First, retrieve stress contribution from Mixture
200 stress = mixture.stress(i);
201
202 // Next, allow Environment to modify stress using virtual
203 // modifyStress method (defined by subclasses)
205
206 // Store stress and its index
207 stress_.append(stress);
208 stressIds_.append(i);
209 }
210 }
211
212 hasStress_ = true;
213 }
214
215} // namespace Rp
216} // namespace Pscf
217#endif
bool needsUpdate() const
Does this Environment need to be updated?
EnvironmentBase()
Constructor.
virtual double modifyStress(int paramId, double stress) const
Modify stress to account for Environment, for one lattice parameter.
void clearStress()
Mark the environment-modified stress as outdated.
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.
void computeStress(Rp::Mixture< D, TT > const &mixture, FSArray< bool, 6 > const &flexibleParams)
Compute and store the environment-modified SCFT stress.
Solver and descriptor for a mixture of polymers and solvents.
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.