LCOV - code coverage report
Current view: top level - ugbase/lib_grid/algorithms - debug_util_impl.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 9 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 7 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2012-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG__debug_util_impl__
      34              : #define __H__UG__debug_util_impl__
      35              : 
      36              : #include <fstream>
      37              : #include <sstream>
      38              : #include "lib_grid/lg_base.h"
      39              : #include "lib_grid/algorithms/geom_obj_util/geom_obj_util.h"
      40              : #include "common/util/table.h"
      41              : #include "lib_grid/tools/periodic_boundary_manager.h"
      42              : 
      43              : namespace ug
      44              : {
      45              : 
      46              : template <class TElem>
      47            0 : vector3 GetGridObjectCenter(Grid& g, TElem* elem)
      48              : {
      49            0 :         if(g.has_vertex_attachment(aPosition)){
      50              :                 Grid::VertexAttachmentAccessor<APosition> aaPos(g, aPosition);
      51            0 :                 return CalculateCenter(elem, aaPos);
      52              :         }
      53            0 :         else if(g.has_vertex_attachment(aPosition2)){
      54              :                 Grid::VertexAttachmentAccessor<APosition2> aaPos(g, aPosition2);
      55            0 :                 vector2 v = CalculateCenter(elem, aaPos);
      56            0 :                 return vector3(v.x(), v.y(), 0);
      57              :         }
      58            0 :         if(g.has_vertex_attachment(aPosition1)){
      59              :                 Grid::VertexAttachmentAccessor<APosition1> aaPos(g, aPosition1);
      60            0 :                 vector1 v = CalculateCenter(elem, aaPos);
      61            0 :                 return vector3(v.x(), 0, 0);
      62              :         }
      63              : 
      64              :         UG_LOG("GetGridObjectCenter failed! No standard position attachment found.\n");
      65              :         return vector3(0, 0, 0);
      66              : }
      67              : 
      68              : 
      69              : inline vector3 GetGridObjectCenter(Grid& g, GridObject* elem)
      70              : {
      71              :         switch(elem->base_object_id()){
      72              :                 case VERTEX:    return GetGridObjectCenter(g, static_cast<Vertex*>(elem));
      73              :                 case EDGE:              return GetGridObjectCenter(g, static_cast<Edge*>(elem));
      74              :                 case FACE:              return GetGridObjectCenter(g, static_cast<Face*>(elem));
      75              :                 case VOLUME:    return GetGridObjectCenter(g, static_cast<Volume*>(elem));
      76              :                 default:                UG_THROW("Unknown base object type."); 
      77              :         }
      78              :         return vector3(0, 0, 0);
      79              : }
      80              : 
      81              : 
      82              : template <class TElem>
      83              : int GetGridObjectIndex(Grid& g, TElem* elem)
      84              : {
      85              :         typedef typename Grid::traits<TElem>::base_object TBase;
      86              : 
      87              :         int counter = 0;
      88              :         for(typename Grid::traits<TBase>::iterator iter = g.begin<TBase>();
      89              :                 iter != g.end<TBase>(); ++iter, ++counter)
      90              :         {
      91              :                 if(*iter == elem)
      92              :                         return counter;
      93              :         }
      94              :         return -1;
      95              : }
      96              : 
      97              : template <class TElem, class TAValue>
      98              : void WriteDebugValuesToFile(const char* filename, Grid& grid,
      99              :                                                         TAValue& aVal, bool levelWise)
     100              : {
     101              :         typedef typename Grid::traits<TElem>::base_object TBase;
     102              : 
     103              :         std::ofstream out(filename);
     104              :         if(!out)
     105              :                 return;
     106              : 
     107              :         Grid::AttachmentAccessor<TBase, TAValue> aaVal(grid, aVal);
     108              : 
     109              :         Table<std::stringstream> table(grid.num<TElem>() + 1, 3);
     110              :         table(0, 0) << "lvl";   table(0, 1) << "center";        table(0, 2) << "value";
     111              : 
     112              :         size_t row = 1;
     113              :         if(levelWise){
     114              :                 GridObjectCollection goc = grid.get_grid_objects();
     115              :                 for(size_t lvl = 0; lvl < goc.num_levels(); ++lvl){
     116              :                         for(typename Grid::traits<TElem>::iterator iter = goc.begin<TElem>(lvl);
     117              :                                 iter != goc.end<TElem>(lvl); ++iter, ++row)
     118              :                         {
     119              :                                 table(row, 0) << lvl;
     120              :                                 table(row, 1) << GetGridObjectCenter(grid, *iter);
     121              :                                 table(row, 2) << aaVal[*iter];
     122              :                         }
     123              :                 }
     124              :         }
     125              :         else if(MultiGrid* pmg = dynamic_cast<MultiGrid*>(&grid)){
     126              :                 MultiGrid& mg = *pmg;
     127              :                 for(typename Grid::traits<TElem>::iterator iter = grid.begin<TElem>();
     128              :                         iter != grid.end<TElem>(); ++iter, ++row)
     129              :                 {
     130              :                         table(row, 0) << mg.get_level(*iter);
     131              :                         table(row, 1) << GetGridObjectCenter(grid, *iter);
     132              :                         table(row, 2) << aaVal[*iter];
     133              :                 }
     134              :         }
     135              :         else{
     136              :                 for(typename Grid::traits<TElem>::iterator iter = grid.begin<TElem>();
     137              :                         iter != grid.end<TElem>(); ++iter, ++row)
     138              :                 {
     139              :                         table(row, 0) << 0;
     140              :                         table(row, 1) << GetGridObjectCenter(grid, *iter);
     141              :                         table(row, 2) << aaVal[*iter];
     142              :                 }
     143              :         }
     144              : 
     145              :         out << table;
     146              :         out.close();
     147              : }
     148              : 
     149              : }//     end of namespace
     150              : 
     151              : #endif
        

Generated by: LCOV version 2.0-1