dune-grid  2.2.0
common/gridinfo.hh
Go to the documentation of this file.
00001 // $Id: gridinfo.hh 7772 2011-11-15 09:31:37Z sander $
00002 
00003 #ifndef DUNE_GRIDINFO_HH
00004 #define DUNE_GRIDINFO_HH
00005 
00006 #include <iostream>
00007 #include <typeinfo>
00008 #include <dune/common/exceptions.hh>
00009 #include <dune/common/classname.hh>
00010 #include <dune/geometry/referenceelements.hh>
00011 #include "grid.hh"
00012 
00019 namespace Dune
00020 {
00029   template<class G>
00030   void gridinfo (const G& grid, std::string prefix="")
00031   {
00032         // first we extract the dimensions of the grid  
00033         const int dim = G::dimension;
00034         const int dimworld = G::dimensionworld;
00035 
00036         // grid type and dimension
00037         std::cout << prefix << "=> " << className(grid)
00038                           << " (dim=" << dim
00039                           << ", dimworld=" << dimworld
00040                           << ")" << std::endl;
00041 
00042         // level information
00043         for (int level=0; level<=grid.maxLevel(); level++)
00044           {
00045                 std::cout << prefix << "level " << level;
00046                 for (int cd=0; cd<=dim; cd++)
00047                   {
00048                         std::cout << " codim[" << cd << "]=" << grid.size(level,cd);
00049                   }
00050                 std::cout << std::endl;
00051           }
00052 
00053         // leaf information
00054         std::cout << prefix << "leaf   ";
00055         for (int cd=0; cd<=dim; cd++)
00056           {
00057                 std::cout << " codim[" << cd << "]=" << grid.size(cd);
00058           }
00059         std::cout << std::endl;
00060 
00061         std::cout << prefix << "leaf"
00062                           << " dim=" << dim
00063                           << " geomTypes=(";
00064         bool first=true;
00065         for (int c=0; c<=dim; c++)
00066           {
00067                 for (std::size_t i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
00068                   {
00069                         if (!first) std::cout << ",";
00070                         std::cout << grid.leafIndexSet().geomTypes(c)[i]
00071                                           << "[" << c << "]"
00072                                           << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
00073                         first=false;
00074                   }
00075           }
00076         std::cout << ")" << std::endl;
00077 
00078 
00079         return;
00080   }
00081 
00082  
00085   template<class G>
00086   void gridlevellist (const G& grid, int level, std::string prefix)
00087   {
00088         // first we extract the dimensions of the grid  
00089         const int dim = G::dimension;
00090 
00091         // type used for coordinates in the grid
00092         typedef typename G::ctype ct;
00093 
00094         // the grid has an iterator providing the access to
00095         // all elements (better codim 0 entities) on a grid level
00096         // Note the use of the typename and template keywords.
00097         typedef typename G::Traits::template Codim<0>::LevelIterator LevelIterator;
00098 
00099         // print info about this level
00100         std::cout << prefix << "level=" << level
00101                           << " dim=" << dim
00102                           << " geomTypes=(";
00103         bool first=true;
00104         for (unsigned i=0; i<grid.levelIndexSet(level).geomTypes(0).size(); i++)
00105           {
00106                 if (!first) std::cout << ",";
00107                 std::cout << grid.levelIndexSet(level).geomTypes(0)[i]
00108                                   << "=" << grid.levelIndexSet(level).size(grid.levelIndexSet(level).geomTypes(0)[i]);
00109                 first=false;
00110           }
00111         std::cout << ")" << std::endl;
00112 
00113         // print info about each element on given level
00114         LevelIterator eendit = grid.template lend<0>(level);
00115         for (LevelIterator it = grid.template lbegin<0>(level); it!=eendit; ++it)
00116           {
00117                 std::cout << prefix << "level=" << it->level()
00118                                   << " " << it->type() << "[" << dim << "]"
00119                                   << " index=" << grid.levelIndexSet(level).index(*it)
00120                                   << " gid=" << grid.globalIdSet().template id<0>(*it)
00121                                   << " leaf=" << it->isLeaf()
00122                                   << " partition=" << PartitionName(it->partitionType())
00123                                   << " center=(" 
00124                                   << it->geometry().global(Dune::GenericReferenceElements<ct,dim>::general(it->type()).position(0,0))
00125                                   << ")"
00126                                   << " first=(" << it->geometry().corner(0) << ")"
00127                                   << std::endl;
00128 
00129                 std::cout << prefix << "codim " << dim << " subindex";
00130                 for (int i=0; i<it->template count<dim>(); i++)
00131                   {
00132               std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(*it,i,dim);
00133                   }
00134                 std::cout << std::endl;
00135                 
00136                 std::cout << prefix << "codim " << dim-1 << " subindex";
00137                 for (int i=0; i<it->template count<dim-1>(); i++)
00138                   {
00139               std::cout << " " << i << ":" << grid.levelIndexSet(level).subIndex(*it,i,dim-1);
00140                   }
00141                 std::cout << std::endl;
00142                 
00143           }
00144 
00145         return;
00146   }
00147 
00148 
00151   template<class G>
00152   void gridleaflist (const G& grid, std::string prefix)
00153   {
00154         // first we extract the dimensions of the grid  
00155         const int dim = G::dimension;
00156 
00157         // type used for coordinates in the grid
00158         typedef typename G::ctype ct;
00159 
00160         // the grid has an iterator providing the access to
00161         // all elements (better codim 0 entities) on a grid level
00162         // Note the use of the typename and template keywords.
00163         typedef typename G::Traits::template Codim<0>::LeafIterator LeafIterator;
00164         typedef typename G::Traits::template Codim<dim>::LeafIterator VLeafIterator;
00165 
00166         // print info about the leaf grid
00167         std::cout << prefix << "leaf"
00168                           << " dim=" << dim
00169                           << " geomTypes=(";
00170         bool first=true;
00171         for (int c=0; c<=dim; c++)
00172           {
00173                 for (unsigned i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
00174                   {
00175                         if (!first) std::cout << ",";
00176                         std::cout << grid.leafIndexSet().geomTypes(c)[i]
00177                                           << "[" << c << "]"
00178                                           << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
00179                         first=false;
00180                   }
00181           }
00182         std::cout << ")" << std::endl;
00183 
00184         // print info about nodes in leaf grid
00185         VLeafIterator veendit = grid.template leafend<dim>();
00186         for (VLeafIterator it = grid.template leafbegin<dim>(); it!=veendit; ++it)
00187           {
00188                 std::cout << prefix << "level=" << it->level()
00189                                   << " " << it->type() << "[" << dim << "]"
00190                                   << " index=" << grid.leafIndexSet().index(*it)
00191                                   << " gid=" << grid.globalIdSet().template id<dim>(*it)
00192                                   << " partition=" << PartitionName(it->partitionType())
00193                                   << " pos=(" << it->geometry().corner(0) << ")"
00194                                   << std::endl;
00195           }
00196 
00197         // print info about each element in leaf grid
00198         LeafIterator eendit = grid.template leafend<0>();
00199         for (LeafIterator it = grid.template leafbegin<0>(); it!=eendit; ++it)
00200           {
00201                 std::cout << prefix << "level=" << it->level()
00202                                   << " " << it->type() << "[" << dim << "]"
00203                                   << " index=" << grid.leafIndexSet().index(*it)
00204                                   << " gid=" << grid.globalIdSet().template id<0>(*it)
00205                                   << " leaf=" << it->isLeaf()
00206                                   << " partition=" << PartitionName(it->partitionType())
00207                                   << " center=(" 
00208                                   << it->geometry().global(Dune::GenericReferenceElements<ct,dim>::general(it->type()).position(0,0))
00209                                   << ")"
00210                                   << " first=(" << it->geometry().corner(0) << ")"
00211                                   << std::endl;
00212 
00213                 std::cout << prefix << "codim " << dim << " subindex";
00214                 for (int i=0; i<it->template count<dim>(); i++)
00215                   {
00216               std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(*it,i,dim);
00217                   }
00218                 std::cout << std::endl;
00219                 
00220                 std::cout << prefix << "codim " << dim-1 << " subindex";
00221                 for (int i=0; i<it->template count<dim-1>(); i++)
00222                   {
00223               std::cout << " " << i << ":" << grid.leafIndexSet().subIndex(*it,i,dim-1);
00224                   }
00225                 std::cout << std::endl;
00226                 
00227           }
00228 
00229         return;
00230   }
00231 
00232  
00235 }
00236 #endif