Skip to content
Snippets Groups Projects
Commit b16638da authored by sander@PCPOOL.MI.FU-BERLIN.DE's avatar sander@PCPOOL.MI.FU-BERLIN.DE
Browse files

FoamGrid: a new grid implementation

FoamGrid is a 2d-in-3d grid which shall support:
- triangle and quad elements
- non-manifold junctions (t-junctions)
- parallel grids
- red/green-refinement, anisotropic refinement and nonconforming refinement



git-svn-id: https://svn.imp.fu-berlin.de/agnumpde/import-sander/trunk/dune-foamgrid@2660 10e313fe-3d75-4ea2-8e88-6fde81de6cbd
parents
No related branches found
No related tags found
No related merge requests found
Showing
with 3004 additions and 0 deletions
# $Id: duneproject 5502 2009-04-03 15:05:58Z sander $
# we need the module file to be able to build via dunecontrol
EXTRA_DIST=dune.module
DIST_SUBDIRS = doc src m4
SUBDIRS = src m4
if BUILD_DOCS
# TODO: set up documentation tree automatically
#SUBDIRS += doc
endif
# don't follow the full GNU-standard
# we need automake 1.5
AUTOMAKE_OPTIONS = foreign 1.5
# pass most important options when "make distcheck" is used
DISTCHECK_CONFIGURE_FLAGS = --with-dune-common=$(DUNE_COMMON_ROOT) --with-dune-grid=$(DUNE_GRID_ROOT) CXX="$(CXX)" CC="$(CC)"
include $(top_srcdir)/am/top-rules
include $(top_srcdir)/am/global-rules
README 0 → 100644
Preparing the Sources
=========================
Additional to the software mentioned in README you'll need the
following programs installed on your system:
automake >= 1.5
autoconf >= 2.50
libtool
Getting started
---------------
If these preliminaries are met, you should run
dunecontrol all
which will find all installed dune modules as well as all dune modules
(not installed) which sources reside in a subdirectory of the current
directory. Note that if dune is not installed properly you will either
have to add the directory where the dunecontrol script resides (probably
./dune-common/bin) to your path or specify the relative path of the script.
On your project and all uninstalled DUNE source modules found the script
will then calls the GNU autoconf/automake to create a ./configure-script
and the Makefiles. Afterwards that configure script will be called and the
modules will be build using make all
Most probably you'll have to provide additional information to dunecontrol
(e. g. compilers, configure options) and/or make options.
The most convenient way is to use options files in this case. The files
defining three variables:
AUTOGEN_FLAGS flags passed to autogen
CONFIGURE_FLAGS flags passed to configure
MAKE_FLAGS flags passed to make
An example options file might look like this:
#use this options to autogen, configure and make if no other options are given
AUTOGEN_FLAGS="--ac=2.50 --ac=1.8" #Forces automake 2,50 and autoconf 1.8
CONFIGURE_FLAGS="CXX=g++-3.4 --prefix=/install/path" #force g++-3.4 as compiler
MAKE_FLAGS=install #Per default run make install instead of simply make
If you save this information into example.opts you can path the opts file to
dunecontrol via the --opts option, e. g.
dunecontrol --opts=example.opts all
To get a full list of available configure flags just run
dunecontrol configure --help
after running at least
dunecontrol autogen
More info
---------
See
dunecontrol --help
for further options.
The full build-system is described in the dune-common/doc/buildsystem (SVN version) or under share/doc/dune-common/buildsystem if you installed DUNE!
$Id: duneproject 5502 2009-04-03 15:05:58Z sander $
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.50)
DUNE_AC_INIT # gets module version from dune.module file
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/dune_foamgrid.cc])
AM_CONFIG_HEADER([config.h])
# we need no more than the standard DE-stuff
# this module depends on dune-common dune-grid
# this implies checking for [dune-common], [dune-grid]
DUNE_CHECK_ALL
DUNE_SYMLINK
# implicitly set the Dune-flags everywhere
AC_SUBST(AM_CPPFLAGS, $DUNE_CPPFLAGS)
AC_SUBST(AM_LDFLAGS, $DUNE_LDFLAGS)
LIBS="$DUNE_LIBS"
AC_CONFIG_FILES([
Makefile
src/Makefile
dune-foamgrid/Makefile
dune-foamgrid/foamgrid/Makefile
dune-foamgrid/test/Makefile
doc/Makefile
doc/doxygen/Makefile
m4/Makefile
dune-foamgrid.pc
])
AC_OUTPUT
# finally print the summary information
DUNE_SUMMARY_ALL
SUBDIRS = doxygen
CURDIR = doc
BASEDIR = ..
docdir=$(datadir)/doc/dune-foamgrid
include $(top_srcdir)/am/webstuff
CLEANFILES = $(PAGES)
if ! BUILD_DOCS
# add tag to notify that dist has been build without documentation
dist-hook:
echo "# No documentation included in distribution! " > $(distdir)/$(DOCUMENTATION_TAG_FILE)
endif
include $(top_srcdir)/am/global-rules
BASEDIR=../..
CURDIR=doc/doxygen
WHAT=
doxygendir = $(datadir)/doc/dune-foamgrid/doxygen
doxygen_DATA = $(WHAT)
#we need this in the distribution
EXTRA_DIST = $(WHAT) $(DOXYGENDISTFILES)
all: $(WHAT) $(DOXYGENFILES)
include $(top_srcdir)/am/doxygen
include $(top_srcdir)/am/global-rules
# file to clean only in svn and not in tarball tree
SVNCLEANFILES = html $(WHAT) $(DOXYGENHEADER)
clean-local:
if test "x$(VPATH)" != "x" && test ! -e $(srcdir)/doxygen-tag; then if test -e $(top_srcdir)/doc/doxygen/Doxydep; then rm -rf $(SVNCLEANFILES); fi; fi
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@
Name: @PACKAGE_NAME@
Version: @VERSION@
Description: dune-foamgrid module
URL: http://dune-project.org/
Requires: dune-common dune-grid
Libs: -L
Cflags: -I
SUBDIRS = foamgrid test
# the standard debug streams are put into the libdune
#noinst_LTLIBRARIES = libcommon.la
#libcommon_la_SOURCES = stdstreams.cc configparser.cc
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/..
subdirincludedir = $(includedir)/dune/foamgrid
subdirinclude_HEADERS = foamgrid.hh
include $(top_srcdir)/am/global-rules
#ifndef DUNE_FOAMGRID_HH
#define DUNE_FOAMGRID_HH
/** \file
* \brief The FoamGrid class
*/
#include <list>
#include <map>
#include <dune/common/collectivecommunication.hh>
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/common/grid.hh>
// Implementation classes
#include "foamgrid/foamgridvertex.hh"
#include "foamgrid/foamgridelements.hh"
// The components of the FoamGrid interface
#include "foamgrid/foamgridgeometry.hh"
#include "foamgrid/foamgridentity.hh"
#include "foamgrid/foamgridentitypointer.hh"
#include "foamgrid/foamgridintersectioniterators.hh"
#include "foamgrid/foamgridleveliterator.hh"
#include "foamgrid/foamgridleafiterator.hh"
#include "foamgrid/foamgridhierarchiciterator.hh"
#include "foamgrid/foamgridindexsets.hh"
namespace Dune {
// Forward declaration
class FoamGrid;
template<int codim>
class FoamGridLevelIteratorFactory;
template<int dim, int dimw>
struct FoamGridFamily
{
typedef GridTraits<
dim, // dim
dimw, // dimworld
Dune::FoamGrid,
FoamGridGeometry,
FoamGridEntity,
FoamGridEntityPointer,
FoamGridLevelIterator,
FoamGridLeafIntersectionIterator, // leaf intersection
FoamGridLevelIntersectionIterator, // level intersection
FoamGridLeafIntersectionIterator, // leaf intersection iterator
FoamGridLevelIntersectionIterator, // level intersection iterator
FoamGridHierarchicIterator,
FoamGridLeafIterator,
FoamGridLevelIndexSet< const FoamGrid >,
FoamGridLeafIndexSet< const FoamGrid >,
FoamGridGlobalIdSet< const FoamGrid >,
unsigned int, // global id type
FoamGridLocalIdSet< const FoamGrid >,
unsigned int, // local id type
CollectiveCommunication<FoamGrid>
> Traits;
};
//**********************************************************************
//
// --FoamGrid
//
//**********************************************************************
/** \brief [<em> provides \ref Dune::Grid </em>]
*
*/
class FoamGrid :
public GridDefaultImplementation <2, 3, double, FoamGridFamily<2,3> >
{
friend class FoamGridLevelIteratorFactory <0>;
friend class FoamGridLevelIteratorFactory <2>;
friend class FoamGridLevelIndexSet<const FoamGrid >;
friend class FoamGridLeafIndexSet<const FoamGrid >;
friend class FoamGridGlobalIdSet<const FoamGrid >;
friend class FoamGridLocalIdSet<const FoamGrid >;
friend class FoamGridHierarchicIterator<const FoamGrid >;
friend class FoamGridLevelIntersectionIterator<const FoamGrid >;
friend class FoamGridLeafIntersectionIterator<const FoamGrid >;
template<int codim, PartitionIteratorType pitype, class GridImp_>
friend class FoamGridLevelIterator;
template<int codim, PartitionIteratorType pitype, class GridImp_>
friend class FoamGridLeafIterator;
template <class GridType_>
friend class GridFactory;
template<int codim_, int dim_, class GridImp_>
friend class FoamGridEntity;
public:
//**********************************************************
// The Interface Methods
//**********************************************************
//! type of the used GridFamily for this grid
typedef FoamGridFamily<2,3> GridFamily;
//! the Traits
typedef FoamGridFamily<2,3>::Traits Traits;
//! The type used to store coordinates, inherited from the HostGrid
typedef double ctype;
/** \brief Constructor
*/
FoamGrid()
: leafIndexSet_(*this),
globalIdSet_(*this),
localIdSet_(*this)
{}
//! Desctructor
~FoamGrid()
{
// Delete level index sets
for (size_t i=0; i<levelIndexSets_.size(); i++)
if (levelIndexSets_[i])
delete (levelIndexSets_[i]);
}
//! return grid name
std::string name() const
{
return "FoamGrid";
}
//! Return maximum level defined in this grid. Levels are numbered
//! 0 ... maxlevel with 0 the coarsest level.
int maxLevel() const {
return vertices_.size()-1;;
}
//! Iterator to first entity of given codim on level
template<int codim>
typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
//! one past the end on this level
template<int codim>
typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
//! Iterator to first entity of given codim on level
template<int codim, PartitionIteratorType PiType>
typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
//! one past the end on this level
template<int codim, PartitionIteratorType PiType>
typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
//! Iterator to first leaf entity of given codim
template<int codim>
typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
return FoamGridLeafIterator<codim,All_Partition, const FoamGrid >(this);
}
//! one past the end of the sequence of leaf entities
template<int codim>
typename Traits::template Codim<codim>::LeafIterator leafend() const {
return FoamGridLeafIterator<codim,All_Partition, const FoamGrid >(this, true);
}
//! Iterator to first leaf entity of given codim
template<int codim, PartitionIteratorType PiType>
typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
return FoamGridLeafIterator<codim,PiType, const FoamGrid >(this);
}
//! one past the end of the sequence of leaf entities
template<int codim, PartitionIteratorType PiType>
typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
return FoamGridLeafIterator<codim,PiType, const FoamGrid >(this, true);
}
/** \brief Number of grid entities per level and codim
*/
int size (int level, int codim) const {
if (codim==0)
return elements_[level].size();
// if (codim==1)
// return edges_[level].size();
if (codim==2)
return vertices_[level].size();
return 0;
}
//! number of leaf entities per codim in this process
int size (int codim) const{
return leafIndexSet().size(codim);
}
//! number of entities per level, codim and geometry type in this process
int size (int level, GeometryType type) const {
return levelIndexSets_[level]->size(type);
}
//! number of leaf entities per codim and geometry type in this process
int size (GeometryType type) const
{
return leafIndexSet().size(type);
}
/** \brief Access to the GlobalIdSet */
const Traits::GlobalIdSet& globalIdSet() const{
return globalIdSet_;
}
/** \brief Access to the LocalIdSet */
const Traits::LocalIdSet& localIdSet() const{
return localIdSet_;
}
/** \brief Access to the LevelIndexSets */
const Traits::LevelIndexSet& levelIndexSet(int level) const
{
if (level<0 || level>maxLevel())
DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
return *levelIndexSets_[level];
}
/** \brief Access to the LeafIndexSet */
const Traits::LeafIndexSet& leafIndexSet() const
{
return leafIndexSet_;
}
/** @name Grid Refinement Methods */
/*@{*/
/** global refinement
*/
void globalRefine (int refCount)
{
DUNE_THROW(NotImplemented, "globalRefine!");
}
/** \brief Mark entity for refinement
*
* This only works for entities of codim 0.
* The parameter is currently ignored
*
* \return <ul>
* <li> true, if marking was succesfull </li>
* <li> false, if marking was not possible </li>
* </ul>
*/
bool mark(int refCount, const Traits::Codim<0>::EntityPointer & e)
{
return false;
}
/** \brief Return refinement mark for entity
*
* \return refinement mark (1,0,-1)
*/
int getMark(const Traits::Codim<0>::EntityPointer & e) const
{
return 0;
}
//! \todo Please doc me !
bool preAdapt() {
DUNE_THROW(NotImplemented, "preAdapt");
}
//! Triggers the grid refinement process
bool adapt()
{
DUNE_THROW(NotImplemented, "adapt");
}
/** \brief Clean up refinement markers */
void postAdapt() {
DUNE_THROW(NotImplemented, "postAdapt");
}
/*@}*/
/** \brief Size of the overlap on the leaf level */
unsigned int overlapSize(int codim) const {
return 0;
}
/** \brief Size of the ghost cell layer on the leaf level */
unsigned int ghostSize(int codim) const {
return 0;
}
/** \brief Size of the overlap on a given level */
unsigned int overlapSize(int level, int codim) const {
return 0;
}
/** \brief Size of the ghost cell layer on a given level */
unsigned int ghostSize(int level, int codim) const {
return 0;
}
#if 0
/** \brief Distributes this grid over the available nodes in a distributed machine
*
* \param minlevel The coarsest grid level that gets distributed
* \param maxlevel does currently get ignored
*/
void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
DUNE_THROW(NotImplemented, "FoamGrid::loadBalance()");
}
/** \brief The communication interface
* @param T: array class holding data associated with the entities
* @param P: type used to gather/scatter data in and out of the message buffer
* @param codim: communicate entites of given codim
* @param if: one of the predifined interface types, throws error if it is not implemented
* @param level: communicate for entities on the given level
*
* Implements a generic communication function sending an object of type P for each entity
* in the intersection of two processors. P has two methods gather and scatter that implement
* the protocol. Therefore P is called the "protocol class".
*/
template<class T, template<class> class P, int codim>
void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
/*! The new communication interface
communicate objects for all codims on a given level
*/
template<class DataHandle>
void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
{}
template<class DataHandle>
void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
{}
#endif
/** dummy collective communication */
const CollectiveCommunication& comm () const
{
return ccobj_;
}
// **********************************************************
// End of Interface Methods
// **********************************************************
private:
//! compute the grid indices and ids
void setIndices()
{
// //////////////////////////////////////////
// Create the index sets
// //////////////////////////////////////////
for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
FoamGridLevelIndexSet<const FoamGrid >* p
= new FoamGridLevelIndexSet<const FoamGrid >();
levelIndexSets_.push_back(p);
}
for (int i=0; i<=maxLevel(); i++)
if (levelIndexSets_[i])
levelIndexSets_[i]->update(*this, i);
//leafIndexSet_.update(*this);
#warning leafIndexSet_.update NOT called
// IdSets don't need updating
}
//! \todo Please doc me !
CollectiveCommunication ccobj_;
// Lists of vertices on each level
std::vector<std::list<FoamGridVertex> > vertices_;
// Lists of edges on each level
//std::vector<std::list<FoamGridEdge> > edges_;
// Lists of elements on each level
std::vector<std::list<FoamGridElement> > elements_;
//! Our set of level indices
std::vector<FoamGridLevelIndexSet<const FoamGrid>*> levelIndexSets_;
//! \todo Please doc me !
FoamGridLeafIndexSet<const FoamGrid > leafIndexSet_;
//! \todo Please doc me !
FoamGridGlobalIdSet<const FoamGrid > globalIdSet_;
//! \todo Please doc me !
FoamGridLocalIdSet<const FoamGrid > localIdSet_;
}; // end Class FoamGrid
namespace Capabilities
{
//! \todo Please doc me !
template<int codim>
struct hasEntity< FoamGrid, codim>
{
static const bool v = true;
};
//! \todo Please doc me !
template <>
struct isParallel< FoamGrid >
{
static const bool v = false;
};
//! \todo Please doc me !
template<>
struct hasHangingNodes< FoamGrid >
{
static const bool v = false;
};
//! \todo Please doc me !
template<>
struct isLevelwiseConforming< FoamGrid >
{
static const bool v = true;
};
//! \todo Please doc me !
template<>
struct isLeafwiseConforming< FoamGrid >
{
static const bool v = true;
};
}
template <int codim>
struct FoamGridLevelIteratorFactory {};
template <>
struct FoamGridLevelIteratorFactory<2>
{
template <Dune::PartitionIteratorType PiType>
static Dune::FoamGridLevelIterator<1,PiType, const Dune::FoamGrid>
lbegin(const Dune::FoamGrid* g, int level) {
return Dune::FoamGridLevelIterator<2,PiType, const Dune::FoamGrid>(const_cast<Dune::FoamGridVertex*>(g->vertices_[level].begin()));
}
template <Dune::PartitionIteratorType PiType>
static Dune::FoamGridLevelIterator<1,PiType, const Dune::FoamGrid>
lend(const Dune::FoamGrid* g, int level) {
return Dune::FoamGridLevelIterator<2,PiType, const Dune::FoamGrid>(const_cast<Dune::FoamGridVertex*>(g->vertices_[level].end()));
}
};
template <>
struct FoamGridLevelIteratorFactory<0>
{
template <Dune::PartitionIteratorType PiType>
static Dune::FoamGridLevelIterator<0,PiType, const Dune::FoamGrid>
lbegin(const Dune::FoamGrid* g, int level) {
return Dune::FoamGridLevelIterator<0,PiType, const Dune::FoamGrid>(g->elements_[level].begin());
}
template <Dune::PartitionIteratorType PiType>
static Dune::FoamGridLevelIterator<0,PiType, const Dune::FoamGrid>
lend(const Dune::FoamGrid* g, int level) {
return Dune::FoamGridLevelIterator<0,PiType, const Dune::FoamGrid>(g->elements_[level].end());
}
};
} // namespace Dune
template <int codim>
typename Dune::FoamGrid::Traits::template Codim<codim>::LevelIterator
Dune::FoamGrid::lbegin(int level) const
{
if (level<0 || level>maxLevel())
DUNE_THROW(Dune::GridError, "LevelIterator in nonexisting level " << level << " requested!");
return FoamGridLevelIteratorFactory<codim>::template lbegin<All_Partition>(this, level);
}
template <int codim>
typename Dune::FoamGrid::Traits::template Codim<codim>::LevelIterator
Dune::FoamGrid::lend(int level) const
{
if (level<0 || level>maxLevel())
DUNE_THROW(GridError, "LevelIterator in nonexisting level " << level << " requested!");
return FoamGridLevelIteratorFactory<codim>::template lend<All_Partition>(this, level);
}
template <int codim, Dune::PartitionIteratorType PiType>
typename Dune::FoamGrid::Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
Dune::FoamGrid::lbegin(int level) const
{
if (level<0 || level>maxLevel())
DUNE_THROW(Dune::GridError, "LevelIterator in nonexisting level " << level << " requested!");
return FoamGridLevelIteratorFactory<codim>::template lbegin<PiType>(this, level);
}
template <int codim, Dune::PartitionIteratorType PiType>
typename Dune::FoamGrid::Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
Dune::FoamGrid::lend(int level) const
{
if (level<0 || level>maxLevel())
DUNE_THROW(GridError, "LevelIterator in nonexisting level " << level << " requested!");
return FoamGridLevelIteratorFactory<codim>::template lend<PiType>(this, level);
}
#include <dune-foamgrid/foamgrid/foamgridfactory.hh>
#endif
foamgriddir = $(includedir)/dune/foamgrid/foamgrid
foamgrid_HEADERS = foamgridentitypointer.hh foamgridhierarchiciterator.hh \
foamgridleafiterator.hh foamgridentity.hh \
foamgridgeometry.hh foamgridindexsets.hh foamgridintersections.hh \
foamgridintersectioniterators.hh foamgridleveliterator.hh
include $(top_srcdir)/am/global-rules
#ifndef DUNE_FOAMGRID_ELEMENTS_HH
#define DUNE_FOAMGRID_ELEMENTS_HH
namespace Dune {
class FoamGridElement
{
public:
/** \brief The different ways to mark an element for grid changes */
enum MarkState { DO_NOTHING , COARSEN , REFINE };
FoamGridElement(int level, unsigned int id)
: id_(id), level_(level),
markState_(DO_NOTHING), isNew_(false)
{
sons_[0] = sons_[1] = NULL;
}
bool isLeaf() const {
DUNE_THROW(NotImplemented, "isLeaf()");
}
array<FoamGridElement*, 4> sons_;
FoamGridElement* father_;
FoamGridVertex* vertex_[3];
//! element number
unsigned int levelIndex_;
unsigned int leafIndex_;
/** \brief Unique and persistent id for elements */
unsigned int id_;
//! the level of the entity
int level_;
/** \brief Stores requests for refinement and coarsening */
MarkState markState_;
/** \brief This flag is set by adapt() if this element has been newly created. */
bool isNew_;
};
}
#endif
#ifndef DUNE_IDENTITYGRIDENTITY_HH
#define DUNE_IDENTITYGRIDENTITY_HH
/** \file
* \brief The FoamGridEntity class
*/
#include <dune/grid/common/referenceelements.hh>
namespace Dune {
// Forward declarations
template<int codim, int dim, class GridImp>
class FoamGridEntity;
template<int codim, class GridImp>
class FoamGridEntityPointer;
template<int codim, PartitionIteratorType pitype, class GridImp>
class FoamGridLevelIterator;
template<class GridImp>
class FoamGridLevelIntersectionIterator;
template<class GridImp>
class FoamGridLeafIntersectionIterator;
template<class GridImp>
class FoamGridHierarchicIterator;
template<int codim, int dim, class GridImp>
class FoamGridMakeableEntity :
public GridImp::template Codim<codim>::Entity
{
public:
typedef typename SelectType<codim==0, FoamGridElement, FoamGridVertex>::Type TargetType;
//! \todo Please doc me !
FoamGridMakeableEntity(const TargetType* target) :
GridImp::template Codim<codim>::Entity (FoamGridEntity<codim, dim, const GridImp>(target))
{}
//! \todo Please doc me !
void setToTarget(const TargetType* target) {
this->realEntity.setToTarget(target);
}
//! \todo Please doc me !
const TargetType* getTarget() {
return this->realEntity.target_;
}
};
//**********************************************************************
//
// --FoamGridEntity
// --Entity
//
/** \brief The implementation of entities in a FoamGrid
* \ingroup FoamGrid
*
* A Grid is a container of grid entities. An entity is parametrized by the codimension.
* An entity of codimension c in dimension d is a d-c dimensional object.
*
*/
template<int codim, int dim, class GridImp>
class FoamGridEntity :
public EntityDefaultImplementation <codim,dim,GridImp,FoamGridEntity>
{
friend class FoamGridMakeableEntity<codim,dim,GridImp>;
template <class GridImp_>
friend class FoamGridLevelIndexSet;
template <class GridImp_>
friend class FoamGridLeafIndexSet;
template <class GridImp_>
friend class FoamGridLocalIdSet;
template <class GridImp_>
friend class FoamGridGlobalIdSet;
template <class GridImp_, int EntityDim>
friend class IndexSetter;
friend class FoamGridEntityPointer<codim,GridImp>;
private:
typedef typename GridImp::ctype ctype;
// The codimension of this entitypointer wrt the host grid
enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
// EntityPointer to the equivalent entity in the host grid
typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
public:
typedef typename GridImp::template Codim<codim>::Geometry Geometry;
//! Constructor for an entity in a given grid level
FoamGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
hostEntity_(hostEntity),
identityGrid_(identityGrid),
geo_(0),
geoInFather_(0)
{}
//! \todo Please doc me !
FoamGridEntity(const FoamGridEntity& original) :
hostEntity_(original.hostEntity_),
identityGrid_(original.identityGrid_),
geo_(0),
geoInFather_(0)
{}
//! Destructor
~FoamGridEntity()
{
if (geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
}
//! \todo Please doc me !
FoamGridEntity& operator=(const FoamGridEntity& original)
{
if (this != &original)
{
if (geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
identityGrid_ = original.identityGrid_;
hostEntity_ = original.hostEntity_;
}
return *this;
}
//! level of this element
int level () const {
return hostEntity_->level();
}
/** \brief The partition type for parallel computing
*/
PartitionType partitionType () const {
return hostEntity_->partitionType();
}
/** Intra-element access to entities of codimension cc > codim. Return number of entities
* with codimension cc.
*/
template<int cc> int count () const{
return hostEntity_->template count<cc>();
}
//! geometry of this entity
const Geometry& geometry () const
{
if (geo_==0)
geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
return *geo_;
}
HostGridEntityPointer hostEntity_;
private:
//! \todo Please doc me !
void setToTarget(const HostGridEntityPointer& target)
{
if(geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
hostEntity_ = target;
}
const GridImp* identityGrid_;
//! the current geometry
mutable MakeableInterfaceObject<Geometry> *geo_;
mutable MakeableInterfaceObject<Geometry> *geoInFather_;
};
//***********************
//
// --FoamGridEntity
//
//***********************
/** \brief Specialization for codim-0-entities.
* \ingroup FoamGrid
*
* This class embodies the topological parts of elements of the grid.
* It has an extended interface compared to the general entity class.
* For example, Entities of codimension 0 allow to visit all neighbors.
*/
template<int dim, class GridImp>
class FoamGridEntity<0,dim,GridImp> :
public EntityDefaultImplementation<0,dim,GridImp, FoamGridEntity>
{
public:
typedef typename GridImp::template Codim<0>::Geometry Geometry;
typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
//! The Iterator over intersections on this level
typedef FoamGridLevelIntersectionIterator<GridImp> LevelIntersectionIterator;
//! The Iterator over intersections on the leaf level
typedef FoamGridLeafIntersectionIterator<GridImp> LeafIntersectionIterator;
//! Iterator over descendants of the entity
typedef FoamGridHierarchicIterator<GridImp> HierarchicIterator;
//! Constructor for an entity in a given grid level
FoamGridEntity(const FoamGridElement* hostEntity) :
geo_(0),
geoInFather_(0),
target_(hostEntity)
{}
//! \todo Please doc me !
FoamGridEntity(const FoamGridEntity& original) :
geo_(0),
geoInFather_(0),
target_(original.target_)
{}
//! Destructor
~FoamGridEntity()
{
if (geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
}
//! \todo Please doc me !
FoamGridEntity& operator=(const FoamGridEntity& original)
{
if (this != &original)
{
if (geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
target_ = original.target_;
}
return *this;
}
//! Level of this element
int level () const
{
return target_->level_;
}
/** \brief The partition type for parallel computing */
PartitionType partitionType () const {
return InteriorEntity;
}
//! Geometry of this entity
const Geometry& geometry () const
{
if (geo_==0)
{
assert(false);
//geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
}
return *geo_;
}
/** \brief Return the number of subEntities of codimension cc.
*/
template<int cc>
int count () const
{
dune_static_assert(0<=cc && cc<=2, "Only codimensions with 0 <= cc <= 2 are valid!");
return (cc==0) ? 1 : 3;
}
/** \brief Return index of sub entity with codim = cc and local number i
*/
int subLevelIndex (int i,unsigned int codim) const {
assert(i==0 || i==2);
return (codim==0)
? target_->levelIndex_
: target_->vertex_[i]->levelIndex_;
}
/** \brief Provide access to sub entity i of given codimension. Entities
* are numbered 0 ... count<cc>()-1
*/
template<int cc>
typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const{
assert(false);
//return FoamGridEntityPointer<cc,GridImp>(hostEntity_->template subEntity<cc>(i));
}
//! First level intersection
FoamGridLevelIntersectionIterator<GridImp> ilevelbegin () const{
assert(false);
//return FoamGridLevelIntersectionIterator<GridImp>(hostEntity_->ilevelbegin());
}
//! Reference to one past the last neighbor
FoamGridLevelIntersectionIterator<GridImp> ilevelend () const{
assert(false);
//return FoamGridLevelIntersectionIterator<GridImp>(hostEntity_->ilevelend());
}
//! First leaf intersection
FoamGridLeafIntersectionIterator<GridImp> ileafbegin () const{
assert(false);
// return FoamGridLeafIntersectionIterator<GridImp>(identityGrid_,
//hostEntity_->ileafbegin());
}
//! Reference to one past the last leaf intersection
FoamGridLeafIntersectionIterator<GridImp> ileafend () const{
assert(false);
// return FoamGridLeafIntersectionIterator<GridImp>(identityGrid_,
// hostEntity_->ileafend());
}
//! returns true if Entity has NO children
bool isLeaf() const {
return target_->isLeaf();
}
//! Inter-level access to father element on coarser grid.
//! Assumes that meshes are nested.
FoamGridEntityPointer<0,GridImp> father () const {
return FoamGridEntityPointer<0,GridImp>(target_->father_);
}
/** \brief Location of this element relative to the reference element element of the father.
* This is sufficient to interpolate all dofs in conforming case.
* Nonconforming may require access to neighbors of father and
* computations with local coordinates.
* On the fly case is somewhat inefficient since dofs are visited several times.
* If we store interpolation matrices, this is tolerable. We assume that on-the-fly
* implementation of numerical algorithms is only done for simple discretizations.
* Assumes that meshes are nested.
*/
const LocalGeometry& geometryInFather () const {
DUNE_THROW(NotImplemented, "geometryInFather");
// if (geoInFather_==0)
// geoInFather_ = new MakeableInterfaceObject<LocalGeometry>(hostEntity_->geometryInFather());
return *geoInFather_;
}
/** \brief Inter-level access to son elements on higher levels<=maxlevel.
* This is provided for sparsely stored nested unstructured meshes.
* Returns iterator to first son.
*/
FoamGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
{
//return FoamGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
}
//! Returns iterator to one past the last son
FoamGridHierarchicIterator<GridImp> hend (int maxLevel) const
{
//return FoamGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
}
// /////////////////////////////////////////
// Internal stuff
// /////////////////////////////////////////
//! \todo Please doc me !
void setToTarget(const FoamGridElement* target)
{
if(geo_!=0)
{
delete geo_;
geo_ = 0;
}
if (geoInFather_!=0)
{
delete geoInFather_;
geoInFather_ = 0;
}
target_ = target;
}
//! the current geometry
mutable MakeableInterfaceObject<Geometry> *geo_;
//! \todo Please doc me !
mutable MakeableInterfaceObject<LocalGeometry> *geoInFather_;
const FoamGridElement* target_;
private:
typedef typename GridImp::ctype ctype;
}; // end of FoamGridEntity codim = 0
} // namespace Dune
#endif
#ifndef DUNE_IDENTITYGRID_ENTITY_POINTER_HH
#define DUNE_IDENTITYGRID_ENTITY_POINTER_HH
/** \file
* \brief The FoamGridEntityPointer class
*/
namespace Dune {
/** Acts as a pointer to an entities of a given codimension.
*/
template<int codim, class GridImp>
class FoamGridEntityPointer
{
private:
enum { dim = GridImp::dimension };
typedef typename SelectType<codim==0, FoamGridElement, FoamGridVertex>::Type TargetType;
public:
//! export the type of the EntityPointer Implementation.
//! Necessary for the typeconversion between Iterators and EntityPointer
typedef FoamGridEntityPointer EntityPointerImp;
/** \brief Codimension of entity pointed to */
enum { codimension = codim };
typedef typename GridImp::template Codim<codim>::Entity Entity;
typedef FoamGridEntityPointer<codim,GridImp> Base;
//! Constructor from a FoamGrid entity
FoamGridEntityPointer (const FoamGridEntity<codim,dim,GridImp>& entity)
: virtualEntity_(entity.target_)
{}
FoamGridEntityPointer (const typename std::list<TargetType>::const_iterator& it)
: virtualEntity_(&(*it))
{}
//! equality
bool equals(const FoamGridEntityPointer<codim,GridImp>& i) const {
return virtualEntity_.getTarget() == i.virtualEntity_.getTarget();
}
//! dereferencing
Entity& dereference() const {
return virtualEntity_;
}
//! Make this pointer as small as possible
void compactify () {
//virtualEntity_.getTarget().compactify();
}
//! ask for level of entity
int level () const {
return virtualEntity_.level();
}
protected:
//! virtual entity
mutable FoamGridMakeableEntity<codim,dim,GridImp> virtualEntity_;
};
} // end namespace Dune
#endif
#ifndef DUNE_FOAMGRID_FACTORY_HH
#define DUNE_FOAMGRID_FACTORY_HH
/** \file
\brief The specialization of the generic GridFactory for FoamGrid
\author Oliver Sander
*/
#include <vector>
#include <map>
#include <dune/common/fvector.hh>
#include <dune/grid/common/gridfactory.hh>
#include <dune-foamgrid/foamgrid.hh>
namespace Dune {
/** \brief Specialization of the generic GridFactory for FoamGrid
*/
template <>
class GridFactory<FoamGrid>
: public GridFactoryInterface<FoamGrid> {
/** \brief Type used by the grid for coordinates */
typedef FoamGrid::ctype ctype;
typedef std::map<FieldVector<ctype,1>, unsigned int >::iterator VertexIterator;
public:
/** \brief Default constructor */
GridFactory()
: factoryOwnsGrid_(true),
vertexIndex_(0)
{
grid_ = new FoamGrid;
grid_->vertices_.resize(1);
grid_->elements_.resize(1);
}
/** \brief Constructor for a given grid object
If you already have your grid object constructed you can
hand it over using this constructor.
If you construct your factory class using this constructor
the pointer handed over to you by the method createGrid() is
the one you supplied here.
*/
GridFactory(FoamGrid* grid)
: factoryOwnsGrid_(false),
vertexIndex_(0)
{
grid_ = grid;
grid_->vertices_.resize(1);
grid_->elements_.resize(1);
}
/** \brief Destructor */
virtual ~GridFactory() {
if (grid_ && factoryOwnsGrid_)
delete grid_;
}
/** \brief Insert a vertex into the coarse grid */
virtual void insertVertex(const FieldVector<ctype,3>& pos) {
grid_->vertices_[0].push_back(FoamGridVertex(0,pos));
vertexArray_.push_back(&*grid_->vertices_[0].rbegin());
}
/** \brief Insert an element into the coarse grid
\param type The GeometryType of the new element
\param vertices The vertices of the new element, using the DUNE numbering
*/
virtual void insertElement(const GeometryType& type,
const std::vector<unsigned int>& vertices) {
assert(type.isTriangle());
FoamGridElement newElement(0,0);
newElement.vertex_[0] = vertexArray_[vertices[0]];
newElement.vertex_[1] = vertexArray_[vertices[1]];
newElement.vertex_[2] = vertexArray_[vertices[2]];
grid_->elements_[0].push_back(newElement);
}
/** \brief Finalize grid creation and hand over the grid
The receiver takes responsibility of the memory allocated for the grid
*/
virtual FoamGrid* createGrid() {
// Prevent a crash when this method is called twice in a row
// You never know who may do this...
if (grid_==NULL)
return NULL;
// Create the index sets
grid_->setIndices();
Dune::FoamGrid* tmp = grid_;
grid_ = NULL;
return tmp;
}
private:
// Initialize the grid structure in UG
void createBegin();
// Pointer to the grid being built
FoamGrid* grid_;
// True if the factory allocated the grid itself, false if the
// grid was handed over from the outside
bool factoryOwnsGrid_;
/** \brief Counter that creates the vertex indices */
unsigned int vertexIndex_;
std::vector<FoamGridVertex*> vertexArray_;
};
}
#endif
#ifndef DUNE_IDENTITYGRIDGEOMETRY_HH
#define DUNE_IDENTITYGRIDGEOMETRY_HH
/** \file
* \brief The FoamGridGeometry class and its specializations
*/
#include <dune/common/fmatrix.hh>
#include <dune/common/typetraits.hh>
namespace Dune {
template<int mydim, int coorddim, class GridImp>
class FoamGridGeometry :
//public GeometryDefaultImplementation <mydim, coorddim, GridImp, FoamGridGeometry>
public GenericGeometry::BasicGeometry<mydim, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,mydim,coorddim> >
{
typedef typename GenericGeometry::BasicGeometry<mydim, GenericGeometry::DefaultGeometryTraits<typename GridImp::ctype,mydim,coorddim> > Base;
public:
/** \brief Constructor with a geometry type and a set of corners */
void setup(const GeometryType& type, const std::vector<FieldVector<typename GridImp::ctype,2> >& coordinates)
{
// set up base class
// Yes, a strange way, but the only way, as BasicGeometry doesn't have a setup method
Base::operator=(Base(type,coordinates));
}
#if 0
private:
typedef typename GridImp::ctype ctype;
public:
// The codimension of this entitypointer wrt the host grid
enum {CodimInHostGrid = GridImp::HostGridType::dimension - mydim};
enum {DimensionWorld = GridImp::HostGridType::dimensionworld};
// select appropiate hostgrid geometry via typeswitch
typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::Geometry HostGridGeometryType;
typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::Geometry HostGridLocalGeometryType;
typedef typename SelectType<coorddim==DimensionWorld, HostGridGeometryType, HostGridLocalGeometryType>::Type HostGridGeometry;
/** Default constructor.
*/
FoamGridGeometry(const HostGridGeometry& hostGeometry)
: hostGeometry_(hostGeometry)
{
}
/** \brief Return the element type identifier
*/
GeometryType type () const {
return hostGeometry_.type();
}
//! return the number of corners of this element. Corners are numbered 0...n-1
int corners () const {
return hostGeometry_.corners();
}
//! access to coordinates of corners. Index is the number of the corner
const FieldVector<ctype, coorddim> corner (int i) const {
return hostGeometry_.corner(i);
}
/** \brief Maps a local coordinate within reference element to
* global coordinate in element */
FieldVector<ctype, coorddim> global (const FieldVector<ctype, mydim>& local) const{
return hostGeometry_.global(local);
}
/** \brief Maps a global coordinate within the element to a
* local coordinate in its reference element */
FieldVector<ctype, mydim> local (const FieldVector<ctype, coorddim>& global) const {
return hostGeometry_.local(global);
}
//! Returns true if the point is in the current element
bool checkInside(const FieldVector<ctype, mydim> &local) const {
return hostGeometry_.checkInside(local);
}
/**
*/
ctype integrationElement (const FieldVector<ctype, mydim>& local) const {
return hostGeometry_.integrationElement(local);
}
//! The Jacobian matrix of the mapping from the reference element to this element
const FieldMatrix<ctype, coorddim,mydim>& jacobianInverseTransposed (const FieldVector<ctype, mydim>& local) const {
return hostGeometry_.jacobianInverseTransposed(local);
}
const HostGridGeometry& hostGeometry_;
#endif
};
} // namespace Dune
#endif
#ifndef DUNE_IDENTITYGRIDHIERITERATOR_HH
#define DUNE_IDENTITYGRIDHIERITERATOR_HH
/** \file
* \brief The FoamGridHierarchicIterator class
*/
namespace Dune {
//**********************************************************************
//
/** \brief Iterator over the descendants of an entity.
* \ingroup FoamGrid
Mesh entities of codimension 0 ("elements") allow to visit all entities of
codimension 0 obtained through nested, hierarchic refinement of the entity.
Iteration over this set of entities is provided by the HierarchicIterator,
starting from a given entity.
*/
template<class GridImp>
class FoamGridHierarchicIterator :
public Dune::FoamGridEntityPointer <0,GridImp>
{
public:
typedef typename GridImp::template Codim<0>::Entity Entity;
typedef FoamGridEntity <0, GridImp::dimension, GridImp> FoamGridElement;
//! the default Constructor
explicit FoamGridHierarchicIterator(const GridImp* identityGrid, const FoamGridElement& startEntity, int maxLevel) :
FoamGridEntityPointer<0,GridImp>(identityGrid, startEntity.hostEntity_->hbegin(maxLevel)),
identityGrid_(identityGrid),
hostGridHierarchicIterator_(startEntity.hostEntity_->hbegin(maxLevel)),
hostGridHierarchicEndIterator_(startEntity.hostEntity_->hend(maxLevel))
{
this->virtualEntity_.setToTarget(hostGridHierarchicIterator_);
}
//! \todo Please doc me !
explicit FoamGridHierarchicIterator(const GridImp* identityGrid, const FoamGridElement& startEntity, int maxLevel, bool endDummy) :
FoamGridEntityPointer<0,GridImp>(identityGrid, startEntity.hostEntity_->hend(maxLevel)),
identityGrid_(identityGrid),
hostGridHierarchicIterator_(startEntity.hostEntity_->hbegin(maxLevel)),
hostGridHierarchicEndIterator_(startEntity.hostEntity_->hend(maxLevel))
{}
//! \todo Please doc me !
void increment()
{
++hostGridHierarchicIterator_;
this->virtualEntity_.setToTarget(hostGridHierarchicIterator_);
}
private:
// Type of the corresponding HierarchicIterator in the host grid
typedef typename GridImp::HostGridType::template Codim<0>::Entity::HierarchicIterator HostGridHierarchicIterator;
enum {dim = GridImp::HostGridType::dimension};
// The level index of the host entity that we are pointing to
//! \todo Please doc me !
unsigned int hostLevelIndex() const {
return identityGrid_->hostgrid_->levelIndexSet(hostGridHierarchicIterator_.level()).index(*hostGridHierarchicIterator_);
}
const GridImp* identityGrid_;
HostGridHierarchicIterator hostGridHierarchicIterator_;
HostGridHierarchicIterator hostGridHierarchicEndIterator_;
};
} // end namespace Dune
#endif
#ifndef DUNE_IDENTITYGRID_INDEXSETS_HH
#define DUNE_IDENTITYGRID_INDEXSETS_HH
/** \file
* \brief The index and id sets for the FoamGrid class
*/
#include <vector>
namespace Dune {
/** \todo Take the index types from the host grid */
template<class GridImp>
class FoamGridLevelIndexSet :
public IndexSet<GridImp,FoamGridLevelIndexSet<GridImp> >
{
public:
//! get index of an entity
template<int codim>
int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const
{
return grid_->getRealImplementation(e).levelIndex();
}
//! get index of subEntity of a codim 0 entity
int subIndex (const typename GridImp::Traits::template Codim<0>::Entity& e, int i, int codim) const
{
return grid_->getRealImplementation(e).subLevelIndex(i,codim);
}
//! get number of entities of given codim, type and on this level
int size (int codim) const {
return grid_->size(level_,codim);
}
//! get number of entities of given codim, type and on this level
int size (GeometryType type) const
{
return grid_->size(level_,type);
}
/** \brief Deliver all geometry types used in this grid */
const std::vector<GeometryType>& geomTypes (int codim) const
{
return myTypes_[codim];
}
/** \brief Return true if the given entity is contained in the index set */
template<class EntityType>
bool contains (const EntityType& e) const
{
DUNE_THROW(NotImplemented, "contains()");
}
/** \brief Set up the index set */
void update(const GridImp& grid, int level)
{
grid_ = &grid;
level_ = level;
// ///////////////////////////////
// Init the element indices
// ///////////////////////////////
numElements_ = 0;
std::list<FoamGridElement>::const_iterator eIt;
for (eIt = grid_->elements_[level_].begin(); eIt!=grid_->elements_[level_].end(); ++eIt)
/** \todo Remove this const cast */
*const_cast<unsigned int*>(&(eIt->levelIndex_)) = numElements_++;
// //////////////////////////////
// Init the vertex indices
// //////////////////////////////
numVertices_ = 0;
std::list<FoamGridVertex>::const_iterator vIt;
for (vIt = grid_->vertices_[level_].begin(); vIt!=grid_->vertices_[level_].end(); ++vIt)
/** \todo Remove this const cast */
*const_cast<unsigned int*>(&(vIt->levelIndex_)) = numVertices_++;
// ///////////////////////////////////////////////
// Update the list of geometry types present
// ///////////////////////////////////////////////
if (numElements_>0) {
myTypes_[0].resize(1);
myTypes_[0][0] = GeometryType(1);
} else
myTypes_[0].resize(0);
if (numVertices_>0) {
myTypes_[1].resize(1);
myTypes_[1][0] = GeometryType(0);
} else
myTypes_[1].resize(0);
}
GridImp* grid_;
int level_;
int numElements_;
int numEdges_;
int numVertices_;
/** \brief The GeometryTypes present for each codim */
std::vector<GeometryType> myTypes_[3];
};
template<class GridImp>
class FoamGridLeafIndexSet :
public IndexSet<GridImp,FoamGridLeafIndexSet<GridImp> >
{
public:
//! constructor stores reference to a grid and level
FoamGridLeafIndexSet (const GridImp& grid)
: grid_(&grid)
{}
//! get index of an entity
/*
We use the RemoveConst to extract the Type from the mutable class,
because the const class is not instantiated yet.
*/
template<int codim>
int index (const typename remove_const<GridImp>::type::template Codim<codim>::Entity& e) const
{
return grid_.getRealImplementation(e).leafIndex();
}
//! get index of subEntity of a codim 0 entity
/*
We use the RemoveConst to extract the Type from the mutable class,
because the const class is not instantiated yet.
*/
int subIndex (const typename remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e,
int i,
int codim) const
{
return grid_.getRealImplementation(e).subLeafIndex(i,codim);
}
//! get number of entities of given type
int size (GeometryType type) const
{
if (type.isVertex()) {
return numVertices_;
} else if (type.isLine()) {
return numEdges_;
} else if (type.dim()==2)
return numElements_;
return 0;
}
//! get number of entities of given codim
int size (int codim) const
{
if (codim==2)
return numVertices_;
if (codim==1)
return numEdges_;
if (codim==0)
return numElements_;
return 0;
}
/** \brief Deliver all geometry types used in this grid */
const std::vector<GeometryType>& geomTypes (int codim) const
{
return myTypes_[codim];
}
/** \brief Return true if the given entity is contained in the index set */
template<class EntityType>
bool contains (const EntityType& e) const
{
DUNE_THROW(NotImplemented, "contains");
}
/** Recompute the leaf numbering */
void update(const GridImp& grid)
{
#if 0
// ///////////////////////////////
// Init the element indices
// ///////////////////////////////
numElements_ = 0;
typename GridImp::Traits::template Codim<0>::LeafIterator eIt = grid_.template leafbegin<0>();
typename GridImp::Traits::template Codim<0>::LeafIterator eEndIt = grid_.template leafend<0>();
for (; eIt!=eEndIt; ++eIt)
grid_.getRealImplementation(*eIt).target_->leafIndex_ = numElements_++;
// //////////////////////////////
// Init the vertex indices
// //////////////////////////////
numVertices_ = 0;
for (int i=grid_.maxLevel(); i>=0; i--) {
std::list<FoamGridVertex>::const_iterator vIt;
for (vIt = grid_.vertices[i].begin(); vIt!=grid_.vertices[i].end(); ++vIt) {
/** \todo Remove the const casts */
if (vIt->isLeaf())
const_cast<OneDEntityImp<0>*>(vIt)->leafIndex_ = numVertices_++;
else
const_cast<OneDEntityImp<0>*>(vIt)->leafIndex_ = vIt->son_->leafIndex_;
}
}
// ///////////////////////////////////////////////
// Update the list of geometry types present
// ///////////////////////////////////////////////
if (numElements_>0) {
myTypes_[0].resize(1);
myTypes_[0][0] = GeometryType(1);
} else
myTypes_[0].resize(0);
if (numVertices_>0) {
myTypes_[1].resize(1);
myTypes_[1][0] = GeometryType(0);
} else
myTypes_[1].resize(0);
#endif
}
GridImp* grid_;
int numElements_;
int numEdges_;
int numVertices_;
/** \brief The GeometryTypes present for each codim */
std::vector<GeometryType> myTypes_[3];
};
template <class GridImp>
class FoamGridGlobalIdSet :
public IdSet<GridImp,FoamGridGlobalIdSet<GridImp>, unsigned int>
{
public:
//! constructor stores reference to a grid
FoamGridGlobalIdSet (const GridImp& g) : grid_(&g) {}
//! define the type used for persistent indices
typedef unsigned int IdType;
//! get id of an entity
/*
We use the remove_const to extract the Type from the mutable class,
because the const class is not instantiated yet.
*/
template<int cd>
IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
{
return grid_.getRealImplementation(e).globalId();
}
//! get id of subEntity
/*
We use the remove_const to extract the Type from the mutable class,
because the const class is not instantiated yet.
*/
IdType subId (const typename remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e, int i, int codim) const
{
return grid_.getRealImplementation(e).subId(i,codim);
}
/** \todo Should be private */
void update() {}
const GridImp* grid_;
};
template<class GridImp>
class FoamGridLocalIdSet :
public IdSet<GridImp,FoamGridLocalIdSet<GridImp>, unsigned int>
{
public:
//! define the type used for persistent local ids
typedef unsigned int IdType;
//! constructor stores reference to a grid
FoamGridLocalIdSet (const GridImp& g) : grid_(&g) {}
//! get id of an entity
/*
We use the remove_const to extract the Type from the mutable class,
because the const class is not instantiated yet.
*/
template<int cd>
IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
{
// Return id of the host entity
return grid_.getRealImplementation(e).globalId();
}
//! get id of subEntity
/*
* We use the remove_const to extract the Type from the mutable class,
* because the const class is not instantiated yet.
*/
IdType subId (const typename remove_const<GridImp>::type::template Codim<0>::Entity& e, int i, int codim) const
{
return grid_.getRealImplementation(e).subId(i,codim);
}
/** \todo Should be private */
void update() {}
const GridImp* grid_;
};
} // namespace Dune
#endif
#ifndef DUNE_IDENTITYGRID_INTERSECTIONITERATOR_HH
#define DUNE_IDENTITYGRID_INTERSECTIONITERATOR_HH
/** \file
* \brief The FoamGridLeafIntersectionIterator and FoamGridLevelIntersectionIterator classes
*/
namespace Dune {
/** \brief Iterator over all element neighbors
* \ingroup FoamGrid
* Mesh entities of codimension 0 ("elements") allow to visit all neighbors, where
* a neighbor is an entity of codimension 0 which has a common entity of codimension 1
* These neighbors are accessed via a IntersectionIterator. This allows the implement
* non-matching meshes. The number of neighbors may be different from the number
* of an element!
*/
template<class GridImp>
class FoamGridLeafIntersectionIterator
{
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
// The type used to store coordinates
typedef typename GridImp::ctype ctype;
typedef typename GridImp::HostGridType::template Codim<0>::Entity::LeafIntersectionIterator HostLeafIntersectionIterator;
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;
typedef Dune::Intersection<const GridImp, Dune::FoamGridLeafIntersectionIterator> Intersection;
FoamGridLeafIntersectionIterator(const GridImp* identityGrid,
const HostLeafIntersectionIterator& hostIterator)
: selfLocal_(NULL), neighborLocal_(NULL), intersectionGlobal_(NULL),
identityGrid_(identityGrid),
hostIterator_(hostIterator)
{}
//! The Destructor
~FoamGridLeafIntersectionIterator() {};
//! equality
bool equals(const FoamGridLeafIntersectionIterator<GridImp>& other) const {
return hostIterator_ == other.hostIterator_;
}
//! prefix increment
void increment() {
++hostIterator_;
// Delete intersection geometry objects, if present
if (intersectionGlobal_ != NULL) {
delete intersectionGlobal_;
intersectionGlobal_ = NULL;
}
if (selfLocal_ != NULL) {
delete selfLocal_;
selfLocal_ = NULL;
}
if (neighborLocal_ != NULL) {
delete neighborLocal_;
neighborLocal_ = NULL;
}
}
//! \brief dereferencing
const Intersection & dereference() const {
return reinterpret_cast<const Intersection&>(*this);
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->inside());
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->outside());
}
//! return true if intersection is with boundary.
bool boundary () const {
return hostIterator_->boundary();
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return hostIterator_->neighbor();
}
//! return information about the Boundary
int boundaryId () const {
return hostIterator_->boundaryId();
}
//! Return true if this is a conforming intersection
bool conforming () const {
return hostIterator_->conforming();
}
//! Geometry type of an intersection
GeometryType type () const {
return hostIterator_->type();
}
//! 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.
const LocalGeometry& geometryInInside () const {
if (selfLocal_ == NULL)
selfLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->geometryInInside());
return *selfLocal_;
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
const LocalGeometry& geometryInOutside () const {
if (neighborLocal_ == NULL)
neighborLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->geometryInOutside());
return *neighborLocal_;
}
//! 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.
const Geometry& geometry () const {
if (intersectionGlobal_ == NULL)
intersectionGlobal_ = new MakeableInterfaceObject<Geometry>(hostIterator_->geometry());
return *intersectionGlobal_;
}
//! local number of codim 1 entity in self where intersection is contained in
int indexInInside () const {
return hostIterator_->indexInInside();
}
//! local number of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const {
return hostIterator_->indexInOutside();
}
//! return outer normal
FieldVector<ctype, GridImp::dimensionworld> outerNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->outerNormal(local);
}
//! return outer normal multiplied by the integration element
FieldVector<ctype, GridImp::dimensionworld> integrationOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->integrationOuterNormal(local);
}
//! return unit outer normal
FieldVector<ctype, GridImp::dimensionworld> unitOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->unitOuterNormal(local);
}
private:
//**********************************************************
// private methods
//**********************************************************
//! pointer to element holding the selfLocal and selfGlobal information.
//! This element is created on demand.
mutable MakeableInterfaceObject<LocalGeometry>* selfLocal_;
mutable MakeableInterfaceObject<LocalGeometry>* neighborLocal_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable MakeableInterfaceObject<Geometry>* intersectionGlobal_;
const GridImp* identityGrid_;
HostLeafIntersectionIterator hostIterator_;
};
//! \todo Please doc me !
template<class GridImp>
class FoamGridLevelIntersectionIterator
{
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
// The type used to store coordinates
typedef typename GridImp::ctype ctype;
typedef typename GridImp::HostGridType::template Codim<0>::Entity::LevelIntersectionIterator HostLevelIntersectionIterator;
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;
typedef Dune::Intersection<const GridImp, Dune::FoamGridLevelIntersectionIterator> Intersection;
FoamGridLevelIntersectionIterator(const GridImp* identityGrid,
const HostLevelIntersectionIterator& hostIterator)
: selfLocal_(NULL), neighborLocal_(NULL), intersectionGlobal_(NULL),
identityGrid_(identityGrid), hostIterator_(hostIterator)
{}
//! equality
bool equals(const FoamGridLevelIntersectionIterator<GridImp>& other) const {
return hostIterator_ == other.hostIterator_;
}
//! prefix increment
void increment() {
++hostIterator_;
// Delete intersection geometry objects, if present
if (intersectionGlobal_ != NULL) {
delete intersectionGlobal_;
intersectionGlobal_ = NULL;
}
if (selfLocal_ != NULL) {
delete selfLocal_;
selfLocal_ = NULL;
}
if (neighborLocal_ != NULL) {
delete neighborLocal_;
neighborLocal_ = NULL;
}
}
//! \brief dereferencing
const Intersection & dereference() const {
return reinterpret_cast<const Intersection&>(*this);
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->inside());
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->outside());
}
/** \brief return true if intersection is with boundary.
*/
bool boundary () const {
return hostIterator_->boundary();
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return hostIterator_->neighbor();
}
//! return information about the Boundary
int boundaryId () const {
return hostIterator_->boundaryId();
}
//! Return true if this is a conforming intersection
bool conforming () const {
return hostIterator_->conforming();
}
//! Geometry type of an intersection
GeometryType type () const {
return hostIterator_->type();
}
//! 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.
const LocalGeometry& geometryInInside () const {
if (selfLocal_ == NULL)
selfLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->geometryInInside());
return *selfLocal_;
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
const LocalGeometry& geometryInOutside () const {
if (neighborLocal_ == NULL)
neighborLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->geometryInOutside());
return *neighborLocal_;
}
//! 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.
const Geometry& geometry () const {
if (intersectionGlobal_ == NULL)
intersectionGlobal_ = new MakeableInterfaceObject<Geometry>(hostIterator_->geometry());
return *intersectionGlobal_;
}
//! local number of codim 1 entity in self where intersection is contained in
int indexInInside () const {
return hostIterator_->indexInInside();
}
//! local number of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const {
return hostIterator_->indexInOutside();
}
//! return outer normal
FieldVector<ctype, dimworld> outerNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->outerNormal(local);
}
//! return outer normal multiplied by the integration element
FieldVector<ctype, dimworld> integrationOuterNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->integrationOuterNormal(local);
}
//! return unit outer normal
FieldVector<ctype, dimworld> unitOuterNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->unitOuterNormal(local);
}
private:
//! pointer to element holding the selfLocal and selfGlobal information.
//! This element is created on demand.
mutable MakeableInterfaceObject<LocalGeometry>* selfLocal_;
mutable MakeableInterfaceObject<LocalGeometry>* neighborLocal_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable MakeableInterfaceObject<Geometry>* intersectionGlobal_;
const GridImp* identityGrid_;
HostLevelIntersectionIterator hostIterator_;
};
} // namespace Dune
#endif
#ifndef DUNE_IDENTITYGRID_INTERSECTIONITERATOR_HH
#define DUNE_IDENTITYGRID_INTERSECTIONITERATOR_HH
/** \file
* \brief The FoamGridLeafIntersectionIterator and FoamGridLevelIntersectionIterator classes
*/
namespace Dune {
/** \brief Iterator over all element neighbors
* \ingroup FoamGrid
* Mesh entities of codimension 0 ("elements") allow to visit all neighbors, where
* a neighbor is an entity of codimension 0 which has a common entity of codimension 1
* These neighbors are accessed via a IntersectionIterator. This allows the implement
* non-matching meshes. The number of neighbors may be different from the number
* of an element!
*/
template<class GridImp>
class FoamGridLeafIntersectionIterator
{
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
// The type used to store coordinates
typedef typename GridImp::ctype ctype;
typedef typename GridImp::HostGridType::template Codim<0>::Entity::LeafIntersectionIterator HostLeafIntersectionIterator;
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;
typedef Dune::Intersection<const GridImp, Dune::FoamGridLeafIntersectionIterator> Intersection;
FoamGridLeafIntersectionIterator(const GridImp* identityGrid,
const HostLeafIntersectionIterator& hostIterator)
: selfLocal_(NULL), neighborLocal_(NULL), intersectionGlobal_(NULL),
identityGrid_(identityGrid),
hostIterator_(hostIterator)
{}
//! The Destructor
~FoamGridLeafIntersectionIterator() {};
//! equality
bool equals(const FoamGridLeafIntersectionIterator<GridImp>& other) const {
return hostIterator_ == other.hostIterator_;
}
//! prefix increment
void increment() {
++hostIterator_;
// Delete intersection geometry objects, if present
if (intersectionGlobal_ != NULL) {
delete intersectionGlobal_;
intersectionGlobal_ = NULL;
}
if (selfLocal_ != NULL) {
delete selfLocal_;
selfLocal_ = NULL;
}
if (neighborLocal_ != NULL) {
delete neighborLocal_;
neighborLocal_ = NULL;
}
}
//! \brief dereferencing
const Intersection & dereference() const {
return reinterpret_cast<const Intersection&>(*this);
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->inside());
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->outside());
}
//! return true if intersection is with boundary.
bool boundary () const {
return hostIterator_->boundary();
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return hostIterator_->neighbor();
}
//! return information about the Boundary
int boundaryId () const {
return hostIterator_->boundaryId();
}
//! Return true if this is a conforming intersection
bool conforming () const {
return hostIterator_->conforming();
}
//! Geometry type of an intersection
GeometryType type () const {
return hostIterator_->type();
}
//! 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.
const LocalGeometry& intersectionSelfLocal () const {
if (selfLocal_ == NULL)
selfLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->intersectionSelfLocal());
return *selfLocal_;
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
const LocalGeometry& intersectionNeighborLocal () const {
if (neighborLocal_ == NULL)
neighborLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->intersectionNeighborLocal());
return *neighborLocal_;
}
//! 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.
const Geometry& intersectionGlobal () const {
if (intersectionGlobal_ == NULL)
intersectionGlobal_ = new MakeableInterfaceObject<Geometry>(hostIterator_->intersectionGlobal());
return *intersectionGlobal_;
}
//! local number of codim 1 entity in self where intersection is contained in
int indexInInside () const {
return hostIterator_->indexInInside();
}
//! local number of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const {
return hostIterator_->indexInOutside();
}
//! return outer normal
FieldVector<ctype, GridImp::dimensionworld> outerNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->outerNormal(local);
}
//! return outer normal multiplied by the integration element
FieldVector<ctype, GridImp::dimensionworld> integrationOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->integrationOuterNormal(local);
}
//! return unit outer normal
FieldVector<ctype, GridImp::dimensionworld> unitOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
return hostIterator_->unitOuterNormal(local);
}
private:
//**********************************************************
// private methods
//**********************************************************
//! pointer to element holding the selfLocal and selfGlobal information.
//! This element is created on demand.
mutable MakeableInterfaceObject<LocalGeometry>* selfLocal_;
mutable MakeableInterfaceObject<LocalGeometry>* neighborLocal_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable MakeableInterfaceObject<Geometry>* intersectionGlobal_;
const GridImp* identityGrid_;
HostLeafIntersectionIterator hostIterator_;
};
//! \todo Please doc me !
template<class GridImp>
class FoamGridLevelIntersectionIterator
{
enum {dim=GridImp::dimension};
enum {dimworld=GridImp::dimensionworld};
// The type used to store coordinates
typedef typename GridImp::ctype ctype;
typedef typename GridImp::HostGridType::template Codim<0>::Entity::LevelIntersectionIterator HostLevelIntersectionIterator;
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;
typedef Dune::Intersection<const GridImp, Dune::FoamGridLevelIntersectionIterator> Intersection;
FoamGridLevelIntersectionIterator(const GridImp* identityGrid,
const HostLevelIntersectionIterator& hostIterator)
: selfLocal_(NULL), neighborLocal_(NULL), intersectionGlobal_(NULL),
identityGrid_(identityGrid), hostIterator_(hostIterator)
{}
//! equality
bool equals(const FoamGridLevelIntersectionIterator<GridImp>& other) const {
return hostIterator_ == other.hostIterator_;
}
//! prefix increment
void increment() {
++hostIterator_;
// Delete intersection geometry objects, if present
if (intersectionGlobal_ != NULL) {
delete intersectionGlobal_;
intersectionGlobal_ = NULL;
}
if (selfLocal_ != NULL) {
delete selfLocal_;
selfLocal_ = NULL;
}
if (neighborLocal_ != NULL) {
delete neighborLocal_;
neighborLocal_ = NULL;
}
}
//! \brief dereferencing
const Intersection & dereference() const {
return reinterpret_cast<const Intersection&>(*this);
}
//! return EntityPointer to the Entity on the inside of this intersection
//! (that is the Entity where we started this Iterator)
EntityPointer inside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->inside());
}
//! return EntityPointer to the Entity on the outside of this intersection
//! (that is the neighboring Entity)
EntityPointer outside() const {
return FoamGridEntityPointer<0,GridImp> (identityGrid_, hostIterator_->outside());
}
/** \brief return true if intersection is with boundary.
*/
bool boundary () const {
return hostIterator_->boundary();
}
//! return true if across the edge an neighbor on this level exists
bool neighbor () const {
return hostIterator_->neighbor();
}
//! return information about the Boundary
int boundaryId () const {
return hostIterator_->boundaryId();
}
//! Return true if this is a conforming intersection
bool conforming () const {
return hostIterator_->conforming();
}
//! Geometry type of an intersection
GeometryType type () const {
return hostIterator_->type();
}
//! 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.
const LocalGeometry& intersectionSelfLocal () const {
if (selfLocal_ == NULL)
selfLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->intersectionSelfLocal());
return *selfLocal_;
}
//! intersection of codimension 1 of this neighbor with element where iteration started.
//! Here returned element is in LOCAL coordinates of neighbor
const LocalGeometry& intersectionNeighborLocal () const {
if (neighborLocal_ == NULL)
neighborLocal_ = new MakeableInterfaceObject<LocalGeometry>(hostIterator_->intersectionNeighborLocal());
return *neighborLocal_;
}
//! 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.
const Geometry& intersectionGlobal () const {
if (intersectionGlobal_ == NULL)
intersectionGlobal_ = new MakeableInterfaceObject<Geometry>(hostIterator_->intersectionGlobal());
return *intersectionGlobal_;
}
//! local number of codim 1 entity in self where intersection is contained in
int indexInInside () const {
return hostIterator_->indexInInside();
}
//! local number of codim 1 entity in neighbor where intersection is contained
int indexInOutside () const {
return hostIterator_->indexInOutside();
}
//! return outer normal
FieldVector<ctype, dimworld> outerNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->outerNormal(local);
}
//! return outer normal multiplied by the integration element
FieldVector<ctype, dimworld> integrationOuterNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->integrationOuterNormal(local);
}
//! return unit outer normal
FieldVector<ctype, dimworld> unitOuterNormal (const FieldVector<ctype, dim-1>& local) const {
return hostIterator_->unitOuterNormal(local);
}
private:
//! pointer to element holding the selfLocal and selfGlobal information.
//! This element is created on demand.
mutable MakeableInterfaceObject<LocalGeometry>* selfLocal_;
mutable MakeableInterfaceObject<LocalGeometry>* neighborLocal_;
//! pointer to element holding the neighbor_global and neighbor_local
//! information.
mutable MakeableInterfaceObject<Geometry>* intersectionGlobal_;
const GridImp* identityGrid_;
HostLevelIntersectionIterator hostIterator_;
};
} // namespace Dune
#endif
#ifndef DUNE_IDENTITYGRIDLEAFITERATOR_HH
#define DUNE_IDENTITYGRIDLEAFITERATOR_HH
/** \file
* \brief The FoamGridLeafIterator class
*/
namespace Dune {
/** \brief Iterator over all entities of a given codimension and level of a grid.
* \ingroup FoamGrid
*/
template<int codim, PartitionIteratorType pitype, class GridImp>
class FoamGridLeafIterator :
public Dune::FoamGridEntityPointer <codim,GridImp>
{
private:
enum {dim = GridImp::dimension};
public:
//! \todo Please doc me !
explicit FoamGridLeafIterator(const GridImp* identityGrid) :
FoamGridEntityPointer<codim,GridImp>(identityGrid, identityGrid->hostgrid_->template leafbegin<codim>()),
hostGridLeafIterator_(identityGrid->hostgrid_->template leafbegin<codim>()),
hostGridLeafEndIterator_(identityGrid->hostgrid_->template leafend<codim>())
{
this->virtualEntity_.setToTarget(hostGridLeafIterator_);
}
/** \brief Constructor which create the end iterator
* \param endDummy Here only to distinguish it from the other constructor
*/
explicit FoamGridLeafIterator(const GridImp* identityGrid, bool endDummy) :
FoamGridEntityPointer<codim,GridImp>(identityGrid, identityGrid->hostgrid_->template leafend<codim>()),
hostGridLeafIterator_(identityGrid->hostgrid_->template leafbegin<codim>()),
hostGridLeafEndIterator_(identityGrid->hostgrid_->template leafend<codim>())
{
}
//! prefix increment
void increment() {
++hostGridLeafIterator_;
this->virtualEntity_.setToTarget(hostGridLeafIterator_);
}
private:
// /////////////////////////////////////
// Data members
// /////////////////////////////////////
// LevelIterator to the equivalent entity in the host grid
typedef typename GridImp::HostGridType::template Codim<codim>::LeafIterator HostGridLeafIterator;
//! \todo Please doc me !
HostGridLeafIterator hostGridLeafIterator_;
//! \todo Please doc me !
HostGridLeafIterator hostGridLeafEndIterator_;
};
} // namespace Dune
#endif
#ifndef DUNE_FOAMGRID_LEVELITERATOR_HH
#define DUNE_FOAMGRID_LEVELITERATOR_HH
/** \file
* \brief The FoamGridLevelIterator class and its specializations
*/
namespace Dune {
//**********************************************************************
//
// --FoamGridLevelIterator
/** \brief Iterator over all entities of a given codimension and level of a grid.
* \ingroup FoamGrid
*/
template<int codim, PartitionIteratorType pitype, class GridImp>
class FoamGridLevelIterator :
public Dune::FoamGridEntityPointer <codim,GridImp>
{
private:
typedef typename SelectType<codim==0, FoamGridElement, FoamGridVertex>::Type TargetType;
public:
//! Constructor
explicit FoamGridLevelIterator(const typename std::list<TargetType>::const_iterator& it)
: FoamGridEntityPointer<codim,GridImp>(it),
levelIterator_(it)
{
this->virtualEntity_.setToTarget(&(*levelIterator_));
}
//! prefix increment
void increment() {
++levelIterator_;
this->virtualEntity_.setToTarget(&(*levelIterator_));
}
private:
//! \todo Please doc me !
typename std::list<TargetType>::const_iterator levelIterator_;
};
} // namespace Dune
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment