/usr/include/dune/grid/uggrid/uggridintersections.hh is in libdune-grid-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | #ifndef DUNE_UGGRID_INTERSECTIONS_HH
#define DUNE_UGGRID_INTERSECTIONS_HH
#include <dune/common/sllist.hh>
#include <dune/common/shared_ptr.hh>
#include <dune/grid/uggrid/uggridrenumberer.hh>
/** \file
* \brief The UGGridLeafIntersection and UGGridLevelIntersection classes
*/
namespace Dune {
/** \brief Implementation class for an intersection with an element on the same level */
template<class GridImp>
class UGGridLevelIntersection
{
public:
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
private:
friend class UGGridEntity<0,dim,GridImp>;
// The type used to store coordinates
typedef typename GridImp::ctype UGCtype;
// The corresponding iterator needs to access all members
friend class UGGridLevelIntersectionIterator<GridImp>;
typedef FieldVector<UGCtype, dimworld> WorldVector;
typedef FieldVector<UGCtype, dim-1> FaceVector;
typedef typename GridImp::Traits::template Codim<1>::GeometryImpl GeometryImpl;
typedef typename GridImp::Traits::template Codim<1>::LocalGeometryImpl LocalGeometryImpl;
public:
typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
typedef typename GridImp::template Codim<1>::Geometry Geometry;
typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
typedef typename GridImp::template Codim<0>::Entity Entity;
/** The default Constructor makes empty Iterator
\todo Should be private
*/
UGGridLevelIntersection(typename UG_NS<dim>::Element* center, int nb, const GridImp* gridImp)
: geometryIsUpToDate_(false),
geometryInInsideIsUpToDate_(false),
geometryInOutsideIsUpToDate_(false),
center_(center), neighborCount_(nb),
gridImp_(gridImp)
{}
//! equality
bool equals(const UGGridLevelIntersection<GridImp>& i) const {
return center_==i.center_ && neighborCount_ == i.neighborCount_;
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the entity where we started this iterator)
EntityPointer inside() const {
return UGGridEntityPointer<0,GridImp>(center_,gridImp_);
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
typename UG_NS<dim>::Element* otherelem = UG_NS<dim>::NbElem(center_, neighborCount_);
if (otherelem==0)
DUNE_THROW(GridError,"no neighbor found in outside()");
return UGGridEntityPointer<0,GridImp>(otherelem,gridImp_);
}
//! return true if intersection is with boundary.
bool boundary () const {
return UG_NS<dim>::Side_On_Bnd(center_, neighborCount_);
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return UG_NS<dim>::NbElem(center_, neighborCount_) != NULL;
}
//! return information about the Boundary
int boundaryId () const DUNE_DEPRECATED {
return boundarySegmentIndex();
}
/** \brief return index of the corresponding coarse grid boundary segment */
size_t boundarySegmentIndex () const {
#ifndef NDEBUG
if (!boundary())
DUNE_THROW(GridError, "Calling boundarySegmentIndex() for a non-boundary intersection!");
#endif
UG_NS<dim>::Set_Current_BVP(gridImp_->multigrid_->theBVP);
return UG_NS<dim>::boundarySegmentIndex(center_, neighborCount_);
}
/** \brief Returns true, because UG level intersections are always conforming */
bool conforming() const {
return true;
}
//! intersection of codimension 1 of this neighbor with element where
//! iteration started.
//! Here returned element is in LOCAL coordinates of the element
//! where iteration started.
LocalGeometry geometryInInside () const;
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in GLOBAL coordinates of the element where iteration started.
Geometry geometry () const;
/** \brief obtain the type of reference element for this intersection */
GeometryType type () const
{
return geometryInInside().type();
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
LocalGeometry geometryInOutside () const;
//! local index of codim 1 entity in self where intersection is contained in
int indexInInside () const
{
return UGGridRenumberer<dim>::facesUGtoDUNE(neighborCount_, UG_NS<dim>::Tag(center_));
}
//! local index of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const;
//! return outer normal
const WorldVector&
outerNormal (const FaceVector& local) const;
//! return outer normal
const FieldVector<UGCtype, dimworld>&
integrationOuterNormal (const FieldVector<UGCtype, dim-1>& local) const
{
integrationOuterNormal_ = outerNormal(local);
const UGCtype scale = geometry().integrationElement( local ) / integrationOuterNormal_.two_norm();
integrationOuterNormal_ *= scale;
return integrationOuterNormal_;
}
//! return outer normal
const FieldVector<UGCtype, GridImp::dimensionworld>&
unitOuterNormal (const FieldVector<UGCtype, dim-1>& local) const
{
unitOuterNormal_ = outerNormal(local);
unitOuterNormal_ /= unitOuterNormal_.two_norm();
return unitOuterNormal_;
}
//! return outer normal
const FieldVector<UGCtype, GridImp::dimensionworld>&
centerUnitOuterNormal () const
{
GeometryType type = geometry().type();
const GenericReferenceElement<UGCtype, dim-1> & refElement =
GenericReferenceElements<UGCtype, dim-1>::general(type);
return unitOuterNormal(refElement.position(0,0));
}
private:
//! vector storing the outer normal
mutable FieldVector<UGCtype, dimworld> outerNormal_;
mutable FieldVector<UGCtype, dimworld> integrationOuterNormal_;
mutable FieldVector<UGCtype, dimworld> unitOuterNormal_;
// The geometries are only constructed when necessary. The following
// flags store whether they have been constructed already.
mutable bool geometryIsUpToDate_;
mutable bool geometryInInsideIsUpToDate_;
mutable bool geometryInOutsideIsUpToDate_;
//! pointer to element holding the self_local and self_global information.
//! This element is created on demand.
mutable LocalGeometryImpl geometryInInside_;
mutable LocalGeometryImpl geometryInOutside_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable GeometryImpl geometry_;
//! The UG element the iterator was created from
typename UG_NS<dim>::Element *center_;
//! count on which neighbor we are looking at. Note that this is interpreted in UG's ordering!
int neighborCount_;
/** \brief The grid we belong to. We need it to call set_Current_BVP */
const GridImp* gridImp_;
};
/** \brief Implementation class for a leaf intersection in a UGGrid */
template<class GridImp>
class UGGridLeafIntersection
{
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
friend class UGGridEntity<0,dim,GridImp>;
// The type used to store coordinates
typedef typename GridImp::ctype UGCtype;
// An element face identfied by the element and a face number
typedef std::pair<const typename UG_NS<dim>::Element*, int> Face;
// The corresponding iterator needs to access all members
friend class UGGridLeafIntersectionIterator<GridImp>;
typedef FieldVector<UGCtype, dimworld> WorldVector;
typedef FieldVector<UGCtype, dim-1> FaceVector;
typedef typename GridImp::Traits::template Codim<1>::GeometryImpl GeometryImpl;
typedef typename GridImp::Traits::template Codim<1>::LocalGeometryImpl LocalGeometryImpl;
public:
typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
typedef typename GridImp::template Codim<1>::Geometry Geometry;
typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
typedef typename GridImp::template Codim<0>::Entity Entity;
UGGridLeafIntersection(typename UG_NS<dim>::Element* center, int nb, const GridImp* gridImp)
: geometryIsUpToDate_(false),
geometryInInsideIsUpToDate_(false),
geometryInOutsideIsUpToDate_(false),
center_(center), neighborCount_(nb), subNeighborCount_(0),
gridImp_(gridImp)
{
if (neighborCount_ < UG_NS<dim>::Sides_Of_Elem(center_))
constructLeafSubfaces();
}
//! equality
bool equals(const UGGridLeafIntersection<GridImp>& other) const {
return center_ == other.center_
&& neighborCount_ == other.neighborCount_
&& subNeighborCount_ == other.subNeighborCount_;
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const {
return UGGridEntityPointer<0,GridImp>(center_,gridImp_);
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
const typename UG_NS<dim>::Element* otherelem = leafSubFaces_[subNeighborCount_].first;
if (otherelem==0)
DUNE_THROW(GridError,"no neighbor found in outside()");
/** \todo Remove the const_cast */
return UGGridEntityPointer<0,GridImp>(const_cast<typename UG_NS<dim>::Element*>(otherelem),gridImp_);
}
//! return true if intersection is with boundary.
bool boundary () const {
return UG_NS<dim>::Side_On_Bnd(center_, neighborCount_);
}
//! return true if a neighbor element exists across this intersection
bool neighbor () const {
return leafSubFaces_[subNeighborCount_].first != NULL;
}
//! return information about the Boundary
int boundaryId () const DUNE_DEPRECATED {
return boundarySegmentIndex();
}
/** \brief Return index of corresponding coarse grid boundary segment */
size_t boundarySegmentIndex () const {
#ifndef NDEBUG
if (!boundary())
DUNE_THROW(GridError, "Calling boundarySegmentIndex() for a non-boundary intersection!");
#endif
UG_NS<dim>::Set_Current_BVP(gridImp_->multigrid_->theBVP);
return UG_NS<dim>::boundarySegmentIndex(center_, neighborCount_);
}
/** \brief Is this intersection conforming? */
bool conforming() const {
const typename UG_NS<dim>::Element* outside = leafSubFaces_[subNeighborCount_].first;
if (outside == NULL // boundary intersection
// inside and outside are on the same level
|| UG_NS<dim>::myLevel(outside) == UG_NS<dim>::myLevel(center_)
// outside is on a higher level, but there is only one intersection
|| (UG_NS<dim>::myLevel(outside) > UG_NS<dim>::myLevel(center_)
&& leafSubFaces_.size()==1))
return true;
// outside is on a lower level. we have to check whether vertices match
int numInsideIntersectionVertices = UG_NS<dim>::Corners_Of_Side(center_, neighborCount_);
int numOutsideIntersectionVertices = UG_NS<dim>::Corners_Of_Side(outside, leafSubFaces_[subNeighborCount_].second);
if (numInsideIntersectionVertices != numOutsideIntersectionVertices)
return false;
// Loop over all vertices of the face of this element that corresponds to this intersection
for (int i=0; i<numInsideIntersectionVertices; i++) {
const typename UG_NS<dim>::Vertex* insideVertex = UG_NS<dim>::Corner(center_, UG_NS<dim>::Corner_Of_Side(center_, neighborCount_, i))->myvertex;
// Loop over all vertices of the corresponding element side of the outside element
bool vertexFound = false;
for (int j=0; j<numOutsideIntersectionVertices; j++) {
// get vertex
const typename UG_NS<dim>::Vertex* outsideVertex = UG_NS<dim>::Corner(outside, UG_NS<dim>::Corner_Of_Side(outside, leafSubFaces_[subNeighborCount_].second, j))->myvertex;
// Stop if we have found corresponding vertices
if (insideVertex==outsideVertex) {
vertexFound = true;
break;
}
}
// One of this face's vertices has not been found in the face of the outside element
if (vertexFound == false)
return false;
}
return true;
}
//! intersection of codimension 1 of this neighbor with element where
//! iteration started.
//! Here returned element is in LOCAL coordinates of the element
//! where iteration started.
LocalGeometry geometryInInside () const;
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in GLOBAL coordinates of the element where iteration started.
Geometry geometry () const;
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
LocalGeometry geometryInOutside () const;
/** \brief obtain the type of reference element for this intersection */
GeometryType type () const
{
return geometryInInside().type();
}
//! local index of codim 1 entity in self where intersection is contained in
int indexInInside () const
{
return UGGridRenumberer<dim>::facesUGtoDUNE(neighborCount_, UG_NS<dimworld>::Tag(center_));
}
//! local index of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const;
//! return outer normal, this should be dependent on local
//! coordinates for higher order boundary
const WorldVector&
outerNormal (const FaceVector& local) const;
//! return outer normal
const FieldVector<UGCtype, dimworld>&
integrationOuterNormal (const FieldVector<UGCtype, dim-1>& local) const
{
integrationOuterNormal_ = outerNormal(local);
//integrationOuterNormal_ /= integrationOuterNormal_.two_norm();
//integrationOuterNormal_ *= geometry().integrationElement(local);
const UGCtype scale = geometry().integrationElement( local ) / integrationOuterNormal_.two_norm();
integrationOuterNormal_ *= scale;
return integrationOuterNormal_;
}
//! return outer normal
const FieldVector<UGCtype, dimworld>&
unitOuterNormal (const FieldVector<UGCtype, dim-1>& local) const {
unitOuterNormal_ = outerNormal(local);
unitOuterNormal_ /= unitOuterNormal_.two_norm();
return unitOuterNormal_;
}
//! return outer normal
const FieldVector<UGCtype, dimworld>&
centerUnitOuterNormal () const
{
GeometryType type = geometry().type();
const GenericReferenceElement<UGCtype, dim-1> & refElement =
GenericReferenceElements<UGCtype, dim-1>::general(type);
return unitOuterNormal(refElement.position(0,0));
}
private:
//**********************************************************
// private methods
//**********************************************************
int numberInNeighbor(const typename UG_NS<dim>::Element* me, const typename UG_NS<dim>::Element* other) const {
const int nSides = UG_NS<dim>::Sides_Of_Elem(other);
for (int i=0; i<nSides; i++)
if (UG_NS<dim>::NbElem(other,i) == me)
return i;
// this point should not be reached, otherwise throw exception
DUNE_THROW(InvalidStateException,"no consistency in numberInNeighbor");
return -1;
}
/** \brief Find the topological father face of a given fact*/
int getFatherSide(const Face& currentFace) const;
/** \brief Precompute list of all leaf intersections of the current element face */
void constructLeafSubfaces();
//! vector storing the outer normal
mutable FieldVector<UGCtype, dimworld> outerNormal_;
mutable FieldVector<UGCtype, dimworld> integrationOuterNormal_;
mutable FieldVector<UGCtype, dimworld> unitOuterNormal_;
// The geometries are only constructed when necessary. The following
// flags store whether they have been constructed already.
mutable bool geometryIsUpToDate_;
mutable bool geometryInInsideIsUpToDate_;
mutable bool geometryInOutsideIsUpToDate_;
//! pointer to element holding the self_local and self_global information.
//! This element is created on demand.
mutable LocalGeometryImpl geometryInInside_;
mutable LocalGeometryImpl geometryInOutside_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable GeometryImpl geometry_;
//! The UG element the iterator was created from
typename UG_NS<dim>::Element *center_;
//! count on which neighbor we are lookin' at. Note that this is interpreted in UG's ordering!
int neighborCount_;
/** \brief List of precomputed intersections */
std::vector<Face> leafSubFaces_;
/** \brief Current position in the leafSubFaces_ array */
unsigned int subNeighborCount_;
/** \brief The grid we belong to. We need it to call set_Current_BVP */
const GridImp* gridImp_;
};
} // namespace Dune
#endif
|