Dune Core Modules (2.5.0)

checkdgf.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_TEST_CHECKDGF_HH
5#define DUNE_GRID_TEST_CHECKDGF_HH
6
7#define DISABLE_DEPRECATED_METHOD_CHECK 1
8#define CHECK 1
9
10#ifndef DUNE_GRID_EXAMPLE_GRIDS_PATH
11#define DUNE_GRID_EXAMPLE_GRIDS_PATH
12#endif
13
14#include <string>
15
17
18#include <dune/grid/common/rangegenerators.hh>
19
20#include <dune/grid/test/gridcheck.hh>
21#include <dune/grid/test/checkgeometryinfather.hh>
22#include <dune/grid/test/checkintersectionit.hh>
23
24#include <dune/grid/io/file/dgfparser.hh>
25#include <dune/grid/io/file/dgfparser/gridptr.hh>
28
29namespace Dune
30{
31
32 template< int dim, int dimworld >
33 class AlbertaGrid;
34
35}
36
37template< int dim, int dimworld >
38struct EnableLevelIntersectionIteratorCheck< Dune::AlbertaGrid< dim, dimworld > >
39{
40 static const bool v = false;
41};
42
43template< class GridView >
44void display ( const std::string &name,
45 const GridView &view,
46 std::vector< double > &elDat, int nofElParams,
47 std::vector< double > &vtxDat, int nofVtxParams )
48{
49 Dune::VTKWriter<GridView> vtkWriter(view);
50 // SubsamplingVTKWriter<GridView> vtkWriter(view,6);
51 if( nofElParams + nofVtxParams > 0 )
52 {
53 vtkWriter.addCellData( elDat, "el. Parameters", nofElParams );
54 vtkWriter.addVertexData( vtxDat, "vtx. Parameters", nofVtxParams );
55 }
56 vtkWriter.write( name );
57}
58
59template< class Grid >
60void test ( Grid &grid )
61{
62 gridcheck( grid );
63
64 // check the method geometryInFather()
65 std::cout << " CHECKING: geometry in father" << std::endl;
66 checkGeometryInFather( grid );
67 // check the intersection iterator and the geometries it returns
68 std::cout << " CHECKING: intersections" << std::endl;
69 bool skip = ! EnableLevelIntersectionIteratorCheck< Grid >::v;
70 checkIntersectionIterator( grid, skip );
71}
72
73template<typename GridType>
74void runDGFTest(int argc, char ** argv)
75{
76 using namespace Dune;
77
78 // this method calls MPI_Init, if MPI is enabled
79 MPIHelper & mpiHelper = MPIHelper::instance(argc,argv);
80
81 std::string filename;
82
83 if (argc>=2)
84 {
85 filename = argv[1];
86 }
87 else
88 {
89 std::stringstream namestr;
90 namestr << "test" << GridType::dimension << "d.dgf";
91 filename = std::string( DUNE_GRID_EXAMPLE_GRIDS_PATH ) + "dgf/" + namestr.str();
92 }
93
94 std::cout << "tester: start grid reading; file " << filename << std::endl;
95
96 typedef typename GridType::LeafGridView GridView;
97 typedef typename GridView::IndexSet IndexSetType;
98
99 // create Grid from DGF parser
100 GridType *grid;
101 size_t nofElParams( 0 ), nofVtxParams( 0 );
102 std::vector< double > eldat( 0 ), vtxdat( 0 );
103 {
104 GridPtr< GridType > gridPtr( filename.c_str(), mpiHelper.getCommunicator() );
105
106 gridPtr.loadBalance();
107
108 GridView gridView = gridPtr->leafGridView();
109 const IndexSetType &indexSet = gridView.indexSet();
110 nofElParams = gridPtr.nofParameters( 0 );
111 if( nofElParams > 0 )
112 {
113 std::cout << "Reading Element Parameters:" << std::endl;
114 eldat.resize( indexSet.size(0) * nofElParams );
115 const PartitionIteratorType partType = All_Partition;
116 typedef typename GridView::template Codim< 0 >::template Partition< partType >::Iterator Iterator;
117 const Iterator enditer = gridView.template end< 0, partType >();
118 for( Iterator iter = gridView.template begin< 0, partType >(); iter != enditer; ++iter )
119 {
120 const std::vector< double > &param = gridPtr.parameters( *iter );
121 assert( param.size() == nofElParams );
122 for( size_t i = 0; i < nofElParams; ++i )
123 {
124 //std::cout << param[i] << " ";
125 eldat[ indexSet.index(*iter) * nofElParams + i ] = param[ i ];
126 }
127 //std::cout << std::endl;
128 }
129 }
130
131 nofVtxParams = gridPtr.nofParameters( (int) GridType::dimension );
132 if( nofVtxParams > 0 )
133 {
134 std::cout << "Reading Vertex Parameters:" << std::endl;
135 vtxdat.resize( indexSet.size( GridType::dimension ) * nofVtxParams );
136 for(const auto & e : elements(gridView /*, Partitions::All */))
137 {
138 const std::vector< double > &param = gridPtr.parameters( e );
139 assert( param.size() == nofVtxParams );
140 for( size_t i = 0; i < nofVtxParams; ++i )
141 {
142 vtxdat[ indexSet.index(e) * nofVtxParams + i ] = param[ i ];
143 }
144 }
145 }
146
147
148#ifndef ModelP // parallel UGGrid can only have one grid at a time. defined ModelP => parallel UG
149 // does a second construction of the grid work?
150 GridPtr< GridType > gridPtr1( filename.c_str(), mpiHelper.getCommunicator() );
151#endif
152
153 grid = gridPtr.release();
154 }
155
156 GridView gridView = grid->leafGridView();
157 std::cout << "Grid size: " << grid->size(0) << std::endl;
158 // display
159 display( filename , gridView, eldat, nofElParams, vtxdat, nofVtxParams );
160 // refine
161#if CHECK
162 std::cout << "tester: refine grid" << std::endl;
164 std::cout << "Grid size: " << grid->size(0) << std::endl;
165 test(*grid);
166#endif
167 delete grid;
168}
169
170#endif // #ifndef DUNE_GRID_TEST_CHECKDGF_HH
Grid view abstract base class.
Definition: gridview.hh:60
A real mpi helper.
Definition: mpihelper.hh:160
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:181
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:87
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:173
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:81
int size(int codim) const
obtain number of entities in a given codimension
Definition: gridview.hh:179
IteratorRange<... > elements(const GV &gv)
Iterates over all elements / cells (entities with codimension 0) of a GridView.
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:134
@ All_Partition
all entities
Definition: gridenums.hh:139
Helpers for dealing with MPI.
Dune namespace.
Definition: alignment.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Some simple static information for a given GridType.
Definition: dgfparser.hh:55
Class for constructing grids from DGF files.
Definition: gridptr.hh:56
Provides subsampled file i/o for the visualization toolkit.
Provides file i/o for the visualization toolkit.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)