Compute mean, std dev, and write them out to VTI for postprocessing.
171{
172 constexpr unsigned D = DESCRIPTOR::d;
173
175
176
178 sLattice.template defineDynamics<NoDynamics>(sGeometry, 0);
179 sLattice.initialize();
180
181
183 size_t numIterations = std::numeric_limits<size_t>::max();
184
186 std::string filePath = uqFolder + std::to_string(n) + "/tmp/iteration_log.txt";
187 std::ifstream inFile(filePath);
188 if (inFile.is_open()) {
189 size_t iVal;
190 while (inFile >> iVal) {
191 iTList[n].push_back(iVal);
192 }
193 inFile.close();
194 numIterations = std::min(numIterations, iTList[n].size());
195 }
196 else {
197 clout << "Could not open file: " << filePath << std::endl;
198 }
199 }
200
201 SuperVTMwriter<T, D> vtmWriter(name);
202
203#ifdef PARALLEL_MODE_MPI
204 const int noOfCuboids = singleton::mpi().getSize();
205#else
206 const int noOfCuboids = 1;
207#endif
208
209
210 for (int rank = 0; rank < noOfCuboids; ++rank) {
211 Cuboid<T, D>& cuboid = cuboidDecomposition.
get(rank);
212 Vector<T, D> origin = cuboid.getOrigin();
213 origin[0] -= cuboid.getDeltaR();
214 origin[1] -= cuboid.getDeltaR();
215 if constexpr (DESCRIPTOR::d == 3) {
216 origin[2] -= cuboid.getDeltaR();
217 }
218
219 Vector<T, D> extent = cuboid.getExtent() * cuboid.getDeltaR();
220 extent[0] += cuboid.getDeltaR();
221 extent[1] += cuboid.getDeltaR();
222 if constexpr (DESCRIPTOR::d == 3) {
223 extent[2] += cuboid.getDeltaR();
224 }
225
226 IndicatorCuboid<T, D> readCuboid(extent, origin);
227 sGeometry.
rename(0, 10 + rank, readCuboid);
228 }
229
230
231 singleton::directories().setOutputDir("./tmp/");
232 SuperLatticeCuboid<T, DESCRIPTOR> cuboid(sLattice);
233 SuperLatticeRank<T, DESCRIPTOR> rankFunctor(sLattice);
234
235 vtmWriter.write(cuboid);
236 vtmWriter.write(rankFunctor);
237 vtmWriter.createMasterFile();
238
239 for (size_t iter = 0; iter < numIterations; ++iter) {
240
241 std::vector<size_t> iT;
242 iT.reserve(iTList.size());
243 for (const auto& list : iTList) {
244 iT.push_back(list[iter]);
245 }
246
247 clout << "Processing iteration " << iT[0] << std::endl;
248
249
250 for (int rank = 0; rank < noOfCuboids; ++rank) {
251 std::string basePath = uqFolder + "0/tmp/";
252 singleton::directories().setOutputDir(basePath);
253
254 std::string fileName =
255 singleton::directories().getVtkOutDir() +
"data/" +
createFileName(name, iT[0], rank) +
".vti";
256
257
258
259 BlockVTIreader<T, T, D> readerMean(fileName, dataName);
260 BlockVTIreader<T, T, D> readerStd(fileName, dataName);
261
262 BlockData<D, T, T>& blockDataMean = readerMean.getBlockData();
263 BlockData<D, T, T>& blockDataStd = readerStd.getBlockData();
264
265
266 std::vector<std::vector<std::vector<T>>> data;
267 FieldGeometryInfo<D, T> info;
268
269 readData<T, DESCRIPTOR>(uq.
getSamplesNumber(), uqFolder, name, dataName, iT, rank, data, info);
270
271
272 computeMeanAndStd<T, D>(uq, data, info, blockDataMean, blockDataStd);
273
274
275 BlockDataF<T, T, D> blockDataFMean(blockDataMean);
276 BlockDataF<T, T, D> blockDataFStd(blockDataStd);
277
278 SpecialAnalyticalFfromBlockF<T, T, D> meanField(blockDataFMean, cuboidDecomposition.
get(rank), info.spacing,
279 1.0);
280 SpecialAnalyticalFfromBlockF<T, T, D> stdField(blockDataFStd, cuboidDecomposition.
get(rank), info.spacing,
281 1.0);
282
283
285 for (
int iBalancer = 0; iBalancer < sGeometry.
getLoadBalancer().size(); ++iBalancer) {
286 sLattice.getBlock(iBalancer).template defineField<descriptors::VELOCITY>(
287 materialIndicator->getBlockIndicatorF(iBalancer), meanField);
288 sLattice.getBlock(iBalancer).template defineField<descriptors::VELOCITY2>(
289 materialIndicator->getBlockIndicatorF(iBalancer), stdField);
290 }
291 }
292
293
294 SuperLatticePhysField<T, DESCRIPTOR, descriptors::VELOCITY> meanPhysField(sLattice,
295 1.0, dataName + "Mean");
296 vtmWriter.addFunctor(meanPhysField);
297
298 SuperLatticePhysField<T, DESCRIPTOR, descriptors::VELOCITY2> stdPhysField(sLattice,
299 1.0, dataName + "Std");
300 vtmWriter.addFunctor(stdPhysField);
301
302
303 singleton::directories().setOutputDir("./tmp/");
304 vtmWriter.write(iT[0]);
305 }
306}
const Cuboid< T, D > & get(int iC) const
Read access to a single cuboid.
class for marking output with some text
void rename(int fromM, int toM)
replace one material with another
std::unique_ptr< SuperIndicatorF< T, D > > getMaterialIndicator(std::vector< int > &&materials)
Returns a material indicator using the given vector of materials.
Super class maintaining block lattices for a cuboid decomposition.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
std::size_t getSamplesNumber()
std::string createFileName(std::string name)
for .pvd masterFile