PSCF v1.3
Environment.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Environment.h"
9
10namespace Pscf {
11namespace Prdc {
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.
25 {
27 hasStress_ = false;
28 stress_.clear();
29 stressIds_.clear();
30 }
31
32 // Modify stress to account for Environment for one lattice parameter
33 double Environment::modifyStress(int paramId, double stress) const
34 { UTIL_THROW("Unimplemented modifyStress() method called."); }
35
36 // Return the environment-modified SCFT stress for one parameter.
37 double Environment::stress(int paramId) const
38 {
39 UTIL_CHECK(hasStress_);
40 for (int i = 0; i < stress_.size(); i++) {
41 if (stressIds_[i] == paramId) {
42 return stress_[i];
43 }
44 }
45
46 // If this point is reached, stress not found
47 UTIL_THROW("Attempt to access stress value that was not calculated.");
48 }
49
50 // Write environment-modified stress to output stream.
51 void Environment::writeStress(std::ostream& out) const
52 {
53 UTIL_CHECK(hasStress_);
54 UTIL_CHECK(nParam_ > 0);
55
56 // If no stresses have been set, do nothing and return
57 if (stress_.size() == 0) return;
58
59 // Write only the modified stresses to the ostream
60 out << "environment-modified stress:" << std::endl;
61 for (int i = 0; i < stress_.size(); i++) {
62 out << Int(stressIds_[i], 5)
63 << " "
64 << Dbl(stress_[i], 18, 11)
65 << std::endl;
66 }
67 out << std::endl;
68 }
69
70 // Has the stress been calculated?
72 { return hasStress_; }
73
74 // Set the number of lattice parameters
75 void Environment::setNParams(int nParams)
76 {
77 UTIL_CHECK(nParam_ == 0);
78 nParam_ = nParams;
79 }
80
81} // namespace Prdc
82} // 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.
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.
Wrapper for a double precision number, for formatted ostream output.
Definition Dbl.h:40
Wrapper for an int, for formatted ostream output.
Definition Int.h:37
#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