PSCF v1.2
rpc/fts/analyzer/MaxOrderParameter.tpp
1#ifndef RPC_MAX_ORDER_PARAMETER_TPP
2#define RPC_MAX_ORDER_PARAMETER_TPP
3
4#include "MaxOrderParameter.h"
5
6#include <rpc/fts/simulator/Simulator.h>
7#include <rpc/System.h>
8
9#include <prdc/cpu/RField.h>
10
11#include <pscf/mesh/MeshIterator.h>
12#include <pscf/math/IntVec.h>
13
14#include <util/param/ParamComposite.h>
15#include <util/misc/FileMaster.h>
16#include <util/misc/ioUtil.h>
17#include <util/format/Int.h>
18#include <util/format/Dbl.h>
19#include <util/global.h>
20
21#include <fftw3.h>
22
23#include <iostream>
24#include <complex>
25#include <vector>
26#include <algorithm>
27
28namespace Pscf {
29namespace Rpc {
30
31 using namespace Util;
32 using namespace Pscf::Prdc;
33
34 /*
35 * Constructor.
36 */
37 template <int D>
39 System<D>& system)
40 : AverageAnalyzer<D>(simulator, system),
41 kSize_(1),
42 isInitialized_(false)
43 { setClassName("MaxOrderParameter"); }
44
45 /*
46 * Destructor.
47 */
48 template <int D>
51
52 /*
53 * MaxOrderParameter setup
54 */
55 template <int D>
57 {
58
59 // Precondition: Require that the system has two monomer types
60 const int nMonomer = system().mixture().nMonomer();
61 UTIL_CHECK(nMonomer == 2);
62
64
65 // Allocate variables
66 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
67 if (!isInitialized_){
68 wK_.allocate(dimensions);
69 }
70
71 // Compute Fourier space dimension
72 for (int i = 0; i < D; ++i) {
73 if (i < D - 1) {
74 kMeshDimensions_[i] = dimensions[i];
75 kSize_ *= dimensions[i];
76 } else {
77 kMeshDimensions_[i] = dimensions[i]/2 + 1;
78 kSize_ *= (dimensions[i]/2 + 1);
79 }
80 }
81
82 isInitialized_ = true;
83
84 if (!isInitialized_) {
85 UTIL_THROW("Error: object is not initialized");
86 }
87 }
88
89 template <int D>
91 {
92 UTIL_CHECK(system().w().hasData());
93
94 if (!simulator().hasWc()){
95 simulator().computeWc();
96 }
97
99 itr.setDimensions(kMeshDimensions_);
100 std::vector<double> psi(kSize_);
101
102 // Conver W_(r) to fourier mode W_(k)
103 system().domain().fft().forwardTransform(simulator().wc(0), wK_);
104
105 for (itr.begin(); !itr.atEnd(); ++itr) {
106 std::complex<double> wK(wK_[itr.rank()][0], wK_[itr.rank()][1]);
107 psi[itr.rank()] = std::norm(wK);
108 }
109
110 auto maxOrderParameterPtr = std::max_element(psi.begin(), psi.end());
111 maxOrderParameter_ = *maxOrderParameterPtr;
112
113 return maxOrderParameter_;
114 }
115
116 template <int D>
117 void MaxOrderParameter<D>::outputValue(int step, double value)
118 {
119 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
120 double chi= system().interaction().chi(0,1);
121
122 UTIL_CHECK(outputFile_.is_open());
123 outputFile_ << Int(step);
124 outputFile_ << Dbl(chi);
125 outputFile_ << Dbl(value);
126 outputFile_ << "\n";
127 } else {
129 }
130 }
131
132}
133}
134#endif
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.
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 double compute()
Compute and return the max order parameter.
MaxOrderParameter(Simulator< D > &simulator, System< D > &system)
Constructor.
void setClassName(const char *className)
Set class name string.
virtual void setup()
Setup before simulation loop.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
Field theoretic simulator (base class).
Definition rpc/System.h:38
Main class for SCFT or PS-FTS simulation of one system.
Definition rpc/System.h:100
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
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.