gridinfo.hh

Go to the documentation of this file.
00001 // $Id: gridinfo.hh 3903 2007-11-14 11:06:34Z sander $
00002 
00003 #ifndef DUNE_GRIDINFO_HH
00004 #define DUNE_GRIDINFO_HH
00005 
00006 #include<iostream>
00007 #include <dune/common/exceptions.hh>
00008 #include "dune/common/helpertemplates.hh"
00009 #include "grid.hh"
00010 #include "referenceelements.hh"
00011 
00018 namespace Dune
00019 {
00028   template<class G>
00029   void gridinfo (const G& grid, std::string prefix="")
00030   {
00031         // first we extract the dimensions of the grid  
00032         const int dim = G::dimension;
00033         const int dimworld = G::dimensionworld;
00034 
00035         // grid type and dimension
00036         std::cout << prefix << "=> " << grid.name()
00037                           << "(dim=" << dim
00038                           << ",dimworld=" << dimworld
00039                           << ")" << std::endl;
00040 
00041         // level information
00042         for (int level=0; level<=grid.maxLevel(); level++)
00043           {
00044                 std::cout << prefix << "level " << level;
00045                 for (int cd=0; cd<=dim; cd++)
00046                   {
00047                         std::cout << " codim[" << cd << "]=" << grid.size(level,cd);
00048                   }
00049                 std::cout << std::endl;
00050           }
00051 
00052         // leaf information
00053         std::cout << prefix << "leaf   ";
00054         for (int cd=0; cd<=dim; cd++)
00055           {
00056                 std::cout << " codim[" << cd << "]=" << grid.size(cd);
00057           }
00058         std::cout << std::endl;
00059 
00060         std::cout << prefix << "leaf"
00061                           << " dim=" << dim
00062                           << " geomTypes=(";
00063         bool first=true;
00064         for (int c=0; c<=dim; c++)
00065           {
00066                 for (std::size_t i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
00067                   {
00068                         if (!first) std::cout << ",";
00069                         std::cout << grid.leafIndexSet().geomTypes(c)[i]
00070                                           << "[" << c << "]"
00071                                           << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
00072                         first=false;
00073                   }
00074           }
00075         std::cout << ")" << std::endl;
00076 
00077 
00078         return;
00079   }
00080 
00081  
00084   template<class G>
00085   void gridlevellist (const G& grid, int level, std::string prefix)
00086   {
00087         // first we extract the dimensions of the grid  
00088         const int dim = G::dimension;
00089         const int dimworld = G::dimensionworld;
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 (int 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::ReferenceElements<ct,dim>::general(it->type()).position(0,0))
00125                                   << ")"
00126                                   << " first=(" << it->geometry()[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).template subIndex<dim>(*it,i);
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).template subIndex<dim-1>(*it,i);
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         const int dimworld = G::dimensionworld;
00157 
00158         // type used for coordinates in the grid
00159         typedef typename G::ctype ct;
00160 
00161         // the grid has an iterator providing the access to
00162         // all elements (better codim 0 entities) on a grid level
00163         // Note the use of the typename and template keywords.
00164         typedef typename G::Traits::template Codim<0>::LeafIterator LeafIterator;
00165         typedef typename G::Traits::template Codim<dim>::LeafIterator VLeafIterator;
00166 
00167         // print info about the leaf grid
00168         std::cout << prefix << "leaf"
00169                           << " dim=" << dim
00170                           << " geomTypes=(";
00171         bool first=true;
00172         for (int c=0; c<=dim; c++)
00173           {
00174                 for (int i=0; i<grid.leafIndexSet().geomTypes(c).size(); i++)
00175                   {
00176                         if (!first) std::cout << ",";
00177                         std::cout << grid.leafIndexSet().geomTypes(c)[i]
00178                                           << "[" << c << "]"
00179                                           << "=" << grid.leafIndexSet().size(grid.leafIndexSet().geomTypes(c)[i]);
00180                         first=false;
00181                   }
00182           }
00183         std::cout << ")" << std::endl;
00184 
00185         // print info about nodes in leaf grid
00186         VLeafIterator veendit = grid.template leafend<dim>();
00187         for (VLeafIterator it = grid.template leafbegin<dim>(); it!=veendit; ++it)
00188           {
00189                 std::cout << prefix << "level=" << it->level()
00190                                   << " " << it->type() << "[" << dim << "]"
00191                                   << " index=" << grid.leafIndexSet().index(*it)
00192                                   << " gid=" << grid.globalIdSet().template id<dim>(*it)
00193                                   << " partition=" << PartitionName(it->partitionType())
00194                                   << " pos=(" << it->geometry()[0] << ")"
00195                                   << std::endl;
00196           }
00197 
00198         // print info about each element in leaf grid
00199         LeafIterator eendit = grid.template leafend<0>();
00200         for (LeafIterator it = grid.template leafbegin<0>(); it!=eendit; ++it)
00201           {
00202                 std::cout << prefix << "level=" << it->level()
00203                                   << " " << it->type() << "[" << dim << "]"
00204                                   << " index=" << grid.leafIndexSet().index(*it)
00205                                   << " gid=" << grid.globalIdSet().template id<0>(*it)
00206                                   << " leaf=" << it->isLeaf()
00207                                   << " partition=" << PartitionName(it->partitionType())
00208                                   << " center=(" 
00209                                   << it->geometry().global(Dune::ReferenceElements<ct,dim>::general(it->type()).position(0,0))
00210                                   << ")"
00211                                   << " first=(" << it->geometry()[0] << ")"
00212                                   << std::endl;
00213 
00214                 std::cout << prefix << "codim " << dim << " subindex";
00215                 for (int i=0; i<it->template count<dim>(); i++)
00216                   {
00217                         std::cout << " " << i << ":" << grid.leafIndexSet().template subIndex<dim>(*it,i);
00218                   }
00219                 std::cout << std::endl;
00220                 
00221                 std::cout << prefix << "codim " << dim-1 << " subindex";
00222                 for (int i=0; i<it->template count<dim-1>(); i++)
00223                   {
00224                         std::cout << " " << i << ":" << grid.leafIndexSet().template subIndex<dim-1>(*it,i);
00225                   }
00226                 std::cout << std::endl;
00227                 
00228           }
00229 
00230         return;
00231   }
00232 
00233  
00236 }
00237 #endif

Generated on 6 Nov 2008 with Doxygen (ver 1.5.6) [logfile].