PSCF v1.4.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 - 2025, The Regents of the University of Minnesota
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
70 template <typename WT=double>
71 class PolymerSpecies : public Species<WT>
72 {
73
74 public:
75
80
84 virtual ~PolymerSpecies() = default;
85
95 virtual void readParameters(std::istream& in);
96
99
109 virtual Edge& edge(int id) = 0;
110
116 virtual Edge const& edge(int id) const = 0;
117
125 const Vertex& vertex(int id) const;
126
130
134 int nBlock() const;
135
142 int nVertex() const;
143
147 int nPropagator() const; //
148
154 double length() const;
155
161 int nBead() const;
162
166 PolymerType::Enum type() const;
167
171
193 Pair<int> const & propagatorId(int id) const;
194
213 Pair<int> const & path(int is, int it) const;
214
216
217 protected:
218
222 virtual void allocateBlocks() = 0;
223
229 virtual void readBlocks(std::istream& in) = 0;
230
251 virtual void makePlan();
252
260 void makePaths();
261
262 private:
263
265 DArray<Vertex> vertices_;
266
268 DArray< Pair<int> > propagatorIds_;
269
271 DArray< DArray< Pair<int> > > paths_;
272
274 int nBlock_;
275
277 int nVertex_;
278
280 int nPropagator_;
281
283 PolymerType::Enum type_;
284
290 void isValid();
291
292 };
293
294 // Inline functions
295
296 /*
297 * Number of blocks in this polymer.
298 */
299 template <typename WT> inline
301 { return nBlock_; }
302
303 /*
304 * Number of vertices (ends and junctions)
305 */
306 template <typename WT> inline
308 { return nVertex_; }
309
310 /*
311 * Number of propagators in this polymer (2*nBlock).
312 */
313 template <typename WT> inline
315 { return nPropagator_; }
316
317 /*
318 * Get a specified Vertex by const reference.
319 */
320 template <typename WT> inline
321 Vertex const & PolymerSpecies<WT>::vertex(int id) const
322 { return vertices_[id]; }
323
324 /*
325 * Get a propagator id, indexed in order of computation.
326 */
327 template <typename WT> inline
329 {
330 UTIL_CHECK(id >= 0);
331 UTIL_CHECK(id < nPropagator_);
332 return propagatorIds_[id];
333 }
334
335 /*
336 * Get a propagator id that leads from a source vertex towards a target.
337 */
338 template <typename WT> inline
339 Pair<int> const & PolymerSpecies<WT>::path(int is, int it) const
340 {
341 UTIL_CHECK(is >= 0);
342 UTIL_CHECK(is < nVertex_);
343 UTIL_CHECK(it >= 0);
344 UTIL_CHECK(it < nVertex_);
345 return paths_[is][it];
346 }
347
348 /*
349 * Get the polymer type enumeration value (Branched or Linear).
350 */
351 template <typename WT> inline
352 PolymerType::Enum PolymerSpecies<WT>::type() const
353 { return type_; }
354
355
356 // Explicit instantiation declaratio
357 extern template class PolymerSpecies<double>;
358
359}
360#endif
Descriptor for a block within a block polymer.
Definition Edge.h:59
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.