/usr/include/dune/grid/onedgrid/onedgridintersections.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 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | #ifndef DUNE_ONE_D_GRID_INTERSECTIONS_HH
#define DUNE_ONE_D_GRID_INTERSECTIONS_HH
/** \file
* \brief The OneDGridLevelIntersection and OneDGridLeafIntersection classes
*/
#include <dune/grid/onedgrid/onedgridentity.hh>
namespace Dune {
/** \brief Intersection between two neighboring elements on a level grid */
template<class GridImp>
class OneDGridLevelIntersection
{
enum { dim=GridImp::dimension };
enum { dimworld=GridImp::dimensionworld };
// The corresponding iterator needs to access all members
friend class OneDGridLevelIntersectionIterator<GridImp>;
//! Constructor for a given grid entity and a given neighbor
OneDGridLevelIntersection(OneDEntityImp<1>* center, int nb)
: center_(center), neighbor_(nb),
intersectionSelfLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionNeighborLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionGlobal_(OneDGridGeometry<0,1,GridImp>())
{}
/** \brief Constructor creating the 'one-after-last'-iterator */
OneDGridLevelIntersection(OneDEntityImp<1>* center)
: center_(center), neighbor_(2),
intersectionSelfLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionNeighborLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionGlobal_(OneDGridGeometry<0,1,GridImp>())
{}
typedef typename GridImp::Traits::template Codim< 1 >::GeometryImpl GeometryImpl;
typedef typename GridImp::Traits::template Codim< 1 >::LocalGeometryImpl LocalGeometryImpl;
public:
typedef typename GridImp::template Codim<1>::Geometry Geometry;
typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
typedef typename GridImp::template Codim<0>::Entity Entity;
//! equality
bool equals(const OneDGridLevelIntersection<GridImp>& other) const {
return (center_ == other.center_) && (neighbor_ == other.neighbor_);
}
OneDEntityImp<1>* target() const {
const bool isValid = center_ && neighbor_>=0 && neighbor_<2;
if (!isValid)
return center_;
else if (neighbor_==0)
return center_->pred_;
else
return center_->succ_;
}
//! return true if intersection is with boundary.
bool boundary () const {
// Check whether we're on the left boundary
if (neighbor_==0) {
// If there's an element to the left we can't be on the boundary
if (center_->pred_)
return false;
const OneDEntityImp<1>* ancestor = center_;
while (ancestor->level_!=0) {
// Check if we're the left son of our father
if (ancestor != ancestor->father_->sons_[0])
return false;
ancestor = ancestor->father_;
}
// We have reached level 0. If there is no element of the left
// we're truly on the boundary
return !ancestor->pred_;
}
// ////////////////////////////////
// Same for the right boundary
// ////////////////////////////////
// If there's an element to the right we can't be on the boundary
if (center_->succ_)
return false;
const OneDEntityImp<1>* ancestor = center_;
while (ancestor->level_!=0) {
// Check if we're the left son of our father
if (ancestor != ancestor->father_->sons_[1])
return false;
ancestor = ancestor->father_;
}
// We have reached level 0. If there is no element of the left
// we're truly on the boundary
return !ancestor->succ_;
}
//! return true if across the edge a neighbor on this level exists
bool neighbor () const {
assert(neighbor_ >= 0 && neighbor_ < 2);
return (neighbor_==0)
? center_->pred_ && center_->pred_->vertex_[1] == center_->vertex_[0]
: center_->succ_ && center_->succ_->vertex_[0] == center_->vertex_[1];
}
//! return true if intersection is conform.
bool conforming () const {
return true;
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const
{
return OneDGridEntityPointer<0,GridImp>(center_);
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const
{
assert(neighbor());
return OneDGridEntityPointer<0,GridImp>(target());
}
//! return information about the Boundary
int boundaryId () const {
return boundarySegmentIndex();
}
//! return index of the boundary segment
int boundarySegmentIndex () const {
// It is hardwired here that the domain is connected, i.e., the boundary consists of two points
return ((neighbor_==0 && center_->reversedBoundarySegmentNumbering_==false)
|| (neighbor_==1 && center_->reversedBoundarySegmentNumbering_==true)) ? 0 : 1;
}
//! Here returned element is in LOCAL coordinates of the element
//! where iteration started.
LocalGeometry geometryInInside () const
{
intersectionSelfLocal_.setPosition( (indexInInside() == 0) ? 0 : 1 );
return LocalGeometry( intersectionSelfLocal_ );
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
LocalGeometry geometryInOutside () const
{
intersectionNeighborLocal_.setPosition( (indexInInside() == 0) ? 1 : 0 );
return LocalGeometry( intersectionNeighborLocal_ );
}
//! 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
{
intersectionGlobal_.target_ = center_->vertex_[neighbor_];
return Geometry( intersectionGlobal_ );
}
/** \brief obtain the type of reference element for this intersection */
GeometryType type () const
{
return GeometryType( 0 );
}
//! local index of codim 1 entity in self where intersection is contained in
int indexInInside () const
{
return neighbor_;
}
//! local index of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const
{
// If numberInSelf is 0 then numberInNeighbor is 1 and vice versa
return 1-neighbor_;
}
//! return outer normal
const FieldVector<typename GridImp::ctype, dimworld>& outerNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const {
return centerUnitOuterNormal();
}
//! Return outer normal scaled with the integration element
const FieldVector<typename GridImp::ctype, dimworld>& integrationOuterNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const {
return centerUnitOuterNormal();
}
//! return unit outer normal
const FieldVector<typename GridImp::ctype, dimworld>& unitOuterNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const {
return centerUnitOuterNormal();
}
//! return unit outer normal at center of intersection
const FieldVector<typename GridImp::ctype, dimworld>& centerUnitOuterNormal () const {
outerNormal_[0] = (neighbor_==0) ? -1 : 1;
return outerNormal_;
}
private:
//**********************************************************
// private methods
//**********************************************************
OneDEntityImp<1>* center_;
//! vector storing the outer normal
mutable FieldVector<typename GridImp::ctype, dimworld> outerNormal_;
/** \brief Count on which neighbor we are lookin' at. Can be only 0 or 1. */
int neighbor_;
/** \brief The geometry that's being returned when intersectionSelfLocal() is called
*/
mutable LocalGeometryImpl intersectionSelfLocal_;
/** \brief The geometry that's being returned when intersectionNeighborLocal() is called
*/
mutable LocalGeometryImpl intersectionNeighborLocal_;
//! The geometry that's being returned when intersectionSelfGlobal() is called
mutable GeometryImpl intersectionGlobal_;
};
/** \brief Intersection between two neighboring elements on a leaf grid */
template<class GridImp>
class OneDGridLeafIntersection
{
enum { dim=GridImp::dimension };
enum { dimworld=GridImp::dimensionworld };
// The corresponding iterator needs to access all members
friend class OneDGridLeafIntersectionIterator<GridImp>;
//! Constructor for a given grid entity and a given neighbor
OneDGridLeafIntersection(OneDEntityImp<1>* center, int nb)
: center_(center), neighbor_(nb),
intersectionSelfLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionNeighborLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionGlobal_(OneDGridGeometry<0,1,GridImp>())
{}
/** \brief Constructor creating the 'one-after-last'-iterator */
OneDGridLeafIntersection(OneDEntityImp<1>* center)
: center_(center), neighbor_(2),
intersectionSelfLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionNeighborLocal_(OneDGridGeometry<0,1,GridImp>()),
intersectionGlobal_(OneDGridGeometry<0,1,GridImp>())
{}
typedef typename GridImp::Traits::template Codim< 1 >::GeometryImpl GeometryImpl;
typedef typename GridImp::Traits::template Codim< 1 >::LocalGeometryImpl LocalGeometryImpl;
public:
typedef typename GridImp::template Codim<1>::Geometry Geometry;
typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
typedef typename GridImp::template Codim<0>::Entity Entity;
//! equality
bool equals(const OneDGridLeafIntersection<GridImp>& other) const {
return (center_ == other.center_) && (neighbor_ == other.neighbor_);
}
OneDEntityImp<1>* target() const {
const bool isValid = center_ && neighbor_>=0 && neighbor_<2;
if (!isValid)
return center_;
if (neighbor_==0) {
// Get left leaf neighbor
if (center_->pred_ && center_->pred_->vertex_[1] == center_->vertex_[0]) {
OneDEntityImp<1>* leftLeafNeighbor = center_->pred_;
while (!leftLeafNeighbor->isLeaf()) {
assert (leftLeafNeighbor->sons_[1] != NULL);
leftLeafNeighbor = leftLeafNeighbor->sons_[1];
}
return leftLeafNeighbor;
} else {
OneDEntityImp<1>* ancestor = center_;
while (ancestor->father_) {
ancestor = ancestor->father_;
if (ancestor->pred_ && ancestor->pred_->vertex_[1] == ancestor->vertex_[0]) {
assert(ancestor->pred_->isLeaf());
return ancestor->pred_;
}
}
DUNE_THROW(GridError, "Programming error, apparently we're on the left boundary, neighbor_==2 should not occur!");
}
} else {
// Get right leaf neighbor
if (center_->succ_ && center_->succ_->vertex_[0] == center_->vertex_[1]) {
OneDEntityImp<1>* rightLeafNeighbor = center_->succ_;
while (!rightLeafNeighbor->isLeaf()) {
assert (rightLeafNeighbor->sons_[0] != NULL);
rightLeafNeighbor = rightLeafNeighbor->sons_[0];
}
return rightLeafNeighbor;
} else {
OneDEntityImp<1>* ancestor = center_;
while (ancestor->father_) {
ancestor = ancestor->father_;
if (ancestor->succ_ && ancestor->succ_->vertex_[0] == ancestor->vertex_[1]) {
assert(ancestor->succ_->isLeaf());
return ancestor->succ_;
}
}
DUNE_THROW(GridError, "Programming error, apparently we're on the right boundary, neighbor_==3 should not occur!");
}
}
}
//! return true if intersection is with boundary.
bool boundary () const {
// Check whether we're on the left boundary
if (neighbor_==0) {
// If there's an element to the left we can't be on the boundary
if (center_->pred_)
return false;
const OneDEntityImp<1>* ancestor = center_;
while (ancestor->level_!=0) {
// Check if we're the left son of our father
if (ancestor != ancestor->father_->sons_[0])
return false;
ancestor = ancestor->father_;
}
// We have reached level 0. If there is no element of the left
// we're truly on the boundary
return !ancestor->pred_;
}
// ////////////////////////////////
// Same for the right boundary
// ////////////////////////////////
// If there's an element to the right we can't be on the boundary
if (center_->succ_)
return false;
const OneDEntityImp<1>* ancestor = center_;
while (ancestor->level_!=0) {
// Check if we're the left son of our father
if (ancestor != ancestor->father_->sons_[1])
return false;
ancestor = ancestor->father_;
}
// We have reached level 0. If there is no element of the left
// we're truly on the boundary
return !ancestor->succ_;
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return !boundary();
}
//! return true if intersection is conform.
bool conforming () const {
return true;
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const
{
return OneDGridEntityPointer<0,GridImp>(center_);
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const
{
return OneDGridEntityPointer<0,GridImp>(target());
}
//! return information about the Boundary
int boundaryId () const {
return boundarySegmentIndex();
}
//! return index of the boundary segment
int boundarySegmentIndex () const {
// It is hardwired here that the domain is connected, i.e., the boundary consists of two points
return ((neighbor_==0 && center_->reversedBoundarySegmentNumbering_==false)
|| (neighbor_==1 && center_->reversedBoundarySegmentNumbering_==true)) ? 0 : 1;
}
//! Here returned element is in LOCAL coordinates of the element
//! where iteration started.
LocalGeometry geometryInInside () const
{
intersectionSelfLocal_.setPosition( (indexInInside() == 0) ? 0 : 1 );
return LocalGeometry( intersectionSelfLocal_ );
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
LocalGeometry geometryInOutside () const
{
intersectionNeighborLocal_.setPosition( (indexInInside() == 0) ? 1 : 0 );
return LocalGeometry( intersectionNeighborLocal_ );
}
//! 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
{
intersectionGlobal_.target_ = center_->vertex_[neighbor_%2];
return Geometry( intersectionGlobal_ );
}
/** \brief obtain the type of reference element for this intersection */
GeometryType type () const
{
return GeometryType( 0 );
}
//! local index of codim 1 entity in self where intersection is contained in
int indexInInside () const
{
return neighbor_ % 2;
}
//! local index of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const
{
// If numberInSelf is 0 then numberInNeighbor is 1 and vice versa
return 1-(neighbor_ % 2);
}
//! return outer normal
const FieldVector<typename GridImp::ctype, dimworld>& outerNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const {
return centerUnitOuterNormal();
}
//! Return outer normal scaled with the integration element
const FieldVector<typename GridImp::ctype, dimworld>& integrationOuterNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const
{
return centerUnitOuterNormal();
}
//! return unit outer normal
const FieldVector<typename GridImp::ctype, dimworld>& unitOuterNormal (const FieldVector<typename GridImp::ctype, dim-1>& local) const {
return centerUnitOuterNormal();
}
//! return unit outer normal at center of intersection
const FieldVector<typename GridImp::ctype, dimworld>& centerUnitOuterNormal () const {
outerNormal_[0] = ((neighbor_%2)==0) ? -1 : 1;
return outerNormal_;
}
private:
//**********************************************************
// private methods
//**********************************************************
OneDEntityImp<1>* center_;
//! vector storing the outer normal
mutable FieldVector<typename GridImp::ctype, dimworld> outerNormal_;
/** \brief Count on which neighbor we are lookin' at
0,1 are the level neighbors, 2 and 3 are the leaf neighbors,
if they differ from the level neighbors. */
int neighbor_;
/** \brief The geometry that's being returned when intersectionSelfLocal() is called
*/
mutable LocalGeometryImpl intersectionSelfLocal_;
/** \brief The geometry that's being returned when intersectionNeighborLocal() is called
*/
mutable LocalGeometryImpl intersectionNeighborLocal_;
//! The geometry that's being returned when intersectionSelfGlobal() is called
mutable GeometryImpl intersectionGlobal_;
};
} // namespace Dune
#endif
|