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