DUNE-FEM (unstable)

gridname.hh
1#ifndef DUNE_FEM_MISC_GRIDNAME_HH
2#define DUNE_FEM_MISC_GRIDNAME_HH
3
4// C++ includes
5#include <cstdlib>
6#include <climits>
7#include <iostream>
8#include <string>
9#include <typeinfo>
10#include <vector>
11
12// dune-common includes
14
15
16namespace Dune
17{
18
19 namespace Fem
20 {
21
22 // Internal forward declaration
23 // ----------------------------
24
25 template< class Grid > struct GridName;
26
27
28
29 // gridName
30 // --------
31
32 template< class GridImp >
33 static const std::string &gridName ()
34 {
35 return GridName< GridImp >::str();
36 }
37
38 template< class GridImp >
39 static const std::string &gridName ( const GridImp &grid )
40 {
41 return gridName< GridImp >();
42 }
43
44
45
46 // UnknownGridException
47 // --------------------
48
49 class UnknownGridException : public Exception {};
50
51
52
53 // GridName
54 // --------
55
56 template< class GridImp >
57 struct GridName
58 {
59 static const std::string &str ()
60 {
61 static std::string str = computeString();
62 return str;
63 }
64
65 private:
66 static std::string computeString ()
67 {
68 std::string name( typeid( GridImp ).name() );
69
70 size_t dunePos = name.find( "Dune" );
71 name.erase( 0, dunePos+4 );
72
73 char *endptr = 0;
74 // get position of strings that are not numbers
75 long int result = std::strtol( name.c_str(), &endptr, 0 );
76 if( result == LONG_MAX || result == LONG_MIN )
77 DUNE_THROW( UnknownGridException, "GridName: faild to determine name of grid!" );
78
79 if( endptr )
80 name = std::string( endptr );
81
82 // Grid seems to be followed by IL
83 size_t pos = name.find( "GridI" );
84 pos += 4; // add length of Grid to get pos of IL
85
86 if( pos < name.size() )
87 name.erase( pos, name.size() - pos );
88#ifndef NDEBUG
89 std::vector< std::string > knownGrids;
90 knownGrids.push_back( "AlbertaGrid" );
91 knownGrids.push_back( "ALUConformGrid" );
92 knownGrids.push_back( "ALUCubeGrid" );
93 knownGrids.push_back( "ALUGrid" );
94 knownGrids.push_back( "ALUSimplexGrid" );
95 knownGrids.push_back( "CacheItGrid" );
96 knownGrids.push_back( "CartesianGrid" );
97 knownGrids.push_back( "GeometryGrid" );
98 knownGrids.push_back( "OneDGrid" );
99 knownGrids.push_back( "P4estGrid" );
100 knownGrids.push_back( "ParallelGrid" );
101 knownGrids.push_back( "ParallelSimplexGrid" );
102 knownGrids.push_back( "PrismGrid" );
103 knownGrids.push_back( "SPGrid" );
104 knownGrids.push_back( "UGGrid" );
105 knownGrids.push_back( "YaspGrid" );
106
107 bool found = false ;
108 for( size_t i=0; i < knownGrids.size(); ++i )
109 {
110 if( name == knownGrids[ i ] )
111 {
112 found = true;
113 break;
114 }
115 }
116
117 if( !found )
118 {
119 std::cerr << "WARNING: Grid name `" << name << "' not found in list of known grids! Please add in file " << __FILE__ << std::endl;
120 }
121#endif
122 return name;
123 }
124 };
125
126 } // namespace Fem
127
128} // namespace Dune
129
130#endif // #ifndef DUNE_FEM_MISC_GRIDNAME_HH
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)