Dune Core Modules (2.7.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 auto pos = name.find_last_of("\\/") + 1;
57 vtkWriter.write( name.substr(pos, name.size() - pos) );
58}
59
60template< class Grid >
61void test ( Grid &grid )
62{
63 gridcheck( grid );
64
65 // check the method geometryInFather()
66 std::cout << " CHECKING: geometry in father" << std::endl;
67 checkGeometryInFather( grid );
68 // check the intersection iterator and the geometries it returns
69 std::cout << " CHECKING: intersections" << std::endl;
70 bool skip = ! EnableLevelIntersectionIteratorCheck< Grid >::v;
71 checkIntersectionIterator( grid, skip );
72}
73
74template<typename GridType>
75void runDGFTest(int argc, char ** argv)
76{
77 using namespace Dune;
78
79 // this method calls MPI_Init, if MPI is enabled
80 MPIHelper & mpiHelper = MPIHelper::instance(argc,argv);
81
82 std::string filename;
83
84 if (argc>=2)
85 {
86 filename = argv[1];
87 }
88 else
89 {
90 std::stringstream namestr;
91#ifdef DGFTEST_USE_GMSH
92 namestr << "hybrid-testgrid-" << GridType::dimension << "d.msh";
93 filename = std::string( DUNE_GRID_EXAMPLE_GRIDS_PATH ) + "gmsh/" + namestr.str();
94#else
95 namestr << "test" << GridType::dimension << "d.dgf";
96 filename = std::string( DUNE_GRID_EXAMPLE_GRIDS_PATH ) + "dgf/" + namestr.str();
97#endif
98 }
99
100 std::cout << "tester: start grid reading; file " << filename << std::endl;
101
102 typedef typename GridType::LeafGridView GridView;
103 typedef typename GridView::IndexSet IndexSetType;
104
105 // create Grid from DGF parser
106 GridType *grid;
107 size_t nofElParams( 0 ), nofVtxParams( 0 );
108 std::vector< double > eldat( 0 ), vtxdat( 0 );
109 {
110 GridPtr< GridType > gridPtr( filename, mpiHelper.getCommunicator() );
111
112 gridPtr.loadBalance();
113
114 GridView gridView = gridPtr->leafGridView();
115 const IndexSetType &indexSet = gridView.indexSet();
116 nofElParams = gridPtr.nofParameters( 0 );
117 if( nofElParams > 0 )
118 {
119 std::cout << "Reading Element Parameters:" << std::endl;
120 eldat.resize( indexSet.size(0) * nofElParams );
121 const PartitionIteratorType partType = All_Partition;
122 typedef typename GridView::template Codim< 0 >::template Partition< partType >::Iterator Iterator;
123 const Iterator enditer = gridView.template end< 0, partType >();
124 for( Iterator iter = gridView.template begin< 0, partType >(); iter != enditer; ++iter )
125 {
126 const std::vector< double > &param = gridPtr.parameters( *iter );
127 assert( param.size() == nofElParams );
128 for( size_t i = 0; i < nofElParams; ++i )
129 {
130 //std::cout << param[i] << " ";
131 eldat[ indexSet.index(*iter) * nofElParams + i ] = param[ i ];
132 }
133 //std::cout << std::endl;
134 }
135 }
136
137 nofVtxParams = gridPtr.nofParameters( (int) GridType::dimension );
138 if( nofVtxParams > 0 )
139 {
140 std::cout << "Reading Vertex Parameters:" << std::endl;
141 vtxdat.resize( indexSet.size( GridType::dimension ) * nofVtxParams );
142 for(const auto & e : elements(gridView /*, Partitions::All */))
143 {
144 const std::vector< double > &param = gridPtr.parameters( e );
145 assert( param.size() == nofVtxParams );
146 for( size_t i = 0; i < nofVtxParams; ++i )
147 {
148 vtxdat[ indexSet.index(e) * nofVtxParams + i ] = param[ i ];
149 }
150 }
151 }
152
153
154#ifndef ModelP // parallel UGGrid can only have one grid at a time. defined ModelP => parallel UG
155 // does a second construction of the grid work?
156 GridPtr< GridType > gridPtr1( filename.c_str(), mpiHelper.getCommunicator() );
157#endif
158
159 grid = gridPtr.release();
160 }
161
162 GridView gridView = grid->leafGridView();
163 std::cout << "Grid size: " << grid->size(0) << std::endl;
164 // display
165 display( filename , gridView, eldat, nofElParams, vtxdat, nofVtxParams );
166 // refine
167#if CHECK
168 std::cout << "tester: refine grid" << std::endl;
170 std::cout << "Grid size: " << grid->size(0) << std::endl;
171 test(*grid);
172#endif
173 delete grid;
174}
175
176#endif // #ifndef DUNE_GRID_TEST_CHECKDGF_HH
Grid view abstract base class.
Definition: gridview.hh:60
A real mpi helper.
Definition: mpihelper.hh:169
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:190
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:91
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:172
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:80
int size(int codim) const
obtain number of entities in a given codimension
Definition: gridview.hh:178
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: alignedallocator.hh:14
Static tag representing a codimension.
Definition: dimension.hh:22
Some simple static information for a given GridType.
Definition: dgfparser.hh:54
Class for constructing grids from DGF files.
Definition: gridptr.hh:64
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 (Jul 15, 22:36, 2024)