PSCF v1.3.3
rpg/scft/sweep/BasisFieldState.tpp
1#ifndef RPG_BASIS_FIELD_STATE_TPP
2#define RPG_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#include "FieldState.tpp"
13#include <rpg/system/System.h>
14#include <rpg/solvers/Mixture.h>
15#include <rpg/field/Domain.h>
16#include <prdc/crystal/Basis.h>
17#include <util/global.h>
18
19namespace Pscf {
20namespace Rpg
21{
22
23 using namespace Util;
24 using namespace Pscf::Prdc;
25
26 /*
27 * Default constructor.
28 */
29 template <int D>
33
34 /*
35 * Constructor.
36 */
37 template <int D>
41
42 /*
43 * Destructor.
44 */
45 template <int D>
48
49 /*
50 * Allocate all fields.
51 */
52 template <int D>
54 {
55 // Precondition
57
58 int nMonomer = system().mixture().nMonomer();
59 UTIL_CHECK(nMonomer > 0);
60 if (fields().isAllocated()) {
61 UTIL_CHECK(fields().capacity() == nMonomer);
62 } else {
63 fields().allocate(nMonomer);
64 }
65
66 int nBasis = system().domain().basis().nBasis();
67 UTIL_CHECK(nBasis > 0);
68 for (int i = 0; i < nMonomer; ++i) {
69 if (field(i).isAllocated()) {
70 UTIL_CHECK(field(i).capacity() == nBasis);
71 } else {
72 field(i).allocate(nBasis);
73 }
74 }
75
76 }
77
81 template <int D>
82 void BasisFieldState<D>::read(const std::string & filename)
83 {
84 allocate();
85 system().domain().fieldIo().readFieldsBasis(filename, fields(),
86 unitCell());
87 }
88
92 template <int D>
93 void BasisFieldState<D>::write(const std::string & filename)
94 {
95 system().domain().fieldIo().writeFieldsBasis(filename, fields(),
96 unitCell());
97 }
98
99 /*
100 * Get current state of associated System.
101 */
102 template <int D>
104 {
105 // Get system unit cell
106 unitCell() = system().domain().unitCell();
107
108 // Get system wFields
109 allocate();
110 int nMonomer = system().mixture().nMonomer();
111 int nBasis = system().domain().basis().nBasis();
112 int i, j;
113 for (i = 0; i < nMonomer; ++i) {
114 DArray<double>& stateField = field(i);
115 const DArray<double>& systemField = system().w().basis(i);
116 for (j = 0; j < nBasis; ++j) {
117 stateField[j] = systemField[j];
118 }
119 }
120
121 }
122
123 /*
124 * Set System state to current state of the BasisFieldState object.
125 */
126 template <int D>
127 void BasisFieldState<D>::setSystemState(bool newCellParams)
128 {
129 system().w().setBasis(fields());
130
131 if (newCellParams) {
132 system().setUnitCell(unitCell());
133 }
134
135 }
136
137} // namespace Rpg
138} // namespace Pscf
139#endif
void getSystemState()
Copy the current state of the associated system.
void read(const std::string &filename)
Read state from file.
void setSystemState(bool newCellParams)
Set the state of the associated system to this state.
void write(const std::string &filename)
Write state to file.
const DArray< double > & field(int monomerId) const
Main class, representing a complete physical system.
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 CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.