11 static const char*
const configGroupName =
12 "instrumentation.normalModeAutocorrelation";
20 namespace Instrumentation
26 : mpcFluid(mpcFluid_),
27 sweepsSinceLastMeasurement(0),
33 configuration.
getSetting(
"instrumentation.normalModeAutocorrelation");
42 configGroup.
read(
"measureEveryNthSweep", &measureEveryNthSweep);
44 "autocorrelationArgumentCount", &autocorrelationArgumentCount);
46 if(configGroup.
has(
"shift"))
47 configGroup.
read(
"shift", &shift);
52 const std::size_t bufferElementCount =
55 for(std::size_t i = 0; i < autocorrelationArgumentCount; ++i)
64 for(std::size_t i = 0; i < snapshots.size(); ++i)
70 return config.
has(configGroupName);
76 if(!group.
has(
"measureEveryNthSweep"))
79 if(!group.
has(
"autocorrelationArgumentCount"))
84 unsigned int measureEveryNthSweep;
85 group.
read(
"measureEveryNthSweep", &measureEveryNthSweep);
87 if(measureEveryNthSweep == 0)
91 unsigned int autocorrelationArgumentCount;
93 "autocorrelationArgumentCount", &autocorrelationArgumentCount);
95 if(autocorrelationArgumentCount == 0)
108 ++sweepsSinceLastMeasurement;
109 if(sweepsSinceLastMeasurement != measureEveryNthSweep)
111 if(autocorrelations.size() != 0)
115 sweepsSinceLastMeasurement = 0;
117 std::vector<DeviceBuffer<MPCParticlePositionType>* > buffers;
120 buffers.reserve(autocorrelationArgumentCount);
121 for(
unsigned int i = 0; i < autocorrelationArgumentCount; ++i)
122 buffers.push_back(NULL);
124 const unsigned int currentMeasurementTime = autocorrelations.size();
127 for(
unsigned int i = 0; i < autocorrelationArgumentCount; ++i)
129 if(i > currentMeasurementTime)
134 (currentMeasurementTime - i) % autocorrelationArgumentCount];
142 buffers[0]->getPointer(),
146 autocorrelations.push_back(
147 std::vector<std::vector<MPCParticlePositionType> >());
150 for(
unsigned int i = 0; i < buffers.size(); ++i)
152 if(buffers[i] == NULL)
155 const std::vector<MPCParticlePositionType> result =
159 buffers[i]->getPointer(),
160 buffers[0]->getPointer());
162 autocorrelations[currentMeasurementTime].push_back(result);
168 return autocorrelations.size();
175 return autocorrelationArgumentCount - 1;
179 const unsigned int t,
180 const unsigned int T,
181 const unsigned int normalMode)
const
192 normalMode <= mpcFluid->getNumberOfParticlesPerLogicalEntity(),
198 return autocorrelations[T][T - t][normalMode];
203 const std::streamsize oldPrecision =
204 stream.precision(std::numeric_limits<FP>::digits10 + 2);
206 const unsigned int normalModeCount =
210 for(
unsigned int dT = 0; dT < autocorrelationArgumentCount; ++dT)
212 const unsigned int T = t + dT;
216 stream << t <<
"\t" << dT;
217 for(
unsigned int n = 0; n < normalModeCount; ++n)
223 stream.precision(oldPrecision);
228 const std::string path = rundir +
"/normalModeAutocorrelations.data";
232 std::ofstream file(path.c_str(), std::ios::trunc);
Base class for MPC fluids.
const Setting getSetting(const std::string &name) const
Returns the setting object with the given name.
bool has(const std::string &setting) const
Returns whether a setting with the given name exists.
MPCParticlePositionType getAutocorrelation(const unsigned int t, const unsigned int T, const unsigned int normalMode) const
Returns the measured value of the autocorrelation at measurement times and , and for normal mode ind...
Represents the configuration of the simulation.
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
~NormalModeAutocorrelation()
The destructor.
NormalModeAutocorrelation(const OpenMPCD::Configuration &configuration, const OpenMPCD::CUDA::MPCFluid::Base *const mpcFluid_)
The constructor.
#define OPENMPCD_DEBUG_ASSERT(assertion)
Asserts that the given expression evaluates to true, but only if OPENMPCD_DEBUG is defined.
void measure()
Takes measurement data.
const std::vector< MPCParticlePositionType > getAverageNormalCoordinateAutocorrelation(const unsigned int chainLength, const unsigned int chainCount, const MPCParticlePositionType *const normalModes0, const MPCParticlePositionType *const normalModesT)
Computes the average normal mode coordinate autocorrelation functions.
void computeNormalCoordinates(const unsigned int chainLength, const unsigned int chainCount, const MPCParticlePositionType *const positions, MPCParticlePositionType *const normalModeCoordinates, const MPCParticlePositionType shift=0)
Calculates all normal coordinates for a number of polymer chains stored contiguously in Device memory...
const MPCParticlePositionType * getDevicePositions() const
Returns a const pointer to the MPC fluid positions on the Device.
FP MPCParticlePositionType
The data type for the positions of MPC particles.
unsigned int getMaximumCorrelationTime() const
Returns, in units of measurement time, the maximum correlation time that is configured to be measured...
bool has(const std::string &settingName) const
Returns whether a setting with the given name exists.
unsigned int getMeasurementCount() const
Returns 1 plus the maximum number t may take in getAutocorrelation.
static void ensureParentDirectory(const std::string &path)
Ensures that the parent directory of the path given exists.
static bool isConfigured(const Configuration &config)
Returns whether the an attempt has been made to configure this class, i.e.
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
void save(std::ostream &stream)
Saves the result to the given stream.
Represents a setting in the configuration.
virtual unsigned int getNumberOfParticlesPerLogicalEntity() const
Returns the number of MPC particles per logical entity.
Represents an invalid configuration.
static bool isValidConfiguration(const Configuration::Setting &group)
Returns whether the given configuration group is a valid configuration.
virtual unsigned int getNumberOfLogicalEntities() const =0
Returns the number of logical entities in the fluid.
Invalid argument exception.
void read(const std::string &name, ValueType *const value) const
Reads the specified setting and stores it at the given location.
virtual bool numberOfParticlesPerLogicalEntityIsConstant() const =0
Returns whether all logical entities consist of the same number of MPC particles.