4 #ifndef DUNE_GEOMETRY_AXISALIGNED_CUBE_GEOMETRY_HH
5 #define DUNE_GEOMETRY_AXISALIGNED_CUBE_GEOMETRY_HH
13 #include <dune/common/fvector.hh>
14 #include <dune/common/fmatrix.hh>
15 #include <dune/common/diagonalmatrix.hh>
46 template <
class CoordType,
unsigned int dim,
unsigned int coorddim>
77 typedef typename std::conditional<dim==coorddim,
78 DiagonalMatrix<ctype,dim>,
87 typedef typename std::conditional<dim==coorddim,
88 DiagonalMatrix<ctype,dim>,
96 const Dune::FieldVector<ctype,coorddim> upper)
101 static_assert(dim==coorddim,
"Use this constructor only if dim==coorddim!");
103 axes_ = (1<<coorddim)-1;
114 const Dune::FieldVector<ctype,coorddim> upper,
115 const std::bitset<coorddim>& axes)
120 assert(axes.count()==dim);
121 for (
size_t i=0; i<coorddim; i++)
123 upper_[i] = lower_[i];
144 if (dim == coorddim) {
145 for (
size_t i=0; i<coorddim; i++)
146 result[i] = lower_[i] +
local[i]*(upper_[i] - lower_[i]);
147 }
else if (dim == 0) {
151 for (
size_t i=0; i<coorddim; i++)
152 result[i] = (axes_[i])
153 ? lower_[i] +
local[lc++]*(upper_[i] - lower_[i])
163 if (dim == coorddim) {
164 for (
size_t i=0; i<dim; i++)
165 result[i] = (
global[i] - lower_[i]) / (upper_[i] - lower_[i]);
166 }
else if (dim != 0) {
168 for (
size_t i=0; i<coorddim; i++)
170 result[lc++] = (
global[i] - lower_[i]) / (upper_[i] - lower_[i]);
215 for (
size_t i=0; i<coorddim; i++)
216 result[i] = CoordType(0.5) * (lower_[i] + upper_[i]);
231 if (dim == coorddim) {
232 for (
size_t i=0; i<coorddim; i++)
233 result[i] = (k & (1<<i)) ? upper_[i] : lower_[i];
234 }
else if (dim == 0) {
237 unsigned int mask = 1;
239 for (
size_t i=0; i<coorddim; i++) {
241 result[i] = lower_[i];
243 result[i] = (k & mask) ? upper_[i] : lower_[i];
257 if (dim == coorddim) {
258 for (
size_t i=0; i<dim; i++)
259 vol *= upper_[i] - lower_[i];
261 }
else if (dim != 0) {
262 for (
size_t i=0; i<coorddim; i++)
264 vol *= upper_[i] - lower_[i];
284 for (
size_t i=0; i<dim; i++)
295 for (
size_t i=0; i<coorddim; i++)
303 for (
size_t i=0; i<dim; i++)
314 for (
size_t i=0; i<coorddim; i++)
319 Dune::FieldVector<ctype,coorddim> lower_;
321 Dune::FieldVector<ctype,coorddim> upper_;
323 std::bitset<coorddim> axes_;
A unique label for each type of element that can occur in a grid.
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:470
unspecified-type ReferenceElement
Returns the type of reference element for the argument types T...
Definition: referenceelements.hh:415
Definition: affinegeometry.hh:19
static const ReferenceElement & cube()
get hypercube reference elements
Definition: referenceelements.hh:208
A geometry implementation for axis-aligned hypercubes.
Definition: axisalignedcubegeometry.hh:48
Volume volume() const
Return the element volume.
Definition: axisalignedcubegeometry.hh:254
AxisAlignedCubeGeometry(const Dune::FieldVector< ctype, coorddim > lower, const Dune::FieldVector< ctype, coorddim > upper, const std::bitset< coorddim > &axes)
Constructor from a lower left and an upper right corner.
Definition: axisalignedcubegeometry.hh:113
AxisAlignedCubeGeometry(const Dune::FieldVector< ctype, coorddim > lower, const Dune::FieldVector< ctype, coorddim > upper)
Constructor from a lower left and an upper right corner.
Definition: axisalignedcubegeometry.hh:95
AxisAlignedCubeGeometry(const Dune::FieldVector< ctype, coorddim > lower)
Constructor from a single point only.
Definition: axisalignedcubegeometry.hh:130
GlobalCoordinate corner(int k) const
Return world coordinates of the k-th corner of the element.
Definition: axisalignedcubegeometry.hh:228
ctype Volume
Type used for volume.
Definition: axisalignedcubegeometry.hh:69
@ mydimension
Definition: axisalignedcubegeometry.hh:54
FieldVector< ctype, dim > LocalCoordinate
Type used for a vector of element coordinates.
Definition: axisalignedcubegeometry.hh:63
JacobianInverseTransposed jacobianInverseTransposed([[maybe_unused]] const LocalCoordinate &local) const
Jacobian transposed of the transformation from local to global coordinates.
Definition: axisalignedcubegeometry.hh:188
friend Dune::Transitional::ReferenceElement< ctype, Dim< dim > > referenceElement(const AxisAlignedCubeGeometry &)
Definition: axisalignedcubegeometry.hh:275
JacobianTransposed jacobianTransposed([[maybe_unused]] const LocalCoordinate &local) const
Jacobian transposed of the transformation from local to global coordinates.
Definition: axisalignedcubegeometry.hh:176
FieldVector< ctype, coorddim > GlobalCoordinate
Type used for a vector of world coordinates.
Definition: axisalignedcubegeometry.hh:66
LocalCoordinate local(const GlobalCoordinate &global) const
Map a point in global (world) coordinates to element coordinates.
Definition: axisalignedcubegeometry.hh:160
CoordType ctype
Type used for single coordinate coefficients.
Definition: axisalignedcubegeometry.hh:60
@ coorddimension
Definition: axisalignedcubegeometry.hh:57
std::conditional< dim==coorddim, DiagonalMatrix< ctype, dim >, FieldMatrix< ctype, dim, coorddim > >::type JacobianTransposed
Return type of jacobianTransposed.
Definition: axisalignedcubegeometry.hh:79
GeometryType type() const
Type of the cube. Here: a hypercube of the correct dimension.
Definition: axisalignedcubegeometry.hh:135
int corners() const
Return the number of corners of the element.
Definition: axisalignedcubegeometry.hh:222
ctype integrationElement([[maybe_unused]] const LocalCoordinate &local) const
Return the integration element, i.e., the determinant term in the integral transformation formula.
Definition: axisalignedcubegeometry.hh:202
std::conditional< dim==coorddim, DiagonalMatrix< ctype, dim >, FieldMatrix< ctype, coorddim, dim > >::type JacobianInverseTransposed
Return type of jacobianInverseTransposed.
Definition: axisalignedcubegeometry.hh:89
GlobalCoordinate center() const
Return center of mass of the element.
Definition: axisalignedcubegeometry.hh:208
bool affine() const
Return if the element is affine. Here: yes.
Definition: axisalignedcubegeometry.hh:270
GlobalCoordinate global(const LocalCoordinate &local) const
Map a point in local (element) coordinates to world coordinates.
Definition: axisalignedcubegeometry.hh:141
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123