20#ifndef DUNE_CPGRID_DGFPARSER_HH
21#define DUNE_CPGRID_DGFPARSER_HH
23#include <dune/grid/io/file/dgfparser/dgfparser.hh>
39 static const int dimension = Grid::dimension;
41 typedef Grid::Codim< dimension >::Entity
Vertex;
43 explicit DGFGridFactory ( std::istream &input,
46 explicit DGFGridFactory (
const std::string &filename,
54 template<
class Intersection >
60 template<
class Intersection >
61 int boundaryId (
const Intersection &intersection )
const
63 return intersection.boundaryId();
72 template<
class Entity >
75 DUNE_THROW( InvalidStateException,
76 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
81 template<
class Intersection >
82 const typename DGFBoundaryParameter::type &
85 return DGFBoundaryParameter::defaultValue();
89 void generate ( std::istream &input );
111 std::ifstream input( filename.c_str() );
113 DUNE_THROW( DGFException,
"Unable to open file: " << filename <<
"." );
119 inline void DGFGridFactory< CpGrid >::generate ( std::istream &input )
121 dgf::IntervalBlock intervalBlock( input );
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." );
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 );
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 ];
138 const double bottom = interval.p[ 0 ][ 2 ];
139 const double top = interval.p[ 1 ][ 2 ];
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 )
147 const double y = j*dy;
148 for(
int i = 0; i <= interval.n[ 0 ]; ++i )
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 );
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 )
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;
171 std::vector< int > actnum( interval.n[ 0 ]*interval.n[ 1 ]*interval.n[ 2 ], 1 );
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 ];
184 grid_->processEclipseFormat( g,
false,
false );
[ provides Dune::Grid ]
Definition: CpGrid.hpp:238
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
bool haveBoundaryParameters() const
Definition: cpgrid/dgfparser.hh:79
Grid::Codim< 0 >::Entity Element
Definition: cpgrid/dgfparser.hh:40
bool wasInserted(const Intersection) const
Definition: cpgrid/dgfparser.hh:55
const DGFBoundaryParameter::type & boundaryParameter(const Intersection &) const
Definition: cpgrid/dgfparser.hh:83
Grid * grid() const
Definition: cpgrid/dgfparser.hh:49
MPIHelper::MPICommunicator MPICommunicatorType
Definition: cpgrid/dgfparser.hh:37
DGFGridFactory(std::istream &input, MPICommunicatorType comm=MPIHelper::getCommunicator())
Definition: cpgrid/dgfparser.hh:100
CpGrid Grid
Definition: cpgrid/dgfparser.hh:35
Grid::Codim< dimension >::Entity Vertex
Definition: cpgrid/dgfparser.hh:41
std::vector< double > & parameter(const Entity &)
Definition: cpgrid/dgfparser.hh:73
int boundaryId(const Intersection &intersection) const
Definition: cpgrid/dgfparser.hh:61
int numParameters() const
Definition: cpgrid/dgfparser.hh:67
CpGrid Grid
Definition: cpgrid/dgfparser.hh:195
static int refineStepsForHalf()
Definition: cpgrid/dgfparser.hh:197
static double refineWeight()
Definition: cpgrid/dgfparser.hh:202
Definition: preprocess.h:56
const double * coord
Definition: preprocess.h:58
int dims[3]
Definition: preprocess.h:57
const double * zcorn
Definition: preprocess.h:59
const int * actnum
Definition: preprocess.h:60