| [48b662] | 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 |
|
|---|
| [dfed1c] | 19 | #include <cstdarg>
|
|---|
| 20 | #include <cstdio>
|
|---|
| 21 | #include <sstream>
|
|---|
| [48b662] | 22 |
|
|---|
| 23 | #include "base/discretization.hpp"
|
|---|
| [dfed1c] | 24 | #include "base/helper.hpp"
|
|---|
| 25 | #include "base/index.hpp"
|
|---|
| 26 | #include "base/linked_cell_list.hpp"
|
|---|
| [48b662] | 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 |
|
|---|
| 34 | using namespace VMG;
|
|---|
| 35 |
|
|---|
| [dfed1c] | 36 | static char print_buffer[512];
|
|---|
| [48b662] | 37 |
|
|---|
| [dfed1c] | 38 | void CommSerial::InitCommSerial()
|
|---|
| [48b662] | 39 | {
|
|---|
| 40 | error_norm_count = 0;
|
|---|
| 41 | residual_count = 0;
|
|---|
| [dfed1c] | 42 | }
|
|---|
| [48b662] | 43 |
|
|---|
| [ac6d04] | 44 | void CommSerial::CommSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
|
|---|
| [dfed1c] | 45 | {
|
|---|
| 46 | Grid::iterator iter;
|
|---|
| [48b662] | 47 |
|
|---|
| [dfed1c] | 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);
|
|---|
| [48b662] | 53 | }
|
|---|
| 54 |
|
|---|
| [ac6d04] | 55 | void CommSerial::CommAddSubgrid(Grid& grid_old, Grid& grid_new, const int& direction)
|
|---|
| [48b662] | 56 | {
|
|---|
| [dfed1c] | 57 | Grid::iterator iter;
|
|---|
| [48b662] | 58 |
|
|---|
| [dfed1c] | 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);
|
|---|
| [48b662] | 64 | }
|
|---|
| 65 |
|
|---|
| 66 | Grid& CommSerial::GetFinerGrid(Multigrid& multigrid)
|
|---|
| 67 | {
|
|---|
| 68 | return multigrid(multigrid.Level()+1);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | Grid& CommSerial::GetCoarserGrid(Multigrid& multigrid)
|
|---|
| 72 | {
|
|---|
| 73 | return multigrid(multigrid.Level()-1);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| [ac6d04] | 76 | void CommSerial::CommFromGhosts(Grid& grid)
|
|---|
| [48b662] | 77 | {
|
|---|
| [dfed1c] | 78 | Grid::iterator iter;
|
|---|
| [48b662] | 79 |
|
|---|
| [ac6d04] | 80 | const GridIteratorSuite& iterators = grid.Iterators();
|
|---|
| 81 | const Index& size = grid.Local().Size();
|
|---|
| [48b662] | 82 |
|
|---|
| [dfed1c] | 83 | if (BoundaryConditions().X() == Periodic) {
|
|---|
| [48b662] | 84 |
|
|---|
| [dfed1c] | 85 | for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
|
|---|
| [ac6d04] | 86 | grid((*iter).X()+size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
|
|---|
| [48b662] | 87 |
|
|---|
| [dfed1c] | 88 | for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
|
|---|
| [ac6d04] | 89 | grid((*iter).X()-size.X(), (*iter).Y(), (*iter).Z()) += grid.GetVal(*iter);
|
|---|
| [dfed1c] | 90 | }
|
|---|
| [48b662] | 91 |
|
|---|
| [dfed1c] | 92 | if (BoundaryConditions().Y() == Periodic) {
|
|---|
| [48b662] | 93 |
|
|---|
| [dfed1c] | 94 | for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
|
|---|
| [ac6d04] | 95 | grid((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z()) += grid.GetVal(*iter);
|
|---|
| [48b662] | 96 |
|
|---|
| [dfed1c] | 97 | for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
|
|---|
| [ac6d04] | 98 | grid((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z()) += grid.GetVal(*iter);
|
|---|
| [48b662] | 99 |
|
|---|
| [dfed1c] | 100 | }
|
|---|
| [48b662] | 101 |
|
|---|
| [dfed1c] | 102 | if (BoundaryConditions().Z() == Periodic) {
|
|---|
| [48b662] | 103 |
|
|---|
| [dfed1c] | 104 | for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
|
|---|
| [ac6d04] | 105 | grid((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z()) += grid.GetVal(*iter);
|
|---|
| [48b662] | 106 |
|
|---|
| [dfed1c] | 107 | for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
|
|---|
| [ac6d04] | 108 | grid((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z()) += grid.GetVal(*iter);
|
|---|
| [48b662] | 109 |
|
|---|
| [dfed1c] | 110 | }
|
|---|
| [48b662] | 111 |
|
|---|
| [dfed1c] | 112 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| [ac6d04] | 113 | grid.IsConsistent();
|
|---|
| [dfed1c] | 114 | #endif
|
|---|
| 115 | }
|
|---|
| [48b662] | 116 |
|
|---|
| [ac6d04] | 117 | void CommSerial::CommToGhosts(Grid& grid)
|
|---|
| [dfed1c] | 118 | {
|
|---|
| 119 | Grid::iterator iter;
|
|---|
| [48b662] | 120 |
|
|---|
| [ac6d04] | 121 | const GridIteratorSuite& iterators = grid.Iterators();
|
|---|
| 122 | const Index& size = grid.Local().Size();
|
|---|
| [48b662] | 123 |
|
|---|
| [dfed1c] | 124 | if (BoundaryConditions().Z() == Periodic) {
|
|---|
| [48b662] | 125 |
|
|---|
| [dfed1c] | 126 | for (iter = iterators.Halo1().Z().Begin(); iter != iterators.Halo1().Z().End(); ++iter)
|
|---|
| [ac6d04] | 127 | grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()+size.Z());
|
|---|
| [48b662] | 128 |
|
|---|
| [dfed1c] | 129 | for (iter = iterators.Halo2().Z().Begin(); iter != iterators.Halo2().Z().End(); ++iter)
|
|---|
| [ac6d04] | 130 | grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y(), (*iter).Z()-size.Z());
|
|---|
| [48b662] | 131 |
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| [dfed1c] | 134 | if (BoundaryConditions().Y() == Periodic) {
|
|---|
| 135 |
|
|---|
| 136 | for (iter = iterators.Halo1().Y().Begin(); iter != iterators.Halo1().Y().End(); ++iter)
|
|---|
| [ac6d04] | 137 | grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()+size.Y(), (*iter).Z());
|
|---|
| [dfed1c] | 138 |
|
|---|
| 139 | for (iter = iterators.Halo2().Y().Begin(); iter != iterators.Halo2().Y().End(); ++iter)
|
|---|
| [ac6d04] | 140 | grid(*iter) = grid.GetVal((*iter).X(), (*iter).Y()-size.Y(), (*iter).Z());
|
|---|
| [dfed1c] | 141 |
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | if (BoundaryConditions().X() == Periodic) {
|
|---|
| 145 |
|
|---|
| 146 | for (iter = iterators.Halo1().X().Begin(); iter != iterators.Halo1().X().End(); ++iter)
|
|---|
| [ac6d04] | 147 | grid(*iter) = grid.GetVal((*iter).X()+size.X(), (*iter).Y(), (*iter).Z());
|
|---|
| [dfed1c] | 148 |
|
|---|
| 149 | for (iter = iterators.Halo2().X().Begin(); iter != iterators.Halo2().X().End(); ++iter)
|
|---|
| [ac6d04] | 150 | grid(*iter) = grid.GetVal((*iter).X()-size.X(), (*iter).Y(), (*iter).Z());
|
|---|
| [dfed1c] | 151 |
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| [ac6d04] | 155 | grid.IsConsistent();
|
|---|
| [48b662] | 156 | #endif
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| [894a5f] | 159 | void CommSerial::CommToGhostsAsyncStart(Grid& grid)
|
|---|
| 160 | {
|
|---|
| 161 | CommToGhosts(grid);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| [ac6d04] | 164 | void CommSerial::CommToGhostsAsyncFinish(Grid& grid)
|
|---|
| [894a5f] | 165 | {
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | void CommSerial::CommFromGhostsAsyncStart(Grid& grid)
|
|---|
| 169 | {
|
|---|
| 170 | CommFromGhosts(grid);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| [322469] | 173 | void CommSerial::CommFromGhostsAsyncFinish(Grid& grid)
|
|---|
| [894a5f] | 174 | {
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| [dfed1c] | 177 | void 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();
|
|---|
| [48b662] | 185 |
|
|---|
| [dfed1c] | 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 |
|
|---|
| [ac6d04] | 190 | void 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 |
|
|---|
| [716da7] | 198 | void CommSerial::CommLCListToGhosts(Particle::LinkedCellList& lc)
|
|---|
| [dfed1c] | 199 | {
|
|---|
| [ac6d04] | 200 | // std::list<Particle::Particle*>::iterator p_iter;
|
|---|
| 201 | // Grid::iterator g_iter;
|
|---|
| [dfed1c] | 202 |
|
|---|
| [ac6d04] | 203 | // for (int i=2; i>=0; --i) {
|
|---|
| [dfed1c] | 204 |
|
|---|
| [ac6d04] | 205 | // if (BoundaryConditions()[i] == Periodic) {
|
|---|
| [dfed1c] | 206 |
|
|---|
| [ac6d04] | 207 | // for (g_iter=lc.Iterators().Halo1()[i].Begin(); g_iter!=lc.Iterators().Halo1()[i].End(); ++g_iter)
|
|---|
| 208 | // lc(*g_iter).clear();
|
|---|
| [dfed1c] | 209 |
|
|---|
| [ac6d04] | 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());
|
|---|
| [dfed1c] | 215 |
|
|---|
| [ac6d04] | 216 | // for (g_iter=lc.Iterators().Halo2()[i].Begin(); g_iter!=lc.Iterators().Halo2()[i].End(); ++g_iter)
|
|---|
| 217 | // lc(*g_iter).clear();
|
|---|
| [dfed1c] | 218 |
|
|---|
| [ac6d04] | 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());
|
|---|
| [dfed1c] | 224 |
|
|---|
| [ac6d04] | 225 | // }
|
|---|
| 226 | // }
|
|---|
| [dfed1c] | 227 | }
|
|---|
| [48b662] | 228 |
|
|---|
| [ac6d04] | 229 | void CommSerial::CommLCListFromGhosts(const Grid& grid, Particle::LinkedCellList& lc)
|
|---|
| [dfed1c] | 230 | {
|
|---|
| 231 |
|
|---|
| [48b662] | 232 | }
|
|---|
| 233 |
|
|---|
| [ac6d04] | 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");
|
|---|
| [48b662] | 238 |
|
|---|
| [ac6d04] | 239 | // for (iter=particles.begin(); iter!=particles.end(); ++iter)
|
|---|
| 240 | // p[iter->Index()] += iter->Pot();
|
|---|
| 241 | // }
|
|---|
| [48b662] | 242 |
|
|---|
| [dfed1c] | 243 | void 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 | }
|
|---|
| [48b662] | 251 |
|
|---|
| [dfed1c] | 252 | void 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 |
|
|---|
| 261 | void 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());
|
|---|
| [48b662] | 270 |
|
|---|
| [dfed1c] | 271 | doc.save_file(filename.c_str());
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | void CommSerial::PrintXMLAll(const std::string& filename, const std::string& xml_data)
|
|---|
| 275 | {
|
|---|
| 276 | PrintXML(filename, xml_data);
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| [ac6d04] | 279 | void CommSerial::PrintGrid(Grid& grid, const char* information)
|
|---|
| [48b662] | 280 | {
|
|---|
| [ac6d04] | 281 | Index i;
|
|---|
| [dfed1c] | 282 | std::stringstream out;
|
|---|
| 283 | std::ofstream out_file;
|
|---|
| 284 |
|
|---|
| [ac6d04] | 285 | OpenFileAndPrintHeader(out_file, grid, information);
|
|---|
| [48b662] | 286 |
|
|---|
| [ac6d04] | 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;
|
|---|
| [48b662] | 291 |
|
|---|
| [dfed1c] | 292 | out_file << out.str();
|
|---|
| 293 | out_file.close();
|
|---|
| [48b662] | 294 | }
|
|---|
| 295 |
|
|---|
| [ac6d04] | 296 | void CommSerial::PrintDefect(Grid& sol, Grid& rhs, const char* information)
|
|---|
| [48b662] | 297 | {
|
|---|
| [ac6d04] | 298 | Grid::iterator iter;
|
|---|
| [dfed1c] | 299 | std::ofstream out_file;
|
|---|
| 300 | std::stringstream out;
|
|---|
| 301 |
|
|---|
| [ac6d04] | 302 | TempGrid *temp = MG::GetTempGrid();
|
|---|
| 303 | temp->SetProperties(sol);
|
|---|
| 304 | temp->ImportFromResidual(sol, rhs);
|
|---|
| [48b662] | 305 |
|
|---|
| [ac6d04] | 306 | OpenFileAndPrintHeader(out_file, *temp, information);
|
|---|
| [48b662] | 307 |
|
|---|
| [ac6d04] | 308 | for (iter=temp->Iterators().Local().Begin(); iter!=temp->Iterators().Local().End(); ++iter)
|
|---|
| 309 | out << std::scientific << temp->GetVal(*iter) << std::endl;
|
|---|
| [48b662] | 310 |
|
|---|
| [dfed1c] | 311 | out_file << out.str();
|
|---|
| 312 | out_file.close();
|
|---|
| [48b662] | 313 | }
|
|---|
| 314 |
|
|---|
| [ac6d04] | 315 | void CommSerial::OpenFileAndPrintHeader(std::ofstream& out, const Grid& grid, const char* information)
|
|---|
| [48b662] | 316 | {
|
|---|
| [ac6d04] | 317 | char path_str[129];
|
|---|
| 318 | int count = OutputCount();
|
|---|
| [48b662] | 319 |
|
|---|
| [ac6d04] | 320 | sprintf(path_str, "%s%04d.dat", OutputPath().c_str(), count);
|
|---|
| [48b662] | 321 |
|
|---|
| [ac6d04] | 322 | out.open(path_str, std::ios::trunc);
|
|---|
| [dfed1c] | 323 |
|
|---|
| [ac6d04] | 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;
|
|---|
| [dfed1c] | 338 | }
|
|---|
| 339 |
|
|---|
| 340 | void 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 |
|
|---|
| [ac6d04] | 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
|
|---|
| [716da7] | 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
|
|---|
| [ac6d04] | 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;
|
|---|
| [dfed1c] | 395 |
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | assert(out.good());
|
|---|
| [48b662] | 399 | out.close();
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | inline 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 |
|
|---|
| 410 | void CommSerial::PrintGridStructureLevel(Grid& grid, std::ofstream& out)
|
|---|
| 411 | {
|
|---|
| [ac6d04] | 412 | const Vector& sp = grid.Extent().MeshWidth();
|
|---|
| [48b662] | 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++)
|
|---|
| [ac6d04] | 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() << " ";
|
|---|
| [48b662] | 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++)
|
|---|
| [ac6d04] | 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() << " ";
|
|---|
| [48b662] | 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 |
|
|---|
| 538 | void CommSerial::DebugPrintGridStructure(Multigrid& grid)
|
|---|
| 539 | {
|
|---|
| 540 | std::ofstream out;
|
|---|
| 541 | char path_str[129];
|
|---|
| 542 |
|
|---|
| [dfed1c] | 543 | sprintf(path_str, "%sgrid.vtp", OutputPath().c_str());
|
|---|
| [48b662] | 544 |
|
|---|
| 545 | out.open(path_str, std::ios::trunc);
|
|---|
| 546 |
|
|---|
| 547 | if (!out.good()) {
|
|---|
| [dfed1c] | 548 | #ifdef DEBUG_OUTPUT
|
|---|
| [48b662] | 549 | printf("Multigrid: File %s not accessible.\n", path_str);
|
|---|
| [dfed1c] | 550 | #endif /* DEBUG_OUTPUT */
|
|---|
| [48b662] | 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 | }
|
|---|
| [dfed1c] | 566 |
|
|---|
| 567 | std::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 | }
|
|---|