PSCF v1.4.0
BasisFieldState.tpp
1#ifndef RP_BASIS_FIELD_STATE_TPP
2#define RP_BASIS_FIELD_STATE_TPP
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 "BasisFieldState.h"
12
13#if 0
14#include <rpc/system/System.h>
15#include <rpc/solvers/Mixture.h>
16#include <rpc/field/Domain.h>
17#include <rpc/field/FieldIo.h>
18#endif
19
20#include <prdc/crystal/Basis.h>
21#include <util/global.h>
22
23namespace Pscf {
24namespace Rp {
25
26 using namespace Util;
27 using namespace Prdc;
28
29 /*
30 * Default constructor.
31 */
32 template <int D, class T>
34 : FieldStateT()
35 {}
36
37 /*
38 * Constructor.
39 */
40 template <int D, class T>
42 : FieldStateT(system)
43 {}
44
45 /*
46 * Allocate all fields.
47 */
48 template <int D, class T>
50 {
51 // Precondition
54 int nMonomer = system().mixture().nMonomer();
55 UTIL_CHECK(nMonomer > 0);
56 if (fields().isAllocated()) {
57 UTIL_CHECK(fields().capacity() == nMonomer);
58 } else {
59 fields().allocate(nMonomer);
60 }
61
62 int nBasis = system().domain().basis().nBasis();
63 UTIL_CHECK(nBasis > 0);
64 for (int i = 0; i < nMonomer; ++i) {
65 if (field(i).isAllocated()) {
66 UTIL_CHECK(field(i).capacity() == nBasis);
67 } else {
68 field(i).allocate(nBasis);
69 }
70 }
71
72 }
73
74 /*
75 * Read fields in symmetry-adapted basis format.
76 */
77 template <int D, class T>
78 void BasisFieldState<D,T>::read(const std::string & filename)
79 {
80 allocate();
81 FieldIoT const & fieldIo = system().domain().fieldIo();
82 fieldIo.readFieldsBasis(filename, fields(), unitCell());
83 }
84
85 /*
86 * Write fields in symmetry-adapted basis format.
87 */
88 template <int D, class T>
89 void BasisFieldState<D,T>::write(const std::string & filename)
90 {
91 FieldIoT const & fieldIo = system().domain().fieldIo();
92 fieldIo.writeFieldsBasis(filename, fields(), unitCell());
93 }
94
95 /*
96 * Get current state of associated System.
97 */
98 template <int D, class T>
100 {
101 // Get system wFields
102 allocate();
103 int nMonomer = system().mixture().nMonomer();
104 int nBasis = system().domain().basis().nBasis();
105 int i, j;
106 for (i = 0; i < nMonomer; ++i) {
107 DArray<double>& stateField = field(i);
108 const DArray<double>& systemField = system().w().basis(i);
109 for (j = 0; j < nBasis; ++j) {
110 stateField[j] = systemField[j];
111 }
112 }
113
114 // Get system unit cell
115 unitCell() = system().domain().unitCell();
116 }
117
118 /*
119 * Set System state to current state of the BasisFieldState object.
120 */
121 template <int D, class T>
123 {
124 system().w().setBasis(fields());
125 if (newCellParams) {
126 system().setUnitCell(unitCell());
127 }
128 }
129
130} // namespace Rp
131} // namespace Pscf
132#endif
BasisFieldState()
Default constructor.
const DArray< FT > & fields() const
const UnitCell< D > & unitCell() const
Get UnitCell (i.e., lattice type and parameters) by const reference.
void write(const std::string &filename)
Write state to file.
const DArray< double > & field(int monomerId) const
Get a field for a single monomer type by const reference.
void getSystemState()
Store the current state of the associated system.
void allocate()
Allocate all fields.
void read(const std::string &filename)
Read state from file.
typename T::System & system()
Get associated System by reference.
void setSystemState(bool newCellParams)
Set the state of the associated system to this state.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Periodic fields and crystallography.
Definition complex.cpp:11
Class templates for real-valued periodic fields.
PSCF package top-level namespace.