source: src/comm/comm_serial.cpp@ e58835d

Last change on this file since e58835d was e58835d, checked in by Julian Iseringhausen <isering@…>, 13 years ago

Renamed GlobalIndices::GlobalSizeNew back to GlobalIndices::GlobalSize.

  • Property mode set to 100644
File size: 18.3 KB
RevLine 
[fcf7f6]1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
[48b662]19/**
20 * @file comm_serial.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:28:12 2011
23 *
24 * @brief VMG::CommSerial
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32#ifdef HAVE_BOOST_FILESYSTEM
33#include <boost/filesystem.hpp>
34namespace fs = boost::filesystem;
35#endif
36
[dfed1c]37#include <cstdarg>
38#include <cstdio>
39#include <sstream>
[48b662]40
41#include "base/discretization.hpp"
[dfed1c]42#include "base/helper.hpp"
43#include "base/index.hpp"
[48b662]44#include "base/stencil.hpp"
45#include "base/vector.hpp"
46#include "comm/comm_serial.hpp"
47#include "grid/multigrid.hpp"
48#include "grid/tempgrid.hpp"
49#include "mg.hpp"
50
51using namespace VMG;
52
[dfed1c]53static char print_buffer[512];
[48b662]54
[dfed1c]55void CommSerial::InitCommSerial()
[48b662]56{
57 error_norm_count = 0;
58 residual_count = 0;
[dfed1c]59}
[48b662]60
[ac6d04]61void CommSerial::CommSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
[dfed1c]62{
63 Grid::iterator iter;
[48b662]64
[dfed1c]65 if (&grid_old == &grid_new)
66 return;
67
68 for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
69 grid_new(*iter) = grid_old.GetVal(*iter);
[48b662]70}
71
[ac6d04]72void CommSerial::CommAddSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
[48b662]73{
[dfed1c]74 Grid::iterator iter;
[48b662]75
[dfed1c]76 if (&grid_old == &grid_new)
77 return;
78
79 for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
80 grid_new(*iter) += grid_old.GetVal(*iter);
[48b662]81}
82
83Grid& CommSerial::GetFinerGrid(Multigrid& multigrid)
84{
85 return multigrid(multigrid.Level()+1);
86}
87
88Grid& CommSerial::GetCoarserGrid(Multigrid& multigrid)
89{
90 return multigrid(multigrid.Level()-1);
91}
92
[ac6d04]93void CommSerial::CommFromGhosts(Grid& grid)
[48b662]94{
[dfed1c]95 Grid::iterator iter;
[48b662]96
[ac6d04]97 const GridIteratorSuite& iterators = grid.Iterators();
98 const Index& size = grid.Local().Size();
[48b662]99
[dfed1c]100 if (BoundaryConditions().X() == Periodic) {
[48b662]101
[dfed1c]102 for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
[ac6d04]103 grid((*iter).X()+size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
[48b662]104
[dfed1c]105 for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
[ac6d04]106 grid((*iter).X()-size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
[dfed1c]107 }
[48b662]108
[dfed1c]109 if (BoundaryConditions().Y() == Periodic) {
[48b662]110
[dfed1c]111 for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
[ac6d04]112 grid((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z()) += grid.GetVal(*iter);
[48b662]113
[dfed1c]114 for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
[ac6d04]115 grid((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z()) += grid.GetVal(*iter);
[48b662]116
[dfed1c]117 }
[48b662]118
[dfed1c]119 if (BoundaryConditions().Z() == Periodic) {
[48b662]120
[dfed1c]121 for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
[ac6d04]122 grid((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z()) += grid.GetVal(*iter);
[48b662]123
[dfed1c]124 for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
[ac6d04]125 grid((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z()) += grid.GetVal(*iter);
[48b662]126
[dfed1c]127 }
128}
[48b662]129
[ac6d04]130void CommSerial::CommToGhosts(Grid& grid)
[dfed1c]131{
132 Grid::iterator iter;
[48b662]133
[ac6d04]134 const GridIteratorSuite& iterators = grid.Iterators();
135 const Index& size = grid.Local().Size();
[48b662]136
[dfed1c]137 if (BoundaryConditions().Z() == Periodic) {
[48b662]138
[dfed1c]139 for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
[ac6d04]140 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z());
[48b662]141
[dfed1c]142 for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
[ac6d04]143 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z());
[48b662]144
145 }
146
[dfed1c]147 if (BoundaryConditions().Y() == Periodic) {
148
149 for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
[ac6d04]150 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z());
[dfed1c]151
152 for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
[ac6d04]153 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z());
[dfed1c]154
155 }
156
157 if (BoundaryConditions().X() == Periodic) {
158
159 for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
[ac6d04]160 grid(*iter) = grid.GetVal((*iter).X()+size.X(), (*iter).Y(), (*iter).Z());
[dfed1c]161
162 for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
[ac6d04]163 grid(*iter) = grid.GetVal((*iter).X()-size.X(), (*iter).Y(), (*iter).Z());
[dfed1c]164
165 }
[48b662]166}
167
[894a5f]168void CommSerial::CommToGhostsAsyncStart(Grid& grid)
169{
170 CommToGhosts(grid);
171}
172
[ac6d04]173void CommSerial::CommToGhostsAsyncFinish(Grid& grid)
[894a5f]174{
175}
176
177void CommSerial::CommFromGhostsAsyncStart(Grid& grid)
178{
179 CommFromGhosts(grid);
180}
181
[322469]182void CommSerial::CommFromGhostsAsyncFinish(Grid& grid)
[894a5f]183{
184}
185
[d13e27]186void CommSerial::Print(const OutputLevel level, const char* format, ...)
[dfed1c]187{
[d13e27]188 bool print = (level == Output);
189
190#ifdef OUTPUT_INFO
191 print |= (level == Info);
192#endif
193#ifdef OUTPUT_DEBUG
194 print |= (level == Debug);
195#endif
196#ifdef OUTPUT_TIMING
197 print |= (level == Timing);
198#endif
199
200 if (print) {
201 va_list args;
202 va_start(args, format);
203 vsprintf(print_buffer, format, args);
204 printf("VMG: %s\n", print_buffer);
205 va_end(args);
206 }
[dfed1c]207}
[48b662]208
[d13e27]209void CommSerial::PrintOnce(const OutputLevel level, const char* format, ...)
[dfed1c]210{
[d13e27]211 bool print = (level == Output);
212
213#ifdef OUTPUT_INFO
214 print |= (level == Info);
215#endif
216#ifdef OUTPUT_DEBUG
217 print |= (level == Debug);
218#endif
219#ifdef OUTPUT_TIMING
220 print |= (level == Timing);
221#endif
222
223 if (print) {
224 va_list args;
225 va_start(args, format);
226 vsprintf(print_buffer, format, args);
227 printf("VMG: %s\n", print_buffer);
228 va_end(args);
229 }
[dfed1c]230}
231
232void CommSerial::PrintXML(const std::string& filename, const std::string& xml_data)
233{
234 pugi::xml_document doc;
235 doc.load(xml_data.c_str());
236
237 pugi::xml_node node_global = doc.prepend_child("Global");
238 pugi::xml_node node_num_processes = node_global.append_child("NumProcesses");
239 pugi::xml_node node_num_processes_data = node_num_processes.append_child(pugi::node_pcdata);
240 node_num_processes_data.set_value(Helper::ToString(GlobalProcs().Product()).c_str());
[48b662]241
[dfed1c]242 doc.save_file(filename.c_str());
243}
244
245void CommSerial::PrintXMLAll(const std::string& filename, const std::string& xml_data)
246{
247 PrintXML(filename, xml_data);
248}
249
[ac6d04]250void CommSerial::PrintGrid(Grid& grid, const char* information)
[48b662]251{
[ac6d04]252 Index i;
[dfed1c]253 std::stringstream out;
254 std::ofstream out_file;
255
[ac6d04]256 OpenFileAndPrintHeader(out_file, grid, information);
[48b662]257
[ac6d04]258 for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z())
259 for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
260 for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
[8180d8]261 out << std::scientific << grid.GetVal(i) << std::endl;
[48b662]262
[dfed1c]263 out_file << out.str();
264 out_file.close();
[48b662]265}
266
[ac6d04]267void CommSerial::PrintDefect(Grid& sol, Grid& rhs, const char* information)
[48b662]268{
[ac6d04]269 Grid::iterator iter;
[dfed1c]270 std::ofstream out_file;
271 std::stringstream out;
272
[ac6d04]273 TempGrid *temp = MG::GetTempGrid();
274 temp->SetProperties(sol);
275 temp->ImportFromResidual(sol, rhs);
[48b662]276
[ac6d04]277 OpenFileAndPrintHeader(out_file, *temp, information);
[48b662]278
[ac6d04]279 for (iter=temp->Iterators().Local().Begin(); iter!=temp->Iterators().Local().End(); ++iter)
280 out << std::scientific << temp->GetVal(*iter) << std::endl;
[48b662]281
[dfed1c]282 out_file << out.str();
283 out_file.close();
[48b662]284}
285
[ac6d04]286void CommSerial::OpenFileAndPrintHeader(std::ofstream& out, const Grid& grid, const char* information)
[48b662]287{
[ac6d04]288 char path_str[129];
289 int count = OutputCount();
[48b662]290
[ac6d04]291 sprintf(path_str, "%s%04d.dat", OutputPath().c_str(), count);
[48b662]292
[ac6d04]293 out.open(path_str, std::ios::trunc);
[dfed1c]294
[ac6d04]295 out << "# vtk DataFile Version 2.0" << std::endl
296 << count << ": " << information << std::endl
297 << "ASCII" << std::endl
298 << "DATASET STRUCTURED_POINTS" << std::endl
299 << grid.Local().Size().X() << " "
300 << grid.Local().Size().Y() << " "
301 << grid.Local().Size().Z() << std::endl
302 << "ORIGIN 0 0 0" << std::endl
303 << "SPACING " << grid.Extent().MeshWidth().X() << " "
304 << grid.Extent().MeshWidth() << " "
305 << grid.Extent().MeshWidth() << std::endl
306 << "POINT_DATA " << grid.Local().Size().Product() << std::endl
307 << "SCALARS residual double 1" << std::endl
308 << "LOOKUP_TABLE default" << std::endl;
[dfed1c]309}
310
311void CommSerial::PrintAllSettings()
312{
313 Multigrid* mg = MG::GetFactory().Get("SOL")->Cast<Multigrid>();
314 std::stringstream buf;
315 std::ofstream out;
316
317 buf << OutputPath() << "settings.txt";
318
319 out.open(buf.str().c_str(), std::ios::trunc);
320
321 for (int i=mg->MinLevel(); i<=mg->MaxLevel(); ++i) {
322
[ac6d04]323 out << "###########################################################" << std::endl
[8180d8]324 << "LEVEL: " << i << std::endl
325 << "GLOBAL:" << std::endl
326 << " LOCAL_BEGIN: " << (*mg)(i).Global().LocalBegin() << std::endl
327 << " LOCAL_END: " << (*mg)(i).Global().LocalEnd() << std::endl
328 << " LOCAL_SIZE: " << (*mg)(i).Global().LocalSize() << std::endl
329 << " GLOBAL_BEGIN: " << (*mg)(i).Global().GlobalBegin() << std::endl
330 << " GLOBAL_END: " << (*mg)(i).Global().GlobalEnd() << std::endl
[e58835d]331 << " GLOBAL_SIZE: " << (*mg)(i).Global().GlobalSize() << std::endl
[8180d8]332 << " GLOBAL_BEGIN_FINEST: " << (*mg)(i).Global().GlobalBeginFinest() << std::endl
333 << " GLOBAL_END_FINEST: " << (*mg)(i).Global().GlobalEndFinest() << std::endl
334 << " GLOBAL_SIZE_FINEST: " << (*mg)(i).Global().GlobalSizeFinest() << std::endl
335 << " BOUNDARY_TYPE: " << (*mg)(i).Global().BoundaryType() << std::endl
336 << "LOCAL:" << std::endl
337 << " BEGIN: " << (*mg)(i).Local().Begin() << std::endl
338 << " END: " << (*mg)(i).Local().End() << std::endl
339 << " SIZE: " << (*mg)(i).Local().Size() << std::endl
340 << " SIZE_TOTAL: " << (*mg)(i).Local().SizeTotal() << std::endl
341 << " HALO_BEGIN_1: " << (*mg)(i).Local().HaloBegin1() << std::endl
342 << " HALO_END_1: " << (*mg)(i).Local().HaloEnd1() << std::endl
343 << " HALO_SIZE_1: " << (*mg)(i).Local().HaloSize1() << std::endl
344 << " HALO_BEGIN_2: " << (*mg)(i).Local().HaloBegin2() << std::endl
345 << " HALO_END_2: " << (*mg)(i).Local().HaloEnd2() << std::endl
346 << " HALO_SIZE_2: " << (*mg)(i).Local().HaloSize2() << std::endl
347 << " BOUNDARY_BEGIN_1: " << (*mg)(i).Local().BoundaryBegin1() << std::endl
348 << " BOUNDARY_END_1: " << (*mg)(i).Local().BoundaryEnd1() << std::endl
349 << " BOUNDARY_SIZE_1: " << (*mg)(i).Local().BoundarySize1() << std::endl
350 << " BOUNDARY_BEGIN_2: " << (*mg)(i).Local().BoundaryBegin2() << std::endl
351 << " BOUNDARY_END_2: " << (*mg)(i).Local().BoundaryEnd2() << std::endl
352 << " BOUNDARY_SIZE_2: " << (*mg)(i).Local().BoundarySize2() << std::endl
353 << "EXTENT:" << std::endl
354 << " BEGIN: " << (*mg)(i).Extent().Begin() << std::endl
355 << " END: " << (*mg)(i).Extent().End() << std::endl
356 << " SIZE: " << (*mg)(i).Extent().Size() << std::endl
357 << " MESH_WIDTH: " << (*mg)(i).Extent().MeshWidth() << std::endl
358 << "###########################################################" << std::endl;
[dfed1c]359
360 }
361
362 assert(out.good());
[48b662]363 out.close();
364}
365
366inline int GetIndex(const Grid& grid, int i, int j, int k)
367{
368 if (grid.Global().BoundaryType() == LocallyRefined)
369 return k + grid.Local().Size().Z() * (j + grid.Local().Size().Y() * i);
370 else
371 return k + grid.Local().SizeTotal().Z() * (j + grid.Local().SizeTotal().Y() * i);
372}
373
374void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
375{
[ac6d04]376 const Vector& sp = grid.Extent().MeshWidth();
[48b662]377 int numLines;
378
379 if (grid.Global().BoundaryType() == LocallyRefined)
380 numLines = grid.Local().Size().X() * grid.Local().Size().Y() +
[8180d8]381 grid.Local().Size().Y() * grid.Local().Size().Z() +
382 grid.Local().Size().X() * grid.Local().Size().Z();
[48b662]383 else
384 numLines = grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Y() +
[8180d8]385 grid.Local().SizeTotal().Y() * grid.Local().SizeTotal().Z() +
386 grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Z();
[48b662]387
388 out << " <Piece";
389
390 if (grid.Global().BoundaryType() == LocallyRefined) {
391 out << " NumberOfPoints=\"" << grid.Local().Size().Product() << "\""
[8180d8]392 << " NumberOfVerts=\"" << grid.Local().Size().Product() << "\"";
[48b662]393 }else {
394 out << " NumberOfPoints=\"" << grid.Local().SizeTotal().Product() << "\""
[8180d8]395 << " NumberOfVerts=\"" << grid.Local().SizeTotal().Product() << "\"";
[48b662]396 }
397
398 out << " NumberOfLines=\"" << numLines << "\""
399 << " NumberOfStrips=\"0\""
400 << " NumberOfPolys=\"0\"" << ">" << std::endl
401 << " <Points>" << std::endl
402 << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl
403 << " ";
404
405 if (grid.Global().BoundaryType() == LocallyRefined) {
406 for (int i=0; i<grid.Local().Size().X(); i++)
407 for (int j=0; j<grid.Local().Size().Y(); j++)
[8180d8]408 for (int k=0; k<grid.Local().Size().Z(); k++)
409 out << grid.Extent().Begin().X() + i * sp.X() << " "
410 << grid.Extent().Begin().Y() + j * sp.Y() << " "
411 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
[48b662]412 }else {
413 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
414 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
[8180d8]415 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
416 out << grid.Extent().Begin().X() + i * sp.X() << " "
417 << grid.Extent().Begin().Y() + j * sp.Y() << " "
418 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
[48b662]419 }
420
421 out << std::endl
422 << " </DataArray>" << std::endl
423 << " </Points>" << std::endl
424 << " <Verts>" << std::endl
425 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
426 << " ";
427
428 if (grid.Global().BoundaryType() == LocallyRefined) {
429 for (int i=0; i<grid.Local().Size().Product(); i++)
430 out << i << " ";
431 }else {
432 for (int i=0; i<grid.Local().SizeTotal().Product(); i++)
433 out << i << " ";
434 }
435
436 out << std::endl
437 << " </DataArray>" << std::endl
438 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
439 << " ";
440
441 if (grid.Global().BoundaryType() == LocallyRefined) {
442 for (int i=1; i<=grid.Local().Size().Product(); i++)
443 out << i << " ";
444 }else {
445 for (int i=1; i<=grid.Local().SizeTotal().Product(); i++)
446 out << i << " ";
447 }
448
449 out << std::endl
450 << " </DataArray>" << std::endl
451 << " </Verts>" << std::endl
452 << " <Lines>" << std::endl
453 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
454 << " ";
455
456 if (grid.Global().BoundaryType() == LocallyRefined) {
457 for (int i=0; i<grid.Local().Size().X(); i++)
458 for (int j=0; j<grid.Local().Size().Y(); j++)
[8180d8]459 out << GetIndex(grid,i,j,0) << " "
460 << GetIndex(grid,i,j,grid.Local().Size().Z()-1) << " ";
[48b662]461
462 for (int j=0; j<grid.Local().Size().Y(); j++)
463 for (int k=0; k<grid.Local().Size().Z(); k++)
[8180d8]464 out << GetIndex(grid,0,j,k) << " "
465 << GetIndex(grid,grid.Local().Size().X()-1,j,k) << " ";
[48b662]466
467 for (int i=0; i<grid.Local().Size().X(); i++)
468 for (int k=0; k<grid.Local().Size().Z(); k++)
[8180d8]469 out << GetIndex(grid,i,0,k) << " "
470 << GetIndex(grid,i,grid.Local().Size().Y()-1,k) << " ";
[48b662]471 }else {
472 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
473 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
[8180d8]474 out << GetIndex(grid,i,j,0) << " "
475 << GetIndex(grid,i,j,grid.Local().SizeTotal().Z()-1) << " ";
[48b662]476
477 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
478 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
[8180d8]479 out << GetIndex(grid,0,j,k) << " "
480 << GetIndex(grid,grid.Local().SizeTotal().X()-1,j,k) << " ";
[48b662]481
482 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
483 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
[8180d8]484 out << GetIndex(grid,i,0,k) << " "
485 << GetIndex(grid,i,grid.Local().SizeTotal().Y()-1,k) << " ";
[48b662]486 }
487
488 out << std::endl
489 << " </DataArray>" << std::endl
490 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
491 << " ";
492
493 for (int i=1; i<=numLines; i++)
494 out << 2*i << " ";
495
496 out << std::endl
497 << " </DataArray>" << std::endl
498 << " </Lines>" << std::endl
499 << " </Piece>" << std::endl;
500}
501
502void CommSerial::DebugPrintGridStructure(Multigrid& grid)
503{
504 std::ofstream out;
505 char path_str[129];
506
[dfed1c]507 sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
[48b662]508
509 out.open(path_str, std::ios::trunc);
510
511 if (!out.good()) {
[d13e27]512 Print(Info, "File %s not accessible.", path_str);
[48b662]513 return;
514 }
515
516 out << "<?xml version=\"1.0\"?>" << std::endl
517 << "<VTKFile type=\"PolyData\">" << std::endl
518 << " <PolyData>" << std::endl;
519
520 for (int i=grid.MinLevel(); i<=grid.MaxLevel(); i++)
521 PrintGridStructureLevel(grid(i), out);
522
523 out << " </PolyData>" << std::endl
524 << "</VTKFile>" << std::endl;
525
526 out.close();
527}
[dfed1c]528
529std::string CommSerial::CreateOutputDirectory()
530{
531#ifdef HAVE_BOOST_FILESYSTEM
532 std::string path, unique_path;
533 std::stringstream unique_suffix;
534 int suffix_counter = 0;
535 char buffer[129];
536 time_t rawtime;
537 struct tm *timeinfo;
538
539 time(&rawtime);
540 timeinfo = localtime(&rawtime);
541 strftime(buffer, 128, "./output/%Y_%m_%d_%H_%M_%S/", timeinfo);
542 path = buffer;
543
544 if (!fs::exists("output"))
545 fs::create_directory("output");
546
547 unique_path = path;
548
549 while (fs::exists(unique_path.c_str())) {
550
551 unique_suffix.str("");
552 unique_suffix << "_" << suffix_counter++ << "/";
553
554 unique_path = path;
555 unique_path.replace(unique_path.size()-1, 1, unique_suffix.str());
556
557 }
558
559 fs::create_directory(unique_path.c_str());
560
561 return unique_path;
562
563#else
564
565 return "./";
566
567#endif
568}
Note: See TracBrowser for help on using the repository browser.