PSCF v1.3
MixtureTmpl.h
1#ifndef PSCF_MIXTURE_TMPL_H
2#define PSCF_MIXTURE_TMPL_H
3
4/*
5* PSCF - Polymer 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 <pscf/chem/MixtureBase.h>
12#include <util/param/ParamComposite.h>
13#include <util/containers/DArray.h>
14
15namespace Pscf
16{
17
18 using namespace Util;
19
25 template <class PT, class ST>
26 class MixtureTmpl : public MixtureBase, public ParamComposite
27 {
28 public:
29
30 // Public typedefs
31
35 using SolventT = ST;
36
40 using PolymerT = PT;
41
45 using BlockT = typename PT::BlockT;
46
50 using PropagatorT = typename BlockT::PropagatorT;
51
52 // Public member functions
53
58
63
69 virtual void readParameters(std::istream& in);
70
73
74 /*
75 * Public member functions inherited from MixtureBase:
76 *
77 * int nMonomer() const;
78 * int nPolymer() const;
79 * int nSolvent() const;
80 * int nBlock() const;
81 * double vMonomer() const;
82 * Monomer const & monomer(int id) const;
83 *
84 * void setVmonomer(double);
85 */
86
92 PolymerT& polymer(int id);
93
99 PolymerT const & polymer(int id) const;
100
108 PolymerSpecies const & polymerSpecies(int id) const final;
109
116
122 SolventT const & solvent(int id) const;
123
131 SolventSpecies const & solventSpecies(int id) const final;
132
134
135 private:
136
142 DArray<PolymerT> polymers_;
143
149 DArray<SolventT> solvents_;
150
151 // Restrict access to inherited protected data
158
159 };
160
161 // Inline member functions
162
163 template <class PT, class ST>
165 {
166 UTIL_CHECK(id < nPolymer_);
167 return polymers_[id];
168 }
169
170 template <class PT, class ST>
171 inline PT const & MixtureTmpl<PT,ST>::polymer(int id) const
172 {
173 UTIL_CHECK(id < nPolymer_);
174 return polymers_[id];
175 }
176
177 template <class PT, class ST>
179 {
180 UTIL_CHECK(id < nSolvent_);
181 return solvents_[id];
182 }
183
184 template <class PT, class ST>
185 inline ST const & MixtureTmpl<PT,ST>::solvent(int id) const
186 {
187 UTIL_CHECK(id < nSolvent_);
188 return solvents_[id];
189 }
190
191 // Non-inline member functions
192
193 /*
194 * Constructor.
195 */
196 template <class PT, class ST>
198 : MixtureBase(),
200 polymers_(),
201 solvents_()
202 {}
203
204 /*
205 * Destructor.
206 */
207 template <class PT, class ST>
210
211 /*
212 * Get a PolymerSpecies descriptor by non-const reference.
213 */
214 template <class PT, class ST>
216 {
217 UTIL_CHECK(id < nPolymer_);
218 return polymers_[id];
219 }
220
221 /*
222 * Get a SolventSpecies descriptor by const reference.
223 */
224 template <class PT, class ST>
226 {
227 UTIL_CHECK(id < nSolvent_);
228 return solvents_[id];
229 }
230
231 /*
232 * Read all parameters and initialize.
233 */
234 template <class PT, class ST>
236 {
237 // Read nMonomer and monomers array
238 read<int>(in, "nMonomer", nMonomer_);
239 monomers_.allocate(nMonomer_);
240 for (int i = 0; i < nMonomer_; ++i) {
241 monomers_[i].setId(i);
242 }
243 readDArray< Monomer >(in, "monomers", monomers_, nMonomer_);
244
245 /*
246 * The input format for a single monomer is defined in the istream
247 * extraction operation (operator >>) for a Pscf::Monomer, in file
248 * pscf/chem/Monomer.cpp. The text representation contains only the
249 * value for the monomer statistical segment Monomer::kuhn.
250 */
251
252 // Read nPolymer (required parameter, must be > 0)
253 read<int>(in, "nPolymer", nPolymer_);
254 UTIL_CHECK(nPolymer_ > 0);
255
256 // Optionally read nSolvent, with nSolvent=0 by default
257 nSolvent_ = 0;
258 readOptional<int>(in, "nSolvent", nSolvent_);
259
260 // Read polymers and compute nBlock
261 nBlock_ = 0;
262 if (nPolymer_ > 0) {
263
264 polymers_.allocate(nPolymer_);
265 for (int i = 0; i < nPolymer_; ++i) {
267 nBlock_ = nBlock_ + polymer(i).nBlock();
268 }
269
270 // Set statistical segment lengths for all blocks
271 double kuhn;
272 int monomerId;
273 for (int i = 0; i < nPolymer_; ++i) {
274 for (int j = 0; j < polymer(i).nBlock(); ++j) {
275 monomerId = polymer(i).block(j).monomerId();
276 kuhn = monomer(monomerId).kuhn();
277 polymer(i).block(j).setKuhn(kuhn);
278 }
279 }
280
281 }
282
283 // Read solvents
284 if (nSolvent_ > 0) {
285
286 solvents_.allocate(nSolvent_);
287 for (int i = 0; i < nSolvent_; ++i) {
289 }
290
291 }
292
293 // Optionally read monomer reference value
294 vMonomer_ = 1.0; // Default value
295 readOptional(in, "vMonomer", vMonomer_);
296
297 }
298
299}
300#endif
int nMonomer_
Number of monomer types.
int nPolymer_
Number of polymer species.
int nBlock_
Number of blocks total, across all polymers.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
int nSolvent_
Number of solvent species.
double vMonomer_
Monomer reference volume (set to 1.0 by default).
MixtureBase()
Constructor.
DArray< Monomer > monomers_
Array of monomer type descriptors.
SolventT & solvent(int id)
Get a solvent solver object.
PolymerSpecies const & polymerSpecies(int id) const final
Get a PolymerSpecies descriptor by const reference.
typename PT::BlockT BlockT
Block polymer block type.
Definition MixtureTmpl.h:45
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
PT PolymerT
Polymer species solver type.
Definition MixtureTmpl.h:40
~MixtureTmpl()
Destructor.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
MixtureTmpl()
Constructor.
SolventSpecies const & solventSpecies(int id) const final
Set a SolventSpecies descriptor object by const reference.
typename BlockT::PropagatorT PropagatorT
Polymer block propagator type.
Definition MixtureTmpl.h:50
ST SolventT
Solvent species solver type.
Definition MixtureTmpl.h:35
Descriptor for a linear or acyclic branched block polymer.
PT PolymerT
Polymer species solver type.
Definition MixtureTmpl.h:40
ST SolventT
Solvent species solver type.
Definition MixtureTmpl.h:35
Descriptor for a solvent species.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
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.
Definition param_pc.dox:1