8#include "PolymerSpecies.h"
12#include <pscf/chem/Edge.h>
13#include <util/containers/GArray.h>
14#include <util/containers/FArray.h>
15#include <util/containers/DMatrix.h>
43 type_ = PolymerType::Linear;
49 nVertex_ = nBlock_ + 1;
54 vertices_.allocate(nVertex_);
55 propagatorIds_.allocate(2*nBlock_);
58 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
64 for (
int vertexId = 0; vertexId < nVertex_; ++vertexId) {
65 vertices_[vertexId].setId(vertexId);
70 if (type_ == PolymerType::Linear) {
71 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
91 int vertexId0, vertexId1;
93 for (
int edgeId = 0; edgeId < nBlock_; ++edgeId) {
94 edgePtr = &(
edge(edgeId));
97 vertices_[vertexId0].addEdge(*edgePtr);
98 vertices_[vertexId1].addEdge(*edgePtr);
120 if (nPropagator_ != 0) {
127 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
128 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
129 isFinished(iBlock, iDirection) =
false;
137 while (nPropagator_ < nBlock_*2) {
138 for (
int iBlock = 0; iBlock < nBlock_; ++iBlock) {
139 for (
int iDirection = 0; iDirection < 2; ++iDirection) {
140 if (isFinished(iBlock, iDirection) ==
false) {
142 inVertexPtr = &vertices_[inVertexId];
144 for (
int j = 0; j < inVertexPtr->
size(); ++j) {
154 propagatorIds_[nPropagator_][0] = iBlock;
155 propagatorIds_[nPropagator_][1] = iDirection;
156 isFinished(iBlock, iDirection) =
true;
190 for (is = 0; is < nVertex_; ++is) {
191 sendPaths[is].clear();
192 recvPaths[is].clear();
193 oldPaths[is].clear();
197 for (is = 0; is < nVertex_; ++is) {
201 sendPaths[is].append(path);
211 for (ir = 0; is < nVertex_; ++is) {
217 for (is = 0; is < nVertex_; ++is) {
220 int n = sendPaths[is].size();
223 Vertex
const & sender =
vertex(is);
226 for (j = 0; j < sender.size(); ++j) {
227 pId = sender.outPropagatorId(j);
238 for (k = 0; k < n; ++k) {
239 path = sendPaths[is][k];
244 recvPaths[ir].append(path);
253 for (is = 0; is < nVertex_; ++is) {
256 n = sendPaths[is].size();
258 for (k = 0; k < n; ++k) {
259 path = sendPaths[is][k];
260 oldPaths[is].append(path);
263 sendPaths[is].clear();
266 n = recvPaths[is].size();
268 for (k = 0; k < n; ++k) {
269 sendPaths[is].append(recvPaths[is][k]);
272 recvPaths[is].clear();
280 paths_.allocate(nVertex_);
281 for (is = 0; is < nVertex_; ++is) {
282 paths_[is].allocate(nVertex_);
283 for (ir = 0; ir < nVertex_; ++ir) {
284 paths_[is][ir][0] = -1;
285 paths_[is][ir][1] = -1;
290 for (is = 0; is < nVertex_; ++is) {
291 n = oldPaths[is].size();
293 for (k = 0; k < n; ++k) {
294 path = oldPaths[is][k];
312 paths_[is][ir][0] = path[1];
313 paths_[is][ir][1] = path[2];
318 std::cout << std::endl <<
"Paths:" ;
319 for (is = 0; is < nVertex_; ++is) {
320 for (ir = 0; ir < nVertex_; ++ir) {
321 pId = paths_[is][ir];
322 std::cout << std::endl;
323 std::cout << is << ir << pId[0] << pId[1];
326 std::cout << std::endl;
337 int ib, iv, ip, id, iv0, iv1, n;
340 for (ib = 0; ib < nBlock_; ++ib) {
352 for (iv = 0; iv < nVertex_; ++iv) {
355 for (ip = 0; ip < n; ++ip) {
368 for (iv = 0; iv < nVertex_; ++iv) {
371 for (ip = 0; ip < n; ++ip) {
388 for (iv0 = 0; iv0 < nVertex_; ++iv0) {
389 for (iv1 = 0; iv1 < nVertex_; ++iv1) {
390 pair = path(iv0, iv1);
410 for (
int blockId = 0; blockId < nBlock_; ++blockId) {
Descriptor for a block within an acyclic block polymer.
void setVertexIds(int vertexAId, int vertexBId)
Set indices of associated vertices.
void setPolymerType(PolymerType::Enum type)
Set the polymer type (branched or linear).
int vertexId(int i) const
Get id of an associated vertex.
void setId(int id)
Set the id for this block.
double length() const
Get the length (number of monomers) in this block.
const Vertex & vertex(int id) const
Get a specified Vertex by const reference.
virtual void readBlocks(std::istream &in)=0
Read array of blocks from parameter file.
PolymerSpecies()
Constructor.
void isValid()
Check validity of graph.
void makePaths()
Create a matrix of vertex-to-vertex path signposts.
virtual void allocateBlocks()=0
Allocate array of blocks.
virtual Edge & edge(int id)=0
Get a specified Edge (block descriptor) by non-const reference.
virtual void readParameters(std::istream &in)
Read parameters and initialize.
virtual void makePlan()
Make a plan for order in which propagators should be computed.
~PolymerSpecies()
Destructor.
double length() const
Sum of the lengths of all blocks in the polymer.
Pair< int > const & propagatorId(int id) const
Get a propagator identifier, indexed by order of computation.
Base class for a molecular species (polymer or solvent).
Ensemble ensemble_
Statistical ensemble for this species (open or closed).
double phi_
Volume fraction, set by either setPhi or a compute function.
double mu_
Chemical potential, set by either setPhi or a compute function.
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.
PSCF package top-level namespace.