PSCF v1.3.3
rpg/fts/analyzer/MaxOrderParameter.tpp
1#ifndef RPG_MAX_ORDER_PARAMETER_TPP
2#define RPG_MAX_ORDER_PARAMETER_TPP
3
4#include "MaxOrderParameter.h"
5
6#include <rpg/fts/simulator/Simulator.h>
7#include <rpg/system/System.h>
8#include <rpg/solvers/Mixture.h>
9#include <rpg/field/Domain.h>
10
11#include <prdc/cuda/FFT.h>
12#include <prdc/cuda/RField.h>
13#include <prdc/cuda/resources.h>
14#include <prdc/crystal/shiftToMinimum.h>
15
16#include <pscf/inter/Interaction.h>
17#include <pscf/mesh/MeshIterator.h>
18#include <pscf/math/IntVec.h>
19
20#include <util/format/Int.h>
21#include <util/format/Dbl.h>
22#include <util/global.h>
23
24namespace Pscf {
25namespace Rpg {
26
27 using namespace Util;
28 using namespace Pscf::Prdc;
29
30 /*
31 * Constructor.
32 */
33 template <int D>
37 kSize_(1),
38 isInitialized_(false)
39 { setClassName("MaxOrderParameter"); }
40
41 /*
42 * Destructor.
43 */
44 template <int D>
47
48 /*
49 * MaxOrderParameter setup
50 */
51 template <int D>
53 {
54 // Local copies of data
55 const int nMonomer = system().mixture().nMonomer();
56 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
57
58 // Preconditions
59 UTIL_CHECK(system().w().hasData());
60 UTIL_CHECK(nMonomer == 2); // Require system has 2 monomer types
61
63 if (!simulator().hasWc()){
64 simulator().computeWc();
65 }
66
67 // Compute Fourier space dimension kMeshDimensions_ and kSize_
68 FFT<D>::computeKMesh(dimensions, kMeshDimensions_, kSize_);
69
70 // Allocate variables
71 if (!isInitialized_){
72 wc0_.allocate(dimensions);
73 wK_.allocate(dimensions);
74 }
75
76 isInitialized_ = true;
77 }
78
79 template <int D>
81 {
82 UTIL_CHECK(system().w().hasData());
83
84 if (!simulator().hasWc()){
85 simulator().computeWc();
86 }
87
88 const int meshSize = system().domain().mesh().size();
89 RField<D> psi;
90 psi.allocate(kMeshDimensions_);
91
92 // Conver W_(r) to fourier mode W_(k)
93 VecOp::eqV(wc0_, simulator().wc(0));
94 system().domain().fft().forwardTransform(wc0_, wK_);
95
96 // Comput W_(k)^2
97 VecOp::sqNormV(psi, wK_);
98
99 HostDArray<cudaReal> psiHost(kSize_);
100
101 psiHost = psi;
102
103 // Obtain max[W_(k)^2]
104 maxOrderParameter_ = psiHost[1];
105 int maxIndex = 1;
106 for (int i = 2; i < kSize_; ++i){
107 if (psiHost[i] > maxOrderParameter_){
108 maxOrderParameter_ = psiHost[i];
109 maxIndex = i;
110 }
111 }
112
113 MeshIterator<D> itr;
114 itr.setDimensions(kMeshDimensions_);
115
116 DArray<IntVec<D>> GminList;
117 GminList.allocate(kSize_);
118 IntVec<D> G;
119 IntVec<D> Gmin;
120 UnitCell<D> const & unitCell = system().domain().unitCell();
121 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
122 for (itr.begin(); !itr.atEnd(); ++itr) {
123 G = itr.position();
124 Gmin = shiftToMinimum(G, dimensions, unitCell);
125 GminList[itr.rank()] = Gmin;
126 }
127
128 GminStar_ = GminList[maxIndex];
129
130 return maxOrderParameter_;
131 }
132
133 template <int D>
134 void MaxOrderParameter<D>::outputValue(int step, double value)
135 {
136 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
137 double chi= system().interaction().chi(0,1);
138
139 UTIL_CHECK(outputFile_.is_open());
140 outputFile_ << Int(step);
141 outputFile_ << Dbl(chi);
142 outputFile_ << " ( ";
143 for (int i = 0; i < D; i++){
144 outputFile_ << Int(GminStar_[i],3) << " ";
145 }
146 outputFile_ << " ) ";
147 outputFile_ << Dbl(value);
148 outputFile_ << "\n";
149 } else {
150 // AverageAnalyzer<D>::outputValue(step, value);
151 outputFile_ << Int(step);
152 outputFile_ << " ( ";
153 for (int i = 0; i < D; i++){
154 outputFile_ << Int(GminStar_[i],3) << " ";
155 }
156 outputFile_ << " ) ";
157 outputFile_ << Dbl(value);
158 outputFile_ << "\n";
159 }
160 }
161
162}
163}
164#endif
Template for dynamic array stored in host CPU memory.
Definition HostDArray.h:43
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Iterator over points in a Mesh<D>.
int rank() const
Get the rank of current element.
void begin()
Set iterator to the first point in the mesh.
bool atEnd() const
Is this the end (i.e., one past the last point)?
void setDimensions(const IntVec< D > &dimensions)
Set the grid dimensions in all directions.
IntVec< D > position() const
Get current position in the grid, as integer vector.
static void computeKMesh(IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
Compute dimensions and size of k-space mesh for DFT of real data.
Definition cpu/FFT.tpp:262
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for an FFT grid.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void setup()
Setup before loop.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
Simulator< D > & simulator()
Return reference to parent simulator.
System< D > & system()
Return reference to parent system.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
void setClassName(const char *className)
Set class name string.
virtual double compute()
Compute and return the max order parameter.
void setup()
Setup before simulation loop.
MaxOrderParameter(Simulator< D > &simulator, System< D > &system)
Constructor.
Field theoretic simulator (base class).
Main class, representing a complete physical system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
void allocate(int capacity)
Allocate the underlying C array.
Definition DArray.h:199
Wrapper for a double precision number, for formatted ostream output.
Definition Dbl.h:40
Wrapper for an int, for formatted ostream output.
Definition Int.h:37
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void eqV(Array< double > &a, Array< double > const &b)
Vector assignment, a[i] = b[i].
Definition VecOp.cpp:23
void sqNormV(DeviceArray< cudaReal > &a, DeviceArray< cudaComplex > const &b)
Squared norm of complex number, a[i] = norm(b[i])^2, kernel wrapper.
Definition VecOpMisc.cu:585
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.