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>
23 template <
typename WT>
38 template <
typename WT>
42 type_ = PolymerType::Linear;
48 nVertex_ = nBlock_ + 1;
52 vertices_.allocate(nVertex_);
53 propagatorIds_.allocate(2*nBlock_);
56 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
57 edge(edgeId).setId(edgeId);
58 edge(edgeId).setPolymerType(type_);
62 for (
int vertexId = 0; vertexId < nVertex_; ++vertexId) {
63 vertices_[vertexId].setId(vertexId);
67 if (type_ == PolymerType::Linear) {
69 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
70 edge(blockId).setVertexIds(blockId, blockId + 1);
83 int vertexId0, vertexId1;
85 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
86 edgePtr = &(
edge(edgeId));
89 vertices_[vertexId0].addEdge(*edgePtr);
90 vertices_[vertexId1].addEdge(*edgePtr);
110 template <
typename WT>
113 if (nPropagator_ != 0) {
120 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
121 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
122 isFinished(iBlock, iDirection) =
false;
130 while (nPropagator_ < nBlock_*2) {
131 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
132 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
133 if (isFinished(iBlock, iDirection) ==
false) {
134 inVertexId =
edge(iBlock).vertexId(iDirection);
135 inVertexPtr = &vertices_[inVertexId];
137 for (
int j = 0; j < inVertexPtr->
size(); ++j) {
139 if (propId[0] != iBlock) {
140 if (!isFinished(propId[0], propId[1])){
147 propagatorIds_[nPropagator_][0] = iBlock;
148 propagatorIds_[nPropagator_][1] = iDirection;
149 isFinished(iBlock, iDirection) =
true;
162 template <
typename WT>
184 for (is = 0; is < nVertex_; ++is) {
185 sendPaths[is].clear();
186 recvPaths[is].clear();
187 oldPaths[is].clear();
191 for (is = 0; is < nVertex_; ++is) {
195 sendPaths[is].append(
path);
205 for (ir = 0; is < nVertex_; ++is) {
211 for (is = 0; is < nVertex_; ++is) {
214 int n = sendPaths[is].size();
220 for (j = 0; j < sender.
size(); ++j) {
231 ir =
edge(ib).vertexId(ii);
232 for (k = 0; k < n; ++k) {
233 path = sendPaths[is][k];
238 recvPaths[ir].append(
path);
247 for (is = 0; is < nVertex_; ++is) {
250 n = sendPaths[is].size();
252 for (k = 0; k < n; ++k) {
253 path = sendPaths[is][k];
254 oldPaths[is].append(
path);
257 sendPaths[is].clear();
260 n = recvPaths[is].size();
262 for (k = 0; k < n; ++k) {
263 sendPaths[is].append(recvPaths[is][k]);
266 recvPaths[is].clear();
274 paths_.allocate(nVertex_);
275 for (is = 0; is < nVertex_; ++is) {
276 paths_[is].allocate(nVertex_);
277 for (ir = 0; ir < nVertex_; ++ir) {
278 paths_[is][ir][0] = -1;
279 paths_[is][ir][1] = -1;
284 for (is = 0; is < nVertex_; ++is) {
285 n = oldPaths[is].size();
287 for (k = 0; k < n; ++k) {
288 path = oldPaths[is][k];
306 paths_[is][ir][0] = path[1];
307 paths_[is][ir][1] = path[2];
312 std::cout << std::endl <<
"Paths:" ;
313 for (is = 0; is < nVertex_; ++is) {
314 for (ir = 0; ir < nVertex_; ++ir) {
315 pId = paths_[is][ir];
316 std::cout << std::endl;
317 std::cout << is << ir << pId[0] << pId[1];
320 std::cout << std::endl;
328 template <
typename WT>
329 void PolymerSpecies<WT>::isValid()
332 int ib, iv, ip, id, iv0, iv1, n;
335 for (ib = 0; ib < nBlock_; ++ib) {
337 iv0 = edge(ib).vertexId(0);
338 iv1 = edge(ib).vertexId(1);
347 for (iv = 0; iv < nVertex_; ++iv) {
349 n = vertex(iv).size();
350 for (ip = 0; ip < n; ++ip) {
351 pair = vertex(iv).outPropagatorId(ip);
363 for (iv = 0; iv < nVertex_; ++iv) {
365 n = vertex(iv).size();
366 for (ip = 0; ip < n; ++ip) {
367 pair = vertex(iv).inPropagatorId(ip);
383 for (iv0 = 0; iv0 < nVertex_; ++iv0) {
384 for (iv1 = 0; iv1 < nVertex_; ++iv1) {
385 pair = path(iv0, iv1);
402 template <
typename WT>
407 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
408 value +=
edge(blockId).length();
416 template <
typename WT>
421 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
422 value +=
edge(blockId).nBead();
Descriptor for a 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).
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 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.
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 (static) contiguous array template.
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.