PSCF v1.1
pspg/field/WFieldContainer.h
1#ifndef PSPG_W_FIELD_CONTAINER_H
2#define PSPG_W_FIELD_CONTAINER_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
12#include <util/param/ParamComposite.h> // base class
13
14#include <pscf/math/IntVec.h> // function parameter
15#include <pscf/crystal/UnitCell.h> // function parameter
16#include <pspg/field/RDField.h> // member template parameter
17#include <util/containers/DArray.h> // member template
18
19namespace Pscf {
20namespace Pspg {
21
22 template <int D> class FieldIo;
23
24 using namespace Util;
25
57 template <int D>
59 {
60
61 public:
62
67
72
76 void setFieldIo(FieldIo<D> const & fieldIo);
77
85 void setNMonomer(int nMonomer);
86
92 void allocateRGrid(IntVec<D> const & dimensions);
93
97 void deallocateRGrid();
98
104 void allocateBasis(int nBasis);
105
109 void deallocateBasis();
110
120 void allocate(int nMonomer, int nBasis, IntVec<D> const & dimensions);
121
131 void setBasis(DArray< DArray<double> > const & fields);
132
148 void setRGrid(DArray< RDField<D> > const & fields,
149 bool isSymmetric = false);
150
159 void setRGrid(DField<cudaReal> & fields);
160
175 void readBasis(std::istream& in, UnitCell<D>& unitCell);
176
191 void readBasis(std::string filename, UnitCell<D>& unitCell);
192
212 void readRGrid(std::istream& in, UnitCell<D>& unitCell,
213 bool isSymmetric = false);
214
234 void readRGrid(std::string filename, UnitCell<D>& unitCell,
235 bool isSymmetric = false);
236
257 void symmetrize();
258
264 DArray< DArray<double> > const & basis() const;
265
273 DArray<double> const & basis(int monomerId) const;
274
280 DArray< RDField<D> > const & rgrid() const;
281
287 RDField<D> const & rgrid(int monomerId) const;
288
292 bool isAllocatedRGrid() const;
293
297 bool isAllocatedBasis() const;
298
304 bool hasData() const;
305
314 bool isSymmetric() const;
315
316 private:
317
318 /*
319 * Array of fields in symmetry-adapted basis format
320 *
321 * Element basis_[i] is an array that contains the components
322 * of the field associated with monomer i, in a symmetry-adapted
323 * Fourier expansion.
324 */
325 DArray< DArray<double> > basis_;
326
327 /*
328 * Array of fields in real-space grid (r-grid) format
329 *
330 * Element basis_[i] is an RDField<D> that contains values of the
331 * field associated with monomer i on the nodes of a regular mesh.
332 */
333 DArray< RDField<D> > rgrid_;
334
335 /*
336 * Pointer to associated FieldIo object
337 */
338 FieldIo<D> const * fieldIoPtr_;
339
340 /*
341 * Integer vector of grid dimensions.
342 *
343 * Element i is the number of grid points along direction i
344 */
345 IntVec<D> meshDimensions_;
346
347 /*
348 * Total number grid points (product of mesh dimensions)
349 */
350 int meshSize_;
351
352 /*
353 * Number of basis functions in symmetry-adapted basis
354 */
355 int nBasis_;
356
357 /*
358 * Number of monomer types (number of fields)
359 */
360 int nMonomer_;
361
362 /*
363 * Has memory been allocated for fields in r-grid format?
364 */
365 bool isAllocatedRGrid_;
366
367 /*
368 * Has memory been allocated for fields in basis format?
369 */
370 bool isAllocatedBasis_;
371
372 /*
373 * Has field data been initialized ?
374 */
375 bool hasData_;
376
377 /*
378 * Are the fields symmetric under space group operations?
379 *
380 * Set true when fields are set using the symmetry adapted basis
381 * format via function setBasis. False by otherwise.
382 */
383 bool isSymmetric_;
384
385 };
386
387 // Inline member functions
388
389 // Get array of all fields in basis format (const)
390 template <int D>
391 inline
393 { return basis_; }
394
395 // Get one field in basis format (const)
396 template <int D>
397 inline
399 { return basis_[id]; }
400
401 // Get all fields in r-grid format (const)
402 template <int D>
403 inline
404 DArray< RDField<D> > const &
406 { return rgrid_; }
407
408 // Get one field in r-grid format (const)
409 template <int D>
410 inline
412 { return rgrid_[id]; }
413
414 // Has memory been allocated for fields in r-grid format?
415 template <int D>
417 { return isAllocatedRGrid_; }
418
419 // Has memory been allocated for fields in basis format?
420 template <int D>
422 { return isAllocatedBasis_; }
423
424 // Has field data been initialized ?
425 template <int D>
426 inline bool WFieldContainer<D>::hasData() const
427 { return hasData_; }
428
429 // Are the fields symmetric under space group operations?
430 template <int D>
432 { return isSymmetric_; }
433
434 #ifndef PSPG_W_FIELD_CONTAINER_TPP
435 // Suppress implicit instantiation
436 extern template class WFieldContainer<1>;
437 extern template class WFieldContainer<2>;
438 extern template class WFieldContainer<3>;
439 #endif
440
441} // namespace Pspg
442} // namespace Pscf
443#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition: IntVec.h:27
Dynamic array on the GPU with alligned data.
Definition: DField.h:30
File input/output operations for fields in several file formats.
Field of real single precision values on an FFT mesh on a device.
Definition: RDField.h:34
A list of fields stored in both basis and r-grid format.
void setRGrid(DArray< RDField< D > > const &fields, bool isSymmetric=false)
Set fields values in real-space (r-grid) format.
bool isAllocatedBasis() const
Has memory been allocated for fields in basis format?
void symmetrize()
Symmetrize r-grid fields, compute corresponding basis components.
void deallocateBasis()
De-allocate fields in basis format.
bool isSymmetric() const
Are fields symmetric under all elements of the space group?
void setBasis(DArray< DArray< double > > const &fields)
Set field component values, in symmetrized Fourier format.
DArray< DArray< double > > const & basis() const
Get array of all fields in basis format.
bool isAllocatedRGrid() const
Has memory been allocated for fields in r-grid format?
void allocate(int nMonomer, int nBasis, IntVec< D > const &dimensions)
Allocate memory for all fields.
void setNMonomer(int nMonomer)
Set stored value of nMonomer.
DArray< RDField< D > > const & rgrid() const
Get array of all fields in r-space grid format.
void deallocateRGrid()
De-allocate fields in rgrid format.
void readRGrid(std::istream &in, UnitCell< D > &unitCell, bool isSymmetric=false)
Reads fields from an input stream in real-space (r-grid) format.
bool hasData() const
Has field data been set in either format?
void setFieldIo(FieldIo< D > const &fieldIo)
Create association with FieldIo (store pointer).
void allocateRGrid(IntVec< D > const &dimensions)
Allocate or re-allocate memory for fields in rgrid format.
void readBasis(std::istream &in, UnitCell< D > &unitCell)
Read field component values from input stream, in symmetrized Fourier format.
void allocateBasis(int nBasis)
Allocate or re-allocate memory for fields in basis format.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition: UnitCell.h:44
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
An object that can read multiple parameters from file.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1