8#include "PolymerSpecies.h"
10#include <pscf/chem/Edge.h>
11#include <util/containers/GArray.h>
12#include <util/containers/FArray.h>
13#include <util/containers/DMatrix.h>
14#include <util/format/Int.h>
24 template <
typename WT>
39 template <
typename WT>
43 type_ = PolymerType::Linear;
49 nVertex_ = nBlock_ + 1;
53 vertices_.allocate(nVertex_);
54 propagatorIds_.allocate(2*nBlock_);
57 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
58 edge(edgeId).setId(edgeId);
59 edge(edgeId).setPolymerType(type_);
63 for (
int vertexId = 0; vertexId < nVertex_; ++vertexId) {
64 vertices_[vertexId].setId(vertexId);
68 if (type_ == PolymerType::Linear) {
70 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
71 edge(blockId).setVertexIds(blockId, blockId + 1);
84 int vertexId0, vertexId1;
86 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
87 edgePtr = &(
edge(edgeId));
90 if (vertexId0 < 0 || vertexId0 >= nVertex_ ||
91 vertexId1 < 0 || vertexId1 >= nVertex_) {
92 UTIL_THROW(
"Vertex id out of range in polymer block");
94 vertices_[vertexId0].addEdge(*edgePtr);
95 vertices_[vertexId1].addEdge(*edgePtr);
99 for (
int vertexId = 0; vertexId <= nBlock_; ++vertexId) {
120 template <
typename WT>
123 if (nPropagator_ != 0) {
130 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
131 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
132 isFinished(iBlock, iDirection) =
false;
141 while (nPropagator_ < nBlock_*2) {
142 nPrevious = nPropagator_;
145 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
146 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
147 if (!isFinished(iBlock, iDirection)) {
148 inVertexId =
edge(iBlock).vertexId(iDirection);
149 inVertexPtr = &vertices_[inVertexId];
153 for (
int j = 0; j < inVertexPtr->
size(); ++j) {
155 if (propId[0] != iBlock) {
156 if (!isFinished(propId[0], propId[1])){
165 propagatorIds_[nPropagator_][0] = iBlock;
166 propagatorIds_[nPropagator_][1] = iDirection;
167 isFinished(iBlock, iDirection) =
true;
176 if (nPropagator_ == nPrevious) {
177 UTIL_THROW(
"Polymer blocks do not form a tree");
187 template <
typename WT>
209 for (is = 0; is < nVertex_; ++is) {
210 sendPaths[is].clear();
211 recvPaths[is].clear();
212 oldPaths[is].clear();
216 for (is = 0; is < nVertex_; ++is) {
220 sendPaths[is].append(
path);
230 for (ir = 0; is < nVertex_; ++is) {
236 for (is = 0; is < nVertex_; ++is) {
239 int n = sendPaths[is].
size();
245 for (j = 0; j < sender.
size(); ++j) {
256 ir = edge(ib).vertexId(ii);
257 for (k = 0; k < n; ++k) {
263 recvPaths[ir].append(
path);
272 for (is = 0; is < nVertex_; ++is) {
275 n = sendPaths[is].
size();
277 for (k = 0; k < n; ++k) {
278 path = sendPaths[is][k];
279 oldPaths[is].append(path);
282 sendPaths[is].clear();
285 n = recvPaths[is].
size();
287 for (k = 0; k < n; ++k) {
288 sendPaths[is].append(recvPaths[is][k]);
291 recvPaths[is].clear();
299 paths_.allocate(nVertex_);
300 for (is = 0; is < nVertex_; ++is) {
301 paths_[is].allocate(nVertex_);
302 for (ir = 0; ir < nVertex_; ++ir) {
303 paths_[is][ir][0] = -1;
304 paths_[is][ir][1] = -1;
309 for (is = 0; is < nVertex_; ++is) {
310 n = oldPaths[is].
size();
312 for (k = 0; k < n; ++k) {
313 path = oldPaths[is][k];
331 paths_[is][ir][0] = path[1];
332 paths_[is][ir][1] = path[2];
341 template <
typename WT>
342 void PolymerSpecies<WT>::isValid()
345 int ib, iv, ip, id, iv0, iv1, n;
348 for (ib = 0; ib < nBlock_; ++ib) {
350 iv0 = edge(ib).vertexId(0);
351 iv1 = edge(ib).vertexId(1);
360 for (iv = 0; iv < nVertex_; ++iv) {
362 n = vertex(iv).size();
363 for (ip = 0; ip < n; ++ip) {
364 pair = vertex(iv).outPropagatorId(ip);
376 for (iv = 0; iv < nVertex_; ++iv) {
378 n = vertex(iv).size();
379 for (ip = 0; ip < n; ++ip) {
380 pair = vertex(iv).inPropagatorId(ip);
396 for (iv0 = 0; iv0 < nVertex_; ++iv0) {
397 for (iv1 = 0; iv1 < nVertex_; ++iv1) {
398 pair = path(iv0, iv1);
415 template <
typename WT>
420 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
421 value +=
edge(blockId).length();
429 template <
typename WT>
434 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
435 value +=
edge(blockId).nBead();
Descriptor for one block within a block polymer.
int vertexId(int i) const
Get the id of one associated vertex.
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).
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.
virtual void allocateBlocks()=0
Allocate array of blocks.
virtual void makePlan()
Make a plan for order in which propagators should be computed.
virtual void readParameters(std::istream &in)
Read phi or mu (but not both) and set ensemble accordingly.
A junction or chain end in a block polymer.
int size() const
Get the number of attached blocks.
Pair< int > const & inPropagatorId(int i) const
Get the block and direction of an incoming propagator.
Pair< int > const & outPropagatorId(int i) const
Get the block and direction of an outgoing propagator.
int size() const
Return logical size of array.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
Dynamically allocated Matrix.
void allocate(int capacity1, int capacity2)
Allocate memory for a matrix.
A fixed size, stack-allocated array.
An array of exactly 2 objects.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
bool isThread()
Is the thread model in use ?
bool isBead()
Is the bead model in use ?
PSCF package top-level namespace.
Struct containing an enumeration of polymer structure types.