PSCF v1.1
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
74 template <class TP>
76 {
77
78 public:
79
84
87
94
103 void setPartner(const TP& partner);
104
114 void addSource(const TP& source);
115
120
124
130 const TP& source(int id) const;
131
135 const TP& partner() const;
136
140 int directionId() const;
141
145 int nSource() const;
146
150 bool hasPartner() const;
151
155 bool isSolved() const;
156
160 bool isReady() const;
161
163
164 private:
165
167 int directionId_;
168
170 TP const * partnerPtr_;
171
173 GArray<TP const *> sourcePtrs_;
174
176 bool isSolved_;
177
178 };
179
180 // Inline member functions
181
182 /*
183 * Get the direction index.
184 */
185 template <class TP>
187 { return directionId_; }
188
189 /*
190 * Get the number of source propagators.
191 */
192 template <class TP>
194 { return sourcePtrs_.size(); }
195
196 /*
197 * Get a source propagator.
198 */
199 template <class TP>
200 inline const TP&
202 { return *(sourcePtrs_[id]); }
203
207 template <class TP>
208 inline
210 { return partnerPtr_; }
211
212 /*
213 * Is the computation of this propagator completed?
214 */
215 template <class TP>
217 { return isSolved_; }
218
219 // Noninline member functions
220
221 /*
222 * Constructor.
223 */
224 template <class TP>
226 : directionId_(-1),
227 partnerPtr_(0),
228 sourcePtrs_(),
229 isSolved_(false)
230 {}
231
232 /*
233 * Set the directionId.
234 */
235 template <class TP>
237 { directionId_ = directionId; }
238
239 /*
240 * Set the partner propagator.
241 */
242 template <class TP>
243 void PropagatorTmpl<TP>::setPartner(const TP& partner)
244 { partnerPtr_ = &partner; }
245
246 /*
247 * Add a source propagator to the list.
248 */
249 template <class TP>
250 void PropagatorTmpl<TP>::addSource(const TP& source)
251 { sourcePtrs_.append(&source); }
252
253 /*
254 * Get partner propagator.
255 */
256 template <class TP>
258 const
259 {
260 UTIL_CHECK(partnerPtr_);
261 return *partnerPtr_;
262 }
263
264 /*
265 * Mark this propagator as solved (true) or not (false).
266 */
267 template <class TP>
269 { isSolved_ = isSolved; }
270
271 /*
272 * Check if all source propagators are marked completed.
273 */
274 template <class TP>
276 {
277 for (int i=0; i < sourcePtrs_.size(); ++i) {
278 if (!sourcePtrs_[i]->isSolved()) {
279 return false;
280 }
281 }
282 return true;
283 }
284
285}
286#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 are 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
#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