OpenMPCD
Base.cpp
2 
7 
8 #include <fstream>
9 #include <sstream>
10 
11 using namespace OpenMPCD;
13 
14 Base::Base(const Simulation* const sim, DeviceMemoryManager* devMemMgr, const MPCFluid::Base* const mpcFluid_,
15  const unsigned int numberOfConstituents)
16  : simulation(sim), deviceMemoryManager(devMemMgr), mpcFluid(mpcFluid_),
17  realBuffer(NULL), imagBuffer(NULL)
18 {
19  readConfig();
20 
21  deviceMemoryManager->allocateMemory(&realBuffer, 3 * numberOfConstituents);
22  deviceMemoryManager->allocateMemory(&imagBuffer, 3 * numberOfConstituents);
23 }
24 
26 {
29 }
30 
31 void Base::save(const std::string& rundir) const
32 {
33  saveFourierTransformedVelocities(rundir+"/fourierTransformedVelocities");
34 }
35 
36 bool Base::isConfigured(const Simulation* const sim)
37 {
38  if(!sim)
40 
41  return sim->getConfiguration().has("instrumentation.fourierTransformedVelocity");
42 }
43 
44 void Base::readConfig()
45 {
46  const Configuration& config = simulation->getConfiguration();
47 
48  const Configuration::List k_n_config = config.getList("instrumentation.fourierTransformedVelocity.k_n");
49 
50  for(unsigned int i=0; i<k_n_config.getSize(); ++i)
51  {
52  const Configuration::List current = k_n_config.getList(i);
53 
54  std::vector<MPCParticlePositionType> n;
55 
56  n.push_back(current.read<MPCParticlePositionType>(0));
57  n.push_back(current.read<MPCParticlePositionType>(1));
58  n.push_back(current.read<MPCParticlePositionType>(2));
59 
60  k_n.push_back(n);
61  }
62 
63  fourierTransformedVelocities.resize(k_n.size());
64 }
65 
66 void Base::saveFourierTransformedVelocities(const std::string& datadir) const
67 {
69 
70  for(unsigned int i=0; i<k_n.size(); ++i)
71  {
72  std::stringstream path;
73  path<<datadir<<"/"<<i<<".data";
74 
75  std::ofstream file(path.str().c_str(), std::ios::trunc);
76  file.precision(std::numeric_limits<FP>::digits10 + 2);
77 
78  saveFourierTransformedVelocities(i, file);
79  }
80 }
81 
82 void Base::saveFourierTransformedVelocities(const unsigned int index, std::ostream& stream) const
83 {
84  if(index >= k_n.size())
86 
87  const Configuration& config = simulation->getConfiguration();
88  const Configuration::List k_n_config = config.getList("instrumentation.fourierTransformedVelocity.k_n");
89  const Configuration::List current = k_n_config.getList(index);
90 
91  stream<<"#k_n:\t"<<current.read<FP>(0)<<"\t"<<current.read<FP>(1)<<"\t"<<current.read<FP>(2)<<"\n";
92 
93  for(unsigned int i=0; i<fourierTransformedVelocities[index].size(); ++i)
94  {
95  const FP mpcTime = fourierTransformedVelocities[index][i].first;
97  = fourierTransformedVelocities[index][i].second;
98 
99  stream
100  <<mpcTime<<"\t"
101  <<value.getX().real()<<"\t"<<value.getX().imag()<<"\t"
102  <<value.getY().real()<<"\t"<<value.getY().imag()<<"\t"
103  <<value.getZ().real()<<"\t"<<value.getZ().imag()<<"\n";
104  }
105 }
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::realBuffer
MPCParticleVelocityType * realBuffer
Device buffer for temporary results.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:109
Base.hpp
OpenMPCD::CUDA::MPCFluid::Base
Base class for MPC fluids.
Definition: CUDA/MPCFluid/Base.hpp:40
OpenMPCD::Configuration::has
bool has(const std::string &setting) const
Returns whether a setting with the given name exists.
Definition: Configuration.hpp:509
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::isConfigured
static bool isConfigured(const Simulation *const sim)
Returns whether the given simulation configured this instrumentation.
Definition: Base.cpp:36
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::k_n
std::vector< std::vector< MPCParticlePositionType > > k_n
The multiples of for each component of each vector.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:112
OpenMPCD::Configuration::getList
const List getList(const std::string &name) const
Returns the list with the given name.
Definition: Configuration.hpp:596
OpenMPCD::Configuration
Represents the configuration of the simulation.
Definition: Configuration.hpp:28
OpenMPCD::Vector3D::getZ
OPENMPCD_CUDA_HOST_AND_DEVICE T getZ() const
Returns the z coordinate.
Definition: Vector3D.hpp:119
OpenMPCD::Configuration::List::getSize
unsigned int getSize() const
Returns the number of elements in the list.
Definition: Configuration.hpp:346
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity
Namespace for classes that measure the Fourier-transformed velocities in MPC fluids.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:35
OpenMPCD::CUDA::DeviceMemoryManager
Class for managing memory on the CUDA Device.
Definition: DeviceMemoryManager.hpp:21
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::FilesystemUtilities::ensureDirectory
static void ensureDirectory(const std::string &path)
Ensures that the given directory exists, creating it and its parents if necessary.
Definition: FilesystemUtilities.cpp:9
OpenMPCD::Vector3D::getX
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
Definition: Vector3D.hpp:61
FilesystemUtilities.hpp
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::imagBuffer
MPCParticleVelocityType * imagBuffer
Device buffer for temporary results.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:110
OpenMPCD::MPCParticlePositionType
FP MPCParticlePositionType
The data type for the positions of MPC particles.
Definition: Types.hpp:15
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::~Base
virtual ~Base()
The destructor.
Definition: Base.cpp:25
OpenMPCD::Configuration::List::read
void read(const unsigned int index, ValueType *const value) const
Reads the specified setting and stores them in the given location.
Definition: Configuration.hpp:400
OpenMPCD::Vector3D::getY
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
Definition: Vector3D.hpp:90
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::deviceMemoryManager
DeviceMemoryManager *const deviceMemoryManager
The Device memory manager.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:106
OpenMPCD::CUDA::Simulation::getConfiguration
const Configuration & getConfiguration() const
Returns the configuration.
Definition: CUDA/Simulation.hpp:81
OpenMPCD::Configuration::List
Represents a list, or an array, of values.
Definition: Configuration.hpp:323
OpenMPCD::CUDA::Simulation
MPCD simulation with Molecular Dynamics on CUDA-capable GPUs.
Definition: CUDA/Simulation.hpp:48
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::simulation
const Simulation *const simulation
The simulation instance.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:105
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::save
virtual void save(const std::string &rundir) const
Saves the data to the given run directory.
Definition: Base.cpp:31
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::Base
Base(const Simulation *const sim, DeviceMemoryManager *devMemMgr, const MPCFluid::Base *const mpcFluid_, const unsigned int numberOfConstituents)
The constructor.
Definition: Base.cpp:14
OpenMPCD::CUDA::MPCFluid::Instrumentation::FourierTransformedVelocity::Base::fourierTransformedVelocities
std::vector< std::deque< std::pair< FP, Vector3D< std::complex< MPCParticleVelocityType > > > > > fourierTransformedVelocities
The Fourier-transformed velocities measured, along with the corresponding simulation timestamps.
Definition: CUDA/MPCFluid/Instrumentation/FourierTransformedVelocity/Base.hpp:115
Simulation.hpp
OpenMPCD::FP
double FP
Default floating point type.
Definition: Types.hpp:13
OpenMPCD::CUDA::DeviceMemoryManager::freeMemory
void freeMemory(void *const pointer)
Frees the Device memory pointed to by the given pointer.
Definition: DeviceMemoryManager.cpp:40
Macros.hpp
OpenMPCD::CUDA::DeviceMemoryManager::allocateMemory
Pointee * allocateMemory(const unsigned int instanceCount)
Allocates Device memory for the given number of instances of the supplied type.
Definition: DeviceMemoryManager.hpp:62
OpenMPCD::OutOfBoundsException
Exception for out-of-bounds access.
Definition: Exceptions.hpp:112
runtime.hpp
OpenMPCD::Configuration::List::getList
const List getList(const unsigned int index) const
Returns the list with the given index.
Definition: Configuration.hpp:376
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96