PSCF v1.2
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.h>
8
9#include <prdc/cuda/RField.h>
10#include <prdc/cuda/resources.h>
11
12#include <pscf/mesh/MeshIterator.h>
13#include <pscf/math/IntVec.h>
14
15#include <util/param/ParamComposite.h>
16#include <util/misc/FileMaster.h>
17#include <util/misc/ioUtil.h>
18#include <util/format/Int.h>
19#include <util/format/Dbl.h>
20#include <util/global.h>
21
22#include <fftw3.h>
23
24#include <iostream>
25#include <complex>
26#include <vector>
27#include <algorithm>
28
29namespace Pscf {
30namespace Rpg {
31
32 using namespace Util;
33 using namespace Pscf::Prdc;
34
35 /*
36 * Constructor.
37 */
38 template <int D>
40 System<D>& system)
41 : AverageAnalyzer<D>(simulator, system),
42 kSize_(1),
43 isInitialized_(false)
44 { setClassName("MaxOrderParameter"); }
45
46 /*
47 * Destructor.
48 */
49 template <int D>
52
53 /*
54 * MaxOrderParameter setup
55 */
56 template <int D>
58 {
59 UTIL_CHECK(system().w().hasData());
60
61 // Precondition: Require that the system has two monomer types
62 const int nMonomer = system().mixture().nMonomer();
63 UTIL_CHECK(nMonomer == 2);
64
66
67 if (!simulator().hasWc()){
68 simulator().computeWc();
69 }
70
71 //Allocate variables
72 IntVec<D> const & dimensions = system().mesh().dimensions();
73 if (!isInitialized_){
74 wc0_.allocate(dimensions);
75 wK_.allocate(dimensions);
76 }
77
78 // Compute Fourier space dimension
79 for (int i = 0; i < D; ++i) {
80 if (i < D - 1) {
81 kMeshDimensions_[i] = dimensions[i];
82 kSize_ *= dimensions[i];
83 } else {
84 kMeshDimensions_[i] = dimensions[i]/2 + 1;
85 kSize_ *= (dimensions[i]/2 + 1);
86 }
87 }
88
89 isInitialized_ = true;
90
91 if (!isInitialized_) {
92 UTIL_THROW("Error: object is not initialized");
93 }
94 }
95
96 template <int D>
98 {
99 UTIL_CHECK(system().w().hasData());
100
101 const int meshSize = system().domain().mesh().size();
102 RField<D> psi;
103 psi.allocate(kMeshDimensions_);
104
105 // Conver W_(r) to fourier mode W_(k)
106 VecOp::eqV(wc0_, simulator().wc(0));
107 system().fft().forwardTransform(wc0_, wK_);
108
109 // Comput W_(k)^2
110 VecOp::sqNormV(psi, wK_);
111
112 // Obtain max[W_(k)^2]
113 maxOrderParameter_ = Reduce::maxAbs(psi);
114
115 return maxOrderParameter_;
116 }
117
118 template <int D>
119 void MaxOrderParameter<D>::outputValue(int step, double value)
120 {
121 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
122 double chi= system().interaction().chi(0,1);
123
124 UTIL_CHECK(outputFile_.is_open());
125 outputFile_ << Int(step);
126 outputFile_ << Dbl(chi);
127 outputFile_ << Dbl(value);
128 outputFile_ << "\n";
129 } else {
131 }
132 }
133
134}
135}
136#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Field of real double precision values on an FFT mesh.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for an FFT grid.
Analyze averages and block averages of several real variables.
virtual void setup()
Setup before loop.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
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).
Definition rpg/System.h:41
Main class for calculations that represent one system.
Definition rpg/System.h:107
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
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:51
cudaReal maxAbs(DeviceArray< cudaReal > const &in)
Get maximum absolute magnitude of array elements (GPU kernel wrapper).
Definition Reduce.cu:648
void eqV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i], kernel wrapper (cudaReal).
Definition VecOp.cu:1020
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
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.