1#ifndef RPG_BINARY_STRUCTURE_FACTOR_GRID_TPP
2#define RPG_BINARY_STRUCTURE_FACTOR_GRID_TPP
4#include "BinaryStructureFactorGrid.h"
6#include <rpg/fts/simulator/Simulator.h>
7#include <rpg/system/System.h>
9#include <prdc/crystal/shiftToMinimum.h>
10#include <prdc/cuda/FFT.h>
11#include <prdc/cuda/resources.h>
12#include <prdc/cuda/complex.h>
14#include <pscf/inter/Interaction.h>
15#include <pscf/mesh/MeshIterator.h>
17#include <util/misc/FileMaster.h>
18#include <util/misc/ioUtil.h>
19#include <util/format/Dbl.h>
20#include <util/format/Int.h>
25#include <unordered_map>
43 isInitialized_(false),
68 const int nMonomer =
system().mixture().nMonomer();
75 for (
int i = 0; i < D; ++i) {
77 kMeshDimensions_[i] = dimensions[i];
79 kMeshDimensions_[i] = dimensions[i]/2 + 1;
83 for(
int i = 0; i < D; ++i) {
84 kSize_ *= kMeshDimensions_[i];
91 wm_.allocate(dimensions);
92 wk_.allocate(dimensions);
96 accumulators_.allocate(
nWave_);
99 qList_.resize(kSize_);
106 qList_[itr.
rank()] = sqrt(
double(kSqHost[itr.
rank()]));
110 for (
int i = 0; i <
nWave_; ++i) {
112 accumulators_[i].setNSamplePerBlock(nSamplePerBlock_);
113 accumulators_[i].clear();
116 isInitialized_ =
true;
134 system().w().rgrid(1), -0.5);
137 system().domain().fft().forwardTransform(wm_, wk_);
141 for (
int k = 0; k < wk_.capacity(); k++) {
151 const double vSystem =
system().domain().unitCell().volume();
152 const double vMonomer =
system().mixture().vMonomer();
153 double n = vSystem / vMonomer;
154 double chi=
system().interaction().chi(0,1);
172 std::map<double, double> SMap;
173 for (
int i = 0; i < qList_.capacity(); ++i) {
174 double q = qList_[i];
180 for (
auto& i : SMap) {
182 double sum = i.second;
183 int count = std::count(qList_.begin(), qList_.end(), q);
184 i.second = sum / count;
188 double tolerance = 1e-5;
189 auto it = SMap.begin();
190 double currentq = it->first;
191 double sumS = it->second;
193 for (++it; it != SMap.end(); ++it) {
194 double key = it->first;
195 double s = it->second;
196 if (std::abs(key - currentq) <= tolerance) {
200 averageSMap_[currentq] = sumS / count;
208 averageSMap_[currentq] = sumS / count;
228 for (
const auto& i : averageSMap_) {
230 double averageS = i.second;
Template for dynamic array stored in host CPU memory.
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.
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.
Field of real double precision values on an FFT mesh.
const std::string & outputFileName() const
Return outputFileName string.
Analyzer()
Default constructor.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void readInterval(std::istream &in)
Read interval from file, with error checking.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
void setup()
Clear accumulators.
void sample(long iStep)
Add particles to BinaryStructureFactor accumulators.
void setClassName(const char *className)
Set class name string.
DArray< double > structureFactors_
Structure factor.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
void averageStructureFactor()
Compute average S(k) over k of equal magnitude.
System< D > * systemPtr_
Pointer to the parent system.
void computeStructureFactor()
Compute structure factor.
int nWave_
Number of wavevectors.
void output()
Output results to predefined output file.
Simulator< D > & simulator()
Return reference to parent Simulator.
void readParameters(std::istream &in)
Read parameters from file.
System< D > & system()
Return reference to parent system.
Simulator< D > * simulatorPtr_
Pointer to parent Simulator.
BinaryStructureFactorGrid(Simulator< D > &simulator, System< D > &system)
Constructor.
std::ofstream outputFile_
Output file stream.
Field theoretic simulator (base class).
Main class, representing one complete system.
Wrapper for a double precision number, for formatted ostream output.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
RT absSq(CT const &a)
Return square of absolute magnitude of a complex number.
void addVcVc(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c, DeviceArray< cudaReal > const &d, cudaReal const e)
Vector addition w/ coefficient, a[i] = (b[i]*c) + (d[i]*e), kernel wrapper.
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Periodic fields and crystallography.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.