PSCF v1.1
MixtureTmpl.h
1#ifndef PSCF_MIXTURE_TMPL_H
2#define PSCF_MIXTURE_TMPL_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/chem/Monomer.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 TP, class TS>
27 {
28 public:
29
30 // Public typedefs
31
35 typedef TP Polymer;
36
40 typedef TS Solvent;
41
42 // Public member functions
43
48
53
59 virtual void readParameters(std::istream& in);
60
63
69 Monomer const & monomer(int id) const;
70
76 Polymer& polymer(int id);
77
83 Polymer const & polymer(int id) const;
84
90 Solvent& solvent(int id);
91
97 Solvent const & solvent(int id) const;
98
102
106 int nMonomer() const;
107
111 int nPolymer() const;
112
116 int nBlock() const;
117
121 int nSolvent() const;
122
126 double vMonomer() const;
127
129
130 protected:
131
137 Monomer& monomer(int id);
138
139 private:
140
144 DArray<Monomer> monomers_;
145
151 DArray<Polymer> polymers_;
152
158 DArray<Solvent> solvents_;
159
163 int nMonomer_;
164
168 int nPolymer_;
169
173 int nSolvent_;
174
178 int nBlock_;
179
183 double vMonomer_;
184
185 };
186
187 // Inline member functions
188
189 template <class TP, class TS>
191 { return nMonomer_; }
192
193 template <class TP, class TS>
195 { return nPolymer_; }
196
197 template <class TP, class TS>
199 { return nSolvent_; }
200
201 template <class TP, class TS>
202 inline int MixtureTmpl<TP,TS>::nBlock() const
203 { return nBlock_; }
204
205 template <class TP, class TS>
206 inline Monomer const & MixtureTmpl<TP,TS>::monomer(int id) const
207 {
208 UTIL_CHECK(id < nMonomer_);
209 return monomers_[id];
210 }
211
212 template <class TP, class TS>
214 {
215 UTIL_CHECK(id < nMonomer_);
216 return monomers_[id];
217 }
218
219 template <class TP, class TS>
221 {
222 UTIL_CHECK(id < nPolymer_);
223 return polymers_[id];
224 }
225
226 template <class TP, class TS>
227 inline TP const & MixtureTmpl<TP,TS>::polymer(int id) const
228 {
229 UTIL_CHECK(id < nPolymer_);
230 return polymers_[id];
231 }
232
233 template <class TP, class TS>
235 {
236 UTIL_CHECK(id < nSolvent_);
237 return solvents_[id];
238 }
239
240 template <class TP, class TS>
241 inline TS const & MixtureTmpl<TP,TS>::solvent(int id) const
242 {
243 UTIL_CHECK(id < nSolvent_);
244 return solvents_[id];
245 }
246
247 template <class TP, class TS>
248 inline double MixtureTmpl<TP,TS>::vMonomer() const
249 { return vMonomer_; }
250
251 // Non-inline member functions
252
253 /*
254 * Constructor.
255 */
256 template <class TP, class TS>
258 : ParamComposite(),
259 monomers_(),
260 polymers_(),
261 solvents_(),
262 nMonomer_(0),
263 nPolymer_(0),
264 nSolvent_(0),
265 nBlock_(0),
266 vMonomer_(1.0)
267 {}
268
269 /*
270 * Destructor.
271 */
272 template <class TP, class TS>
274 {}
275
276 /*
277 * Read all parameters and initialize.
278 */
279 template <class TP, class TS>
281 {
282 // Read nMonomer and monomers array
283 read<int>(in, "nMonomer", nMonomer_);
284 monomers_.allocate(nMonomer_);
285 for (int i = 0; i < nMonomer_; ++i) {
286 monomers_[i].setId(i);
287 }
288 readDArray< Monomer >(in, "monomers", monomers_, nMonomer_);
289
290 /*
291 * The input format for a single monomer is defined in the istream
292 * extraction operation (operator >>) for a Pscf::Monomer, in file
293 * pscf/chem/Monomer.cpp. The text representation contains only the
294 * value for the monomer statistical segment Monomer::kuhn.
295 */
296
297 // Read nPolymer
298 read<int>(in, "nPolymer", nPolymer_);
299 UTIL_CHECK(nPolymer_ > 0);
300
301 // Optionally read nSolvent, with nSolvent=0 by default
302 nSolvent_ = 0;
303 readOptional<int>(in, "nSolvent", nSolvent_);
304
305 // Read polymers and compute nBlock
306 nBlock_ = 0;
307 if (nPolymer_ > 0) {
308
309 polymers_.allocate(nPolymer_);
310 for (int i = 0; i < nPolymer_; ++i) {
311 readParamComposite(in, polymer(i));
312 nBlock_ = nBlock_ + polymer(i).nBlock();
313 }
314
315 // Set statistical segment lengths for all blocks
316 double kuhn;
317 int monomerId;
318 for (int i = 0; i < nPolymer_; ++i) {
319 for (int j = 0; j < polymer(i).nBlock(); ++j) {
320 monomerId = polymer(i).block(j).monomerId();
321 kuhn = monomer(monomerId).kuhn();
322 polymer(i).block(j).setKuhn(kuhn);
323 }
324 }
325
326 }
327
328 // Read solvents
329 if (nSolvent_ > 0) {
330
331 solvents_.allocate(nSolvent_);
332 for (int i = 0; i < nSolvent_; ++i) {
333 readParamComposite(in, solvent(i));
334 }
335
336 }
337
338 // Optionally read monomer reference value
339 vMonomer_ = 1.0; // Default value
340 readOptional(in, "vMonomer", vMonomer_);
341
342 }
343
344}
345#endif
A mixture of polymer and solvent species.
Definition: MixtureTmpl.h:27
MixtureTmpl()
Constructor.
Definition: MixtureTmpl.h:257
Polymer & polymer(int id)
Get a polymer object.
Definition: MixtureTmpl.h:220
int nBlock() const
Get number of total blocks in the mixture across all polymers.
Definition: MixtureTmpl.h:202
int nSolvent() const
Get number of solvent (point particle) species.
Definition: MixtureTmpl.h:198
Solvent const & solvent(int id) const
Set a solvent solver object.
Definition: MixtureTmpl.h:241
double vMonomer() const
Get monomer reference volume (set to 1.0 by default).
Definition: MixtureTmpl.h:248
Polymer const & polymer(int id) const
Get a polymer object by const reference.
Definition: MixtureTmpl.h:227
Monomer & monomer(int id)
Get a Monomer type descriptor (non-const reference).
Definition: MixtureTmpl.h:213
TP Polymer
Polymer species solver typename.
Definition: MixtureTmpl.h:35
int nMonomer() const
Get number of monomer types.
Definition: MixtureTmpl.h:190
~MixtureTmpl()
Destructor.
Definition: MixtureTmpl.h:273
Monomer const & monomer(int id) const
Get a Monomer type descriptor (const reference).
Definition: MixtureTmpl.h:206
Solvent & solvent(int id)
Set a solvent solver object.
Definition: MixtureTmpl.h:234
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
Definition: MixtureTmpl.h:280
TS Solvent
Solvent species solver typename.
Definition: MixtureTmpl.h:40
int nPolymer() const
Get number of polymer species.
Definition: MixtureTmpl.h:194
Descriptor for a monomer or particle type.
Definition: Monomer.h:32
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
An object that can read multiple parameters from file.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1