PSCF v1.2
VertexIterator.cpp
1/*
2* PSCF - Polymer Self-Consistent Field Theory
3*
4* Copyright 2016 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "VertexIterator.h"
9#include <pscf/chem/PolymerSpecies.h>
10#include <pscf/chem/Edge.h>
11
12namespace Pscf {
13
14 /*
15 * Constructor
16 */
18 : currentId_(-1),
19 targetId_(-1),
20 polymerPtr_(&polymer)
21 {}
22
23 /*
24 * Destructor
25 */
28
29 /*
30 * Initialize iterator.
31 */
32 void VertexIterator::begin(int sourceId, int targetId)
33 {
34 currentId_ = sourceId;
35 targetId_ = targetId;
36 }
37
38 /*
39 * Increment vertex - update current vertex to next one in path.
40 */
42 {
44 Pair<int> propId = polymerPtr_->path(currentId_, targetId_);
45 int edgeId = propId[0];
46 int dirId = propId[1];
47 UTIL_CHECK(edgeId >= 0);
48 UTIL_CHECK(edgeId < polymerPtr_->nBlock());
49 UTIL_CHECK(dirId >= 0);
50 UTIL_CHECK(dirId < 2);
51 Edge const & edge = polymerPtr_->edge(edgeId);
52 if (dirId == 0) {
53 currentId_ = edge.vertexId(1);
54 } else {
55 currentId_ = edge.vertexId(0);
56 }
57 return *this;
58 }
59
60 /*
61 * Get the current vertex id.
62 */
64 { return currentId_; }
65
66 /*
67 * Is the current vertex equal to the target:
68 */
70 {
71 return (bool)( currentId_ == targetId_ );
72 }
73
74 /*
75 * Is the current vertex not equal to the target.
76 */
78 {
79 return (bool)( currentId_ != targetId_ );
80 }
81
82}
Descriptor for a block within an acyclic block polymer.
Definition Edge.h:50
int vertexId(int i) const
Get id of an associated vertex.
Definition Edge.h:247
Descriptor for a linear or acyclic branched block polymer.
Pair< int > const & path(int is, int it) const
Get an id for a propagator from one vertex towards a target.
virtual Edge & edge(int id)=0
Get a specified Edge (block descriptor) by non-const reference.
Vertex iterator for graph associated with a polymer.
bool notEnd() const
Return true iff currentId != targetId.
VertexIterator & operator++()
Increment operator - move to next vertex.
~VertexIterator()
Destructor.
int currentId() const
Get index of the current vertex.
bool isEnd() const
Return true iff currentId == targetId.
void begin(int sourceId, int targetId)
Initialize iterator.
VertexIterator(PolymerSpecies const &polymer)
Constructor.
An array of exactly 2 objects.
Definition Pair.h:24
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Definition param_pc.dox:1