source: src/comm/comm_serial.cpp@ 5ba22b

Last change on this file since 5ba22b was a72216, checked in by Olaf Lenz <olenz@…>, 13 years ago

Fixed permissions.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@2428 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 18.2 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 }
[48b662]128
[dfed1c]129#ifdef DEBUG_MATRIX_CHECKS
[ac6d04]130 grid.IsConsistent();
[dfed1c]131#endif
132}
[48b662]133
[ac6d04]134void CommSerial::CommToGhosts(Grid& grid)
[dfed1c]135{
136 Grid::iterator iter;
[48b662]137
[ac6d04]138 const GridIteratorSuite& iterators = grid.Iterators();
139 const Index& size = grid.Local().Size();
[48b662]140
[dfed1c]141 if (BoundaryConditions().Z() == Periodic) {
[48b662]142
[dfed1c]143 for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
[ac6d04]144 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z());
[48b662]145
[dfed1c]146 for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
[ac6d04]147 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z());
[48b662]148
149 }
150
[dfed1c]151 if (BoundaryConditions().Y() == Periodic) {
152
153 for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
[ac6d04]154 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z());
[dfed1c]155
156 for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
[ac6d04]157 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z());
[dfed1c]158
159 }
160
161 if (BoundaryConditions().X() == Periodic) {
162
163 for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
[ac6d04]164 grid(*iter) = grid.GetVal((*iter).X()+size.X(), (*iter).Y(), (*iter).Z());
[dfed1c]165
166 for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
[ac6d04]167 grid(*iter) = grid.GetVal((*iter).X()-size.X(), (*iter).Y(), (*iter).Z());
[dfed1c]168
169 }
170
171#ifdef DEBUG_MATRIX_CHECKS
[ac6d04]172 grid.IsConsistent();
[48b662]173#endif
174}
175
[894a5f]176void CommSerial::CommToGhostsAsyncStart(Grid& grid)
177{
178 CommToGhosts(grid);
179}
180
[ac6d04]181void CommSerial::CommToGhostsAsyncFinish(Grid& grid)
[894a5f]182{
183}
184
185void CommSerial::CommFromGhostsAsyncStart(Grid& grid)
186{
187 CommFromGhosts(grid);
188}
189
[322469]190void CommSerial::CommFromGhostsAsyncFinish(Grid& grid)
[894a5f]191{
192}
193
[dfed1c]194void CommSerial::PrintString(const char* format, ...)
195{
196 va_list args;
197 va_start(args, format);
198 vsprintf(print_buffer, format, args);
199 printf("VMG: %s\n", print_buffer);
200 va_end(args);
201}
[48b662]202
[dfed1c]203void CommSerial::PrintStringOnce(const char* format, ...)
204{
205 va_list args;
206 va_start(args, format);
207 vsprintf(print_buffer, format, args);
208 printf("VMG: %s\n", print_buffer);
209 va_end(args);
210}
211
212void CommSerial::PrintXML(const std::string& filename, const std::string& xml_data)
213{
214 pugi::xml_document doc;
215 doc.load(xml_data.c_str());
216
217 pugi::xml_node node_global = doc.prepend_child("Global");
218 pugi::xml_node node_num_processes = node_global.append_child("NumProcesses");
219 pugi::xml_node node_num_processes_data = node_num_processes.append_child(pugi::node_pcdata);
220 node_num_processes_data.set_value(Helper::ToString(GlobalProcs().Product()).c_str());
[48b662]221
[dfed1c]222 doc.save_file(filename.c_str());
223}
224
225void CommSerial::PrintXMLAll(const std::string& filename, const std::string& xml_data)
226{
227 PrintXML(filename, xml_data);
228}
229
[ac6d04]230void CommSerial::PrintGrid(Grid& grid, const char* information)
[48b662]231{
[ac6d04]232 Index i;
[dfed1c]233 std::stringstream out;
234 std::ofstream out_file;
235
[ac6d04]236 OpenFileAndPrintHeader(out_file, grid, information);
[48b662]237
[ac6d04]238 for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z())
239 for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
240 for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
241 out << std::scientific << grid.GetVal(i) << std::endl;
[48b662]242
[dfed1c]243 out_file << out.str();
244 out_file.close();
[48b662]245}
246
[ac6d04]247void CommSerial::PrintDefect(Grid& sol, Grid& rhs, const char* information)
[48b662]248{
[ac6d04]249 Grid::iterator iter;
[dfed1c]250 std::ofstream out_file;
251 std::stringstream out;
252
[ac6d04]253 TempGrid *temp = MG::GetTempGrid();
254 temp->SetProperties(sol);
255 temp->ImportFromResidual(sol, rhs);
[48b662]256
[ac6d04]257 OpenFileAndPrintHeader(out_file, *temp, information);
[48b662]258
[ac6d04]259 for (iter=temp->Iterators().Local().Begin(); iter!=temp->Iterators().Local().End(); ++iter)
260 out << std::scientific << temp->GetVal(*iter) << std::endl;
[48b662]261
[dfed1c]262 out_file << out.str();
263 out_file.close();
[48b662]264}
265
[ac6d04]266void CommSerial::OpenFileAndPrintHeader(std::ofstream& out, const Grid& grid, const char* information)
[48b662]267{
[ac6d04]268 char path_str[129];
269 int count = OutputCount();
[48b662]270
[ac6d04]271 sprintf(path_str, "%s%04d.dat", OutputPath().c_str(), count);
[48b662]272
[ac6d04]273 out.open(path_str, std::ios::trunc);
[dfed1c]274
[ac6d04]275 out << "# vtk DataFile Version 2.0" << std::endl
276 << count << ": " << information << std::endl
277 << "ASCII" << std::endl
278 << "DATASET STRUCTURED_POINTS" << std::endl
279 << grid.Local().Size().X() << " "
280 << grid.Local().Size().Y() << " "
281 << grid.Local().Size().Z() << std::endl
282 << "ORIGIN 0 0 0" << std::endl
283 << "SPACING " << grid.Extent().MeshWidth().X() << " "
284 << grid.Extent().MeshWidth() << " "
285 << grid.Extent().MeshWidth() << std::endl
286 << "POINT_DATA " << grid.Local().Size().Product() << std::endl
287 << "SCALARS residual double 1" << std::endl
288 << "LOOKUP_TABLE default" << std::endl;
[dfed1c]289}
290
291void CommSerial::PrintAllSettings()
292{
293 Multigrid* mg = MG::GetFactory().Get("SOL")->Cast<Multigrid>();
294 std::stringstream buf;
295 std::ofstream out;
296
297 buf << OutputPath() << "settings.txt";
298
299 out.open(buf.str().c_str(), std::ios::trunc);
300
301 for (int i=mg->MinLevel(); i<=mg->MaxLevel(); ++i) {
302
[ac6d04]303 out << "###########################################################" << std::endl
304 << "LEVEL: " << i << std::endl
305 << "GLOBAL:" << std::endl
306 << " LOCAL_BEGIN: " << (*mg)(i).Global().LocalBegin() << std::endl
307 << " LOCAL_END: " << (*mg)(i).Global().LocalEnd() << std::endl
308 << " LOCAL_SIZE: " << (*mg)(i).Global().LocalSize() << std::endl
309 << " GLOBAL_FINER_BEGIN: " << (*mg)(i).Global().GlobalFinerBegin() << std::endl
310 << " GLOBAL_FINER_END: " << (*mg)(i).Global().GlobalFinerEnd() << std::endl
311 << " GLOBAL_FINER_SIZE: " << (*mg)(i).Global().GlobalFinerSize() << std::endl
312 << " LOCAL_FINER_BEGIN: " << (*mg)(i).Global().LocalFinerBegin() << std::endl
313 << " LOCAL_FINER_END: " << (*mg)(i).Global().LocalFinerEnd() << std::endl
314 << " LOCAL_FINER_SIZE: " << (*mg)(i).Global().LocalFinerSize() << std::endl
315 << " FINEST_ABS_BEGIN: " << (*mg)(i).Global().FinestAbsBegin() << std::endl
316 << " FINEST_ABS_END: " << (*mg)(i).Global().FinestAbsEnd() << std::endl
317 << " FINEST_ABS_SIZE: " << (*mg)(i).Global().FinestAbsSize() << std::endl
318 << " GLOBAL_SIZE: " << (*mg)(i).Global().GlobalSize() << std::endl
319 << " BOUNDARY_TYPE: " << (*mg)(i).Global().BoundaryType() << std::endl
320 << "LOCAL:" << std::endl
321 << " BEGIN: " << (*mg)(i).Local().Begin() << std::endl
322 << " END: " << (*mg)(i).Local().End() << std::endl
323 << " SIZE: " << (*mg)(i).Local().Size() << std::endl
324 << " SIZE_TOTAL: " << (*mg)(i).Local().SizeTotal() << std::endl
325 << " HALO_BEGIN_1: " << (*mg)(i).Local().HaloBegin1() << std::endl
326 << " HALO_END_1: " << (*mg)(i).Local().HaloEnd1() << std::endl
327 << " HALO_SIZE_1: " << (*mg)(i).Local().HaloSize1() << std::endl
328 << " HALO_BEGIN_2: " << (*mg)(i).Local().HaloBegin2() << std::endl
329 << " HALO_END_2: " << (*mg)(i).Local().HaloEnd2() << std::endl
330 << " HALO_SIZE_2: " << (*mg)(i).Local().HaloSize2() << std::endl
331 << " BOUNDARY_BEGIN_1: " << (*mg)(i).Local().BoundaryBegin1() << std::endl
332 << " BOUNDARY_END_1: " << (*mg)(i).Local().BoundaryEnd1() << std::endl
333 << " BOUNDARY_SIZE_1: " << (*mg)(i).Local().BoundarySize1() << std::endl
334 << " BOUNDARY_BEGIN_2: " << (*mg)(i).Local().BoundaryBegin2() << std::endl
335 << " BOUNDARY_END_2: " << (*mg)(i).Local().BoundaryEnd2() << std::endl
336 << " BOUNDARY_SIZE_2: " << (*mg)(i).Local().BoundarySize2() << std::endl
[716da7]337 << " FINER_BEGIN: " << (*mg)(i).Local().FinerBegin() << std::endl
338 << " FINER_END: " << (*mg)(i).Local().FinerEnd() << std::endl
339 << " FINER_SIZE: " << (*mg)(i).Local().FinerSize() << std::endl
[ac6d04]340 << "EXTENT:" << std::endl
341 << " BEGIN: " << (*mg)(i).Extent().Begin() << std::endl
342 << " END: " << (*mg)(i).Extent().End() << std::endl
343 << " SIZE: " << (*mg)(i).Extent().Size() << std::endl
344 << " MESH_WIDTH: " << (*mg)(i).Extent().MeshWidth() << std::endl
345 << "###########################################################" << std::endl;
[dfed1c]346
347 }
348
349 assert(out.good());
[48b662]350 out.close();
351}
352
353inline int GetIndex(const Grid& grid, int i, int j, int k)
354{
355 if (grid.Global().BoundaryType() == LocallyRefined)
356 return k + grid.Local().Size().Z() * (j + grid.Local().Size().Y() * i);
357 else
358 return k + grid.Local().SizeTotal().Z() * (j + grid.Local().SizeTotal().Y() * i);
359}
360
361void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
362{
[ac6d04]363 const Vector& sp = grid.Extent().MeshWidth();
[48b662]364 int numLines;
365
366 if (grid.Global().BoundaryType() == LocallyRefined)
367 numLines = grid.Local().Size().X() * grid.Local().Size().Y() +
368 grid.Local().Size().Y() * grid.Local().Size().Z() +
369 grid.Local().Size().X() * grid.Local().Size().Z();
370 else
371 numLines = grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Y() +
372 grid.Local().SizeTotal().Y() * grid.Local().SizeTotal().Z() +
373 grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Z();
374
375 out << " <Piece";
376
377 if (grid.Global().BoundaryType() == LocallyRefined) {
378 out << " NumberOfPoints=\"" << grid.Local().Size().Product() << "\""
379 << " NumberOfVerts=\"" << grid.Local().Size().Product() << "\"";
380 }else {
381 out << " NumberOfPoints=\"" << grid.Local().SizeTotal().Product() << "\""
382 << " NumberOfVerts=\"" << grid.Local().SizeTotal().Product() << "\"";
383 }
384
385 out << " NumberOfLines=\"" << numLines << "\""
386 << " NumberOfStrips=\"0\""
387 << " NumberOfPolys=\"0\"" << ">" << std::endl
388 << " <Points>" << std::endl
389 << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl
390 << " ";
391
392 if (grid.Global().BoundaryType() == LocallyRefined) {
393 for (int i=0; i<grid.Local().Size().X(); i++)
394 for (int j=0; j<grid.Local().Size().Y(); j++)
395 for (int k=0; k<grid.Local().Size().Z(); k++)
[ac6d04]396 out << grid.Extent().Begin().X() + i * sp.X() << " "
397 << grid.Extent().Begin().Y() + j * sp.Y() << " "
398 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
[48b662]399 }else {
400 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
401 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
402 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
[ac6d04]403 out << grid.Extent().Begin().X() + i * sp.X() << " "
404 << grid.Extent().Begin().Y() + j * sp.Y() << " "
405 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
[48b662]406 }
407
408 out << std::endl
409 << " </DataArray>" << std::endl
410 << " </Points>" << std::endl
411 << " <Verts>" << std::endl
412 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
413 << " ";
414
415 if (grid.Global().BoundaryType() == LocallyRefined) {
416 for (int i=0; i<grid.Local().Size().Product(); i++)
417 out << i << " ";
418 }else {
419 for (int i=0; i<grid.Local().SizeTotal().Product(); i++)
420 out << i << " ";
421 }
422
423 out << std::endl
424 << " </DataArray>" << std::endl
425 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
426 << " ";
427
428 if (grid.Global().BoundaryType() == LocallyRefined) {
429 for (int i=1; i<=grid.Local().Size().Product(); i++)
430 out << i << " ";
431 }else {
432 for (int i=1; i<=grid.Local().SizeTotal().Product(); i++)
433 out << i << " ";
434 }
435
436 out << std::endl
437 << " </DataArray>" << std::endl
438 << " </Verts>" << std::endl
439 << " <Lines>" << std::endl
440 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
441 << " ";
442
443 if (grid.Global().BoundaryType() == LocallyRefined) {
444 for (int i=0; i<grid.Local().Size().X(); i++)
445 for (int j=0; j<grid.Local().Size().Y(); j++)
446 out << GetIndex(grid,i,j,0) << " "
447 << GetIndex(grid,i,j,grid.Local().Size().Z()-1) << " ";
448
449 for (int j=0; j<grid.Local().Size().Y(); j++)
450 for (int k=0; k<grid.Local().Size().Z(); k++)
451 out << GetIndex(grid,0,j,k) << " "
452 << GetIndex(grid,grid.Local().Size().X()-1,j,k) << " ";
453
454 for (int i=0; i<grid.Local().Size().X(); i++)
455 for (int k=0; k<grid.Local().Size().Z(); k++)
456 out << GetIndex(grid,i,0,k) << " "
457 << GetIndex(grid,i,grid.Local().Size().Y()-1,k) << " ";
458 }else {
459 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
460 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
461 out << GetIndex(grid,i,j,0) << " "
462 << GetIndex(grid,i,j,grid.Local().SizeTotal().Z()-1) << " ";
463
464 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
465 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
466 out << GetIndex(grid,0,j,k) << " "
467 << GetIndex(grid,grid.Local().SizeTotal().X()-1,j,k) << " ";
468
469 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
470 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
471 out << GetIndex(grid,i,0,k) << " "
472 << GetIndex(grid,i,grid.Local().SizeTotal().Y()-1,k) << " ";
473 }
474
475 out << std::endl
476 << " </DataArray>" << std::endl
477 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
478 << " ";
479
480 for (int i=1; i<=numLines; i++)
481 out << 2*i << " ";
482
483 out << std::endl
484 << " </DataArray>" << std::endl
485 << " </Lines>" << std::endl
486 << " </Piece>" << std::endl;
487}
488
489void CommSerial::DebugPrintGridStructure(Multigrid& grid)
490{
491 std::ofstream out;
492 char path_str[129];
493
[dfed1c]494 sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
[48b662]495
496 out.open(path_str, std::ios::trunc);
497
498 if (!out.good()) {
[dfed1c]499#ifdef DEBUG_OUTPUT
[48b662]500 printf("Multigrid: File %s not accessible.\n", path_str);
[dfed1c]501#endif /* DEBUG_OUTPUT */
[48b662]502 return;
503 }
504
505 out << "<?xml version=\"1.0\"?>" << std::endl
506 << "<VTKFile type=\"PolyData\">" << std::endl
507 << " <PolyData>" << std::endl;
508
509 for (int i=grid.MinLevel(); i<=grid.MaxLevel(); i++)
510 PrintGridStructureLevel(grid(i), out);
511
512 out << " </PolyData>" << std::endl
513 << "</VTKFile>" << std::endl;
514
515 out.close();
516}
[dfed1c]517
518std::string CommSerial::CreateOutputDirectory()
519{
520#ifdef HAVE_BOOST_FILESYSTEM
521 std::string path, unique_path;
522 std::stringstream unique_suffix;
523 int suffix_counter = 0;
524 char buffer[129];
525 time_t rawtime;
526 struct tm *timeinfo;
527
528 time(&rawtime);
529 timeinfo = localtime(&rawtime);
530 strftime(buffer, 128, "./output/%Y_%m_%d_%H_%M_%S/", timeinfo);
531 path = buffer;
532
533 if (!fs::exists("output"))
534 fs::create_directory("output");
535
536 unique_path = path;
537
538 while (fs::exists(unique_path.c_str())) {
539
540 unique_suffix.str("");
541 unique_suffix << "_" << suffix_counter++ << "/";
542
543 unique_path = path;
544 unique_path.replace(unique_path.size()-1, 1, unique_suffix.str());
545
546 }
547
548 fs::create_directory(unique_path.c_str());
549
550 return unique_path;
551
552#else
553
554 return "./";
555
556#endif
557}
Note: See TracBrowser for help on using the repository browser.