- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_DGFS_HH 00002 #define DUNE_DGFS_HH 00003 00004 #include <dune/grid/sgrid.hh> 00005 #include "dgfparser.hh" 00006 00007 namespace Dune 00008 { 00009 00010 template< int dim, int dimworld, class ctype > 00011 struct DGFGridFactory< SGrid< dim, dimworld, ctype > > 00012 { 00013 typedef SGrid< dim, dimworld, ctype > Grid; 00014 00015 const static int dimension = Grid::dimension; 00016 00017 typedef MPIHelper::MPICommunicator MPICommunicatorType; 00018 00019 explicit DGFGridFactory ( std::istream &input, 00020 MPICommunicatorType comm = MPIHelper::getCommunicator() ) 00021 { 00022 generate( input, comm ); 00023 } 00024 00025 explicit DGFGridFactory ( const std::string &filename, 00026 MPICommunicatorType comm = MPIHelper::getCommunicator() ) 00027 { 00028 std::ifstream input( filename.c_str() ); 00029 generate( input, comm ); 00030 } 00031 00032 Grid *grid() const 00033 { 00034 return grid_; 00035 } 00036 00037 template< class Intersection > 00038 bool wasInserted ( const Intersection &intersection ) const 00039 { 00040 return false; 00041 } 00042 00043 template< class Intersection > 00044 int boundaryId ( const Intersection &intersection ) const 00045 { 00046 return intersection.boundaryId(); 00047 } 00048 00049 template< int codim > 00050 int numParameters () const 00051 { 00052 return 0; 00053 } 00054 00055 template< class Entity > 00056 std::vector< double > ¶meter ( const Entity &entity ) 00057 { 00058 return emptyParam; 00059 } 00060 00061 private: 00062 void generate( std::istream &gridin, MPICommunicatorType comm ); 00063 00064 Grid *grid_; 00065 std::vector< double > emptyParam; 00066 }; 00067 00068 00069 00070 template< int dim, int dimworld, class ctype > 00071 inline void DGFGridFactory< SGrid< dim, dimworld, ctype > > 00072 ::generate ( std::istream &gridin, MPICommunicatorType comm ) 00073 { 00074 dgf::IntervalBlock intervalBlock( gridin ); 00075 00076 if( !intervalBlock.isactive() ) 00077 DUNE_THROW( DGFException, "SGrid can only be created from an interval block." ); 00078 00079 if( intervalBlock.numIntervals() != 1 ) 00080 DUNE_THROW( DGFException, "SGrid can only handle 1 interval block." ); 00081 00082 if( intervalBlock.dimw() != dim ) 00083 { 00084 DUNE_THROW( DGFException, 00085 "Cannot read an interval of dimension " << intervalBlock.dimw() 00086 << "into a SGrid< " << dim << ", " << dimworld << " >." ); 00087 } 00088 00089 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 ); 00090 00091 FieldVector< double, dimension > lower, upper; 00092 FieldVector< int, dimension > anz; 00093 for( int i = 0; i < dimension; ++i ) 00094 { 00095 lower[ i ] = interval.p[ 0 ][ i ]; 00096 upper[ i ] = interval.p[ 1 ][ i ]; 00097 anz[ i ] = interval.n[ i ]; 00098 } 00099 00100 grid_ = new Grid( anz, lower, upper ); 00101 } 00102 00103 00104 00105 template< int dim, int dimworld, class ctype > 00106 struct DGFGridInfo< SGrid< dim, dimworld, ctype > > 00107 { 00108 static int refineStepsForHalf () 00109 { 00110 return 1; 00111 } 00112 00113 static double refineWeight () 00114 { 00115 return 1.0 / double( 1 << dim ); 00116 } 00117 }; 00118 00119 } 00120 #endif // #ifndef DUNE_DGFS_HH
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].