11 #include <boost/filesystem.hpp>
16 using namespace OpenMPCD;
19 const Simulation*
const sim,
const unsigned int rngSeed_,
20 const std::string& gitRevision_)
21 : simulation(sim), rngSeed(rngSeed_), gitRevision(gitRevision_),
32 if(!config.
has(
"instrumentation"))
37 std::set<std::string> knownSettings;
38 knownSettings.insert(
"velocityMagnitudeHistogram");
39 knownSettings.insert(
"densityProfile");
40 knownSettings.insert(
"flowProfile");
42 knownSettings.insert(
"dumbbellBondLengthHistogram");
43 knownSettings.insert(
"dumbbellBondLengthSquaredHistogram");
44 knownSettings.insert(
"dumbbellBondXHistogram");
45 knownSettings.insert(
"dumbbellBondYHistogram");
46 knownSettings.insert(
"dumbbellBondZHistogram");
47 knownSettings.insert(
"dumbbellBondXXHistogram");
48 knownSettings.insert(
"dumbbellBondYYHistogram");
49 knownSettings.insert(
"dumbbellBondZZHistogram");
50 knownSettings.insert(
"dumbbellBondXYHistogram");
51 knownSettings.insert(
"dumbbellBondAngleWithFlowDirectionHistogram");
52 knownSettings.insert(
"dumbbellBondXYAngleWithFlowDirectionHistogram");
53 knownSettings.insert(
"fourierTransformedVelocity");
54 knownSettings.insert(
"gaussianChains");
55 knownSettings.insert(
"gaussianRods");
56 knownSettings.insert(
"harmonicTrimers");
57 knownSettings.insert(
"logicalEntityMeanSquareDisplacement");
58 knownSettings.insert(
"normalModeAutocorrelation");
59 knownSettings.insert(
"selfDiffusionCoefficient");
60 knownSettings.insert(
"velocityAutocorrelation");
68 std::string(
"Unknown setting in `instrumentation`: ") +
77 if(setting.
has(
"velocityMagnitudeHistogram"))
79 velocityMagnitudeHistogram.reset(
80 new Histogram(
"velocityMagnitudeHistogram", config));
83 if(setting.
has(
"densityProfile"))
93 if(setting.
has(
"flowProfile"))
107 save(autosave_rundir);
122 if(velocityMagnitudeHistogram)
124 velocityMagnitudeHistogram->save(
125 rundir +
"/velocityMagnitudeHistogram.data");
129 densityProfile->saveToFile(rundir +
"/densityProfile.data");
132 flowProfile->saveToFile(rundir +
"/flowProfile.data");
134 if(totalFluidVelocityMagnitudeVSTime)
136 totalFluidVelocityMagnitudeVSTime->save(
137 rundir +
"/totalFluidVelocityMagnitudeVSTime.data",
false);
140 if(simulation->hasMPCFluid())
141 simulation->getMPCFluid().getInstrumentation().save(rundir);
143 if(simulation->hasSolute())
145 if(simulation->getMPCSolute().hasInstrumentation())
146 simulation->getMPCSolute().getInstrumentation().save(rundir);
151 std::stringstream ss;
152 ss <<
"numberOfCompletedSweeps: ";
153 ss << simulation->getNumberOfCompletedSweeps() <<
"\n";
155 ss <<
"executingHost: \"";
159 ss <<
"DefaultCUDADevicePCIAddress: \"";
162 ss <<
"startTimeUTC: \"";
163 ss << constructionTimeUTC <<
"\"\n";
165 ss <<
"endTimeUTC: \"";
168 const std::string outname=rundir+
"/metadata.txt";
169 std::ofstream dst(outname.c_str(), std::ios::trunc);
174 saveStaticData(rundir);
177 void CUDA::Instrumentation::measureMPCFluid()
179 if(!simulation->hasMPCFluid())
187 simulation->getBoundaryConditions());
189 if(leesEdwardsBoundaryConditions == NULL)
193 "Non-Lees-Edwards currently not supported");
198 flowProfile->newSweep();
201 const MPCFluid::Base& mpcFluid = simulation->getMPCFluid();
205 mpcFluid.fetchFromDevice();
212 mpcFluid.getPosition(i);
214 mpcFluid.getVelocity(i);
216 if(velocityMagnitudeHistogram)
217 velocityMagnitudeHistogram->fill(velocity.
getMagnitude());
223 simulation->getMPCTime(),
225 simulation->getSimulationBoxSizeX(),
226 simulation->getSimulationBoxSizeY(),
227 simulation->getSimulationBoxSizeZ(),
228 &velocityCorrection);
231 correctedVelocity.
addToX(velocityCorrection);
235 const std::size_t x =
236 static_cast<std::size_t
>(
237 image.
getX() * densityProfile->getCellSubdivisionsX());
238 const std::size_t y =
239 static_cast<std::size_t
>(
240 image.
getY() * densityProfile->getCellSubdivisionsY());
241 const std::size_t z =
242 static_cast<std::size_t
>(
243 image.
getZ() * densityProfile->getCellSubdivisionsZ());
245 densityProfile->add(x, y, z, mpcFluid.getParticleMass());
250 const std::size_t x =
251 static_cast<std::size_t
>(
252 image.
getX() * flowProfile->getCellSubdivisionsX());
253 const std::size_t y =
254 static_cast<std::size_t
>(
255 image.
getY() * flowProfile->getCellSubdivisionsY());
256 const std::size_t z =
257 static_cast<std::size_t
>(
258 image.
getZ() * flowProfile->getCellSubdivisionsZ());
260 flowProfile->add(x, y, z, correctedVelocity);
263 totalFluidVelocity += correctedVelocity;
267 densityProfile->incrementFillCount();
269 if(totalFluidVelocityMagnitudeVSTime)
271 totalFluidVelocityMagnitudeVSTime->addPoint(
272 simulation->getMPCTime(), totalFluidVelocity.getMagnitude());
275 mpcFluid.getInstrumentation().measure();
278 void CUDA::Instrumentation::measureMPCSolute()
280 if(!simulation->hasSolute())
283 if(!simulation->getMPCSolute().hasInstrumentation())
288 simulation->getMPCSolute().getInstrumentation().measure();
291 void CUDA::Instrumentation::saveStaticData(
const std::string& rundir)
const
294 std::stringstream ss;
297 const std::string outname=rundir+
"/rngSeed.txt";
298 std::ofstream dst(outname.c_str(), std::ios::trunc);
302 if(!boost::filesystem::exists(rundir +
"/config.txt"))
303 simulation->getConfiguration().writeToFile(rundir +
"/config.txt");
305 if(!gitRevision.empty())
307 const std::string outname=rundir+
"/git-revision";
308 std::ofstream dst(outname.c_str(), std::ios::trunc);