PSCF v1.5.0
FourthOrderParameter.tpp
1#ifndef RP_FOURTH_ORDER_PARAMETER_TPP
2#define RP_FOURTH_ORDER_PARAMETER_TPP
3
4#include "FourthOrderParameter.h"
5
6#include <rp/system/System.h>
7#include <rp/fts/simulator/Simulator.h>
8#include <rp/solvers/Mixture.h>
9#include <rp/field/Domain.h>
10#include <rp/field/WFields.h>
11#include <rp/field/CFields.h>
12
13#include <pscf/field/FFT.h>
14#include <pscf/field/WaveList.h>
15#include <pscf/crystal/shiftToMinimum.h>
16
17#include <pscf/backend/HostSendArray.h>
18#include <pscf/backend/Reduce.h>
19#include <pscf/backend/VecOp.h>
20#include <pscf/interaction/Interaction.h>
21#include <pscf/mesh/MeshIterator.h>
22
23#include <util/containers/Array.h>
24#include <util/containers/DArray.h>
25#include <util/misc/ioUtil.h>
26#include <util/format/Int.h>
27#include <util/format/Dbl.h>
28#include <util/global.h>
29
30#include <iostream>
31#include <cmath>
32
33namespace Pscf {
34namespace Rp {
35
36 using namespace Util;
37
38 /*
39 * Constructor.
40 */
41 template <int D, class T>
46 kSize_(1),
47 isInitialized_(false)
48 { ParamComposite::setClassName("FourthOrderParameter"); }
49
50 /*
51 * Setup before the main loop.
52 */
53 template <int D, class T>
55 {
56 // Precondition: The system must have exactly two monomer types
57 UTIL_CHECK(system().mixture().nMonomer() == 2);
58
60
61 // Compute k-space mesh kMeshDimensions_ and kSize_
62 IntVec<D> const & dimensions = system().domain().mesh().dimensions();
63 FFT<D,T>::computeKMesh(dimensions, kMeshDimensions_, kSize_);
64
65 // Allocate variables
66 if (!isInitialized_){
67 wK_.allocate(dimensions);
68 prefactor_.allocate(kMeshDimensions_);
69 psi_.allocate(kMeshDimensions_);
70 VecOp::eqS(prefactor_, 0.0);
71 }
72
73 computePrefactor();
74 isInitialized_ = true;
75 }
76
77 /*
78 * Compute and return the order parameter.
79 */
80 template <int D, class T>
82 {
83 UTIL_CHECK(isInitialized_);
84 UTIL_CHECK(wK_.capacity() == kSize_);
85 UTIL_CHECK(prefactor_.capacity() == kSize_);
86 UTIL_CHECK(psi_.capacity() == kSize_);
87 UTIL_CHECK(system().w().hasData());
88
89 if (!simulator().hasWc()){
90 simulator().computeWc();
91 }
92
93 // Fourier transform W_(r) to obtain wK_ = W_(k)
94 system().domain().fft().forwardTransform(simulator().wc(0), wK_);
95
96 // Evaluate fourth powers, scaled by prefactors
97 VecOp::sqSqAbsV(psi_, wK_);
98 VecOp::mulEqV(psi_, prefactor_);
99
100 // Summation
101 double orderParameter = Reduce::sum(psi_, 1, kSize_);
102 orderParameter = std::pow(orderParameter, 0.25);
103
104 return orderParameter;
105 }
106
107 /*
108 * Initialize private prefactor_ member variable.
109 */
110 template <int D, class T>
111 void FourthOrderParameter<D,T>::computePrefactor()
112 {
113 // Precondition - prefactor_ must be allocated
114 int kSize = kSize_;
115 UTIL_CHECK(prefactor_.capacity() == kSize);
116
117 // Setup prefactor_h host array
119 prefactor_h.associate(prefactor_);
120 UTIL_CHECK(prefactor_h.capacity() == kSize_);
121
122 // Setup prefactor_h values
123 DArray<bool> const & implicit = system().waveList().implicitInverse();
124 UTIL_CHECK(implicit.size() == kSize_);
125 for (int i = 0; i < kSize_; ++i) {
126 if (implicit[i]) {
127 prefactor_h[i] = 1.0;
128 } else {
129 prefactor_h[i] = 0.5;
130 }
131 }
132
133 // Copy to device
134 prefactor_ = prefactor_h;
135
136 prefactor_h.dissociate();
137 }
138
139}
140}
141#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
Definition Analyzer.h:233
System< D, T > & system()
Get the parent System by reference.
Definition Analyzer.h:243
AverageAnalyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
virtual void setup()
Setup before loop.
double compute() override
Compute and return the order parameter.
void setup() override
Setup before the main loop.
FourthOrderParameter(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Base class template for classes that represent a complete system.
int size() const
Return logical size of array.
Definition Array.h:243
Dynamically allocatable contiguous array template.
Definition DArray.h:32
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
double sum(Array< double > const &in)
Compute sum of array elements (real).
Definition Reduce.cpp:19
void mulEqV(Array< double > &a, Array< double > const &b)
Vector-vector in-place multiplication, a[i] *= b[i] (real).
Definition VecOp.cpp:257
void sqSqAbsV(Array< double > &a, Array< fftw_complex > const &b)
Fourth power of absolute magnitude, a[i] = |b[i]|^4 (complex).
Definition VecOp.cpp:1198
void eqS(Array< double > &a, double b)
Vector assignment, a[i] = b (real).
Definition VecOp.cpp:55
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.