PSCF v1.5.0
PolymerSpecies.h
1#ifndef PSCF_POLYMER_SPECIES_H
2#define PSCF_POLYMER_SPECIES_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/chem/Species.h> // base class template
12
13#include <pscf/chem/Vertex.h> // member
14#include <pscf/chem/PolymerType.h> // member
15#include <pscf/chem/PolymerModel.h> // member
16#include <util/containers/Pair.h> // member
17#include <util/containers/DArray.h> // member
18
19namespace Pscf
20{
21
22 // Forward declaration
23 class Edge;
24
25 using namespace Util;
26
68 template <typename WT=double>
69 class PolymerSpecies : public Species<WT>
70 {
71
72 public:
73
78
82 virtual ~PolymerSpecies() = default;
83
93 virtual void readParameters(std::istream& in);
94
97
107 virtual Edge& edge(int id) = 0;
108
114 virtual Edge const& edge(int id) const = 0;
115
123 const Vertex& vertex(int id) const;
124
128
132 int nBlock() const;
133
140 int nVertex() const;
141
145 int nPropagator() const; //
146
152 double length() const;
153
159 int nBead() const;
160
164 PolymerType::Enum type() const;
165
169
191 Pair<int> const & propagatorId(int id) const;
192
211 Pair<int> const & path(int is, int it) const;
212
214
215 protected:
216
220 virtual void allocateBlocks() = 0;
221
227 virtual void readBlocks(std::istream& in) = 0;
228
249 virtual void makePlan();
250
258 void makePaths();
259
260 private:
261
263 DArray<Vertex> vertices_;
264
266 DArray< Pair<int> > propagatorIds_;
267
269 DArray< DArray< Pair<int> > > paths_;
270
272 int nBlock_;
273
275 int nVertex_;
276
278 int nPropagator_;
279
281 PolymerType::Enum type_;
282
288 void isValid();
289
290 };
291
292 // Inline functions
293
294 /*
295 * Number of blocks in this polymer.
296 */
297 template <typename WT> inline
299 { return nBlock_; }
300
301 /*
302 * Number of vertices (ends and junctions)
303 */
304 template <typename WT> inline
306 { return nVertex_; }
307
308 /*
309 * Number of propagators in this polymer (2*nBlock).
310 */
311 template <typename WT> inline
313 { return nPropagator_; }
314
315 /*
316 * Get a specified Vertex by const reference.
317 */
318 template <typename WT> inline
319 Vertex const & PolymerSpecies<WT>::vertex(int id) const
320 { return vertices_[id]; }
321
322 /*
323 * Get a propagator id, indexed in order of computation.
324 */
325 template <typename WT> inline
327 {
328 UTIL_CHECK(id >= 0);
329 UTIL_CHECK(id < nPropagator_);
330 return propagatorIds_[id];
331 }
332
333 /*
334 * Get a propagator id that leads from a source vertex towards a target.
335 */
336 template <typename WT> inline
337 Pair<int> const & PolymerSpecies<WT>::path(int is, int it) const
338 {
339 UTIL_CHECK(is >= 0);
340 UTIL_CHECK(is < nVertex_);
341 UTIL_CHECK(it >= 0);
342 UTIL_CHECK(it < nVertex_);
343 return paths_[is][it];
344 }
345
346 /*
347 * Get the polymer type enumeration value (Branched or Linear).
348 */
349 template <typename WT> inline
350 PolymerType::Enum PolymerSpecies<WT>::type() const
351 { return type_; }
352
353
354 // Explicit instantiation declaratio
355 extern template class PolymerSpecies<double>;
356
357}
358#endif
Descriptor for one block within a block polymer.
Definition Edge.h:62
Descriptor for a linear or acyclic branched block polymer.
int nVertex() const
Number of vertices (junctions and chain ends).
virtual Edge & edge(int id)=0
Get a specified Edge (block descriptor) by non-const reference.
int nBead() const
Total number of beads in the polymer (bead model).
double length() const
Sum of the lengths of all blocks in the polymer (thread model).
virtual Edge const & edge(int id) const =0
Get a specified Edge (block descriptor) by const reference.
void makePaths()
Create a matrix of vertex-to-vertex path signposts.
Pair< int > const & path(int is, int it) const
Get an id for a propagator from one vertex towards a target.
PolymerSpecies()
Constructor.
virtual void readParameters(std::istream &in)
Read parameters and initialize.
virtual void readBlocks(std::istream &in)=0
Read array of blocks from parameter file.
const Vertex & vertex(int id) const
Get a specified Vertex by const reference.
int nBlock() const
Number of blocks.
int nPropagator() const
Number of propagators (2*nBlock).
virtual ~PolymerSpecies()=default
Destructor.
Pair< int > const & propagatorId(int id) const
Get a propagator identifier, indexed by order of computation.
virtual void allocateBlocks()=0
Allocate array of blocks.
PolymerType::Enum type() const
Get Polymer type (Branched or Linear).
virtual void makePlan()
Make a plan for order in which propagators should be computed.
A junction or chain end in a block polymer.
Definition Vertex.h:31
Dynamically allocatable contiguous array template.
Definition DArray.h:32
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.