1#ifndef RPC_BINARY_STRUCTURE_FACTOR_GRID_TPP
2#define RPC_BINARY_STRUCTURE_FACTOR_GRID_TPP
4#include "BinaryStructureFactorGrid.h"
6#include <rpc/fts/simulator/Simulator.h>
7#include <rpc/system/System.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/param/ParamComposite.h>
20#include <util/misc/FileMaster.h>
21#include <util/misc/ioUtil.h>
22#include <util/format/Dbl.h>
47 isInitialized_(false),
74 const int nMonomer =
system().mixture().nMonomer();
81 wKGrid_.allocate(nMonomer);
82 wm_.allocate(dimensions);
83 wk_.allocate(dimensions);
84 for (
int i = 0; i < nMonomer; ++i) {
85 wKGrid_[i].allocate(dimensions);
89 qList_.resize(kSize_);
98 Gmin = shiftToMinimum(G, dimensions, unitCell);
99 Gsq = unitCell.
ksq(Gmin);
100 qList_[itr.
rank()] = sqrt(Gsq);
107 accumulators_.allocate(
nWave_);
108 isInitialized_ =
true;
111 for (
int i = 0; i <
nWave_; ++i) {
113 accumulators_[i].setNSamplePerBlock(nSamplePerBlock_);
114 accumulators_[i].clear();
117 if (!isInitialized_) {
118 UTIL_THROW(
"Error: object is not initialized");
133 for (
int i = 0; i < wm_.capacity(); ++i) {
134 wm_[i] = (
system().w().rgrid(0)[i] -
system().w().rgrid(1)[i])/2;
138 system().domain().fft().forwardTransform(wm_, wk_);
141 for (
int k=0; k< wk_.capacity(); k++) {
142 std::complex<double> wmKGrid(wk_[k][0], wk_[k][1]);
143 double squared_magnitude = std::norm(wmKGrid);
144 accumulators_[k].sample(squared_magnitude);
153 const double vSystem =
system().domain().unitCell().volume();
154 const double vMonomer =
system().mixture().vMonomer();
155 double n = vSystem / vMonomer;
156 double chi=
system().interaction().chi(0,1);
173 const int nMonomer =
system().mixture().nMonomer();
174 for (
int i = 0; i < nMonomer; ++i) {
175 system().domain().fft().forwardTransform(
system().w().rgrid()[i],
179 std::map<double, double> SMap;
181 int qListcapacity = (int)qList_.capacity();
184 for (
int i = 0; i < qListcapacity; ++i) {
192 for (
auto& i : SMap) {
194 double sum = i.second;
195 int count = std::count(qList_.begin(), qList_.end(), q);
196 i.second = sum / count;
200 double tolerance = 1e-5;
201 auto it = SMap.begin();
202 double currentq = it->first;
203 double sumS = it->second;
205 for (++it; it != SMap.end(); ++it) {
206 double key = it->first;
207 double s = it->second;
208 if (std::abs(key - currentq) <= tolerance) {
212 averageSMap_[currentq] = sumS / count;
220 averageSMap_[currentq] = sumS / count;
237 for (
const auto& i : averageSMap_) {
239 double averageS = i.second;
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.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
void readInterval(std::istream &in)
Optionally read interval from file, with error checking.
const std::string & outputFileName() const
Return outputFileName string.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
Analyzer()
Default constructor.
void setup()
Clear accumulators.
void setClassName(const char *className)
Set class name string.
System< D > & system()
Return reference to parent system.
void readParameters(std::istream &in)
Read parameters from file.
BinaryStructureFactorGrid(Simulator< D > &simulator, System< D > &system)
Constructor.
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.
Simulator< D > & simulator()
Return reference to parent Simulator.
System< D > * systemPtr_
Pointer to the parent system.
std::ofstream outputFile_
Output file stream.
void sample(long iStep)
Add particles to BinaryStructureFactor accumulators.
void averageStructureFactor()
Compute average S(k) over k of equal magnitude.
int nWave_
Number of wavevectors.
void computeStructureFactor()
Compute structure factor.
Simulator< D > * simulatorPtr_
Pointer to parent Simulator.
void output()
Output results to predefined output file.
Field theoretic simulator (base class).
Main class, representing one complete system.
Wrapper for a double precision number, for formatted ostream output.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Periodic fields and crystallography.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.