| 1 | /**
|
|---|
| 2 | * @file comm_serial.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:28:12 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief VMG::CommSerial
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #ifdef HAVE_BOOST_FILESYSTEM
|
|---|
| 15 | #include <boost/filesystem.hpp>
|
|---|
| 16 | namespace fs = boost::filesystem;
|
|---|
| 17 | #endif
|
|---|
| 18 |
|
|---|
| 19 | #include <cstdarg>
|
|---|
| 20 | #include <cstdio>
|
|---|
| 21 | #include <sstream>
|
|---|
| 22 |
|
|---|
| 23 | #include "base/discretization.hpp"
|
|---|
| 24 | #include "base/helper.hpp"
|
|---|
| 25 | #include "base/index.hpp"
|
|---|
| 26 | #include "base/linked_cell_list.hpp"
|
|---|
| 27 | #include "base/stencil.hpp"
|
|---|
| 28 | #include "base/vector.hpp"
|
|---|
| 29 | #include "comm/comm_serial.hpp"
|
|---|
| 30 | #include "comm/comm.hpp"
|
|---|
| 31 | #include "grid/multigrid.hpp"
|
|---|
| 32 | #include "grid/tempgrid.hpp"
|
|---|
| 33 | #include "mg.hpp"
|
|---|
| 34 |
|
|---|
| 35 | using namespace VMG;
|
|---|
| 36 |
|
|---|
| 37 | static char print_buffer[512];
|
|---|
| 38 |
|
|---|
| 39 | void CommSerial::InitCommSerial()
|
|---|
| 40 | {
|
|---|
| 41 | error_norm_count = 0;
|
|---|
| 42 | residual_count = 0;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void CommSerial::CommSubgrid(Grid& grid_old, Grid& grid_new)
|
|---|
| 46 | {
|
|---|
| 47 | Grid::iterator iter;
|
|---|
| 48 |
|
|---|
| 49 | if (&grid_old == &grid_new)
|
|---|
| 50 | return;
|
|---|
| 51 |
|
|---|
| 52 | for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
|
|---|
| 53 | grid_new(*iter) = grid_old.GetVal(*iter);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | void CommSerial::CommAddSubgrid(Grid& grid_old, Grid& grid_new)
|
|---|
| 57 | {
|
|---|
| 58 | Grid::iterator iter;
|
|---|
| 59 |
|
|---|
| 60 | if (&grid_old == &grid_new)
|
|---|
| 61 | return;
|
|---|
| 62 |
|
|---|
| 63 | for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
|
|---|
| 64 | grid_new(*iter) += grid_old.GetVal(*iter);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | Grid& CommSerial::GetFinerGrid(Multigrid& multigrid)
|
|---|
| 68 | {
|
|---|
| 69 | return multigrid(multigrid.Level()+1);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | Grid& CommSerial::GetCoarserGrid(Multigrid& multigrid)
|
|---|
| 73 | {
|
|---|
| 74 | return multigrid(multigrid.Level()-1);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void CommSerial::CommFromGhosts(Grid& mesh)
|
|---|
| 78 | {
|
|---|
| 79 | Grid::iterator iter;
|
|---|
| 80 |
|
|---|
| 81 | const GridIteratorSuite& iterators = mesh.Iterators();
|
|---|
| 82 | const Index& size = mesh.Local().Size();
|
|---|
| 83 |
|
|---|
| 84 | if (BoundaryConditions().X() == Periodic) {
|
|---|
| 85 |
|
|---|
| 86 | for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
|
|---|
| 87 | mesh((*iter).X()+size.X(), (*iter).Y(), (*iter).Z()) += mesh.GetVal(*iter);
|
|---|
| 88 |
|
|---|
| 89 | for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
|
|---|
| 90 | mesh((*iter).X()-size.X(), (*iter).Y(), (*iter).Z()) += mesh.GetVal(*iter);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | if (BoundaryConditions().Y() == Periodic) {
|
|---|
| 94 |
|
|---|
| 95 | for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
|
|---|
| 96 | mesh((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z()) += mesh.GetVal(*iter);
|
|---|
| 97 |
|
|---|
| 98 | for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
|
|---|
| 99 | mesh((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z()) += mesh.GetVal(*iter);
|
|---|
| 100 |
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | if (BoundaryConditions().Z() == Periodic) {
|
|---|
| 104 |
|
|---|
| 105 | for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
|
|---|
| 106 | mesh((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z()) += mesh.GetVal(*iter);
|
|---|
| 107 |
|
|---|
| 108 | for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
|
|---|
| 109 | mesh((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z()) += mesh.GetVal(*iter);
|
|---|
| 110 |
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 114 | mesh.IsConsistent();
|
|---|
| 115 | #endif
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | void CommSerial::CommToGhosts(Grid& mesh)
|
|---|
| 119 | {
|
|---|
| 120 | Grid::iterator iter;
|
|---|
| 121 |
|
|---|
| 122 | const GridIteratorSuite& iterators = mesh.Iterators();
|
|---|
| 123 | const Index& size = mesh.Local().Size();
|
|---|
| 124 |
|
|---|
| 125 | if (BoundaryConditions().Z() == Periodic) {
|
|---|
| 126 |
|
|---|
| 127 | for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
|
|---|
| 128 | mesh(*iter) = mesh.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z());
|
|---|
| 129 |
|
|---|
| 130 | for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
|
|---|
| 131 | mesh(*iter) = mesh.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z());
|
|---|
| 132 |
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | if (BoundaryConditions().Y() == Periodic) {
|
|---|
| 136 |
|
|---|
| 137 | for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
|
|---|
| 138 | mesh(*iter) = mesh.GetVal((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z());
|
|---|
| 139 |
|
|---|
| 140 | for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
|
|---|
| 141 | mesh(*iter) = mesh.GetVal((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z());
|
|---|
| 142 |
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | if (BoundaryConditions().X() == Periodic) {
|
|---|
| 146 |
|
|---|
| 147 | for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
|
|---|
| 148 | mesh(*iter) = mesh.GetVal((*iter).X()+size.X(), (*iter).Y(), (*iter).Z());
|
|---|
| 149 |
|
|---|
| 150 | for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
|
|---|
| 151 | mesh(*iter) = mesh.GetVal((*iter).X()-size.X(), (*iter).Y(), (*iter).Z());
|
|---|
| 152 |
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 156 | mesh.IsConsistent();
|
|---|
| 157 | #endif
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void CommSerial::CommToGhostsRB(Grid& grid, const int& offset)
|
|---|
| 161 | {
|
|---|
| 162 | CommToGhosts(grid);
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | void CommSerial::CommToGhostsAsyncStart(Grid& grid)
|
|---|
| 166 | {
|
|---|
| 167 | CommToGhosts(grid);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | void CommSerial::CommToGhostsAsyncFinish()
|
|---|
| 171 | {
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | void CommSerial::CommFromGhostsAsyncStart(Grid& grid)
|
|---|
| 175 | {
|
|---|
| 176 | CommFromGhosts(grid);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | void CommFromGhostsAsyncFinish(Grid& grid)
|
|---|
| 180 | {
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | Grid& CommSerial::GetGlobalCoarseGrid(Multigrid& multigrid)
|
|---|
| 184 | {
|
|---|
| 185 | return multigrid(multigrid.MinLevel());
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | void CommSerial::CommParticles(const Grid& grid, std::list<Particle::Particle>& particles)
|
|---|
| 189 | {
|
|---|
| 190 | Factory& factory = MG::GetFactory();
|
|---|
| 191 | const vmg_int& num_particles_local = factory.GetObjectStorageVal<vmg_int>("PARTICLE_NUM_LOCAL");
|
|---|
| 192 | vmg_float* x = factory.GetObjectStorageArray<vmg_float>("PARTICLE_POS_ARRAY");
|
|---|
| 193 | vmg_float* q = factory.GetObjectStorageArray<vmg_float>("PARTICLE_CHARGE_ARRAY");
|
|---|
| 194 |
|
|---|
| 195 | particles.clear();
|
|---|
| 196 |
|
|---|
| 197 | for (vmg_int i=0; i<num_particles_local; ++i)
|
|---|
| 198 | particles.push_back(Particle::Particle(&x[3*i], q[i], 0.0, 0.0, 0, i));
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | void CommSerial::CommLCListGhosts(const Grid& grid, Particle::LinkedCellList& lc)
|
|---|
| 202 | {
|
|---|
| 203 | std::list<Particle::Particle>::iterator p_iter;
|
|---|
| 204 | Grid::iterator g_iter;
|
|---|
| 205 |
|
|---|
| 206 | for (int i=2; i>=0; --i) {
|
|---|
| 207 |
|
|---|
| 208 | if (BoundaryConditions()[i] == Periodic) {
|
|---|
| 209 |
|
|---|
| 210 | for (g_iter=lc.Iterators().Boundary1()[i].Begin(); g_iter!=lc.Iterators().Boundary1()[i].End(); ++g_iter)
|
|---|
| 211 | lc(*g_iter).clear();
|
|---|
| 212 |
|
|---|
| 213 | for (g_iter=lc.Iterators().NearBoundary1()[i].Begin(); g_iter!=lc.Iterators().NearBoundary1()[i].End(); ++g_iter)
|
|---|
| 214 | for (p_iter=lc(*g_iter).begin(); p_iter!=lc(*g_iter).end(); ++p_iter)
|
|---|
| 215 | lc.AddParticleToComplete(p_iter->Pos() + grid.Extent().Size(), p_iter->Charge(),
|
|---|
| 216 | p_iter->Pot(), p_iter->Force(),
|
|---|
| 217 | p_iter->Rank(), p_iter->Index());
|
|---|
| 218 |
|
|---|
| 219 | for (g_iter=lc.Iterators().Boundary2()[i].Begin(); g_iter!=lc.Iterators().Boundary2()[i].End(); ++g_iter)
|
|---|
| 220 | lc(*g_iter).clear();
|
|---|
| 221 |
|
|---|
| 222 | for (g_iter=lc.Iterators().NearBoundary2()[i].Begin(); g_iter!=lc.Iterators().NearBoundary2()[i].End(); ++g_iter)
|
|---|
| 223 | for (p_iter=lc(*g_iter).begin(); p_iter!=lc(*g_iter).end(); ++p_iter)
|
|---|
| 224 | lc.AddParticleToComplete(p_iter->Pos() - grid.Extent().Size(), p_iter->Charge(),
|
|---|
| 225 | p_iter->Pot(), p_iter->Force(),
|
|---|
| 226 | p_iter->Rank(), p_iter->Index());
|
|---|
| 227 |
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | void CommSerial::CommAddPotential(std::list<Particle::Particle>& particles)
|
|---|
| 233 | {
|
|---|
| 234 | std::list<Particle::Particle>::iterator iter;
|
|---|
| 235 | vmg_float* p = MG::GetFactory().GetObjectStorageArray<vmg_float>("PARTICLE_POTENTIAL_ARRAY");
|
|---|
| 236 |
|
|---|
| 237 | for (iter=particles.begin(); iter!=particles.end(); ++iter)
|
|---|
| 238 | p[iter->Index()] += iter->Pot();
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | void CommSerial::CommAddPotential(Particle::LinkedCellList& lc)
|
|---|
| 242 | {
|
|---|
| 243 | Grid::iterator lc_iter;
|
|---|
| 244 | std::list<Particle::Particle>::iterator p_iter;
|
|---|
| 245 | vmg_float* p = MG::GetFactory().GetObjectStorageArray<vmg_float>("PARTICLE_POTENTIAL_ARRAY");
|
|---|
| 246 |
|
|---|
| 247 | for (lc_iter=lc.Iterators().Local().Begin(); lc_iter!=lc.Iterators().Local().End(); ++lc_iter)
|
|---|
| 248 | for (p_iter=lc(*lc_iter).begin(); p_iter!=lc(*lc_iter).end(); ++p_iter)
|
|---|
| 249 | p[p_iter->Index()] += p_iter->Pot();
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | void CommSerial::PrintString(const char* format, ...)
|
|---|
| 253 | {
|
|---|
| 254 | va_list args;
|
|---|
| 255 | va_start(args, format);
|
|---|
| 256 | vsprintf(print_buffer, format, args);
|
|---|
| 257 | printf("VMG: %s\n", print_buffer);
|
|---|
| 258 | va_end(args);
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | void CommSerial::PrintStringOnce(const char* format, ...)
|
|---|
| 262 | {
|
|---|
| 263 | va_list args;
|
|---|
| 264 | va_start(args, format);
|
|---|
| 265 | vsprintf(print_buffer, format, args);
|
|---|
| 266 | printf("VMG: %s\n", print_buffer);
|
|---|
| 267 | va_end(args);
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | void CommSerial::PrintXML(const std::string& filename, const std::string& xml_data)
|
|---|
| 271 | {
|
|---|
| 272 | pugi::xml_document doc;
|
|---|
| 273 | doc.load(xml_data.c_str());
|
|---|
| 274 |
|
|---|
| 275 | pugi::xml_node node_global = doc.prepend_child("Global");
|
|---|
| 276 | pugi::xml_node node_num_processes = node_global.append_child("NumProcesses");
|
|---|
| 277 | pugi::xml_node node_num_processes_data = node_num_processes.append_child(pugi::node_pcdata);
|
|---|
| 278 | node_num_processes_data.set_value(Helper::ToString(GlobalProcs().Product()).c_str());
|
|---|
| 279 |
|
|---|
| 280 | doc.save_file(filename.c_str());
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | void CommSerial::PrintXMLAll(const std::string& filename, const std::string& xml_data)
|
|---|
| 284 | {
|
|---|
| 285 | PrintXML(filename, xml_data);
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | void CommSerial::OpenFileAndPrintHeader(std::ofstream& out, const Grid& mesh, const char* information, bool inner)
|
|---|
| 289 | {
|
|---|
| 290 | char path_str[129];
|
|---|
| 291 | int count = OutputCount();
|
|---|
| 292 |
|
|---|
| 293 | sprintf(path_str, "%s%04d.dat", OutputPath().c_str(), count);
|
|---|
| 294 |
|
|---|
| 295 | out.open(path_str, std::ios::trunc);
|
|---|
| 296 |
|
|---|
| 297 | if (!out.good()) {
|
|---|
| 298 | #ifdef DEBUG_OUTPUT
|
|---|
| 299 | printf("Multigrid: File %s not accessible.\n", path_str);
|
|---|
| 300 | #endif /* DEBUG_OUTPUT */
|
|---|
| 301 | return;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | out << "# vtk DataFile Version 2.0" << std::endl
|
|---|
| 305 | << count << ": " << information << std::endl
|
|---|
| 306 | << "ASCII" << std::endl
|
|---|
| 307 | << "DATASET STRUCTURED_POINTS" << std::endl;
|
|---|
| 308 |
|
|---|
| 309 | if (inner) {
|
|---|
| 310 | out << "DIMENSIONS "
|
|---|
| 311 | << mesh.Local().Size().X() << " "
|
|---|
| 312 | << mesh.Local().Size().Y() << " "
|
|---|
| 313 | << mesh.Local().Size().Z() << std::endl;
|
|---|
| 314 | }else {
|
|---|
| 315 | out << "DIMENSIONS "
|
|---|
| 316 | << mesh.Local().SizeTotal().X() << " "
|
|---|
| 317 | << mesh.Local().SizeTotal().Y() << " "
|
|---|
| 318 | << mesh.Local().SizeTotal().Z() << std::endl;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | out << "ORIGIN 0 0 0" << std::endl
|
|---|
| 322 | << "SPACING " << mesh.MeshWidth() << " "
|
|---|
| 323 | << mesh.MeshWidth() << " "
|
|---|
| 324 | << mesh.MeshWidth() << std::endl;
|
|---|
| 325 |
|
|---|
| 326 | if (inner)
|
|---|
| 327 | out << "POINT_DATA " << mesh.Local().Size().Product() << std::endl;
|
|---|
| 328 | else
|
|---|
| 329 | out << "POINT_DATA " << mesh.Local().SizeTotal().Product() << std::endl;
|
|---|
| 330 |
|
|---|
| 331 | out << "SCALARS residual double 1" << std::endl
|
|---|
| 332 | << "LOOKUP_TABLE default" << std::endl;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | void CommSerial::PrintDefect(Grid& sol, Grid& rhs, const char* information)
|
|---|
| 336 | {
|
|---|
| 337 | std::ofstream out_file;
|
|---|
| 338 | std::stringstream out;
|
|---|
| 339 |
|
|---|
| 340 | TempGrid *temp = MG::GetTempGrid();
|
|---|
| 341 | temp->SetProperties(sol);
|
|---|
| 342 | temp->ImportFromResidual(sol, rhs);
|
|---|
| 343 |
|
|---|
| 344 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 345 | temp->IsConsistent();
|
|---|
| 346 | #endif
|
|---|
| 347 |
|
|---|
| 348 | OpenFileAndPrintHeader(out_file, *temp, information, true);
|
|---|
| 349 |
|
|---|
| 350 | assert(out_file.good());
|
|---|
| 351 |
|
|---|
| 352 | if (!out_file.good())
|
|---|
| 353 | return;
|
|---|
| 354 |
|
|---|
| 355 | for (int k=temp->Local().Begin().Z(); k<temp->Local().End().Z(); k++)
|
|---|
| 356 | for (int j=temp->Local().Begin().Y(); j<temp->Local().End().Y(); j++)
|
|---|
| 357 | for (int i=temp->Local().Begin().X(); i<temp->Local().End().X(); i++)
|
|---|
| 358 | out << std::scientific << temp->GetVal(i,j,k) << std::endl;
|
|---|
| 359 |
|
|---|
| 360 | out_file << out.str();
|
|---|
| 361 |
|
|---|
| 362 | out_file.close();
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | void CommSerial::PrintGrid(Grid& mesh, const char* information)
|
|---|
| 366 | {
|
|---|
| 367 | std::stringstream out;
|
|---|
| 368 | std::ofstream out_file;
|
|---|
| 369 |
|
|---|
| 370 | CommToGhosts(mesh);
|
|---|
| 371 |
|
|---|
| 372 | OpenFileAndPrintHeader(out_file, mesh, information, false);
|
|---|
| 373 |
|
|---|
| 374 | for (int k=0; k<mesh.Local().SizeTotal().Z(); k++)
|
|---|
| 375 | for (int j=0; j<mesh.Local().SizeTotal().Y(); j++)
|
|---|
| 376 | for (int i=0; i<mesh.Local().SizeTotal().X(); i++)
|
|---|
| 377 | out << std::scientific << mesh.GetVal(i,j,k) << std::endl;
|
|---|
| 378 |
|
|---|
| 379 | out_file << out.str();
|
|---|
| 380 | out_file.close();
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | void CommSerial::PrintCorrectedGrid(Grid& mesh, const char* information)
|
|---|
| 384 | {
|
|---|
| 385 | std::ofstream out_file;
|
|---|
| 386 | std::stringstream out;
|
|---|
| 387 |
|
|---|
| 388 | CommToGhosts(mesh);
|
|---|
| 389 |
|
|---|
| 390 | OpenFileAndPrintHeader(out_file, mesh, information, false);
|
|---|
| 391 |
|
|---|
| 392 | for (int k=0; k<mesh.Local().SizeTotal().Z(); k++)
|
|---|
| 393 | for (int j=0; j<mesh.Local().SizeTotal().Y(); j++)
|
|---|
| 394 | for (int i=0; i<mesh.Local().SizeTotal().X(); i++)
|
|---|
| 395 | out << std::scientific << mesh.GetCorrectedVal(i,j,k) << std::endl;
|
|---|
| 396 |
|
|---|
| 397 | out_file << out.str();
|
|---|
| 398 |
|
|---|
| 399 | out_file.close();
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | void CommSerial::PrintInnerGrid(Grid& mesh, const char* information)
|
|---|
| 403 | {
|
|---|
| 404 | std::ofstream out_file;
|
|---|
| 405 | std::stringstream out;
|
|---|
| 406 |
|
|---|
| 407 | CommToGhosts(mesh);
|
|---|
| 408 |
|
|---|
| 409 | OpenFileAndPrintHeader(out_file, mesh, information, true);
|
|---|
| 410 |
|
|---|
| 411 | for (int k=mesh.Local().Begin().Z(); k<mesh.Local().End().Z(); k++)
|
|---|
| 412 | for (int j=mesh.Local().Begin().Y(); j<mesh.Local().End().Y(); j++)
|
|---|
| 413 | for (int i=mesh.Local().Begin().X(); i<mesh.Local().End().X(); i++)
|
|---|
| 414 | out << std::scientific << mesh.GetVal(i,j,k) << std::endl;
|
|---|
| 415 |
|
|---|
| 416 | out_file << out.str();
|
|---|
| 417 |
|
|---|
| 418 | out_file.close();
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | void CommSerial::PrintInnerCorrectedGrid(Grid& mesh, const char* information)
|
|---|
| 422 | {
|
|---|
| 423 | std::ofstream out_file;
|
|---|
| 424 | std::stringstream out;
|
|---|
| 425 |
|
|---|
| 426 | CommToGhosts(mesh);
|
|---|
| 427 |
|
|---|
| 428 | OpenFileAndPrintHeader(out_file, mesh, information, true);
|
|---|
| 429 |
|
|---|
| 430 | for (int k=mesh.Local().Begin().Z(); k<mesh.Local().End().Z(); k++)
|
|---|
| 431 | for (int j=mesh.Local().Begin().Y(); j<mesh.Local().End().Y(); j++)
|
|---|
| 432 | for (int i=mesh.Local().Begin().X(); i<mesh.Local().End().X(); i++)
|
|---|
| 433 | out << std::scientific << mesh.GetCorrectedVal(i,j,k) << std::endl;
|
|---|
| 434 |
|
|---|
| 435 | out_file << out.str();
|
|---|
| 436 |
|
|---|
| 437 | out_file.close();
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 440 | void CommSerial::PrintAllSettings()
|
|---|
| 441 | {
|
|---|
| 442 | Multigrid* mg = MG::GetFactory().Get("SOL")->Cast<Multigrid>();
|
|---|
| 443 | std::stringstream buf;
|
|---|
| 444 | std::ofstream out;
|
|---|
| 445 |
|
|---|
| 446 | buf << OutputPath() << "settings.txt";
|
|---|
| 447 |
|
|---|
| 448 | out.open(buf.str().c_str(), std::ios::trunc);
|
|---|
| 449 |
|
|---|
| 450 | for (int i=mg->MinLevel(); i<=mg->MaxLevel(); ++i) {
|
|---|
| 451 |
|
|---|
| 452 | out << "GRID LEVEL " << i << std::endl
|
|---|
| 453 |
|
|---|
| 454 | << "GLOBAL" << std::endl
|
|---|
| 455 | << "BEGINFINEST: " << (*mg)(i).Global().BeginFinest() << std::endl
|
|---|
| 456 | << "ENDFINEST: " << (*mg)(i).Global().EndFinest() << std::endl
|
|---|
| 457 | << "SIZEFINEST: " << (*mg)(i).Global().SizeFinest() << std::endl
|
|---|
| 458 | << "BEGINLOCAL: " << (*mg)(i).Global().BeginLocal() << std::endl
|
|---|
| 459 | << "ENDLOCAL: " << (*mg)(i).Global().EndLocal() << std::endl
|
|---|
| 460 | << "SIZELOCAL: " << (*mg)(i).Global().SizeLocal() << std::endl
|
|---|
| 461 | << "SIZEGLOBAL: " << (*mg)(i).Global().SizeGlobal() << std::endl
|
|---|
| 462 | << "BOUNDARYTYPE: " << (*mg)(i).Global().BoundaryType() << std::endl
|
|---|
| 463 |
|
|---|
| 464 | << "LOCAL" << std::endl
|
|---|
| 465 | << "SIZE: " << (*mg)(i).Local().Size() << std::endl
|
|---|
| 466 | << "SIZETOTAL: " << (*mg)(i).Local().SizeTotal() << std::endl
|
|---|
| 467 | << "BEGIN: " << (*mg)(i).Local().Begin() << std::endl
|
|---|
| 468 | << "END: " << (*mg)(i).Local().End() << std::endl
|
|---|
| 469 | << "HALOBEGIN1: " << (*mg)(i).Local().HaloBegin1() << std::endl
|
|---|
| 470 | << "HALOEND1: " << (*mg)(i).Local().HaloEnd1() << std::endl
|
|---|
| 471 | << "HALOBEGIN2: " << (*mg)(i).Local().HaloBegin2() << std::endl
|
|---|
| 472 | << "HALOEND2: " << (*mg)(i).Local().HaloEnd2() << std::endl
|
|---|
| 473 | << "BOUNDARYBEGIN1: " << (*mg)(i).Local().BoundaryBegin1() << std::endl
|
|---|
| 474 | << "BOUNDARYEND1: " << (*mg)(i).Local().BoundaryEnd1() << std::endl
|
|---|
| 475 | << "BOUNDARYBEGIN2: " << (*mg)(i).Local().BoundaryBegin2() << std::endl
|
|---|
| 476 | << "BOUNDARYEND2: " << (*mg)(i).Local().BoundaryEnd2() << std::endl
|
|---|
| 477 | << "ALIGNMENTBEGIN: " << (*mg)(i).Local().AlignmentBegin() << std::endl
|
|---|
| 478 | << "ALIGNMENTEND: " << (*mg)(i).Local().AlignmentEnd() << std::endl
|
|---|
| 479 |
|
|---|
| 480 | << "EXTENT" << std::endl
|
|---|
| 481 | << "SIZE: " << (*mg)(i).Extent().Size() << std::endl
|
|---|
| 482 | << "SIZEFACTOR: " << (*mg)(i).Extent().SizeFactor() << std::endl
|
|---|
| 483 | << "BEGIN: " << (*mg)(i).Extent().Begin() << std::endl
|
|---|
| 484 | << "END: " << (*mg)(i).Extent().End() << std::endl
|
|---|
| 485 | << "MESHWIDTH: " << (*mg)(i).Extent().MeshWidth() << std::endl;
|
|---|
| 486 |
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | assert(out.good());
|
|---|
| 490 | out.close();
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| 493 | void CommSerial::DebugPrintError(const Grid& sol, const char* information)
|
|---|
| 494 | {
|
|---|
| 495 | Index i;
|
|---|
| 496 | std::ofstream out_file;
|
|---|
| 497 | std::stringstream out;
|
|---|
| 498 |
|
|---|
| 499 | OpenFileAndPrintHeader(out_file, sol, information, false);
|
|---|
| 500 |
|
|---|
| 501 | for (i.Z()=0; i.Z()<sol.Local().SizeTotal().Z(); ++i.Z())
|
|---|
| 502 | for (i.Y()=0; i.Y()<sol.Local().SizeTotal().Y(); ++i.Y())
|
|---|
| 503 | for (i.X()=0; i.X()<sol.Local().SizeTotal().X(); ++i.X())
|
|---|
| 504 | out << std::scientific << sol.DebugKnownSolution(i) - sol.GetVal(i) << std::endl;
|
|---|
| 505 |
|
|---|
| 506 | out_file << out.str();
|
|---|
| 507 |
|
|---|
| 508 | out_file.close();
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | void CommSerial::DebugPrintErrorNorm(Grid& sol)
|
|---|
| 512 | {
|
|---|
| 513 | #ifdef HAVE_LIBGSL
|
|---|
| 514 | char path_str[129];
|
|---|
| 515 | std::ofstream out;
|
|---|
| 516 | const vmg_float sp = sol.MeshWidth();
|
|---|
| 517 | const vmg_float sp_3_inv = 1.0/(sp*sp*sp);
|
|---|
| 518 | const int numsamples = 1e6;
|
|---|
| 519 | const vmg_float numsamples_inv = 1.0 / numsamples;
|
|---|
| 520 | vmg_float val1, val2, diff;
|
|---|
| 521 |
|
|---|
| 522 | vmg_float norm_L1 = 0.0;
|
|---|
| 523 | vmg_float norm_L2 = 0.0;
|
|---|
| 524 | vmg_float norm_Linfty = 0.0;
|
|---|
| 525 | vmg_float norm_u_L1 = 0.0;
|
|---|
| 526 | vmg_float norm_u_L2 = 0.0;
|
|---|
| 527 | vmg_float norm_u_Linfty = 0.0;
|
|---|
| 528 |
|
|---|
| 529 | Vector x, x_le, x_ri;
|
|---|
| 530 | Index ind;
|
|---|
| 531 |
|
|---|
| 532 | gsl_qrng *q = gsl_qrng_alloc(gsl_qrng_niederreiter_2, 3);
|
|---|
| 533 |
|
|---|
| 534 | sprintf(path_str, "%serror.txt", defects_path_str.c_str());
|
|---|
| 535 |
|
|---|
| 536 | out.open(path_str, std::ios::app);
|
|---|
| 537 |
|
|---|
| 538 | assert(out.good());
|
|---|
| 539 |
|
|---|
| 540 | CommToGhosts(sol);
|
|---|
| 541 |
|
|---|
| 542 | for (int i=0; i<numsamples; i++) {
|
|---|
| 543 |
|
|---|
| 544 | gsl_qrng_get(q, x.vec());
|
|---|
| 545 |
|
|---|
| 546 | ind = x / sp;
|
|---|
| 547 |
|
|---|
| 548 | x_le = x - sp * static_cast<Vector>(ind);
|
|---|
| 549 | x_ri = sp - x_le;
|
|---|
| 550 |
|
|---|
| 551 | for (int j=0; j<3; ++j)
|
|---|
| 552 | if (this->BoundaryConditions()[j] == Periodic)
|
|---|
| 553 | ind[j] += sol.Local().Begin()[j];
|
|---|
| 554 |
|
|---|
| 555 | val1 = ( sol.GetVal(ind) * x_ri[0] * x_ri[1] * x_ri[2] +
|
|---|
| 556 | sol.GetVal(ind[0]+1, ind[1] , ind[2] ) * x_le[0] * x_ri[1] * x_ri[2] +
|
|---|
| 557 | sol.GetVal(ind[0] , ind[1]+1, ind[2] ) * x_ri[0] * x_le[1] * x_ri[2] +
|
|---|
| 558 | sol.GetVal(ind[0] , ind[1] , ind[2]+1) * x_ri[0] * x_ri[1] * x_le[2] +
|
|---|
| 559 | sol.GetVal(ind[0]+1, ind[1]+1, ind[2] ) * x_le[0] * x_le[1] * x_ri[2] +
|
|---|
| 560 | sol.GetVal(ind[0]+1, ind[1] , ind[2]+1) * x_le[0] * x_ri[1] * x_le[2] +
|
|---|
| 561 | sol.GetVal(ind[0] , ind[1]+1, ind[2]+1) * x_ri[0] * x_le[1] * x_le[2] +
|
|---|
| 562 | sol.GetVal(ind[0]+1, ind[1]+1, ind[2]+1) * x_le[0] * x_le[1] * x_le[2] ) * sp_3_inv;
|
|---|
| 563 |
|
|---|
| 564 | val2 = sol.DebugKnownSolution(x);
|
|---|
| 565 |
|
|---|
| 566 | diff = fabs(val1 - val2);
|
|---|
| 567 |
|
|---|
| 568 | norm_L1 += diff * numsamples_inv;
|
|---|
| 569 | norm_L2 += diff*diff * numsamples_inv;
|
|---|
| 570 | norm_Linfty = std::max(norm_Linfty, diff);
|
|---|
| 571 |
|
|---|
| 572 | norm_u_L1 += fabs(val2) * numsamples_inv;
|
|---|
| 573 | norm_u_L2 += val2*val2 * numsamples_inv;
|
|---|
| 574 | norm_u_Linfty = std::max(norm_u_Linfty, fabs(val2));
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | norm_L2 = sqrt(norm_L2);
|
|---|
| 578 | norm_u_L2 = sqrt(norm_u_L2);
|
|---|
| 579 |
|
|---|
| 580 | std::cout << std::scientific << std::endl
|
|---|
| 581 | << "Error L1-norm: " << norm_L1 << std::endl
|
|---|
| 582 | << "Error L2-norm: " << norm_L2 << std::endl
|
|---|
| 583 | << "Error Linfty-norm: " << norm_Linfty << std::endl
|
|---|
| 584 | << "Relative error L1-norm: " << norm_L1 / norm_u_L1 << std::endl
|
|---|
| 585 | << "Relative error L2-norm: " << norm_L2 / norm_u_L2 << std::endl
|
|---|
| 586 | << "Relative error Linfty-norm: " << norm_Linfty / norm_u_Linfty << std::endl;
|
|---|
| 587 |
|
|---|
| 588 | gsl_qrng_free(q);
|
|---|
| 589 |
|
|---|
| 590 | out << std::scientific << error_norm_count++ << " "
|
|---|
| 591 | << norm_L1 << " "
|
|---|
| 592 | << norm_L2 << " "
|
|---|
| 593 | << norm_Linfty << " "
|
|---|
| 594 | << norm_L1/norm_u_L1 << " "
|
|---|
| 595 | << norm_L2/norm_u_L2 << " "
|
|---|
| 596 | << norm_Linfty/norm_u_Linfty << std::endl;
|
|---|
| 597 |
|
|---|
| 598 | out.close();
|
|---|
| 599 |
|
|---|
| 600 | #endif
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | inline int GetIndex(const Grid& grid, int i, int j, int k)
|
|---|
| 604 | {
|
|---|
| 605 | if (grid.Global().BoundaryType() == LocallyRefined)
|
|---|
| 606 | return k + grid.Local().Size().Z() * (j + grid.Local().Size().Y() * i);
|
|---|
| 607 | else
|
|---|
| 608 | return k + grid.Local().SizeTotal().Z() * (j + grid.Local().SizeTotal().Y() * i);
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
|
|---|
| 612 | {
|
|---|
| 613 | const vmg_float sp = grid.MeshWidth();
|
|---|
| 614 | int numLines;
|
|---|
| 615 |
|
|---|
| 616 | if (grid.Global().BoundaryType() == LocallyRefined)
|
|---|
| 617 | numLines = grid.Local().Size().X() * grid.Local().Size().Y() +
|
|---|
| 618 | grid.Local().Size().Y() * grid.Local().Size().Z() +
|
|---|
| 619 | grid.Local().Size().X() * grid.Local().Size().Z();
|
|---|
| 620 | else
|
|---|
| 621 | numLines = grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Y() +
|
|---|
| 622 | grid.Local().SizeTotal().Y() * grid.Local().SizeTotal().Z() +
|
|---|
| 623 | grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Z();
|
|---|
| 624 |
|
|---|
| 625 | out << " <Piece";
|
|---|
| 626 |
|
|---|
| 627 | if (grid.Global().BoundaryType() == LocallyRefined) {
|
|---|
| 628 | out << " NumberOfPoints=\"" << grid.Local().Size().Product() << "\""
|
|---|
| 629 | << " NumberOfVerts=\"" << grid.Local().Size().Product() << "\"";
|
|---|
| 630 | }else {
|
|---|
| 631 | out << " NumberOfPoints=\"" << grid.Local().SizeTotal().Product() << "\""
|
|---|
| 632 | << " NumberOfVerts=\"" << grid.Local().SizeTotal().Product() << "\"";
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | out << " NumberOfLines=\"" << numLines << "\""
|
|---|
| 636 | << " NumberOfStrips=\"0\""
|
|---|
| 637 | << " NumberOfPolys=\"0\"" << ">" << std::endl
|
|---|
| 638 | << " <Points>" << std::endl
|
|---|
| 639 | << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl
|
|---|
| 640 | << " ";
|
|---|
| 641 |
|
|---|
| 642 | if (grid.Global().BoundaryType() == LocallyRefined) {
|
|---|
| 643 | for (int i=0; i<grid.Local().Size().X(); i++)
|
|---|
| 644 | for (int j=0; j<grid.Local().Size().Y(); j++)
|
|---|
| 645 | for (int k=0; k<grid.Local().Size().Z(); k++)
|
|---|
| 646 | out << grid.Extent().Begin().X() + i * sp << " "
|
|---|
| 647 | << grid.Extent().Begin().Y() + j * sp << " "
|
|---|
| 648 | << grid.Extent().Begin().Z() + k * sp << " ";
|
|---|
| 649 | }else {
|
|---|
| 650 | for (int i=0; i<grid.Local().SizeTotal().X(); i++)
|
|---|
| 651 | for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
|
|---|
| 652 | for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
|
|---|
| 653 | out << grid.Extent().Begin().X() + i * sp << " "
|
|---|
| 654 | << grid.Extent().Begin().Y() + j * sp << " "
|
|---|
| 655 | << grid.Extent().Begin().Z() + k * sp << " ";
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | out << std::endl
|
|---|
| 659 | << " </DataArray>" << std::endl
|
|---|
| 660 | << " </Points>" << std::endl
|
|---|
| 661 | << " <Verts>" << std::endl
|
|---|
| 662 | << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
|
|---|
| 663 | << " ";
|
|---|
| 664 |
|
|---|
| 665 | if (grid.Global().BoundaryType() == LocallyRefined) {
|
|---|
| 666 | for (int i=0; i<grid.Local().Size().Product(); i++)
|
|---|
| 667 | out << i << " ";
|
|---|
| 668 | }else {
|
|---|
| 669 | for (int i=0; i<grid.Local().SizeTotal().Product(); i++)
|
|---|
| 670 | out << i << " ";
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | out << std::endl
|
|---|
| 674 | << " </DataArray>" << std::endl
|
|---|
| 675 | << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
|
|---|
| 676 | << " ";
|
|---|
| 677 |
|
|---|
| 678 | if (grid.Global().BoundaryType() == LocallyRefined) {
|
|---|
| 679 | for (int i=1; i<=grid.Local().Size().Product(); i++)
|
|---|
| 680 | out << i << " ";
|
|---|
| 681 | }else {
|
|---|
| 682 | for (int i=1; i<=grid.Local().SizeTotal().Product(); i++)
|
|---|
| 683 | out << i << " ";
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | out << std::endl
|
|---|
| 687 | << " </DataArray>" << std::endl
|
|---|
| 688 | << " </Verts>" << std::endl
|
|---|
| 689 | << " <Lines>" << std::endl
|
|---|
| 690 | << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
|
|---|
| 691 | << " ";
|
|---|
| 692 |
|
|---|
| 693 | if (grid.Global().BoundaryType() == LocallyRefined) {
|
|---|
| 694 | for (int i=0; i<grid.Local().Size().X(); i++)
|
|---|
| 695 | for (int j=0; j<grid.Local().Size().Y(); j++)
|
|---|
| 696 | out << GetIndex(grid,i,j,0) << " "
|
|---|
| 697 | << GetIndex(grid,i,j,grid.Local().Size().Z()-1) << " ";
|
|---|
| 698 |
|
|---|
| 699 | for (int j=0; j<grid.Local().Size().Y(); j++)
|
|---|
| 700 | for (int k=0; k<grid.Local().Size().Z(); k++)
|
|---|
| 701 | out << GetIndex(grid,0,j,k) << " "
|
|---|
| 702 | << GetIndex(grid,grid.Local().Size().X()-1,j,k) << " ";
|
|---|
| 703 |
|
|---|
| 704 | for (int i=0; i<grid.Local().Size().X(); i++)
|
|---|
| 705 | for (int k=0; k<grid.Local().Size().Z(); k++)
|
|---|
| 706 | out << GetIndex(grid,i,0,k) << " "
|
|---|
| 707 | << GetIndex(grid,i,grid.Local().Size().Y()-1,k) << " ";
|
|---|
| 708 | }else {
|
|---|
| 709 | for (int i=0; i<grid.Local().SizeTotal().X(); i++)
|
|---|
| 710 | for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
|
|---|
| 711 | out << GetIndex(grid,i,j,0) << " "
|
|---|
| 712 | << GetIndex(grid,i,j,grid.Local().SizeTotal().Z()-1) << " ";
|
|---|
| 713 |
|
|---|
| 714 | for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
|
|---|
| 715 | for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
|
|---|
| 716 | out << GetIndex(grid,0,j,k) << " "
|
|---|
| 717 | << GetIndex(grid,grid.Local().SizeTotal().X()-1,j,k) << " ";
|
|---|
| 718 |
|
|---|
| 719 | for (int i=0; i<grid.Local().SizeTotal().X(); i++)
|
|---|
| 720 | for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
|
|---|
| 721 | out << GetIndex(grid,i,0,k) << " "
|
|---|
| 722 | << GetIndex(grid,i,grid.Local().SizeTotal().Y()-1,k) << " ";
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | out << std::endl
|
|---|
| 726 | << " </DataArray>" << std::endl
|
|---|
| 727 | << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
|
|---|
| 728 | << " ";
|
|---|
| 729 |
|
|---|
| 730 | for (int i=1; i<=numLines; i++)
|
|---|
| 731 | out << 2*i << " ";
|
|---|
| 732 |
|
|---|
| 733 | out << std::endl
|
|---|
| 734 | << " </DataArray>" << std::endl
|
|---|
| 735 | << " </Lines>" << std::endl
|
|---|
| 736 | << " </Piece>" << std::endl;
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 | void CommSerial::DebugPrintGridStructure(Multigrid& grid)
|
|---|
| 740 | {
|
|---|
| 741 | std::ofstream out;
|
|---|
| 742 | char path_str[129];
|
|---|
| 743 |
|
|---|
| 744 | sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
|
|---|
| 745 |
|
|---|
| 746 | out.open(path_str, std::ios::trunc);
|
|---|
| 747 |
|
|---|
| 748 | if (!out.good()) {
|
|---|
| 749 | #ifdef DEBUG_OUTPUT
|
|---|
| 750 | printf("Multigrid: File %s not accessible.\n", path_str);
|
|---|
| 751 | #endif /* DEBUG_OUTPUT */
|
|---|
| 752 | return;
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | out << "<?xml version=\"1.0\"?>" << std::endl
|
|---|
| 756 | << "<VTKFile type=\"PolyData\">" << std::endl
|
|---|
| 757 | << " <PolyData>" << std::endl;
|
|---|
| 758 |
|
|---|
| 759 | for (int i=grid.MinLevel(); i<=grid.MaxLevel(); i++)
|
|---|
| 760 | PrintGridStructureLevel(grid(i), out);
|
|---|
| 761 |
|
|---|
| 762 | out << " </PolyData>" << std::endl
|
|---|
| 763 | << "</VTKFile>" << std::endl;
|
|---|
| 764 |
|
|---|
| 765 | out.close();
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | std::string CommSerial::CreateOutputDirectory()
|
|---|
| 769 | {
|
|---|
| 770 | #ifdef HAVE_BOOST_FILESYSTEM
|
|---|
| 771 | std::string path, unique_path;
|
|---|
| 772 | std::stringstream unique_suffix;
|
|---|
| 773 | int suffix_counter = 0;
|
|---|
| 774 | char buffer[129];
|
|---|
| 775 | time_t rawtime;
|
|---|
| 776 | struct tm *timeinfo;
|
|---|
| 777 |
|
|---|
| 778 | time(&rawtime);
|
|---|
| 779 | timeinfo = localtime(&rawtime);
|
|---|
| 780 | strftime(buffer, 128, "./output/%Y_%m_%d_%H_%M_%S/", timeinfo);
|
|---|
| 781 | path = buffer;
|
|---|
| 782 |
|
|---|
| 783 | if (!fs::exists("output"))
|
|---|
| 784 | fs::create_directory("output");
|
|---|
| 785 |
|
|---|
| 786 | unique_path = path;
|
|---|
| 787 |
|
|---|
| 788 | while (fs::exists(unique_path.c_str())) {
|
|---|
| 789 |
|
|---|
| 790 | unique_suffix.str("");
|
|---|
| 791 | unique_suffix << "_" << suffix_counter++ << "/";
|
|---|
| 792 |
|
|---|
| 793 | unique_path = path;
|
|---|
| 794 | unique_path.replace(unique_path.size()-1, 1, unique_suffix.str());
|
|---|
| 795 |
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | fs::create_directory(unique_path.c_str());
|
|---|
| 799 |
|
|---|
| 800 | return unique_path;
|
|---|
| 801 |
|
|---|
| 802 | #else
|
|---|
| 803 |
|
|---|
| 804 | return "./";
|
|---|
| 805 |
|
|---|
| 806 | #endif
|
|---|
| 807 | }
|
|---|