DUNE PDELab (git)

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