PSCF v1.4.0
PropagatorTmpl.h
1#ifndef PSCF_PROPAGATOR_TMPL_H
2#define PSCF_PROPAGATOR_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/PolymerModel.h>
12#include <util/containers/GArray.h>
13
14namespace Pscf
15{
16
17 using namespace Util;
18
92 template <class QT>
94 {
95
96 public:
97
98 // Protected constructor and destructor (see below).
99
102
109
118 void setPartner(const QT& partner);
119
129 void addSource(const QT& source);
130
135
143
147
153 const QT& source(int id) const;
154
158 const QT& partner() const;
159
163 int directionId() const;
164
168 int nSource() const;
169
173 bool hasPartner() const;
174
180 bool isHeadEnd() const;
181
187 bool isTailEnd() const;
188
192 bool isSolved() const;
193
197 bool isReady() const;
198
200
201 protected:
202
207
208 ~PropagatorTmpl() = default;
209
210 private:
211
213 int directionId_;
214
216 QT const * partnerPtr_;
217
219 GArray<QT const *> sourcePtrs_;
220
222 bool isHeadEnd_;
223
225 bool isTailEnd_;
226
228 bool isSolved_;
229
230 };
231
232 // Inline member functions
233
234 /*
235 * Get the direction index.
236 */
237 template <class QT>
239 { return directionId_; }
240
241 /*
242 * Get the number of source propagators.
243 */
244 template <class QT>
246 { return sourcePtrs_.size(); }
247
248 /*
249 * Get a source propagator.
250 */
251 template <class QT>
252 inline const QT&
254 { return *(sourcePtrs_[id]); }
255
259 template <class QT>
261 { return partnerPtr_; }
262
263 /*
264 * Does this propagator own the head vertex bead?
265 */
266 template <class QT>
268 { return isHeadEnd_; }
269
270 /*
271 * Does this propagator own the tail vertex bead?
272 */
273 template <class QT>
275 { return isTailEnd_; }
276
277 /*
278 * Is the computation of this propagator completed?
279 */
280 template <class QT>
282 { return isSolved_; }
283
284 // Noninline member functions
285
286 /*
287 * Constructor.
288 */
289 template <class QT>
291 : directionId_(-1),
292 partnerPtr_(0),
293 sourcePtrs_(),
294 isSolved_(false)
295 {}
296
297 /*
298 * Set the directionId.
299 */
300 template <class QT>
303
304 /*
305 * Set the partner propagator.
306 */
307 template <class QT>
309 { partnerPtr_ = &partner; }
310
311 /*
312 * Add a source propagator to the list.
313 */
314 template <class QT>
316 { sourcePtrs_.append(&source); }
317
318 /*
319 * Set flags indicate whether vertices are are chain ends.
320 */
321 template <class QT>
323 {
324 isHeadEnd_ = isHeadEnd;
325 isTailEnd_ = isTailEnd;
326 }
327
328 /*
329 * Check if all source propagators are marked completed.
330 */
331 template <class QT>
333 {
334 for (int i=0; i < sourcePtrs_.size(); ++i) {
335 if (!sourcePtrs_[i]->isSolved()) {
336 return false;
337 }
338 }
339 return true;
340 }
341
342 /*
343 * Mark this propagator as solved (true) or not (false).
344 */
345 template <class QT>
347 { isSolved_ = isSolved; }
348
349 /*
350 * Get partner propagator.
351 */
352 template <class QT>
354 const
355 {
356 UTIL_CHECK(partnerPtr_);
357 return *partnerPtr_;
358 }
359
360}
361#endif
int nSource() const
Number of source / prerequisite propagators.
bool hasPartner() const
Does this have a partner propagator?
void setIsSolved(bool isSolved)
Set the isSolved flag to true or false.
void setDirectionId(int directionId)
Associate this propagator with a direction index.
void setEndFlags(bool isHeadEnd, bool isTailEnd)
Set flags indicating whether vertices are chain ends.
const typename T::Propagator & partner() const
void setPartner(const QT &partner)
Set the partner of this propagator.
PropagatorTmpl()
Constructor.
const typename T::Propagator & source(int id) const
bool isReady() const
Are all source propagators solved?
void addSource(const QT &source)
Add a propagator to the list of sources for this one.
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:450
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.