PSCF v1.4.0
Edge.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 "Edge.h"
9
10namespace Pscf
11{
12
13 /*
14 * Constructor.
15 */
17 : id_(-1),
18 monomerId_(-1),
19 nBead_(-1),
20 length_(-1.0),
21 vertexIds_(),
22 polymerType_(PolymerType::Branched)
23 {
24 // Initialize vertex ids to null value -1.
25 vertexIds_[0] = -1;
26 vertexIds_[1] = -1;
27 }
28
29 /*
30 * Set the id for this block.
31 */
32 void Edge::setId(int id)
33 { id_ = id; }
34
35 /*
36 * Set the monomer type id.
37 */
39 { monomerId_ = monomerId; }
40
41 /*
42 * Set the indices of the two associated vertices.
43 */
44 void Edge::setVertexIds(int vertexId0, int vertexId1)
45 {
46 vertexIds_[0] = vertexId0;
47 vertexIds_[1] = vertexId1;
48 }
49
50 /*
51 * Set the number of beads in the block.
52 */
54 {
56 nBead_ = nBead;
57 }
58
59 /*
60 * Set the length of this block.
61 */
63 {
65 length_ = length;
66 }
67
68 /*
69 * Set the type of the polymer containing this block.
70 */
71 void Edge::setPolymerType(PolymerType::Enum type)
72 { polymerType_ = type; }
73
74 /*
75 * Extract a Edge from an istream.
76 */
77 std::istream& operator >> (std::istream& in, Edge& block)
78 {
79 // Read monomer type id
80 in >> block.monomerId_;
81
82 // Read length or nBead
84 in >> block.length_;
85 } else
87 in >> block.nBead_;
88 }
90 // For branched polyimers, read topology information
91 if (block.polymerType_ == PolymerType::Branched) {
92 in >> block.vertexIds_[0];
93 in >> block.vertexIds_[1];
94 }
95
96 return in;
97 }
98
99 /*
100 * Output a Edge to an ostream, without line breaks.
101 */
102 std::ostream& operator << (std::ostream& out,
103 Edge const & block)
105 // Write monomer type id
106 out << " " << block.monomerId_;
107 out << " ";
108
109 // Write length or nBead
111 out.setf(std::ios::scientific);
112 out.width(20);
113 out.precision(12);
114 out << block.length_;
115 } else
116 if (PolymerModel::isBead()) {
117 out << block.nBead_;
118 }
119
120 // For branched polymer, write topology information
121 if (block.polymerType_ == PolymerType::Branched) {
122 out << " " << block.vertexIds_[0];
123 out << " " << block.vertexIds_[1];
124 }
125
126 return out;
127 }
128
129}
virtual void setNBead(int nBead)
Set the number of beads in this block (only valid for bead model).
Definition Edge.cpp:53
int id() const
Get the id of this block (unique within the polymer).
Definition Edge.h:278
void setPolymerType(PolymerType::Enum type)
Set the type of the parent polymer (branched or linear).
Definition Edge.cpp:71
void setVertexIds(int vertexId0, int vertexId1)
Set indices of associated vertices.
Definition Edge.cpp:44
int nBead() const
Get the number of beads in this block, in the bead model.
Definition Edge.h:302
virtual void setLength(double length)
Set the length of this block (only valid for thread model).
Definition Edge.cpp:62
int monomerId() const
Get the monomer type id for this block.
Definition Edge.h:284
Edge()
Constructor.
Definition Edge.cpp:16
void setMonomerId(int monomerId)
Set the monomer type id.
Definition Edge.cpp:38
void setId(int id)
Set the id for this block.
Definition Edge.cpp:32
double length() const
Get the length of this block, in the thread model.
Definition Edge.h:311
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
bool isThread()
Is the thread model in use ?
bool isBead()
Is the bead model in use ?
PSCF package top-level namespace.
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
Struct containing an enumeration of polymer structure types.
Definition PolymerType.h:27