Dune Core Modules (2.8.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 CHECK 1
8
9#ifndef DUNE_GRID_EXAMPLE_GRIDS_PATH
10#define DUNE_GRID_EXAMPLE_GRIDS_PATH
11#endif
12
13#include <string>
14
16
17#include <dune/grid/common/rangegenerators.hh>
18
19#include <dune/grid/test/gridcheck.hh>
20#include <dune/grid/test/checkgeometryinfather.hh>
21#include <dune/grid/test/checkintersectionit.hh>
22
23#include <dune/grid/io/file/dgfparser.hh>
24#include <dune/grid/io/file/dgfparser/gridptr.hh>
27
28namespace Dune
29{
30
31 template< int dim, int dimworld >
32 class AlbertaGrid;
33
34}
35
36template< int dim, int dimworld >
37struct EnableLevelIntersectionIteratorCheck< Dune::AlbertaGrid< dim, dimworld > >
38{
39 static const bool v = false;
40};
41
42template< class GridView >
43void display ( const std::string &name,
44 const GridView &view,
45 std::vector< double > &elDat, int nofElParams,
46 std::vector< double > &vtxDat, int nofVtxParams )
47{
48 Dune::VTKWriter<GridView> vtkWriter(view);
49 // SubsamplingVTKWriter<GridView> vtkWriter(view,6);
50 if( nofElParams + nofVtxParams > 0 )
51 {
52 vtkWriter.addCellData( elDat, "el. Parameters", nofElParams );
53 vtkWriter.addVertexData( vtxDat, "vtx. Parameters", nofVtxParams );
54 }
55 auto pos = name.find_last_of("\\/") + 1;
56 vtkWriter.write( name.substr(pos, name.size() - pos) );
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#ifdef DGFTEST_USE_GMSH
91 namestr << "hybrid-testgrid-" << GridType::dimension << "d.msh";
92 filename = std::string( DUNE_GRID_EXAMPLE_GRIDS_PATH ) + "gmsh/" + namestr.str();
93#else
94 namestr << "test" << GridType::dimension << "d.dgf";
95 filename = std::string( DUNE_GRID_EXAMPLE_GRIDS_PATH ) + "dgf/" + namestr.str();
96#endif
97 }
98
99 std::cout << "tester: start grid reading; file " << filename << std::endl;
100
101 typedef typename GridType::LeafGridView GridView;
102 typedef typename GridView::IndexSet IndexSetType;
103
104 // create Grid from DGF parser
105 GridType *grid;
106 size_t nofElParams( 0 ), nofVtxParams( 0 );
107 std::vector< double > eldat( 0 ), vtxdat( 0 );
108 {
109 GridPtr< GridType > gridPtr( filename, mpiHelper.getCommunicator() );
110
111 gridPtr.loadBalance();
112
113 GridView gridView = gridPtr->leafGridView();
114 const IndexSetType &indexSet = gridView.indexSet();
115 nofElParams = gridPtr.nofParameters( 0 );
116 if( nofElParams > 0 )
117 {
118 std::cout << "Reading Element Parameters:" << std::endl;
119 eldat.resize( indexSet.size(0) * nofElParams );
120 const PartitionIteratorType partType = All_Partition;
121 typedef typename GridView::template Codim< 0 >::template Partition< partType >::Iterator Iterator;
122 const Iterator enditer = gridView.template end< 0, partType >();
123 for( Iterator iter = gridView.template begin< 0, partType >(); iter != enditer; ++iter )
124 {
125 const std::vector< double > &param = gridPtr.parameters( *iter );
126 assert( param.size() == nofElParams );
127 for( size_t i = 0; i < nofElParams; ++i )
128 {
129 //std::cout << param[i] << " ";
130 eldat[ indexSet.index(*iter) * nofElParams + i ] = param[ i ];
131 }
132 //std::cout << std::endl;
133 }
134 }
135
136 nofVtxParams = gridPtr.nofParameters( (int) GridType::dimension );
137 if( nofVtxParams > 0 )
138 {
139 std::cout << "Reading Vertex Parameters:" << std::endl;
140 vtxdat.resize( indexSet.size( GridType::dimension ) * nofVtxParams );
141 for(const auto & e : elements(gridView /*, Partitions::All */))
142 {
143 const std::vector< double > &param = gridPtr.parameters( e );
144 assert( param.size() == nofVtxParams );
145 for( size_t i = 0; i < nofVtxParams; ++i )
146 {
147 vtxdat[ indexSet.index(e) * nofVtxParams + i ] = param[ i ];
148 }
149 }
150 }
151
152
153#ifndef ModelP // parallel UGGrid can only have one grid at a time. defined ModelP => parallel UG
154 // does a second construction of the grid work?
155 GridPtr< GridType > gridPtr1( filename.c_str(), mpiHelper.getCommunicator() );
156#endif
157
158 grid = gridPtr.release();
159 }
160
161 GridView gridView = grid->leafGridView();
162 std::cout << "Grid size: " << grid->size(0) << std::endl;
163 // display
164 display( filename , gridView, eldat, nofElParams, vtxdat, nofVtxParams );
165 // refine
166#if CHECK
167 std::cout << "tester: refine grid" << std::endl;
169 std::cout << "Grid size: " << grid->size(0) << std::endl;
170 test(*grid);
171#endif
172 delete grid;
173}
174
175#endif // #ifndef DUNE_GRID_TEST_CHECKDGF_HH
Grid view abstract base class.
Definition: gridview.hh:63
A real mpi helper.
Definition: mpihelper.hh:175
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:196
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:93
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:175
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:83
int size(int codim) const
obtain number of entities in a given codimension
Definition: gridview.hh:181
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:11
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 (Nov 13, 23:29, 2024)