source: src/comm/comm_serial.cpp@ b51c3b

Last change on this file since b51c3b was 716da7, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Fix energy calculation.

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

  • Property mode set to 100644
File size: 20.0 KB
Line 
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>
16namespace 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 "grid/multigrid.hpp"
31#include "grid/tempgrid.hpp"
32#include "mg.hpp"
33
34using namespace VMG;
35
36static char print_buffer[512];
37
38void CommSerial::InitCommSerial()
39{
40 error_norm_count = 0;
41 residual_count = 0;
42}
43
44void CommSerial::CommSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
45{
46 Grid::iterator iter;
47
48 if (&grid_old == &grid_new)
49 return;
50
51 for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
52 grid_new(*iter) = grid_old.GetVal(*iter);
53}
54
55void CommSerial::CommAddSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
56{
57 Grid::iterator iter;
58
59 if (&grid_old == &grid_new)
60 return;
61
62 for (iter = grid_old.Iterators().CompleteGrid().Begin(); iter != grid_old.Iterators().CompleteGrid().End(); ++iter)
63 grid_new(*iter) += grid_old.GetVal(*iter);
64}
65
66Grid& CommSerial::GetFinerGrid(Multigrid& multigrid)
67{
68 return multigrid(multigrid.Level()+1);
69}
70
71Grid& CommSerial::GetCoarserGrid(Multigrid& multigrid)
72{
73 return multigrid(multigrid.Level()-1);
74}
75
76void CommSerial::CommFromGhosts(Grid& grid)
77{
78 Grid::iterator iter;
79
80 const GridIteratorSuite& iterators = grid.Iterators();
81 const Index& size = grid.Local().Size();
82
83 if (BoundaryConditions().X() == Periodic) {
84
85 for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
86 grid((*iter).X()+size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
87
88 for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
89 grid((*iter).X()-size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
90 }
91
92 if (BoundaryConditions().Y() == Periodic) {
93
94 for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
95 grid((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z()) += grid.GetVal(*iter);
96
97 for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
98 grid((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z()) += grid.GetVal(*iter);
99
100 }
101
102 if (BoundaryConditions().Z() == Periodic) {
103
104 for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
105 grid((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z()) += grid.GetVal(*iter);
106
107 for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
108 grid((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z()) += grid.GetVal(*iter);
109
110 }
111
112#ifdef DEBUG_MATRIX_CHECKS
113 grid.IsConsistent();
114#endif
115}
116
117void CommSerial::CommToGhosts(Grid& grid)
118{
119 Grid::iterator iter;
120
121 const GridIteratorSuite& iterators = grid.Iterators();
122 const Index& size = grid.Local().Size();
123
124 if (BoundaryConditions().Z() == Periodic) {
125
126 for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
127 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z());
128
129 for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
130 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z());
131
132 }
133
134 if (BoundaryConditions().Y() == Periodic) {
135
136 for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
137 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z());
138
139 for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
140 grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z());
141
142 }
143
144 if (BoundaryConditions().X() == Periodic) {
145
146 for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
147 grid(*iter) = grid.GetVal((*iter).X()+size.X(), (*iter).Y(), (*iter).Z());
148
149 for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
150 grid(*iter) = grid.GetVal((*iter).X()-size.X(), (*iter).Y(), (*iter).Z());
151
152 }
153
154#ifdef DEBUG_MATRIX_CHECKS
155 grid.IsConsistent();
156#endif
157}
158
159void CommSerial::CommToGhostsAsyncStart(Grid& grid)
160{
161 CommToGhosts(grid);
162}
163
164void CommSerial::CommToGhostsAsyncFinish(Grid& grid)
165{
166}
167
168void CommSerial::CommFromGhostsAsyncStart(Grid& grid)
169{
170 CommFromGhosts(grid);
171}
172
173void CommSerial::CommFromGhostsAsyncFinish(Grid& grid)
174{
175}
176
177void CommSerial::CommParticles(const Grid& grid, std::list<Particle::Particle>& particles)
178{
179 Factory& factory = MG::GetFactory();
180 const vmg_int& num_particles_local = factory.GetObjectStorageVal<vmg_int>("PARTICLE_NUM_LOCAL");
181 vmg_float* x = factory.GetObjectStorageArray<vmg_float>("PARTICLE_POS_ARRAY");
182 vmg_float* q = factory.GetObjectStorageArray<vmg_float>("PARTICLE_CHARGE_ARRAY");
183
184 particles.clear();
185
186 for (vmg_int i=0; i<num_particles_local; ++i)
187 particles.push_back(Particle::Particle(&x[3*i], q[i], 0.0, 0.0, 0, i));
188}
189
190void CommSerial::CommParticlesBack(std::list<Particle::Particle>& particles)
191{
192 std::list<Particle::Particle>::iterator iter;
193 vmg_float* p = MG::GetFactory().GetObjectStorageArray<vmg_float>("PARTICLE_POTENTIAL_ARRAY");
194 for (iter=particles.begin(); iter!=particles.end(); ++iter)
195 p[iter->Index()] = iter->Pot();
196}
197
198void CommSerial::CommLCListToGhosts(Particle::LinkedCellList& lc)
199{
200 // std::list<Particle::Particle*>::iterator p_iter;
201 // Grid::iterator g_iter;
202
203 // for (int i=2; i>=0; --i) {
204
205 // if (BoundaryConditions()[i] == Periodic) {
206
207 // for (g_iter=lc.Iterators().Halo1()[i].Begin(); g_iter!=lc.Iterators().Halo1()[i].End(); ++g_iter)
208 // lc(*g_iter).clear();
209
210 // for (g_iter=lc.Iterators().NearBoundary1()[i].Begin(); g_iter!=lc.Iterators().NearBoundary1()[i].End(); ++g_iter)
211 // for (p_iter=lc(*g_iter).begin(); p_iter!=lc(*g_iter).end(); ++p_iter)
212 // lc.AddParticleToComplete((*p_iter)->Pos() + grid.Extent().Size(), (*p_iter)->Charge(),
213 // (*p_iter)->Pot(), (*p_iter)->Force(),
214 // (*p_iter)->Rank(), (*p_iter)->Index());
215
216 // for (g_iter=lc.Iterators().Halo2()[i].Begin(); g_iter!=lc.Iterators().Halo2()[i].End(); ++g_iter)
217 // lc(*g_iter).clear();
218
219 // for (g_iter=lc.Iterators().NearBoundary2()[i].Begin(); g_iter!=lc.Iterators().NearBoundary2()[i].End(); ++g_iter)
220 // for (p_iter=lc(*g_iter).begin(); p_iter!=lc(*g_iter).end(); ++p_iter)
221 // lc.AddParticleToComplete((*p_iter)->Pos() - grid.Extent().Size(), (*p_iter)->Charge(),
222 // (*p_iter)->Pot(), (*p_iter)->Force(),
223 // (*p_iter)->Rank(), (*p_iter)->Index());
224
225 // }
226 // }
227}
228
229void CommSerial::CommLCListFromGhosts(const Grid& grid, Particle::LinkedCellList& lc)
230{
231
232}
233
234// void CommSerial::CommAddPotential(std::list<Particle::Particle>& particles)
235// {
236// std::list<Particle::Particle>::iterator iter;
237// vmg_float* p = MG::GetFactory().GetObjectStorageArray<vmg_float>("PARTICLE_POTENTIAL_ARRAY");
238
239// for (iter=particles.begin(); iter!=particles.end(); ++iter)
240// p[iter->Index()] += iter->Pot();
241// }
242
243void CommSerial::PrintString(const char* format, ...)
244{
245 va_list args;
246 va_start(args, format);
247 vsprintf(print_buffer, format, args);
248 printf("VMG: %s\n", print_buffer);
249 va_end(args);
250}
251
252void CommSerial::PrintStringOnce(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
261void CommSerial::PrintXML(const std::string& filename, const std::string& xml_data)
262{
263 pugi::xml_document doc;
264 doc.load(xml_data.c_str());
265
266 pugi::xml_node node_global = doc.prepend_child("Global");
267 pugi::xml_node node_num_processes = node_global.append_child("NumProcesses");
268 pugi::xml_node node_num_processes_data = node_num_processes.append_child(pugi::node_pcdata);
269 node_num_processes_data.set_value(Helper::ToString(GlobalProcs().Product()).c_str());
270
271 doc.save_file(filename.c_str());
272}
273
274void CommSerial::PrintXMLAll(const std::string& filename, const std::string& xml_data)
275{
276 PrintXML(filename, xml_data);
277}
278
279void CommSerial::PrintGrid(Grid& grid, const char* information)
280{
281 Index i;
282 std::stringstream out;
283 std::ofstream out_file;
284
285 OpenFileAndPrintHeader(out_file, grid, information);
286
287 for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z())
288 for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
289 for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
290 out << std::scientific << grid.GetVal(i) << std::endl;
291
292 out_file << out.str();
293 out_file.close();
294}
295
296void CommSerial::PrintDefect(Grid& sol, Grid& rhs, const char* information)
297{
298 Grid::iterator iter;
299 std::ofstream out_file;
300 std::stringstream out;
301
302 TempGrid *temp = MG::GetTempGrid();
303 temp->SetProperties(sol);
304 temp->ImportFromResidual(sol, rhs);
305
306 OpenFileAndPrintHeader(out_file, *temp, information);
307
308 for (iter=temp->Iterators().Local().Begin(); iter!=temp->Iterators().Local().End(); ++iter)
309 out << std::scientific << temp->GetVal(*iter) << std::endl;
310
311 out_file << out.str();
312 out_file.close();
313}
314
315void CommSerial::OpenFileAndPrintHeader(std::ofstream& out, const Grid& grid, const char* information)
316{
317 char path_str[129];
318 int count = OutputCount();
319
320 sprintf(path_str, "%s%04d.dat", OutputPath().c_str(), count);
321
322 out.open(path_str, std::ios::trunc);
323
324 out << "# vtk DataFile Version 2.0" << std::endl
325 << count << ": " << information << std::endl
326 << "ASCII" << std::endl
327 << "DATASET STRUCTURED_POINTS" << std::endl
328 << grid.Local().Size().X() << " "
329 << grid.Local().Size().Y() << " "
330 << grid.Local().Size().Z() << std::endl
331 << "ORIGIN 0 0 0" << std::endl
332 << "SPACING " << grid.Extent().MeshWidth().X() << " "
333 << grid.Extent().MeshWidth() << " "
334 << grid.Extent().MeshWidth() << std::endl
335 << "POINT_DATA " << grid.Local().Size().Product() << std::endl
336 << "SCALARS residual double 1" << std::endl
337 << "LOOKUP_TABLE default" << std::endl;
338}
339
340void CommSerial::PrintAllSettings()
341{
342 Multigrid* mg = MG::GetFactory().Get("SOL")->Cast<Multigrid>();
343 std::stringstream buf;
344 std::ofstream out;
345
346 buf << OutputPath() << "settings.txt";
347
348 out.open(buf.str().c_str(), std::ios::trunc);
349
350 for (int i=mg->MinLevel(); i<=mg->MaxLevel(); ++i) {
351
352 out << "###########################################################" << std::endl
353 << "LEVEL: " << i << std::endl
354 << "GLOBAL:" << std::endl
355 << " LOCAL_BEGIN: " << (*mg)(i).Global().LocalBegin() << std::endl
356 << " LOCAL_END: " << (*mg)(i).Global().LocalEnd() << std::endl
357 << " LOCAL_SIZE: " << (*mg)(i).Global().LocalSize() << std::endl
358 << " GLOBAL_FINER_BEGIN: " << (*mg)(i).Global().GlobalFinerBegin() << std::endl
359 << " GLOBAL_FINER_END: " << (*mg)(i).Global().GlobalFinerEnd() << std::endl
360 << " GLOBAL_FINER_SIZE: " << (*mg)(i).Global().GlobalFinerSize() << std::endl
361 << " LOCAL_FINER_BEGIN: " << (*mg)(i).Global().LocalFinerBegin() << std::endl
362 << " LOCAL_FINER_END: " << (*mg)(i).Global().LocalFinerEnd() << std::endl
363 << " LOCAL_FINER_SIZE: " << (*mg)(i).Global().LocalFinerSize() << std::endl
364 << " FINEST_ABS_BEGIN: " << (*mg)(i).Global().FinestAbsBegin() << std::endl
365 << " FINEST_ABS_END: " << (*mg)(i).Global().FinestAbsEnd() << std::endl
366 << " FINEST_ABS_SIZE: " << (*mg)(i).Global().FinestAbsSize() << std::endl
367 << " GLOBAL_SIZE: " << (*mg)(i).Global().GlobalSize() << std::endl
368 << " BOUNDARY_TYPE: " << (*mg)(i).Global().BoundaryType() << std::endl
369 << "LOCAL:" << std::endl
370 << " BEGIN: " << (*mg)(i).Local().Begin() << std::endl
371 << " END: " << (*mg)(i).Local().End() << std::endl
372 << " SIZE: " << (*mg)(i).Local().Size() << std::endl
373 << " SIZE_TOTAL: " << (*mg)(i).Local().SizeTotal() << std::endl
374 << " HALO_BEGIN_1: " << (*mg)(i).Local().HaloBegin1() << std::endl
375 << " HALO_END_1: " << (*mg)(i).Local().HaloEnd1() << std::endl
376 << " HALO_SIZE_1: " << (*mg)(i).Local().HaloSize1() << std::endl
377 << " HALO_BEGIN_2: " << (*mg)(i).Local().HaloBegin2() << std::endl
378 << " HALO_END_2: " << (*mg)(i).Local().HaloEnd2() << std::endl
379 << " HALO_SIZE_2: " << (*mg)(i).Local().HaloSize2() << std::endl
380 << " BOUNDARY_BEGIN_1: " << (*mg)(i).Local().BoundaryBegin1() << std::endl
381 << " BOUNDARY_END_1: " << (*mg)(i).Local().BoundaryEnd1() << std::endl
382 << " BOUNDARY_SIZE_1: " << (*mg)(i).Local().BoundarySize1() << std::endl
383 << " BOUNDARY_BEGIN_2: " << (*mg)(i).Local().BoundaryBegin2() << std::endl
384 << " BOUNDARY_END_2: " << (*mg)(i).Local().BoundaryEnd2() << std::endl
385 << " BOUNDARY_SIZE_2: " << (*mg)(i).Local().BoundarySize2() << std::endl
386 << " FINER_BEGIN: " << (*mg)(i).Local().FinerBegin() << std::endl
387 << " FINER_END: " << (*mg)(i).Local().FinerEnd() << std::endl
388 << " FINER_SIZE: " << (*mg)(i).Local().FinerSize() << std::endl
389 << "EXTENT:" << std::endl
390 << " BEGIN: " << (*mg)(i).Extent().Begin() << std::endl
391 << " END: " << (*mg)(i).Extent().End() << std::endl
392 << " SIZE: " << (*mg)(i).Extent().Size() << std::endl
393 << " MESH_WIDTH: " << (*mg)(i).Extent().MeshWidth() << std::endl
394 << "###########################################################" << std::endl;
395
396 }
397
398 assert(out.good());
399 out.close();
400}
401
402inline int GetIndex(const Grid& grid, int i, int j, int k)
403{
404 if (grid.Global().BoundaryType() == LocallyRefined)
405 return k + grid.Local().Size().Z() * (j + grid.Local().Size().Y() * i);
406 else
407 return k + grid.Local().SizeTotal().Z() * (j + grid.Local().SizeTotal().Y() * i);
408}
409
410void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
411{
412 const Vector& sp = grid.Extent().MeshWidth();
413 int numLines;
414
415 if (grid.Global().BoundaryType() == LocallyRefined)
416 numLines = grid.Local().Size().X() * grid.Local().Size().Y() +
417 grid.Local().Size().Y() * grid.Local().Size().Z() +
418 grid.Local().Size().X() * grid.Local().Size().Z();
419 else
420 numLines = grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Y() +
421 grid.Local().SizeTotal().Y() * grid.Local().SizeTotal().Z() +
422 grid.Local().SizeTotal().X() * grid.Local().SizeTotal().Z();
423
424 out << " <Piece";
425
426 if (grid.Global().BoundaryType() == LocallyRefined) {
427 out << " NumberOfPoints=\"" << grid.Local().Size().Product() << "\""
428 << " NumberOfVerts=\"" << grid.Local().Size().Product() << "\"";
429 }else {
430 out << " NumberOfPoints=\"" << grid.Local().SizeTotal().Product() << "\""
431 << " NumberOfVerts=\"" << grid.Local().SizeTotal().Product() << "\"";
432 }
433
434 out << " NumberOfLines=\"" << numLines << "\""
435 << " NumberOfStrips=\"0\""
436 << " NumberOfPolys=\"0\"" << ">" << std::endl
437 << " <Points>" << std::endl
438 << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl
439 << " ";
440
441 if (grid.Global().BoundaryType() == LocallyRefined) {
442 for (int i=0; i<grid.Local().Size().X(); i++)
443 for (int j=0; j<grid.Local().Size().Y(); j++)
444 for (int k=0; k<grid.Local().Size().Z(); k++)
445 out << grid.Extent().Begin().X() + i * sp.X() << " "
446 << grid.Extent().Begin().Y() + j * sp.Y() << " "
447 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
448 }else {
449 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
450 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
451 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
452 out << grid.Extent().Begin().X() + i * sp.X() << " "
453 << grid.Extent().Begin().Y() + j * sp.Y() << " "
454 << grid.Extent().Begin().Z() + k * sp.Z() << " ";
455 }
456
457 out << std::endl
458 << " </DataArray>" << std::endl
459 << " </Points>" << std::endl
460 << " <Verts>" << std::endl
461 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
462 << " ";
463
464 if (grid.Global().BoundaryType() == LocallyRefined) {
465 for (int i=0; i<grid.Local().Size().Product(); i++)
466 out << i << " ";
467 }else {
468 for (int i=0; i<grid.Local().SizeTotal().Product(); i++)
469 out << i << " ";
470 }
471
472 out << std::endl
473 << " </DataArray>" << std::endl
474 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
475 << " ";
476
477 if (grid.Global().BoundaryType() == LocallyRefined) {
478 for (int i=1; i<=grid.Local().Size().Product(); i++)
479 out << i << " ";
480 }else {
481 for (int i=1; i<=grid.Local().SizeTotal().Product(); i++)
482 out << i << " ";
483 }
484
485 out << std::endl
486 << " </DataArray>" << std::endl
487 << " </Verts>" << std::endl
488 << " <Lines>" << std::endl
489 << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl
490 << " ";
491
492 if (grid.Global().BoundaryType() == LocallyRefined) {
493 for (int i=0; i<grid.Local().Size().X(); i++)
494 for (int j=0; j<grid.Local().Size().Y(); j++)
495 out << GetIndex(grid,i,j,0) << " "
496 << GetIndex(grid,i,j,grid.Local().Size().Z()-1) << " ";
497
498 for (int j=0; j<grid.Local().Size().Y(); j++)
499 for (int k=0; k<grid.Local().Size().Z(); k++)
500 out << GetIndex(grid,0,j,k) << " "
501 << GetIndex(grid,grid.Local().Size().X()-1,j,k) << " ";
502
503 for (int i=0; i<grid.Local().Size().X(); i++)
504 for (int k=0; k<grid.Local().Size().Z(); k++)
505 out << GetIndex(grid,i,0,k) << " "
506 << GetIndex(grid,i,grid.Local().Size().Y()-1,k) << " ";
507 }else {
508 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
509 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
510 out << GetIndex(grid,i,j,0) << " "
511 << GetIndex(grid,i,j,grid.Local().SizeTotal().Z()-1) << " ";
512
513 for (int j=0; j<grid.Local().SizeTotal().Y(); j++)
514 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
515 out << GetIndex(grid,0,j,k) << " "
516 << GetIndex(grid,grid.Local().SizeTotal().X()-1,j,k) << " ";
517
518 for (int i=0; i<grid.Local().SizeTotal().X(); i++)
519 for (int k=0; k<grid.Local().SizeTotal().Z(); k++)
520 out << GetIndex(grid,i,0,k) << " "
521 << GetIndex(grid,i,grid.Local().SizeTotal().Y()-1,k) << " ";
522 }
523
524 out << std::endl
525 << " </DataArray>" << std::endl
526 << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl
527 << " ";
528
529 for (int i=1; i<=numLines; i++)
530 out << 2*i << " ";
531
532 out << std::endl
533 << " </DataArray>" << std::endl
534 << " </Lines>" << std::endl
535 << " </Piece>" << std::endl;
536}
537
538void CommSerial::DebugPrintGridStructure(Multigrid& grid)
539{
540 std::ofstream out;
541 char path_str[129];
542
543 sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
544
545 out.open(path_str, std::ios::trunc);
546
547 if (!out.good()) {
548#ifdef DEBUG_OUTPUT
549 printf("Multigrid: File %s not accessible.\n", path_str);
550#endif /* DEBUG_OUTPUT */
551 return;
552 }
553
554 out << "<?xml version=\"1.0\"?>" << std::endl
555 << "<VTKFile type=\"PolyData\">" << std::endl
556 << " <PolyData>" << std::endl;
557
558 for (int i=grid.MinLevel(); i<=grid.MaxLevel(); i++)
559 PrintGridStructureLevel(grid(i), out);
560
561 out << " </PolyData>" << std::endl
562 << "</VTKFile>" << std::endl;
563
564 out.close();
565}
566
567std::string CommSerial::CreateOutputDirectory()
568{
569#ifdef HAVE_BOOST_FILESYSTEM
570 std::string path, unique_path;
571 std::stringstream unique_suffix;
572 int suffix_counter = 0;
573 char buffer[129];
574 time_t rawtime;
575 struct tm *timeinfo;
576
577 time(&rawtime);
578 timeinfo = localtime(&rawtime);
579 strftime(buffer, 128, "./output/%Y_%m_%d_%H_%M_%S/", timeinfo);
580 path = buffer;
581
582 if (!fs::exists("output"))
583 fs::create_directory("output");
584
585 unique_path = path;
586
587 while (fs::exists(unique_path.c_str())) {
588
589 unique_suffix.str("");
590 unique_suffix << "_" << suffix_counter++ << "/";
591
592 unique_path = path;
593 unique_path.replace(unique_path.size()-1, 1, unique_suffix.str());
594
595 }
596
597 fs::create_directory(unique_path.c_str());
598
599 return unique_path;
600
601#else
602
603 return "./";
604
605#endif
606}
Note: See TracBrowser for help on using the repository browser.