Dune Core Modules (unstable)

recipe-iterate-over-grid.cc

See explanation at Iterating over a grid

// always include the config file
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
// C++ includes
#include<math.h>
#include<iostream>
// dune-common includes
// dune-grid includes
int main(int argc, char** argv)
{
// Maybe initialize Mpi
// [set up grid]
const int dim = 4;
using Grid = Dune::YaspGrid<dim>;
Dune::FieldVector<double,dim> len; for (auto& l : len) l=1.0;
std::array<int,dim> cells; for (auto& c : cells) c=4;
Grid grid(len,cells);
// [extract gridview]
auto gv = grid.leafGridView();
// [iterate over codim]
const int codim = 2;
for (const auto& e : entities(gv,Dune::Codim<codim>{}))
if (!e.type().isCube()) std::cout << "not a cube" << std::endl;
// [iterate over grid view]
for (const auto& e : elements(gv)); // codim=0
for (const auto& e : vertices(gv)); // codim=dim
for (const auto& e : edges(gv)); // codim=dim-1
for (const auto& e : facets(gv)); // codim=1
// [access to subentities]
const int mycodim = 2;
for (const auto& e : elements(gv))
for (unsigned int i=0; i<e.subEntities(mycodim); ++i)
auto v = e.template subEntity<codim>(i);
}
[ provides Dune::Grid ]
Definition: yaspgrid.hh:164
vector space out of a tensor product of fields.
Definition: fvector.hh:96
Helpers for dealing with MPI.
Various parser methods to get data into a ParameterTree object.
Static tag representing a codimension.
Definition: dimension.hh:22
static DUNE_EXPORT FakeMPIHelper & instance(int argc, char **argv)
Get the singleton instance of the helper.
Definition: mpihelper.hh:138
IteratorRange<... > vertices(const GV &gv)
Iterates over all vertices (entities with dimension 0) of a GridView.
IteratorRange<... > edges(const GV &gv)
Iterates over all edges (entities with dimension 1) of a GridView.
A simple timing class.
IteratorRange<... > facets(const GV &gv)
Iterates over all facets (entities with codimension 1) of a GridView.
IteratorRange<... > entities(const GV &gv, Codim< codim > cd)
Iterates over all entities of a GridView with the given codimension.
A fake mpi helper.
Definition: mpihelper.hh:70
IteratorRange<... > elements(const GV &gv)
Iterates over all elements / cells (entities with codimension 0) of a GridView.
Creative Commons License   |  Legal Statements / Impressum  |  generated with Hugo v0.69.0 (Mar 1, 23:27, 2021)