All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
dgfparser.hh
1 /*
2  Contributed by Martin Nolte, University of Freiburg.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef DUNE_CPGRID_DGFPARSER_HH
21 #define DUNE_CPGRID_DGFPARSER_HH
22 
23 #include <dune/grid/io/file/dgfparser/dgfparser.hh>
24 #include <dune/grid/CpGrid.hpp>
25 
26 namespace Dune
27 {
28 
29  // DGFGridFactory< CpGrid >
30  // ------------------------
31 
32  template<>
33  struct DGFGridFactory< CpGrid >
34  {
35  typedef CpGrid Grid;
36 
37  typedef MPIHelper::MPICommunicator MPICommunicatorType;
38 
39  static const int dimension = Grid::dimension;
40  typedef Grid::Codim< 0 >::Entity Element;
41  typedef Grid::Codim< dimension >::Entity Vertex;
42 
43  explicit DGFGridFactory ( std::istream &input,
44  MPICommunicatorType comm = MPIHelper::getCommunicator() );
45 
46  explicit DGFGridFactory ( const std::string &filename,
47  MPICommunicatorType comm = MPIHelper::getCommunicator() );
48 
49  Grid *grid () const
50  {
51  return grid_;
52  }
53 
54  template< class Intersection >
55  bool wasInserted ( const Intersection &intersection ) const
56  {
57  return false;
58  }
59 
60  template< class Intersection >
61  int boundaryId ( const Intersection &intersection ) const
62  {
63  return intersection.boundaryId();
64  }
65 
66  template< int codim >
67  int numParameters () const
68  {
69  return 0;
70  }
71 
72  template< class Entity >
73  std::vector< double > &parameter ( const Entity &entity )
74  {
75  DUNE_THROW( InvalidStateException,
76  "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
77  }
78 
79  bool haveBoundaryParameters () const { return false; }
80 
81  template< class Intersection >
82  const typename DGFBoundaryParameter::type &
83  boundaryParameter ( const Intersection &intersection ) const
84  {
85  return DGFBoundaryParameter::defaultValue();
86  }
87 
88  private:
89  void generate ( std::istream &input );
90 
91  Grid *grid_;
92  };
93 
94 
95 
96  // Implementation of DGFGridFactory< CpGrid >
97  // ------------------------------------------
98 
99  inline DGFGridFactory< CpGrid >
100  ::DGFGridFactory ( std::istream &input, MPICommunicatorType )
101  : grid_( 0 )
102  {
103  generate( input );
104  }
105 
106 
107  inline DGFGridFactory< CpGrid >
108  ::DGFGridFactory ( const std::string &filename, MPICommunicatorType )
109  : grid_( 0 )
110  {
111  std::ifstream input( filename.c_str() );
112  if( !input )
113  DUNE_THROW( DGFException, "Unable to open file: " << filename << "." );
114  generate( input );
115  input.close();
116  }
117 
118 
119  inline void DGFGridFactory< CpGrid >::generate ( std::istream &input )
120  {
121  dgf::IntervalBlock intervalBlock( input );
122 
123  if( !intervalBlock.isactive() )
124  DUNE_THROW( DGFException, "DGF stream must contain an interval block to be used with CpGrid." );
125  if( intervalBlock.numIntervals() != 1 )
126  DUNE_THROW( DGFException, "Currently, CpGrid can only handle 1 interval block." );
127 
128  if( intervalBlock.dimw() != dimension )
129  DUNE_THROW( DGFException, "CpGrid cannot handle an interval of dimension " << intervalBlock.dimw() << "." );
130  const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
131 
132  // compute some values
133 
134  const double dx = (interval.p[ 1 ][ 0 ] - interval.p[ 0 ][ 0 ]) / interval.n[ 0 ];
135  const double dy = (interval.p[ 1 ][ 1 ] - interval.p[ 0 ][ 1 ]) / interval.n[ 1 ];
136  const double dz = (interval.p[ 1 ][ 2 ] - interval.p[ 0 ][ 2 ]) / interval.n[ 2 ];
137 
138  const double bottom = interval.p[ 0 ][ 2 ];
139  const double top = interval.p[ 1 ][ 2 ];
140 
141  // compute pillars
142 
143  std::vector< double > coord;
144  coord.reserve( 6*(interval.n[ 0 ] + 1)*(interval.n[ 1 ] + 1) );
145  for( int j = 0; j <= interval.n[ 1 ]; ++j )
146  {
147  const double y = j*dy;
148  for( int i = 0; i <= interval.n[ 0 ]; ++i )
149  {
150  const double x = i*dx;
151  const double pillar[ 6 ] = { x, y, bottom, x, y, top };
152  coord.insert( coord.end(), pillar, pillar + 6 );
153  }
154  }
155 
156  // create cubes
157  const int num_per_layer = 4*interval.n[ 0 ]*interval.n[ 1 ];
158  std::vector< double > zcorn( 2*num_per_layer*interval.n[ 2 ] );
159  double *offset = &zcorn[ 0 ];
160  for( int k = 0; k < interval.n[ 2 ]; ++k )
161  {
162  const double zlow = k*dz;
163  std::fill( offset, offset + num_per_layer, zlow );
164  offset += num_per_layer;
165  const double zhigh = (k+1)*dz;
166  std::fill( offset, offset + num_per_layer, zhigh );
167  offset += num_per_layer;
168  }
169 
170  // ???
171  std::vector< int > actnum( interval.n[ 0 ]*interval.n[ 1 ]*interval.n[ 2 ], 1 );
172 
173  // create eclipse format description
174  grdecl g;
175  g.dims[ 0 ] = interval.n[ 0 ];
176  g.dims[ 1 ] = interval.n[ 1 ];
177  g.dims[ 2 ] = interval.n[ 2 ];
178  g.coord = &coord[ 0 ];
179  g.zcorn = &zcorn[ 0 ];
180  g.actnum = &actnum[ 0 ];
181 
182  // create grid
183  grid_ = new Grid;
184  grid_->processEclipseFormat( g, 0.0, false, false );
185  }
186 
187 
188 
189  // DGFGridInfo< CpGrid >
190  // ---------------------
191 
192  template<>
193  struct DGFGridInfo< CpGrid >
194  {
195  typedef CpGrid Grid;
196 
197  static int refineStepsForHalf ()
198  {
199  return 1;
200  }
201 
202  static double refineWeight ()
203  {
204  return 1.0 / 8.0;
205  }
206  };
207 
208 }
209 
210 #endif // #ifndef DUNE_CPGRID_DGFPARSER_HH
Raw corner-point specification of a particular geological model.
Definition: preprocess.h:56
const int * actnum
Explicit &quot;active&quot; map.
Definition: preprocess.h:60
[ provides Dune::Grid ]
Definition: CpGrid.hpp:213
const double * coord
Pillar end-points.
Definition: preprocess.h:58
const double * zcorn
Corner-point depths.
Definition: preprocess.h:59
int dims[3]
Cartesian box dimensions.
Definition: preprocess.h:57