"Fossies" - the Fresh Open Source Software Archive

Member "dune-grid-howto-2.7.0/basicunitcube.hh" (20 Dec 2019, 3723 Bytes) of package /linux/misc/dune/dune-grid-howto-2.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "basicunitcube.hh" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.6.0_vs_2.7.0.

    1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    2 // vi: set et ts=4 sw=2 sts=2:
    3 #ifndef  BASICUNITCUBE_HH
    4 #define  BASICUNITCUBE_HH
    5 
    6 #include <dune/geometry/type.hh>
    7 #include <dune/grid/common/gridfactory.hh>
    8 
    9 // declaration of a basic unit cube that uses the GridFactory
   10 template< int dim >
   11 class BasicUnitCube;
   12 
   13 // unit cube in two dimensions with 2 variants: triangle and rectangle elements
   14 template<>
   15 class BasicUnitCube< 2 >
   16 {
   17 protected:
   18   template< class Grid >
   19   static void insertVertices ( Dune::GridFactory< Grid > &factory )
   20   {
   21     Dune::FieldVector<double,2> pos;
   22 
   23     pos[0] = 0;  pos[1] = 0;
   24     factory.insertVertex(pos);                         /*@\label{uc:iv}@*/
   25 
   26     pos[0] = 1;  pos[1] = 0;
   27     factory.insertVertex(pos);
   28 
   29     pos[0] = 0;  pos[1] = 1;
   30     factory.insertVertex(pos);
   31 
   32     pos[0] = 1;  pos[1] = 1;
   33     factory.insertVertex(pos);
   34   }
   35 
   36   template< class Grid >
   37   static void insertSimplices ( Dune::GridFactory< Grid > &factory )
   38   {
   39     const Dune::GeometryType type( Dune::GeometryTypes::triangle );
   40     std::vector< unsigned int > cornerIDs( 3 );
   41 
   42     cornerIDs[0] = 0;  cornerIDs[1] = 1;  cornerIDs[2] = 2;
   43     factory.insertElement( type, cornerIDs );          /*@\label{uc:ie}@*/
   44 
   45     cornerIDs[0] = 2;  cornerIDs[1] = 1;  cornerIDs[2] = 3;
   46     factory.insertElement( type, cornerIDs );
   47   }
   48 
   49   template< class Grid >
   50   static void insertCubes ( Dune::GridFactory< Grid > &factory )
   51   {
   52     const Dune::GeometryType type( Dune::GeometryTypes::quadrilateral );
   53     std::vector< unsigned int > cornerIDs( 4 );
   54     for( int i = 0; i < 4; ++i )
   55       cornerIDs[ i ] = i;
   56     factory.insertElement( type, cornerIDs );
   57   }
   58 };
   59 
   60 // unit cube in 3 dimensions with two variants: tetraheda and hexahedra
   61 template<>
   62 class BasicUnitCube< 3 >
   63 {
   64 protected:
   65   template< class Grid >
   66   static void insertVertices ( Dune::GridFactory< Grid > &factory )
   67   {
   68     Dune::FieldVector< double, 3 > pos;
   69 
   70     pos[0] = 0;  pos[1] = 0;  pos[2] = 0;    factory.insertVertex(pos);
   71     pos[0] = 1;  pos[1] = 0;  pos[2] = 0;    factory.insertVertex(pos);
   72     pos[0] = 0;  pos[1] = 1;  pos[2] = 0;    factory.insertVertex(pos);
   73     pos[0] = 1;  pos[1] = 1;  pos[2] = 0;    factory.insertVertex(pos);
   74     pos[0] = 0;  pos[1] = 0;  pos[2] = 1;    factory.insertVertex(pos);
   75     pos[0] = 1;  pos[1] = 0;  pos[2] = 1;    factory.insertVertex(pos);
   76     pos[0] = 0;  pos[1] = 1;  pos[2] = 1;    factory.insertVertex(pos);
   77     pos[0] = 1;  pos[1] = 1;  pos[2] = 1;    factory.insertVertex(pos);
   78   }
   79 
   80   template< class Grid >
   81   static void insertSimplices ( Dune::GridFactory< Grid > &factory )
   82   {
   83     const Dune::GeometryType type( Dune::GeometryTypes::tetrahedron );
   84     std::vector< unsigned int > cornerIDs( 4 );
   85 
   86     cornerIDs[0] = 0;  cornerIDs[1] = 1;  cornerIDs[2] = 2;  cornerIDs[3] = 4;
   87     factory.insertElement( type, cornerIDs );
   88 
   89     cornerIDs[0] = 1;  cornerIDs[1] = 3;  cornerIDs[2] = 2;  cornerIDs[3] = 7;
   90     factory.insertElement( type, cornerIDs );
   91 
   92     cornerIDs[0] = 1;  cornerIDs[1] = 7;  cornerIDs[2] = 2;  cornerIDs[3] = 4;
   93     factory.insertElement( type, cornerIDs );
   94 
   95     cornerIDs[0] = 1;  cornerIDs[1] = 7;  cornerIDs[2] = 4;  cornerIDs[3] = 5;
   96     factory.insertElement( type, cornerIDs );
   97 
   98     cornerIDs[0] = 4;  cornerIDs[1] = 7;  cornerIDs[2] = 2;  cornerIDs[3] = 6;
   99     factory.insertElement( type, cornerIDs );
  100   }
  101 
  102   template< class Grid >
  103   static void insertCubes ( Dune::GridFactory< Grid > &factory )
  104   {
  105     const Dune::GeometryType type( Dune::GeometryTypes::hexahedron );
  106     std::vector< unsigned int > cornerIDs( 8 );
  107     for( int i = 0; i < 8; ++i )
  108       cornerIDs[ i ] = i;
  109     factory.insertElement( type, cornerIDs );
  110   }
  111 };
  112 
  113 #endif  /*BASICUNITCUBE_HH*/