PSCF v1.2
PropagatorTmpl.h
1#ifndef PSCF_PROPAGATOR_TMPL_H
2#define PSCF_PROPAGATOR_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 <util/containers/GArray.h>
12
13namespace Pscf
14{
15
16 using namespace Util;
17
90 template <class TP>
92 {
93
94 public:
95
100
103
110
119 void setPartner(const TP& partner);
120
130 void addSource(const TP& source);
131
136
140
146 const TP& source(int id) const;
147
151 const TP& partner() const;
152
156 int directionId() const;
157
161 int nSource() const;
162
166 bool hasPartner() const;
167
171 bool isSolved() const;
172
176 bool isReady() const;
177
179
180 private:
181
183 int directionId_;
184
186 TP const * partnerPtr_;
187
189 GArray<TP const *> sourcePtrs_;
190
192 bool isSolved_;
193
194 };
195
196 // Inline member functions
197
198 /*
199 * Get the direction index.
200 */
201 template <class TP>
203 { return directionId_; }
204
205 /*
206 * Get the number of source propagators.
207 */
208 template <class TP>
210 { return sourcePtrs_.size(); }
211
212 /*
213 * Get a source propagator.
214 */
215 template <class TP>
216 inline const TP&
218 { return *(sourcePtrs_[id]); }
219
223 template <class TP>
224 inline
226 { return partnerPtr_; }
227
228 /*
229 * Is the computation of this propagator completed?
230 */
231 template <class TP>
233 { return isSolved_; }
234
235 // Noninline member functions
236
237 /*
238 * Constructor.
239 */
240 template <class TP>
242 : directionId_(-1),
243 partnerPtr_(0),
244 sourcePtrs_(),
245 isSolved_(false)
246 {}
247
248 /*
249 * Set the directionId.
250 */
251 template <class TP>
253 { directionId_ = directionId; }
254
255 /*
256 * Set the partner propagator.
257 */
258 template <class TP>
259 void PropagatorTmpl<TP>::setPartner(const TP& partner)
260 { partnerPtr_ = &partner; }
261
262 /*
263 * Add a source propagator to the list.
264 */
265 template <class TP>
266 void PropagatorTmpl<TP>::addSource(const TP& source)
267 { sourcePtrs_.append(&source); }
268
269 /*
270 * Get partner propagator.
271 */
272 template <class TP>
274 const
275 {
276 UTIL_CHECK(partnerPtr_);
277 return *partnerPtr_;
278 }
279
280 /*
281 * Mark this propagator as solved (true) or not (false).
282 */
283 template <class TP>
285 { isSolved_ = isSolved; }
286
287 /*
288 * Check if all source propagators are marked completed.
289 */
290 template <class TP>
292 {
293 for (int i=0; i < sourcePtrs_.size(); ++i) {
294 if (!sourcePtrs_[i]->isSolved()) {
295 return false;
296 }
297 }
298 return true;
299 }
300
301}
302#endif
Template for propagator classes.
void setIsSolved(bool isSolved)
Set the isSolved flag to true or false.
void addSource(const TP &source)
Add a propagator to the list of sources for this one.
const TP & partner() const
Get partner propagator.
const TP & source(int id) const
Get a source propagator.
void setDirectionId(int directionId)
Associate this propagator with a direction index.
bool isSolved() const
Has the modified diffusion equation been solved?
int directionId() const
Get direction index for this propagator.
bool hasPartner() const
Does this have a partner propagator?
bool isReady() const
Are all source propagators solved?
void setPartner(const TP &partner)
Set the partner of this propagator.
PropagatorTmpl()
Constructor.
int nSource() const
Number of source / prerequisite propagators.
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
int size() const
Return logical size of this array (i.e., current number of elements).
Definition GArray.h:455
#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
Utility classes for scientific computation.