PSCF v1.5.0
Environment.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Environment.h"
9
10namespace Pscf {
11namespace Rp {
12
13 // Constructor
15 : hasStress_(false),
16 nParam_(0)
17 { setClassName("Environment"); }
18
19 // Destructor
22
23 // Sets needsUpdate() to true and hasStress() to false.
29
30 // Mark the stress as outdated, keeping the generated fields.
32 {
33 hasStress_ = false;
34 stress_.clear();
35 stressIds_.clear();
36 }
37
38 // Modify stress to account for Environment for one lattice parameter
39 double Environment::modifyStress(int paramId, double stress) const
40 { UTIL_THROW("Unimplemented modifyStress() method called."); }
41
42 // Return the environment-modified SCFT stress for one parameter.
43 double Environment::stress(int paramId) const
44 {
45 UTIL_CHECK(hasStress_);
46 for (int i = 0; i < stress_.size(); i++) {
47 if (stressIds_[i] == paramId) {
48 return stress_[i];
49 }
50 }
51
52 // If this point is reached, stress not found
53 UTIL_THROW("Attempt to access stress value that was not calculated.");
54 }
55
56 // Write environment-modified stress to output stream.
57 void Environment::writeStress(std::ostream& out) const
58 {
59 UTIL_CHECK(hasStress_);
60 UTIL_CHECK(nParam_ > 0);
61
62 // If no stresses have been set, do nothing and return
63 if (stress_.size() == 0) return;
64
65 // Write only the modified stresses to the ostream
66 out << "environment-modified stress:" << std::endl;
67 for (int i = 0; i < stress_.size(); i++) {
68 out << Int(stressIds_[i], 5)
69 << " "
70 << Dbl(stress_[i], 18, 11)
71 << std::endl;
72 }
73 out << std::endl;
74 }
75
76 // Has the stress been calculated?
78 { return hasStress_; }
79
80 // Set the number of lattice parameters
81 void Environment::setNParams(int nParams)
82 {
83 UTIL_CHECK(nParam_ == 0);
84 nParam_ = nParams;
85 }
86
87} // namespace Rp
88} // namespace Pscf
void setClassName(const char *className)
Set class name string.
virtual void reset()
Sets needsUpdate() to true.
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.
~Environment()
Destructor.
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.
Dbl()
Default constructor.
Definition Dbl.cpp:17
Int()
Default constructor.
Definition Int.cpp:19
#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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.