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>
8#include <rpg/solvers/Mixture.h>
9#include <rpg/field/Domain.h>
11#include <prdc/crystal/shiftToMinimum.h>
12#include <prdc/cuda/WaveList.h>
13#include <prdc/cuda/FFT.h>
14#include <prdc/cuda/resources.h>
15#include <prdc/cuda/complex.h>
17#include <pscf/inter/Interaction.h>
18#include <pscf/mesh/MeshIterator.h>
20#include <util/misc/FileMaster.h>
21#include <util/misc/ioUtil.h>
22#include <util/format/Dbl.h>
23#include <util/format/Int.h>
28#include <unordered_map>
46 isInitialized_(false),
71 const int nMonomer =
system().mixture().nMonomer();
78 for (
int i = 0; i < D; ++i) {
80 kMeshDimensions_[i] = dimensions[i];
82 kMeshDimensions_[i] = dimensions[i]/2 + 1;
86 for(
int i = 0; i < D; ++i) {
87 kSize_ *= kMeshDimensions_[i];
94 wm_.allocate(dimensions);
95 wk_.allocate(dimensions);
99 accumulators_.allocate(
nWave_);
102 qList_.resize(kSize_);
109 qList_[itr.
rank()] = sqrt(
double(kSqHost[itr.
rank()]));
113 for (
int i = 0; i <
nWave_; ++i) {
115 accumulators_[i].setNSamplePerBlock(nSamplePerBlock_);
116 accumulators_[i].clear();
119 isInitialized_ =
true;
137 system().w().rgrid(1), -0.5);
140 system().domain().fft().forwardTransform(wm_, wk_);
144 for (
int k = 0; k < wk_.capacity(); k++) {
154 const double vSystem =
system().domain().unitCell().volume();
155 const double vMonomer =
system().mixture().vMonomer();
156 double n = vSystem / vMonomer;
157 double chi=
system().interaction().chi(0,1);
175 std::map<double, double> SMap;
176 for (
int i = 0; i < qList_.capacity(); ++i) {
177 double q = qList_[i];
183 for (
auto& i : SMap) {
185 double sum = i.second;
186 int count = std::count(qList_.begin(), qList_.end(), q);
187 i.second = sum / count;
191 double tolerance = 1e-5;
192 auto it = SMap.begin();
193 double currentq = it->first;
194 double sumS = it->second;
196 for (++it; it != SMap.end(); ++it) {
197 double key = it->first;
198 double s = it->second;
199 if (std::abs(key - currentq) <= tolerance) {
203 averageSMap_[currentq] = sumS / count;
211 averageSMap_[currentq] = sumS / count;
231 for (
const auto& i : averageSMap_) {
233 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 a complete physical 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.