PSCF v1.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 <prdc/crystal/Basis.h>
15#include <util/global.h>
16
17namespace Pscf {
18namespace Rpg
19{
20
21 using namespace Util;
22 using namespace Pscf::Prdc;
23
24 /*
25 * Default constructor.
26 */
27 template <int D>
31
32 /*
33 * Constructor.
34 */
35 template <int D>
39
40 /*
41 * Destructor.
42 */
43 template <int D>
46
47 /*
48 * Allocate all fields.
49 */
50 template <int D>
52 {
53 // Precondition
55
56 int nMonomer = system().mixture().nMonomer();
57 UTIL_CHECK(nMonomer > 0);
58 if (fields().isAllocated()) {
59 UTIL_CHECK(fields().capacity() == nMonomer);
60 } else {
61 fields().allocate(nMonomer);
62 }
63
64 int nBasis = system().domain().basis().nBasis();
65 UTIL_CHECK(nBasis > 0);
66 for (int i = 0; i < nMonomer; ++i) {
67 if (field(i).isAllocated()) {
68 UTIL_CHECK(field(i).capacity() == nBasis);
69 } else {
70 field(i).allocate(nBasis);
71 }
72 }
73
74 }
75
79 template <int D>
80 void BasisFieldState<D>::read(const std::string & filename)
81 {
82 allocate();
83 system().domain().fieldIo().readFieldsBasis(filename, fields(),
84 unitCell());
85 }
86
90 template <int D>
91 void BasisFieldState<D>::write(const std::string & filename)
92 {
93 system().domain().fieldIo().writeFieldsBasis(filename, fields(),
94 unitCell());
95 }
96
97 /*
98 * Get current state of associated System.
99 */
100 template <int D>
102 {
103 // Get system unit cell
104 unitCell() = system().domain().unitCell();
105
106 // Get system wFields
107 allocate();
108 int nMonomer = system().mixture().nMonomer();
109 int nBasis = system().domain().basis().nBasis();
110 int i, j;
111 for (i = 0; i < nMonomer; ++i) {
112 DArray<double>& stateField = field(i);
113 const DArray<double>& systemField = system().w().basis(i);
114 for (j = 0; j < nBasis; ++j) {
115 stateField[j] = systemField[j];
116 }
117 }
118
119 }
120
121 /*
122 * Set System state to current state of the BasisFieldState object.
123 */
124 template <int D>
125 void BasisFieldState<D>::setSystemState(bool newCellParams)
126 {
127 system().w().setBasis(fields());
128
129 if (newCellParams) {
130 system().setUnitCell(unitCell());
131 }
132
133 }
134
135} // namespace Rpg
136} // namespace Pscf
137#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 one complete 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.
Definition param_pc.dox:1