PSCF v1.1
Molecule.cpp
1/*
2* PSCF - Polymer Self-Consistent Field Theory
3*
4* Copyright 2016 - 2022, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Molecule.h"
9
10namespace Pscf{
11
12 /*
13 * Constructor.
14 */
16 : clumps_(),
17 nClump_(0),
18 size_(0.0),
19 hasSize_(false)
20 { setClassName("Molecule"); }
21
22 /*
23 * Destructor.
24 */
26 {}
27
28 /*
29 * Read chemical composition from file.
30 */
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<Homogeneous::Clump>(in, "clumps", clumps_, nClump_);
41 computeSize();
42 }
43
44 /*
45 * Allocate memory for specified number of clumps.
46 */
48 {
49 UTIL_ASSERT(clumps_.capacity() == 0);
50
51 nClump_ = nClump;
52 clumps_.allocate(nClump_);
53 }
54
55 /*
56 * Compute molecular size, by adding all clump sizes.
57 */
59 {
60 UTIL_ASSERT(clumps_.capacity() > 0);
61 UTIL_ASSERT(clumps_.capacity() == nClump_);
62
63 size_ = 0.0;
64 for (int clumpId = 0; clumpId < nClump_; ++clumpId) {
65 size_ += clumps_[clumpId].size();
66 }
67 hasSize_ = true;
68 }
69
70}
void setNClump(int nClump)
Set the number of clumps, and allocate memory.
Definition: Molecule.cpp:47
void computeSize()
Compute total molecule size by adding clump sizes.
Definition: Molecule.cpp:58
virtual void readParameters(std::istream &in)
Read and initialize.
Definition: Molecule.cpp:31
void setClassName(const char *className)
Set class name string.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).