Loading...
Searching...
No Matches
extractor.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-dune-grid-glue-exception
/*
* Filename: extractor.hh
* Version: 1.0
* Created on: Oct 05, 2009
* Author: Christian Engwer
* ---------------------------------
* Project: dune-grid-glue
* Description: base class for all grid extractors
*
*/
#ifndef DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
#define DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
#include <vector>
#include <map>
#include <algorithm>
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/common/version.hh>
#include <dune/grid/common/geometry.hh>
#include <dune/grid/common/grid.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/geometry/multilineargeometry.hh>
namespace Dune {
namespace GridGlue {
template<typename GV, int cd>
class Extractor
{
public:
static constexpr auto dimworld = GV::dimensionworld;
static constexpr auto dim = GV::dimension;
static constexpr auto codim = cd;
static constexpr int cube_corners = 1 << (dim-codim);
typedef GV GridView;
typedef typename GridView::Grid Grid;
typedef typename GV::Grid::ctype ctype;
typedef Dune::FieldVector<ctype, dimworld> Coords;
typedef Dune::FieldVector<ctype, dim> LocalCoords;
typedef typename GV::Traits::template Codim<dim>::Entity Vertex;
typedef typename Vertex::EntitySeed VertexSeed;
typedef typename GV::Traits::template Codim<0>::Entity Element;
typedef typename Element::EntitySeed ElementSeed;
typedef std::vector<unsigned int> VertexVector;
using CellMapper = MultipleCodimMultipleGeomTypeMapper<GridView>;
// typedef typename CellMapper::IndexType IndexType;
typedef int IndexType;
public:
// transformations
typedef Dune::MultiLinearGeometry<ctype, dim-codim, dimworld> Geometry;
typedef Dune::MultiLinearGeometry<ctype, dim-codim, dim> LocalGeometry;
protected:
/************************** PRIVATE SUBCLASSES **********************/
struct CornerInfo
{
unsigned int idx : 28;
unsigned int num : 4;
};
struct CoordinateInfo
{
CoordinateInfo()
{}
CoordinateInfo(unsigned int index_, IndexType vtxindex_)
: vtxindex(vtxindex_), index(index_)
{}
IndexType vtxindex;
Coords coord;
unsigned int index;
};
struct VertexInfo
{
VertexInfo(unsigned int idx_, const Vertex& p_) : idx(idx_), p(p_.seed())
{}
unsigned int idx;
VertexSeed p;
};
struct ElementInfo
{
ElementInfo(unsigned int idx_, const Element& p_, unsigned int f_) : idx(idx_), faces(f_), p(p_.seed())
{}
unsigned int idx : 28;
unsigned int faces : 4;
ElementSeed p;
};
struct SubEntityInfo
{
SubEntityInfo()
/*
* TODO: move default value of `geometryType_` to member declaration
* when removing support for older dune-geometry
*/
: geometryType_(GeometryTypes::simplex(dim-codim))
{}
SubEntityInfo(IndexType parent_, unsigned int num_in_parent_,
const Dune::GeometryType& geometryType)
: parent(parent_), num_in_parent(num_in_parent_), geometryType_(geometryType)
{}
unsigned int nCorners() const
{
return Dune::ReferenceElements<ctype, dim-codim>::general(geometryType_).size(dim-codim);
}
IndexType parent;
unsigned int num_in_parent : 3;
Dune::GeometryType geometryType_;
CornerInfo corners[cube_corners]; // sim = number of vertices in a simplex
};
typedef std::map<IndexType, ElementInfo> ElementInfoMap;
typedef std::map<IndexType, VertexInfo> VertexInfoMap;
/************************** MEMBER VARIABLES ************************/
const GridView gv_;
/* Geometrical and Topological Information */
std::vector<CoordinateInfo> coords_;
std::vector<SubEntityInfo> subEntities_;
VertexInfoMap vtxInfo_;
ElementInfoMap elmtInfo_;
CellMapper cellMapper_;
public:
/* C O N S T R U C T O R S A N D D E S T R U C T O R S */
Extractor(const GV& gv)
: gv_(gv)
, cellMapper_(gv, mcmgElementLayout())
{}
/* F U N C T I O N A L I T Y */
void clear()
{
coords_.clear();
coords_.shrink_to_fit();
subEntities_.clear();
subEntities_.shrink_to_fit();
// ...then clear the maps themselves, too
vtxInfo_.clear();
elmtInfo_.clear();
}
/* G E T T E R S */
void getCoords(std::vector<Dune::FieldVector<ctype, dimworld> >& coords) const
{
coords.resize(coords_.size());
for (unsigned int i = 0; i < coords_.size(); ++i)
coords[i] = coords_[i].coord;
}
unsigned int nCoords() const
{
return coords_.size();
}
void getGeometryTypes(std::vector<Dune::GeometryType>& geometryTypes) const
{
geometryTypes.resize(subEntities_.size());
for (size_t i=0; i<subEntities_.size(); i++)
geometryTypes[i] = subEntities_[i].geometryType_;
}
void getFaces(std::vector<VertexVector>& faces) const
{
faces.resize(subEntities_.size());
for (unsigned int i = 0; i < subEntities_.size(); ++i) {
faces[i].resize(subEntities_[i].nCorners());
for (unsigned int j = 0; j < subEntities_[i].nCorners(); ++j)
faces[i][j] = subEntities_[i].corners[j].idx;
}
}
bool faceIndices(const Element& e, int& first, int& count) const
{
typename ElementInfoMap::const_iterator it =
elmtInfo_.find(cellMapper_.map(e));
if (it == elmtInfo_.end())
{
first = -1;
count = 0;
return false;
}
// the iterator is valid, fill the out params
first = it->second.idx;
count = it->second.faces;
return true;
}
int indexInInside(unsigned int index) const
{
return index < subEntities_.size() ? subEntities_[index].num_in_parent : -1;
}
// /**
// * @brief tests that a given entry in the extraction set does have local couplings
// * @todo parallel interface
// */
// bool contains (unsigned int global, unsigned int & local) const
// {
// local = global;
// return true;
// }
const GridView & gridView() const
{
return gv_;
}
const Grid& grid() const
{
return gv_.grid();
}
Element
element(unsigned int index) const
{
if (index >= subEntities_.size())
DUNE_THROW(Dune::GridError, "invalid face index");
const ElementSeed seed = elmtInfo_.at(subEntities_[index].parent).p;
return grid().entity(seed);
}
#if 1
Vertex
vertex(unsigned int index) const
{
if (index >= coords_.size())
DUNE_THROW(Dune::GridError, "invalid coordinate index");
const VertexSeed seed = vtxInfo_.at(coords_[index].vtxindex).p;
return grid().entity(seed);
}
#endif
Geometry geometry(unsigned int index) const;
LocalGeometry geometryLocal(unsigned int index) const;
};
template<typename GV, int cd>
typename Extractor<GV,cd>::Geometry Extractor<GV,cd>::geometry(unsigned int index) const
{
std::vector<Coords> corners(subEntities_[index].nCorners());
for (unsigned int i = 0; i < subEntities_[index].nCorners(); ++i)
corners[i] = coords_[subEntities_[index].corners[i].idx].coord;
return Geometry(subEntities_[index].geometryType_, corners);
}
template<typename GV, int cd>
typename Extractor<GV,cd>::LocalGeometry Extractor<GV,cd>::geometryLocal(unsigned int index) const
{
std::vector<LocalCoords> corners(subEntities_[index].nCorners());
// get face info
const SubEntityInfo & face = subEntities_[index];
Dune::GeometryType facetype = subEntities_[index].geometryType_;
// get reference element
const auto elmtseed = elmtInfo_.at(face.parent).p;
const auto elmt = grid().entity(elmtseed);
const Dune::GeometryType celltype = elmt.type();
const auto& re = Dune::ReferenceElements<ctype, dim>::general(celltype);
for (unsigned int i = 0; i < subEntities_[index].nCorners(); ++i)
corners[i] = re.position(face.corners[i].num,dim);
return LocalGeometry(facetype, corners);
}
} // namespace GridGlue
} // namespace Dune
#endif // DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
Dune
Definition gridglue.hh:37
Dune::GridGlue
Definition gridglue.hh:38
Dune::GridGlue::ctype::Vertex
GV::Traits::template Codim< dim >::Entity Vertex
Definition extractor.hh:63
Dune::GridGlue::ctype::vtxInfo_
VertexInfoMap vtxInfo_
Definition extractor.hh:206
Dune::GridGlue::Extractor::grid
const Grid & grid() const
Definition extractor.hh:349
Dune::GridGlue::Extractor::element
Element element(unsigned int index) const
gets the parent element for a given face index, throws an exception if index not valid
Definition extractor.hh:361
Dune::GridGlue::Extractor::indexInInside
int indexInInside(unsigned int index) const
gets the number face in the parent element
Definition extractor.hh:326
Dune::GridGlue::ctype::LocalCoords
Dune::FieldVector< ctype, dim > LocalCoords
Definition extractor.hh:61
Dune::GridGlue::Extractor::geometryLocal
LocalGeometry geometryLocal(unsigned int index) const
Get geometry of the extracted face in element coordinates.
Definition extractor.hh:409
Dune::GridGlue::ctype::dimworld
static constexpr auto dimworld
Definition extractor.hh:50
Dune::GridGlue::ctype::Geometry
Dune::MultiLinearGeometry< ctype, dim-codim, dimworld > Geometry
Definition extractor.hh:77
Dune::GridGlue::ctype::IndexType
int IndexType
Definition extractor.hh:73
Dune::GridGlue::ctype::coords_
std::vector< CoordinateInfo > coords_
Definition extractor.hh:196
Dune::GridGlue::ctype::Element
GV::Traits::template Codim< 0 >::Entity Element
Definition extractor.hh:66
Dune::GridGlue::Extractor::gridView
const GridView & gridView() const
tests that a given entry in the extraction set does have local couplings
Definition extractor.hh:344
Dune::GridGlue::Extractor::getFaces
void getFaces(std::vector< VertexVector > &faces) const
Get the corners of the extracted subentities.
Definition extractor.hh:285
Dune::GridGlue::ctype::VertexVector
std::vector< unsigned int > VertexVector
Definition extractor.hh:69
Dune::GridGlue::ctype::gv_
const GridView gv_
Definition extractor.hh:191
Dune::GridGlue::ctype::subEntities_
std::vector< SubEntityInfo > subEntities_
Definition extractor.hh:199
Dune::GridGlue::ctype::cube_corners
static constexpr int cube_corners
Definition extractor.hh:54
Dune::GridGlue::Extractor::vertex
Vertex vertex(unsigned int index) const
gets the vertex for a given coordinate index throws an exception if index not valid
Definition extractor.hh:377
Dune::GridGlue::ctype::codim
static constexpr auto codim
Definition extractor.hh:52
Dune::GridGlue::ctype::Coords
Dune::FieldVector< ctype, dimworld > Coords
Definition extractor.hh:60
Dune::GridGlue::Extractor::getGeometryTypes
void getGeometryTypes(std::vector< Dune::GeometryType > &geometryTypes) const
Get the list of geometry types.
Definition extractor.hh:274
Dune::GridGlue::ctype::CellMapper
MultipleCodimMultipleGeomTypeMapper< GridView > CellMapper
Definition extractor.hh:70
Dune::GridGlue::ctype::VertexInfoMap
std::map< IndexType, VertexInfo > VertexInfoMap
Definition extractor.hh:186
Dune::GridGlue::ctype::Grid
GridView::Grid Grid
Definition extractor.hh:57
Dune::GridGlue::Extractor::faceIndices
bool faceIndices(const Element &e, int &first, int &count) const
gets index of first subentity as well as the total number of subentities that were extracted from thi...
Definition extractor.hh:304
Dune::GridGlue::Extractor::geometry
Geometry geometry(unsigned int index) const
Get world geometry of the extracted face.
Definition extractor.hh:397
Dune::GridGlue::ctype::GridView
GV GridView
Definition extractor.hh:56
Dune::GridGlue::Extractor::nCoords
unsigned int nCoords() const
getter for the count of coordinates
Definition extractor.hh:268
Dune::GridGlue::ctype::ctype
GV::Grid::ctype ctype
Definition extractor.hh:59
Dune::GridGlue::ctype::ElementInfoMap
std::map< IndexType, ElementInfo > ElementInfoMap
Definition extractor.hh:185
Dune::GridGlue::Extractor::Extractor
Extractor(const GV &gv)
Constructor.
Definition extractor.hh:225
Dune::GridGlue::Extractor::getCoords
void getCoords(std::vector< Dune::FieldVector< ctype, dimworld > > &coords) const
getter for the coordinates array
Definition extractor.hh:256
Dune::GridGlue::ctype::cellMapper_
CellMapper cellMapper_
Definition extractor.hh:215
Dune::GridGlue::ctype::ElementSeed
Element::EntitySeed ElementSeed
Definition extractor.hh:67
Dune::GridGlue::ctype::VertexSeed
Vertex::EntitySeed VertexSeed
Definition extractor.hh:64
Dune::GridGlue::ctype::elmtInfo_
ElementInfoMap elmtInfo_
Definition extractor.hh:213
Dune::GridGlue::Extractor::clear
void clear()
delete everything build up so far and free the memory
Definition extractor.hh:235
Dune::GridGlue::ctype::dim
static constexpr auto dim
Definition extractor.hh:51
Dune::GridGlue::ctype::LocalGeometry
Dune::MultiLinearGeometry< ctype, dim-codim, dim > LocalGeometry
Definition extractor.hh:78
Dune::GridGlue::Extractor::CornerInfo
Helpful struct holding one index for the coordinate (vertex) to which it is associated and the elemen...
Definition extractor.hh:88
Dune::GridGlue::Extractor::CornerInfo::idx
unsigned int idx
index of the vertex
Definition extractor.hh:89
Dune::GridGlue::Extractor::CornerInfo::num
unsigned int num
element corner
Definition extractor.hh:90
Dune::GridGlue::Extractor::CoordinateInfo::CoordinateInfo
CoordinateInfo(unsigned int index_, IndexType vtxindex_)
Definition extractor.hh:98
Dune::GridGlue::Extractor::CoordinateInfo::index
unsigned int index
the index of this coordinate (in internal storage scheme) // NEEDED??
Definition extractor.hh:109
Dune::GridGlue::Extractor::CoordinateInfo::CoordinateInfo
CoordinateInfo()
Definition extractor.hh:95
Dune::GridGlue::Extractor::CoordinateInfo::coord
Coords coord
the coordinate
Definition extractor.hh:106
Dune::GridGlue::Extractor::CoordinateInfo::vtxindex
IndexType vtxindex
the index of the parent element (from index set)
Definition extractor.hh:103
Dune::GridGlue::Extractor::VertexInfo::idx
unsigned int idx
Definition extractor.hh:119
Dune::GridGlue::Extractor::VertexInfo::VertexInfo
VertexInfo(unsigned int idx_, const Vertex &p_)
Definition extractor.hh:117
Dune::GridGlue::Extractor::VertexInfo::p
VertexSeed p
Definition extractor.hh:120
Dune::GridGlue::Extractor::ElementInfo::idx
unsigned int idx
the index of this element's first face in the internal list of extracted faces
Definition extractor.hh:133
Dune::GridGlue::Extractor::ElementInfo::faces
unsigned int faces
the number of extracted faces for this element
Definition extractor.hh:136
Dune::GridGlue::Extractor::ElementInfo::ElementInfo
ElementInfo(unsigned int idx_, const Element &p_, unsigned int f_)
Definition extractor.hh:129
Dune::GridGlue::Extractor::ElementInfo::p
ElementSeed p
the entity seed for the element
Definition extractor.hh:139
Dune::GridGlue::Extractor::SubEntityInfo
Holds some information about an element's subentity involved in a coupling.
Definition extractor.hh:147
Dune::GridGlue::Extractor::SubEntityInfo::nCorners
unsigned int nCorners() const
Definition extractor.hh:161
Dune::GridGlue::Extractor::SubEntityInfo::corners
CornerInfo corners[cube_corners]
the corner indices plus the numbers of the vertices in the parent element
Definition extractor.hh:181
Dune::GridGlue::Extractor::SubEntityInfo::parent
IndexType parent
the index of the parent element (from index set)
Definition extractor.hh:167
Dune::GridGlue::Extractor::SubEntityInfo::SubEntityInfo
SubEntityInfo(IndexType parent_, unsigned int num_in_parent_, const Dune::GeometryType &geometryType)
Definition extractor.hh:156
Dune::GridGlue::Extractor::SubEntityInfo::num_in_parent
unsigned int num_in_parent
the number of the face in the parent element
Definition extractor.hh:170
Dune::GridGlue::Extractor::SubEntityInfo::geometryType_
Dune::GeometryType geometryType_
The GeometryType of the subentity.
Definition extractor.hh:173
Dune::GridGlue::Extractor::SubEntityInfo::SubEntityInfo
SubEntityInfo()
Definition extractor.hh:148