PSCF v1.1
pspc/sweep/BasisFieldState.tpp
1#ifndef PSPC_BASIS_FIELD_STATE_TPP
2#define PSPC_BASIS_FIELD_STATE_TPP
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 "BasisFieldState.h"
12#include "FieldState.tpp"
13#include <util/global.h>
14
15namespace Pscf {
16namespace Pspc
17{
18
19 using namespace Util;
20
21 /*
22 * Default constructor.
23 */
24 template <int D>
26 : FieldState<D, DArray<double> >()
27 {}
28
29 /*
30 * Constructor.
31 */
32 template <int D>
34 : FieldState<D, DArray<double> >(system)
35 {}
36
37 /*
38 * Destructor.
39 */
40 template <int D>
42 {}
43
44 /*
45 * Allocate all fields.
46 */
47 template <int D>
49 {
50 // Precondition
51 UTIL_CHECK(hasSystem());
52
53 int nMonomer = system().mixture().nMonomer();
54 UTIL_CHECK(nMonomer > 0);
55 if (fields().isAllocated()) {
56 UTIL_CHECK(fields().capacity() == nMonomer);
57 } else {
58 fields().allocate(nMonomer);
59 }
60
61 int nBasis = system().basis().nBasis();
62 UTIL_CHECK(nBasis > 0);
63 for (int i = 0; i < nMonomer; ++i) {
64 if (field(i).isAllocated()) {
65 UTIL_CHECK(field(i).capacity() == nBasis);
66 } else {
67 field(i).allocate(nBasis);
68 }
69 }
70
71 }
72
73 /*
74 * Read fields in symmetry-adapted basis format.
75 */
76 template <int D>
77 void BasisFieldState<D>::read(const std::string & filename)
78 {
79 allocate();
80 system().fieldIo().readFieldsBasis(filename, fields(), unitCell());
81 }
82
86 template <int D>
87 void BasisFieldState<D>::write(const std::string & filename)
88 {
89 system().fieldIo().writeFieldsBasis(filename, fields(), unitCell());
90 }
91
92 /*
93 * Gjt current state of associated System.
94 */
95 template <int D>
97 {
98 // Get system wFields
99 allocate();
100 int nMonomer = system().mixture().nMonomer();
101 int nBasis = system().basis().nBasis();
102 int i, j;
103 for (i = 0; i < nMonomer; ++i) {
104 DArray<double>& stateField = field(i);
105 const DArray<double>& systemField = system().w().basis(i);
106 for (j = 0; j < nBasis; ++j) {
107 stateField[j] = systemField[j];
108 }
109 }
110
111 // Get system unit cell
112 unitCell() = system().unitCell();
113 }
114
115 /*
116 * Set System state to current state of the BasisFieldState object.
117 */
118 template <int D>
120 {
121 system().setWBasis(fields());
122 if (isFlexible) {
123 system().setUnitCell(unitCell());
124 }
125 }
126
127} // namespace Pspc
128} // namespace Pscf
129#endif
void read(const std::string &filename)
Read state from file.
void getSystemState()
Copy the current state of the associated system.
void allocate()
Allocate all fields.
void write(const std::string &filename)
Write state to file.
void setSystemState(bool isFlexible)
Set the state of the associated system to this state.
Record of a state of a System (fields + unit cell).
Main class for SCFT simulation of one system.
Definition: pspc/System.h:76
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
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1