source: src/comm/comm_serial.cpp@ d13e27

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

vmg: Work on output verbosity.

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

  • Property mode set to 100644
File size: 18.5 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())
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
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_FINER_BEGIN: " << (*mg)(i).Global().GlobalFinerBegin() << std::endl
330 << " GLOBAL_FINER_END: " << (*mg)(i).Global().GlobalFinerEnd() << std::endl
331 << " GLOBAL_FINER_SIZE: " << (*mg)(i).Global().GlobalFinerSize() << std::endl
332 << " LOCAL_FINER_BEGIN: " << (*mg)(i).Global().LocalFinerBegin() << std::endl
333 << " LOCAL_FINER_END: " << (*mg)(i).Global().LocalFinerEnd() << std::endl
334 << " LOCAL_FINER_SIZE: " << (*mg)(i).Global().LocalFinerSize() << std::endl
335 << " FINEST_ABS_BEGIN: " << (*mg)(i).Global().FinestAbsBegin() << std::endl
336 << " FINEST_ABS_END: " << (*mg)(i).Global().FinestAbsEnd() << std::endl
337 << " FINEST_ABS_SIZE: " << (*mg)(i).Global().FinestAbsSize() << std::endl
338 << " GLOBAL_SIZE: " << (*mg)(i).Global().GlobalSize() << std::endl
339 << " BOUNDARY_TYPE: " << (*mg)(i).Global().BoundaryType() << std::endl
340 << "LOCAL:" << std::endl
341 << " BEGIN: " << (*mg)(i).Local().Begin() << std::endl
342 << " END: " << (*mg)(i).Local().End() << std::endl
343 << " SIZE: " << (*mg)(i).Local().Size() << std::endl
344 << " SIZE_TOTAL: " << (*mg)(i).Local().SizeTotal() << std::endl
345 << " HALO_BEGIN_1: " << (*mg)(i).Local().HaloBegin1() << std::endl
346 << " HALO_END_1: " << (*mg)(i).Local().HaloEnd1() << std::endl
347 << " HALO_SIZE_1: " << (*mg)(i).Local().HaloSize1() << std::endl
348 << " HALO_BEGIN_2: " << (*mg)(i).Local().HaloBegin2() << std::endl
349 << " HALO_END_2: " << (*mg)(i).Local().HaloEnd2() << std::endl
350 << " HALO_SIZE_2: " << (*mg)(i).Local().HaloSize2() << std::endl
351 << " BOUNDARY_BEGIN_1: " << (*mg)(i).Local().BoundaryBegin1() << std::endl
352 << " BOUNDARY_END_1: " << (*mg)(i).Local().BoundaryEnd1() << std::endl
353 << " BOUNDARY_SIZE_1: " << (*mg)(i).Local().BoundarySize1() << std::endl
354 << " BOUNDARY_BEGIN_2: " << (*mg)(i).Local().BoundaryBegin2() << std::endl
355 << " BOUNDARY_END_2: " << (*mg)(i).Local().BoundaryEnd2() << std::endl
356 << " BOUNDARY_SIZE_2: " << (*mg)(i).Local().BoundarySize2() << std::endl
[716da7]357 << " FINER_BEGIN: " << (*mg)(i).Local().FinerBegin() << std::endl
358 << " FINER_END: " << (*mg)(i).Local().FinerEnd() << std::endl
359 << " FINER_SIZE: " << (*mg)(i).Local().FinerSize() << std::endl
[ac6d04]360 << "EXTENT:" << std::endl
361 << " BEGIN: " << (*mg)(i).Extent().Begin() << std::endl
362 << " END: " << (*mg)(i).Extent().End() << std::endl
363 << " SIZE: " << (*mg)(i).Extent().Size() << std::endl
364 << " MESH_WIDTH: " << (*mg)(i).Extent().MeshWidth() << std::endl
365 << "###########################################################" << std::endl;
[dfed1c]366
367 }
368
369 assert(out.good());
[48b662]370 out.close();
371}
372
373inline int GetIndex(const Grid& grid, int i, int j, int k)
374{
375 if (grid.Global().BoundaryType() == LocallyRefined)
376 return k + grid.Local().Size().Z() * (j + grid.Local().Size().Y() * i);
377 else
378 return k + grid.Local().SizeTotal().Z() * (j + grid.Local().SizeTotal().Y() * i);
379}
380
381void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
382{
[ac6d04]383 const Vector& sp = grid.Extent().MeshWidth();
[48b662]384 int numLines;
385
386 if (grid.Global().BoundaryType() == LocallyRefined)
387 numLines = grid.Local().Size().X() * grid.Local().Size().Y() +
388 grid.Local().Size().Y() * grid.Local().Size().Z() +
389 grid.Local().Size().X() * grid.Local().Size().Z();
390 else
391 numLines = grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Y() +
392 grid.Local().SizeTotal().Y() * grid.Local().SizeTotal().Z() +
393 grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Z();
394
395 out << " <Piece";
396
397 if (grid.Global().BoundaryType() == LocallyRefined) {
398 out << " NumberOfPoints=\"" << grid.Local().Size().Product() << "\""
399 << " NumberOfVerts=\"" << grid.Local().Size().Product() << "\"";
400 }else {
401 out << " NumberOfPoints=\"" << grid.Local().SizeTotal().Product() << "\""
402 << " NumberOfVerts=\"" << grid.Local().SizeTotal().Product() << "\"";
403 }
404
405 out << " NumberOfLines=\"" << numLines << "\""
406 << " NumberOfStrips=\"0\""
407 << " NumberOfPolys=\"0\"" << ">" << std::endl
408 << " <Points>" << std::endl
409 << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl
410 << " ";
411
412 if (grid.Global().BoundaryType() == LocallyRefined) {
413 for (int i=0; i<grid.Local().Size().X(); i++)
414 for (int j=0; j<grid.Local().Size().Y(); j++)
415 for (int k=0; k<grid.Local().Size().Z(); k++)
[ac6d04]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 }else {
420 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
421 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
422 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
[ac6d04]423 out << grid.Extent().Begin().X() + i * sp.X() << " "
424 << grid.Extent().Begin().Y() + j * sp.Y() << " "
425 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
[48b662]426 }
427
428 out << std::endl
429 << " </DataArray>" << std::endl
430 << " </Points>" << std::endl
431 << " <Verts>" << std::endl
432 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
433 << " ";
434
435 if (grid.Global().BoundaryType() == LocallyRefined) {
436 for (int i=0; i<grid.Local().Size().Product(); i++)
437 out << i << " ";
438 }else {
439 for (int i=0; i<grid.Local().SizeTotal().Product(); i++)
440 out << i << " ";
441 }
442
443 out << std::endl
444 << " </DataArray>" << std::endl
445 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
446 << " ";
447
448 if (grid.Global().BoundaryType() == LocallyRefined) {
449 for (int i=1; i<=grid.Local().Size().Product(); i++)
450 out << i << " ";
451 }else {
452 for (int i=1; i<=grid.Local().SizeTotal().Product(); i++)
453 out << i << " ";
454 }
455
456 out << std::endl
457 << " </DataArray>" << std::endl
458 << " </Verts>" << std::endl
459 << " <Lines>" << std::endl
460 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
461 << " ";
462
463 if (grid.Global().BoundaryType() == LocallyRefined) {
464 for (int i=0; i<grid.Local().Size().X(); i++)
465 for (int j=0; j<grid.Local().Size().Y(); j++)
466 out << GetIndex(grid,i,j,0) << " "
467 << GetIndex(grid,i,j,grid.Local().Size().Z()-1) << " ";
468
469 for (int j=0; j<grid.Local().Size().Y(); j++)
470 for (int k=0; k<grid.Local().Size().Z(); k++)
471 out << GetIndex(grid,0,j,k) << " "
472 << GetIndex(grid,grid.Local().Size().X()-1,j,k) << " ";
473
474 for (int i=0; i<grid.Local().Size().X(); i++)
475 for (int k=0; k<grid.Local().Size().Z(); k++)
476 out << GetIndex(grid,i,0,k) << " "
477 << GetIndex(grid,i,grid.Local().Size().Y()-1,k) << " ";
478 }else {
479 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
480 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
481 out << GetIndex(grid,i,j,0) << " "
482 << GetIndex(grid,i,j,grid.Local().SizeTotal().Z()-1) << " ";
483
484 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
485 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
486 out << GetIndex(grid,0,j,k) << " "
487 << GetIndex(grid,grid.Local().SizeTotal().X()-1,j,k) << " ";
488
489 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
490 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
491 out << GetIndex(grid,i,0,k) << " "
492 << GetIndex(grid,i,grid.Local().SizeTotal().Y()-1,k) << " ";
493 }
494
495 out << std::endl
496 << " </DataArray>" << std::endl
497 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
498 << " ";
499
500 for (int i=1; i<=numLines; i++)
501 out << 2*i << " ";
502
503 out << std::endl
504 << " </DataArray>" << std::endl
505 << " </Lines>" << std::endl
506 << " </Piece>" << std::endl;
507}
508
509void CommSerial::DebugPrintGridStructure(Multigrid& grid)
510{
511 std::ofstream out;
512 char path_str[129];
513
[dfed1c]514 sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
[48b662]515
516 out.open(path_str, std::ios::trunc);
517
518 if (!out.good()) {
[d13e27]519 Print(Info, "File %s not accessible.", path_str);
[48b662]520 return;
521 }
522
523 out << "<?xml version=\"1.0\"?>" << std::endl
524 << "<VTKFile type=\"PolyData\">" << std::endl
525 << " <PolyData>" << std::endl;
526
527 for (int i=grid.MinLevel(); i<=grid.MaxLevel(); i++)
528 PrintGridStructureLevel(grid(i), out);
529
530 out << " </PolyData>" << std::endl
531 << "</VTKFile>" << std::endl;
532
533 out.close();
534}
[dfed1c]535
536std::string CommSerial::CreateOutputDirectory()
537{
538#ifdef HAVE_BOOST_FILESYSTEM
539 std::string path, unique_path;
540 std::stringstream unique_suffix;
541 int suffix_counter = 0;
542 char buffer[129];
543 time_t rawtime;
544 struct tm *timeinfo;
545
546 time(&rawtime);
547 timeinfo = localtime(&rawtime);
548 strftime(buffer, 128, "./output/%Y_%m_%d_%H_%M_%S/", timeinfo);
549 path = buffer;
550
551 if (!fs::exists("output"))
552 fs::create_directory("output");
553
554 unique_path = path;
555
556 while (fs::exists(unique_path.c_str())) {
557
558 unique_suffix.str("");
559 unique_suffix << "_" << suffix_counter++ << "/";
560
561 unique_path = path;
562 unique_path.replace(unique_path.size()-1, 1, unique_suffix.str());
563
564 }
565
566 fs::create_directory(unique_path.c_str());
567
568 return unique_path;
569
570#else
571
572 return "./";
573
574#endif
575}
Note: See TracBrowser for help on using the repository browser.