PSCF v1.3.3
rpc/scft/sweep/BasisFieldState.tpp
1#ifndef RPC_BASIS_FIELD_STATE_TPP
2#define RPC_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 <rpc/solvers/Mixture.h>
14#include <rpc/field/Domain.h>
15#include <util/global.h>
16
17namespace Pscf {
18namespace Rpc
19{
20
21 using namespace Util;
22
23 /*
24 * Default constructor.
25 */
26 template <int D>
30
31 /*
32 * Constructor.
33 */
34 template <int D>
38
39 /*
40 * Destructor.
41 */
42 template <int D>
45
46 /*
47 * Allocate all fields.
48 */
49 template <int D>
51 {
52 // Precondition
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().domain().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
75 /*
76 * Read fields in symmetry-adapted basis format.
77 */
78 template <int D>
79 void BasisFieldState<D>::read(const std::string & filename)
80 {
81 allocate();
82 FieldIo<D> const & fieldIo = system().domain().fieldIo();
83 fieldIo.readFieldsBasis(filename,
84 fields(),
85 unitCell());
86 }
87
91 template <int D>
92 void BasisFieldState<D>::write(const std::string & filename)
93 {
94 FieldIo<D> const & fieldIo = system().domain().fieldIo();
95 fieldIo.writeFieldsBasis(filename, fields(), unitCell());
96 }
97
98 /*
99 * Gjt current state of associated System.
100 */
101 template <int D>
103 {
104 // Get system wFields
105 allocate();
106 int nMonomer = system().mixture().nMonomer();
107 int nBasis = system().domain().basis().nBasis();
108 int i, j;
109 for (i = 0; i < nMonomer; ++i) {
110 DArray<double>& stateField = field(i);
111 const DArray<double>& systemField = system().w().basis(i);
112 for (j = 0; j < nBasis; ++j) {
113 stateField[j] = systemField[j];
114 }
115 }
116
117 // Get system unit cell
118 unitCell() = system().domain().unitCell();
119 }
120
121 /*
122 * Set System state to current state of the BasisFieldState object.
123 */
124 template <int D>
126 {
127 system().w().setBasis(fields());
128 if (isFlexible) {
129 system().setUnitCell(unitCell());
130 }
131 }
132
133} // namespace Rpc
134} // namespace Pscf
135#endif
void write(const std::string &filename)
Write state to file.
void setSystemState(bool isFlexible)
Set the state of the associated system to this state.
void read(const std::string &filename)
Read state from file.
void getSystemState()
Copy the current state of the associated system.
File input/output operations and format conversions for fields.
void writeFieldsBasis(std::ostream &out, DArray< DArray< double > > const &fields, UnitCell< D > const &unitCell) const
Write an array of fields in basis format to an output stream.
void readFieldsBasis(std::istream &in, DArray< DArray< double > > &fields, UnitCell< D > &unitCell) const
Read an array of fields in basis format from an input stream.
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
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.