PSCF v1.3.1
MixtureTmpl.tpp
1#ifndef PSCF_MIXTURE_TMPL_TPP
2#define PSCF_MIXTURE_TMPL_TPP
3
4/*
5* PSCF - Mixture Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "MixtureTmpl.h" // base class
12
13namespace Pscf
14{
15
16 /*
17 * Constructor.
18 */
19 template <class PT, class ST>
21 : MixtureBase(),
23 polymers_(),
24 solvents_()
25 {}
26
27 /*
28 * Destructor.
29 */
30 template <class PT, class ST>
33
34 /*
35 * Get a PolymerSpecies descriptor by non-const reference.
36 */
37 template <class PT, class ST>
39 {
40 UTIL_CHECK(id < nPolymer_);
41 return polymers_[id];
42 }
43
44 /*
45 * Get a SolventSpecies descriptor by const reference.
46 */
47 template <class PT, class ST>
49 {
50 UTIL_CHECK(id < nSolvent_);
51 return solvents_[id];
52 }
53
54 /*
55 * Read all parameters and initialize.
56 */
57 template <class PT, class ST>
59 {
60 // Read nMonomer and monomers array
61 read<int>(in, "nMonomer", nMonomer_);
62 monomers_.allocate(nMonomer_);
63 for (int i = 0; i < nMonomer_; ++i) {
64 monomers_[i].setId(i);
65 }
66 readDArray< Monomer >(in, "monomers", monomers_, nMonomer_);
67
68 /*
69 * The input format for a single monomer is defined in the istream
70 * extraction operation (operator >>) for a Pscf::Monomer, in file
71 * pscf/chem/Monomer.cpp. The text representation contains only the
72 * value for the monomer statistical segment Monomer::kuhn.
73 */
74
75 // Read nPolymer (required parameter, must be > 0)
76 read<int>(in, "nPolymer", nPolymer_);
77 UTIL_CHECK(nPolymer_ > 0);
78
79 // Optionally read nSolvent, with nSolvent=0 by default
80 nSolvent_ = 0;
81 readOptional<int>(in, "nSolvent", nSolvent_);
82
83 // Read polymers and compute nBlock
84 nBlock_ = 0;
85 if (nPolymer_ > 0) {
86
87 polymers_.allocate(nPolymer_);
88 for (int i = 0; i < nPolymer_; ++i) {
90 nBlock_ = nBlock_ + polymer(i).nBlock();
91 }
92
93 // Set statistical segment lengths for all blocks
94 double kuhn;
95 int monomerId;
96 for (int i = 0; i < nPolymer_; ++i) {
97 for (int j = 0; j < polymer(i).nBlock(); ++j) {
98 monomerId = polymer(i).block(j).monomerId();
99 kuhn = monomer(monomerId).kuhn();
100 polymer(i).block(j).setKuhn(kuhn);
101 }
102 }
103
104 }
105
106 // Read solvents
107 if (nSolvent_ > 0) {
109 solvents_.allocate(nSolvent_);
110 for (int i = 0; i < nSolvent_; ++i) {
112 }
113
114 }
115
116 // Optionally read monomer reference value
117 vMonomer_ = 1.0; // Default value
118 readOptional(in, "vMonomer", vMonomer_);
119
120 }
121
122}
123#endif
MixtureBase()
Constructor.
PolymerSpecies const & polymerSpecies(int id) const final
Get a PolymerSpecies descriptor by const reference.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
~MixtureTmpl()
Destructor.
MixtureTmpl()
Constructor.
SolventSpecies const & solventSpecies(int id) const final
Set a SolventSpecies descriptor object by const reference.
Descriptor for a linear or acyclic branched block polymer.
SolventT & solvent(int id)
Get a solvent solver object.
Descriptor for a solvent species.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
ParamComposite()
Constructor.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Definition param_pc.dox:1