1#ifndef RPC_FOURTH_ORDER_PARAMETER_TPP
2#define RPC_FOURTH_ORDER_PARAMETER_TPP
4#include "FourthOrderParameter.h"
6#include <rpc/system/System.h>
7#include <rpc/fts/simulator/Simulator.h>
8#include <rpc/solvers/Mixture.h>
9#include <rpc/field/Domain.h>
11#include <prdc/cpu/RField.h>
12#include <prdc/cpu/FFT.h>
13#include <prdc/crystal/shiftToMinimum.h>
15#include <pscf/inter/Interaction.h>
16#include <pscf/mesh/MeshIterator.h>
17#include <pscf/math/IntVec.h>
19#include <util/containers/DArray.h>
20#include <util/param/ParamComposite.h>
21#include <util/misc/FileMaster.h>
22#include <util/misc/ioUtil.h>
23#include <util/format/Int.h>
24#include <util/format/Dbl.h>
67 const int nMonomer =
system().mixture().nMonomer();
76 wK_.allocate(dimensions);
77 prefactor_.allocate(kSize_);
78 for (
int i = 0; i < kSize_; ++i){
83 isInitialized_ =
true;
99 std::vector<double> psi(kSize_);
105 std::complex<double> wK(wK_[itr.
rank()][0], wK_[itr.
rank()][1]);
106 psi[itr.
rank()] = std::norm(wK) * std::norm(wK);
107 psi[itr.
rank()] *= prefactor_[itr.
rank()];
110 FourthOrderParameter_ = 0.0;
113 for (
int i = 1; i < kSize_; ++i){
114 FourthOrderParameter_ += psi[i];
117 FourthOrderParameter_ = std::pow(FourthOrderParameter_, 0.25);
119 return FourthOrderParameter_;
129 std::vector<double> k(kSize_);
134 Gmin = shiftToMinimum(G, meshDimensions, unitCell);
135 kSq = unitCell.
ksq(Gmin);
139 auto maxIt = std::max_element(psi.begin(), psi.end());
142 size_t maxIndex = std::distance(psi.begin(), maxIt);
143 double kmax = k[maxIndex];
147 if (k[itr.
rank()] == kmax){
149 Gmin = shiftToMinimum(G, meshDimensions, unitCell);
152 Log::file() <<
" Gmin: " << Gmin<< std::endl;
153 Log::file() <<
" prefactor: " << prefactor_[itr.
rank()]<< std::endl;
166 double chi=
system().interaction().chi(0,1);
169 outputFile_ <<
Int(step);
170 outputFile_ <<
Dbl(chi);
171 outputFile_ <<
Dbl(value);
194 Gmin = shiftToMinimum(G, meshDimensions, unitCell);
195 GminList[itr.
rank()] = Gmin;
200 bool inverseFound =
false;
203 if (prefactor_[itr.
rank()] == 0){
204 Gmin = GminList[itr.
rank()];
211 for (; !searchItr.
atEnd(); ++searchItr){
212 if (nGmin == GminList[searchItr.
rank()]){
213 prefactor_[itr.
rank()] = 1.0/2.0;
214 prefactor_[searchItr.
rank()] = 1.0/2.0;
219 if (inverseFound ==
false){
220 prefactor_[itr.
rank()] = 1.0;
An IntVec<D, T> is a D-component vector of elements of integer type T.
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.
virtual double ksq(IntVec< D > const &k) const
Compute square magnitude of reciprocal lattice vector.
Base template for UnitCell<D> classes, D=1, 2 or 3.
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void setup()
Setup before loop.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
Simulator< D > & simulator()
Return reference to parent simulator.
System< D > & system()
Return reference to parent system.
void setClassName(const char *className)
Set class name string.
FourthOrderParameter(Simulator< D > &simulator, System< D > &system)
Constructor.
void computePrefactor()
Compute prefactor for each Fourier wavevector.
virtual void setup()
Setup before simulation loop.
virtual ~FourthOrderParameter()
Destructor.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
virtual double compute()
Compute and return the derivative of H w/ respect to chi.
Field theoretic simulator (base class).
Main class, representing one complete system.
Vec< D, T > & negate(const Vec< D, T > &v)
Return negative of vector v.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
Wrapper for a double precision number, for formatted ostream output.
Wrapper for an int, for formatted ostream output.
static std::ostream & file()
Get log ostream by reference.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Periodic fields and crystallography.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.