PSCF v1.4.0
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"
12
13namespace Pscf
14{
15
16 /*
17 * Constructor.
18 */
19 template <class PT, class ST, typename WT>
21 : MixtureBase<WT>(),
23 polymers_(),
24 solvents_()
25 {}
26
27 /*
28 * Get a PolymerSpecies descriptor by non-const reference.
29 */
30 template <class PT, class ST, typename WT>
31 PolymerSpecies<WT> const &
33 {
35 return polymers_[id];
36 }
37
38 /*
39 * Get a SolventSpecies descriptor by const reference.
40 */
41 template <class PT, class ST, typename WT>
42 SolventSpecies<WT> const &
44 {
46 return solvents_[id];
47 }
48
49 /*
50 * Read all parameters and initialize.
51 */
52 template <class PT, class ST, typename WT>
54 {
55 // Read nMonomer and monomers array
56 read<int>(in, "nMonomer", nMonomer_);
57 monomers_.allocate(nMonomer_);
58 for (int i = 0; i < nMonomer_; ++i) {
59 monomers_[i].setId(i);
60 }
63 /*
64 * The input format for a single monomer is defined in the istream
65 * extraction operation (operator >>) for a Pscf::Monomer, in file
66 * pscf/chem/Monomer.cpp. The text representation contains only the
67 * value for the monomer statistical segment Monomer::kuhn.
68 */
69
70 // Read nPolymer (required parameter, must be > 0)
71 read<int>(in, "nPolymer", nPolymer_);
73
74 // Optionally read nSolvent, with nSolvent=0 by default
75 nSolvent_ = 0;
76 readOptional<int>(in, "nSolvent", nSolvent_);
77
78 // Read polymers and compute nBlock
79 nBlock_ = 0;
80 if (nPolymer_ > 0) {
81
82 polymers_.allocate(nPolymer_);
83 for (int i = 0; i < nPolymer_; ++i) {
85 nBlock_ = nBlock_ + polymer(i).nBlock();
86 }
87
88 // Set statistical segment lengths for all blocks
89 double kuhn;
90 int monomerId;
91 for (int i = 0; i < nPolymer_; ++i) {
92 for (int j = 0; j < polymer(i).nBlock(); ++j) {
93 monomerId = polymer(i).block(j).monomerId();
94 kuhn = MixtureBase<WT>::monomer(monomerId).kuhn();
95 polymer(i).block(j).setKuhn(kuhn);
96 }
97 }
98
99 }
100
101 // Read solvents
102 if (nSolvent_ > 0) {
103
104 solvents_.allocate(nSolvent_);
105 for (int i = 0; i < nSolvent_; ++i) {
106 readParamComposite(in, solvent(i));
107 }
108
109 }
110
111 // Optionally read monomer reference value
112 vMonomer_ = 1.0; // Default value
113 readOptional(in, "vMonomer", vMonomer_);
114
115 }
116
117}
118#endif
DArray< Monomer > monomers_
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
SolventSpecies< WT > const & solventSpecies(int id) const final
Set a SolventSpecies descriptor object by const reference.
MixtureTmpl()
Constructor.
void readParameters(std::istream &in) override
Read parameters from file and initialize.
PolymerSpecies< WT > const & polymerSpecies(int id) const final
Get a PolymerSpecies descriptor by const reference.
double kuhn() const
Statistical segment length (random walk step size).
Definition Monomer.h:131
Descriptor for a linear or acyclic branched block polymer.
Descriptor for a solvent species.
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.
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.