PSCF v1.4.0
rp/field/CFields.h
1#ifndef RP_C_FIELDS_H
2#define RP_C_FIELDS_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 <util/containers/DArray.h> // member template
12#include <pscf/math/IntVec.h> // template with defaults
13
14// Forward declarations
15namespace Pscf {
16 namespace Prdc {
17 template <int D> class UnitCell;
18 }
19}
20
21namespace Pscf {
22namespace Rp {
23
24 using namespace Util;
25 using namespace Prdc;
26
68 template <int D, class RFT, class FIT>
69 class CFields
70 {
71
72 public:
73
76
82 void setFieldIo(FIT const & fieldIo);
83
94 void setWriteUnitCell(UnitCell<D> const & cell);
95
104 void setNMonomer(int nMonomer);
105
113 void allocateRGrid(IntVec<D> const & dimensions);
114
122 void allocateBasis(int nBasis);
123
133 void allocate(int nMonomer, int nBasis, IntVec<D> const & dimensions);
134
138
143
149 DArray< DArray<double> > const & basis() const;
150
156 DArray<double> & basis(int monomerId);
157
163 DArray<double> const & basis(int monomerId) const;
164
169
173 DArray<RFT> const & rgrid() const;
174
180 RFT & rgrid(int monomerId);
181
187 RFT const & rgrid(int monomerId) const;
188
192
198 void writeBasis(std::ostream& out) const;
199
205 void writeBasis(std::string filename) const;
206
212 void writeRGrid(std::ostream& out) const;
213
219 void writeRGrid(std::string filename) const;
220
224
228 bool isAllocatedRGrid() const;
229
233 bool isAllocatedBasis() const;
234
238 bool hasData() const;
239
243 bool isSymmetric() const;
244
248
256 void setHasData(bool hasData);
257
265 void setIsSymmetric(bool isSymmetric);
266
268
269 protected:
270
274 CFields();
275
279 ~CFields() = default;
280
284 FIT const & fieldIo() const;
285
286 private:
287
288 /*
289 * Array of fields in symmetry-adapted basis format
290 *
291 * Element basis_[i] is an array that contains the components
292 * of the field associated with monomer i, in a symmetry-adapted
293 * Fourier basis expansion.
294 */
295 DArray< DArray<double> > basis_;
296
297 /*
298 * Array of fields in real-space grid (r-grid) format
299 *
300 * Element basis_[i] is an RFT that contains values of the
301 * field associated with monomer i on the nodes of a regular mesh.
302 */
303 DArray<RFT> rgrid_;
304
305 /*
306 * Number of monomer types.
307 */
308 int nMonomer_;
309
310 /*
311 * Pointer to associated UnitCell<D> object.
312 */
313 UnitCell<D> const * writeUnitCellPtr_;
314
315 /*
316 * Pointer to associated FIT (FieldIo) object
317 */
318 FIT const * fieldIoPtr_;
319
320 /*
321 * Has memory been allocated for fields in r-grid format?
322 */
323 bool isAllocatedRGrid_;
324
325 /*
326 * Has memory been allocated for fields in basis format?
327 */
328 bool isAllocatedBasis_;
329
330 /*
331 * Does this container hold up-to-date field data?
332 */
333 bool hasData_;
334
335 /*
336 * Are the fields symmetric?
337 */
338 bool isSymmetric_;
339
340 };
341
342 // Public inline member functions
343
344 // Get array of all fields in basis format (non-const)
345 template <int D, class RFT, class FIT> inline
347 {
348 UTIL_ASSERT(isAllocatedBasis_);
349 return basis_;
350 }
351
352 // Get array of all fields in basis format (const)
353 template <int D, class RFT, class FIT> inline
355 {
356 UTIL_ASSERT(isAllocatedBasis_);
357 return basis_;
358 }
359
360 // Get one field in basis format (non-const)
361 template <int D, class RFT, class FIT> inline
363 {
364 UTIL_ASSERT(isAllocatedBasis_);
365 return basis_[id];
366 }
367
368 // Get one field in basis format (const)
369 template <int D, class RFT, class FIT> inline
371 const
372 {
373 UTIL_ASSERT(isAllocatedBasis_);
374 return basis_[id];
375 }
376
377 // Get all fields in r-grid format (non-const)
378 template <int D, class RFT, class FIT> inline
380 {
381 UTIL_ASSERT(isAllocatedRGrid_);
382 return rgrid_;
383 }
384
385 // Get all fields in r-grid format (const)
386 template <int D, class RFT, class FIT> inline
388 {
389 UTIL_ASSERT(isAllocatedRGrid_);
390 return rgrid_;
391 }
392
393 // Get one field in r-grid format (non-const)
394 template <int D, class RFT, class FIT> inline
396 {
397 UTIL_ASSERT(isAllocatedRGrid_);
398 return rgrid_[id];
399 }
400
401 // Get one field in r-grid format (const)
402 template <int D, class RFT, class FIT> inline
403 RFT const & CFields<D,RFT,FIT>::rgrid(int id) const
404 {
405 UTIL_ASSERT(isAllocatedRGrid_);
406 return rgrid_[id];
407 }
408
409 // Has memory been allocated for fields in r-grid format?
410 template <int D, class RFT, class FIT> inline
412 { return isAllocatedRGrid_; }
413
414 // Has memory been allocated for fields in basis format?
415 template <int D, class RFT, class FIT> inline
417 { return isAllocatedBasis_; }
418
419 // Are the fields up-to-date?
420 template <int D, class RFT, class FIT> inline
422 { return hasData_; }
423
424 // Are the fields symmetric under elements of the space group?
425 template <int D, class RFT, class FIT> inline
427 { return isSymmetric_; }
428
429 // Protected inline member function
430
431 // Associated FieldIo object (const reference).
432 template <int D, class RFT, class FIT> inline
433 FIT const & CFields<D,RFT,FIT>::fieldIo() const
434 {
435 UTIL_CHECK(fieldIoPtr_);
436 return *fieldIoPtr_;
437 }
438
439} // namespace Rp
440} // namespace Pscf
441#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
bool isAllocatedRGrid() const
Has memory been allocated for fields in r-grid format?
void writeBasis(std::ostream &out) const
Write fields to an input stream in symmetrized basis format.
bool hasData() const
Does this container have up-to-date fields?
~CFields()=default
Destructor.
void setFieldIo(FIT const &fieldIo)
Create association with FIT (store pointer).
void writeRGrid(std::ostream &out) const
Writes fields to an input stream in real-space (r-grid) format.
void setNMonomer(int nMonomer)
Set stored value of nMonomer.
void allocate(int nMonomer, int nBasis, IntVec< D > const &dimensions)
Allocate memory for both r-grid and basis field formats.
void allocateRGrid(IntVec< D > const &dimensions)
Allocate memory for fields in rgrid format.
bool isSymmetric() const
Are the fields invariant under elements of the space group?
FIT const & fieldIo() const
Get associated FieldIo object (const reference).
void setHasData(bool hasData)
Set the hasData flag.
DArray< DArray< double > > & basis()
Get array of all fields in basis format (non-const).
bool isAllocatedBasis() const
Has memory been allocated for fields in basis format?
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag.
DArray< RFT > & rgrid()
Get array of all fields in r-grid format (non-const).
void allocateBasis(int nBasis)
Allocate or re-allocate memory for fields in basis format.
void setWriteUnitCell(UnitCell< D > const &cell)
Set unit cell used when writing field files.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Periodic fields and crystallography.
Definition complex.cpp:11
Class templates for real-valued periodic fields.
PSCF package top-level namespace.
Utility classes for scientific computation.