PSCF v1.3
PolymerModel.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 "PolymerModel.h"
9#include <util/global.h>
10#include <string>
11
12// Anonymous namespace containing pseudo-private variables.
13namespace {
14
15 // Comments:
16 //
17 // 1) Variables model_, nSet_ and isLocked_ defined in this anonmymous
18 // namespace are only accessible in this file, and are thus
19 // pseudo-private
20 //
21 // 2) model_ is initialized to PolymerModel::Thread
22 //
23 // 3) If isLocked_ , model_ may never be altered again.
24 //
25 // 4) isLocked_ is initialized to false
26
27 Pscf::PolymerModel::Type model_ = Pscf::PolymerModel::Thread;
28
29 bool isLocked_ = false;
30
31 int nSet_ = 0;
32
33}
34
35namespace Pscf {
36namespace PolymerModel {
37
38 using namespace Util;
39
40 // Mutators
41
42 /*
43 * Set the global polymer model enumeration value.
44 */
46 {
47 UTIL_CHECK(!isLocked_);
48 model_ = model;
49 ++nSet_;
50 }
51
52 /*
53 * Permanently lock the model type.
54 */
55 void lock()
56 { isLocked_ = true; }
57
58 // Accessors
59
60 /*
61 * Get the global polymer model enumeration value.
62 */
64 { return model_; }
65
66 /*
67 * Is the global polymer model a continuous thread model?
68 */
69 bool isThread()
70 { return (model_ == Type::Thread); }
71
72 /*
73 * Is the global polymer model a discrete bead model?
74 */
75 bool isBead()
76 { return (model_ == Type::Bead); }
77
78 /*
79 * Is the model type locked?
80 */
81 bool isLocked()
82 { return isLocked_; }
83
84 /*
85 * How many times has the choice of model been set ?
86 */
87 int nSet()
88 { return nSet_; }
89
90 /*
91 * Input stream extractor for a PolymerModel::Type enumeration.
92 */
93 std::istream& operator >> (std::istream& in,
95 {
96 std::string buffer;
97 in >> buffer;
98 if (buffer == "Thread" || buffer == "thread") {
99 type = PolymerModel::Thread;
100 } else
101 if (buffer == "Bead" || buffer == "bead") {
102 type = PolymerModel::Type::Bead;
103 } else {
104 std::string msg = "Unknown input PolymerModel value string: ";
105 msg += buffer;
106 UTIL_THROW(msg.c_str());
107 }
108 return in;
109 }
110
111 /*
112 * Output stream inserter for a PolymerModel::Type enumeration.
113 */
114 std::ostream& operator << (std::ostream& out,
115 PolymerModel::Type const & type)
116 {
117 if (type == PolymerModel::Thread) {
118 out << "thread";
119 } else
120 if (type == PolymerModel::Type::Bead) {
121 out << "bead";
122 } else {
123 UTIL_THROW("Error writing a PolymerModel value");
124 }
125 return out;
126 }
127
128} // end namespace PolymerModel
129} // end namespace Pscf
File containing preprocessor macros for error handling.
#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
Type
Scoped enumeration of polymer model types.
Enumeration and functions to specify a model for polymer chains.
int nSet()
How many times has setModel been called?
void lock()
Make the polymer model immutable.
Type model()
Get the global polymer model type enumeration value.
void setModel(Type model)
Set the global polymer model enumeration value.
bool isThread()
Is the thread model in use ?
bool isBead()
Is the bead model in use ?
bool isLocked()
Has the model type been locked (i.e., made immutable) ?
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition Pair.h:57