PSCF v1.5.0
FhMolecule.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "FhMolecule.h"
9
10namespace Pscf {
11
12 /*
13 * Constructor.
14 */
16 : clumps_(),
17 nClump_(0),
18 size_(0.0),
19 hasSize_(false)
20 { setClassName("FhMolecule"); }
21
22 /*
23 * Destructor.
24 */
27
28 /*
29 * Read chemical composition from file.
30 */
31 void FhMolecule::readParameters(std::istream& in)
32 {
33 UTIL_ASSERT(clumps_.capacity() == 0);
34
35 read<int>(in, "nClump", nClump_);
36
37 // Allocate all arrays
38 clumps_.allocate(nClump_);
39
40 readDArray<FhClump>(in, "clumps", clumps_, nClump_);
42 }
43
44 /*
45 * Allocate or resize array of clumps, as needed.
46 */
48 {
49 UTIL_CHECK(nClump > 0);
50 if (clumps_.isAllocated()) {
51 if (clumps_.capacity() == nClump) return;
52 clumps_.deallocate();
53 }
54 UTIL_CHECK(!clumps_.isAllocated());
55 nClump_ = nClump;
56 clumps_.allocate(nClump_);
57 }
58
59 /*
60 * Compute molecular size, by adding all clump sizes.
61 */
63 {
64 UTIL_ASSERT(clumps_.capacity() > 0);
65 UTIL_ASSERT(clumps_.capacity() == nClump_);
66
67 size_ = 0.0;
68 for (int clumpId = 0; clumpId < nClump_; ++clumpId) {
69 size_ += clumps_[clumpId].size();
70 }
71 hasSize_ = true;
72 }
73
74}
FhMolecule()
Constructor.
void setNClump(int nClump)
Set the number of clumps, and allocate memory.
void computeSize()
Compute total molecule size by adding clump sizes.
virtual void readParameters(std::istream &in)
Read and initialize.
int nClump() const
Number of monomer clumps (monomer types).
Definition FhMolecule.h:122
~FhMolecule()
Destructor.
DArrayParam< Type > & readDArray(std::istream &in, const char *label, DArray< Type > &array, int n)
Add and read a required DArray < Type > parameter.
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.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
PSCF package top-level namespace.