dune-grid 2.9.0
polyhedron.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=2 sw=2 sts=2:
5#ifndef DUNE_POLYHEDRON_HH
6#define DUNE_POLYHEDRON_HH
7
8#include <algorithm>
9
11
12namespace Dune
13{
14
15 namespace dgf
16 {
17
18 // PolyhedronBlock
19 // ---------------
20
22 : public BasicBlock
23 {
24 explicit PolyhedronBlock ( std::istream &in, int numPolys )
25 : BasicBlock( in, "Polyhedron" ), numPolys_( numPolys )
26 {}
27
28 int get ( std::vector< std::vector< int > > &polyhedra )
29 {
30 reset();
31 std::vector< int > polyhedron;
32 int minPolyId = 1;
33 while( getnextline() )
34 {
35 polyhedron.clear();
36 for( int polyIdx; getnextentry( polyIdx ); )
37 {
38 if( (polyIdx < 0) || (polyIdx > numPolys_) )
39 DUNE_THROW( DGFException, "Error in " << *this << ": Invalid polygon index (" << polyIdx << " not int [0, " << numPolys_ << "])" );
40
41 minPolyId = std::min( minPolyId, polyIdx );
42 polyhedron.push_back( polyIdx );
43 }
44
45 polyhedra.push_back( polyhedron );
46 }
47
48 // subtract minimal number to have 0 starting numbering
49 if( minPolyId > 0 )
50 {
51 const size_t polySize = polyhedra.size();
52 for( size_t i=0; i<polySize; ++i )
53 {
54 const size_t pSize = polyhedra[ i ].size();
55 for( size_t j=0; j<pSize; ++j )
56 {
57 polyhedra[ i ][ j ] -= minPolyId;
58 }
59 }
60 }
61 return polyhedra.size();
62 }
63
64 protected:
65 const int numPolys_;
66 };
67
68 } // namespace dgf
69} // end namespace Dune
70
71#endif // #ifndef DUNE_POLYHEDRON_HH
Include standard header files.
Definition: agrid.hh:60
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
@ polyhedron
Definition: common.hh:142
Definition: basic.hh:31
void reset()
Definition: basic.hh:51
bool getnextline()
Definition: basic.cc:94
bool getnextentry(ENTRY &entry)
Definition: basic.hh:63
Definition: polyhedron.hh:23
const int numPolys_
Definition: polyhedron.hh:65
PolyhedronBlock(std::istream &in, int numPolys)
Definition: polyhedron.hh:24
int get(std::vector< std::vector< int > > &polyhedra)
Definition: polyhedron.hh:28
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:16