Commit b79c020c authored by Praetorius, Simon's avatar Praetorius, Simon

cleanup and small corrections in the finished () function

parent 4423c539
Preparing the Sources
=========================
Additional to the software mentioned in README you'll need the
following programs installed on your system:
cmake >= 2.8.12
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.
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
define four variables:
CMAKE_FLAGS flags passed to cmake (during configure)
An example options file might look like this:
#use this options to configure and make if no other options are given
CMAKE_FLAGS=" \
-DCMAKE_CXX_COMPILER=g++-5 \
-DCMAKE_CXX_FLAGS='-Wall -pedantic' \
-DCMAKE_INSTALL_PREFIX=/install/path" #Force g++-5 and set compiler flags
If you save this information into example.opts you can pass the opts file to
dunecontrol via the --opts option, e. g.
dunecontrol --opts=example.opts all
More info
---------
See
dunecontrol --help
for further options.
The full build system is described in the dune-common/doc/buildsystem (Git version) or under share/doc/dune-common/buildsystem if you installed DUNE!
A MultiMesh Wrapper for Dune Grids
==================================
The aim of this module is to allow to construct a vector of hierarchically
nested grids indipendently refined and a GridView that allows to iterate
through all grids simultaneously priving a multi-entity on each node of the
combined leaf/level grid.
Installation
------------
Building the module follows the standard Dune guideline, i.e. simply call
dunecontrol --current all
In the modules root directory. Required dependencies are the modules
- dune-common
- dune-grid
and optionally you may provide different grid modules that can be used with
dune-multimesh, e.g.
- dune-alugrid
- dune-foamgrid
- dune-uggrid (currently limited, due to a lack of multi grid support)
Getting started
---------------
In order to build a MultiMesh, simply wrap your host-grid type into a the
`MultiMesh` class and set the number of grids to construct.
using HostGrid = ALUGrid<2, 2, simplex, conforming>;
MultiMesh<HostGrid> multimesh(2);
If the host-grid allows to pass arguments to its constructo, these can be
appended to the MultiMesh constructor after the size argument, e.g.
using HostGrid = AlbertaGrid<3,3>;
MultiMesh<HostGrid> multimesh(2, filename);
Since grids are not copy-constructable, all grids in a MultiMesh are constructed
from scratch from the same arguments or the same grid-factory, to guarantee
that the coarse-grid level is the same in all grids. When using a `GridFactory`
with MultiMesh, it is required to set the number grids to create in the
GridFactory constructor. This is different to other GridFactories. The default-
constructor creates one grid only. (This is just to be conform the the
GridFactory interface). In order to use, e.g. structured grid-factory builders,
you have to pass the MultiMesh GridFactory:
using HostGrid = ALUGrid<2, 2, simplex, conforming>;
using Factory = StructuredGridBuilder<MultiMesh<HostGrid> >;
GridFactory<MultiMesh<HostGrid> > gridFactory(3); // create 3 grids
auto gridPtr = Factory::createSimplexGrid(gridFactory, lower, upper, num);
Since the dune-grid StructuredGridFactory does not allow to pass an own
GridFactory object to fill, a modified StructuredGridFactory is provided in the
utility folder, called `StructuredGridBuilder`.
......@@ -10,6 +10,6 @@ Name: @PACKAGE_NAME@
Version: @VERSION@
Description: dune-multimesh module
URL: http://dune-project.org/
Requires: dune-common dune-geometry dune-grid dune-uggrid dune-alugrid dune-foamgrid
Requires: dune-common dune-grid
Libs: -L${libdir}
Cflags: -I${includedir}
......@@ -7,5 +7,5 @@ Module: dune-multimesh
Version: 0.1
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-common dune-geometry dune-grid
Depends: dune-common dune-grid
Suggests: dune-uggrid dune-alugrid dune-foamgrid
#install headers
install(FILES multimesh.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/multimesh)
install(FILES
mmentityseed.hh
mmgridfactory.hh
mmgridview.hh
mmiterator.hh
multimesh.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/multimesh)
add_subdirectory(utility/)
\ No newline at end of file
......@@ -3,11 +3,6 @@
#ifndef DUNE_MULTIMESH_ENTITYSEED_HH
#define DUNE_MULTIMESH_ENTITYSEED_HH
/**
* \file
* \brief The MultiMeshEntitySeed class
*/
namespace Dune
{
/**
......@@ -20,25 +15,21 @@ namespace Dune
{
protected:
// Entity type of the hostgrid
/// Entity type of the hostgrid
typedef typename GridImp::HostGridType::Traits::template Codim<codim>::Entity HostEntity;
// EntitySeed type of the hostgrid
/// EntitySeed type of the hostgrid
typedef typename GridImp::HostGridType::Traits::template Codim<codim>::EntitySeed HostEntitySeed;
public:
enum { codimension = codim };
/**
* \brief Construct an empty (i.e. isValid() == false) seed.
*/
/// Construct an empty (i.e. isValid() == false) seed.
MultiMeshEntitySeed()
{}
/// \brief Create EntitySeed from hostgrid Entity
/**
* \brief Create EntitySeed from hostgrid Entity
*
* We call hostEntity.seed() directly in the constructor
* of MultiMeshEntitySeed to allow for return value optimization.
*/
......@@ -48,25 +39,24 @@ namespace Dune
{}
/// Get stored HostEntitySeed
const HostEntitySeed& hostEntitySeed() const
const HostEntitySeed& hostEntitySeed () const
{
return hostEntitySeed_;
}
/// Check whether it is safe to create an Entity from this Seed
bool isValid() const
bool isValid () const
{
return hostEntitySeed_.isValid();
}
/// Return the index of the grid the entity belongs to
std::size_t gridIndex() const
std::size_t gridIndex () const
{
return gridIdx_;
}
private:
HostEntitySeed hostEntitySeed_;
std::size_t gridIdx_;
};
......
......@@ -4,10 +4,6 @@
#ifndef DUNE_MULTIMESH_GRIDFACTORY_HH
#define DUNE_MULTIMESH_GRIDFACTORY_HH
/** \file
* \brief Specialization of the generic GridFactory for MultiMesh
*/
#include <memory>
#include <type_traits>
#include <vector>
......@@ -167,4 +163,4 @@ namespace Dune
} // end namespace Dune
#endif // #ifndef DUNE_MULTIMESH_GRIDFACTORY_HH
#endif // DUNE_MULTIMESH_GRIDFACTORY_HH
......@@ -11,30 +11,19 @@
namespace Dune
{
// forward declaration
template <class GridImp>
class MultiMeshLevelGridView;
template <class GridImp>
class MultiMeshLeafGridView;
template <class GridImp>
struct MultiMeshLevelGridViewTraits
{
using GridViewImp = MultiMeshLevelGridView<GridImp>;
/** \brief type of the grid */
using Grid = typename std::remove_const<GridImp>::type;
/** \brief type of the index set */
using IndexSet = typename Grid::Traits::LevelIndexSet;
/** \brief type of the intersection */
using Intersection = typename Grid::Traits::LevelIntersection;
/** \brief type of the intersection iterator */
using IntersectionIterator = typename Grid::Traits::LevelIntersectionIterator;
/** \brief type of the collective communication */
using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication;
template <int cd>
......@@ -46,11 +35,9 @@ namespace Dune
using Geometry = typename Grid::template Codim<cd>::Geometry;
using LocalGeometry = typename Grid::template Codim<cd>::LocalGeometry;
/** \brief Define types needed to iterate over entities of a given partition type */
template <PartitionIteratorType pit>
struct Partition
{
/** \brief iterator over a given codim and partition type */
using Iterator = typename Grid::template Codim<cd>::template Partition<pit>::LevelIterator;
};
};
......@@ -65,24 +52,17 @@ namespace Dune
public:
using Traits = MultiMeshLevelGridViewTraits<GridImp>;
/** \brief type of the grid */
/// The MultiMesh GridType
using Grid = typename Traits::Grid;
/// Type of the corresponding GridType hosted by the MultiMesh
using HostGrid = typename GridImp::HostGridType;
/** \brief type of the index set */
using IndexSet = typename Traits::IndexSet;
/** \brief type of the intersection */
using Intersection = typename Traits::Intersection;
/** \brief type of the intersection iterator */
using IntersectionIterator = typename Traits::IntersectionIterator;
/** \brief type of the collective communication */
using CollectiveCommunication = typename Traits::CollectiveCommunication;
/** \brief Codim Structure */
template <int cd>
struct Codim : public Traits::template Codim<cd> {};
......@@ -189,7 +169,7 @@ namespace Dune
return grid().ghostSize(level_, codim);
}
/** communicate data on this view */
/// Communicate data on this view
template <class DataHandleImp, class DataType>
void communicate (CommDataHandleIF<DataHandleImp, DataType>& data,
InterfaceType iftype,
......@@ -204,24 +184,19 @@ namespace Dune
};
// forward declaration
template <class GridImp>
class MultiMeshLeafGridView;
template <class GridImp>
struct MultiMeshLeafGridViewTraits
{
using GridViewImp = MultiMeshLeafGridView<GridImp>;
/** \brief type of the grid */
using Grid = typename std::remove_const<GridImp>::type;
/** \brief type of the index set */
using IndexSet = typename Grid::Traits::LeafIndexSet;
/** \brief type of the intersection */
using Intersection = typename Grid::Traits::LeafIntersection;
/** \brief type of the intersection iterator */
using IntersectionIterator = typename Grid::Traits::LeafIntersectionIterator;
/** \brief type of the collective communication */
using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication;
template <int cd>
......@@ -233,11 +208,9 @@ namespace Dune
using Geometry = typename Grid::template Codim<cd>::Geometry;
using LocalGeometry = typename Grid::template Codim<cd>::LocalGeometry;
/** \brief Define types needed to iterate over entities of a given partition type */
template <PartitionIteratorType pit>
struct Partition
{
/** \brief iterator over a given codim and partition type */
using Iterator = typename Grid::template Codim<cd>::template Partition<pit>::LeafIterator;
};
};
......@@ -252,24 +225,17 @@ namespace Dune
public:
using Traits = MultiMeshLevelGridViewTraits<GridImp>;
/** \brief type of the grid */
/// The MultiMesh GridType
using Grid = typename Traits::Grid;
/// Type of the corresponding GridType hosted by the MultiMesh
using HostGrid = typename GridImp::HostGridType;
/** \brief type of the index set */
using IndexSet = typename Traits::IndexSet;
/** \brief type of the intersection */
using Intersection = typename Traits::Intersection;
/** \brief type of the intersection iterator */
using IntersectionIterator = typename Traits::IntersectionIterator;
/** \brief type of the collective communication */
using CollectiveCommunication = typename Traits::CollectiveCommunication;
/** \brief Codim Structure */
template <int cd>
struct Codim : public Traits::template Codim<cd> {};
......@@ -374,7 +340,7 @@ namespace Dune
return grid().ghostSize(codim);
}
/** communicate data on this view */
/// Communicate data on this view
template <class DataHandleImp, class DataType>
void communicate (CommDataHandleIF<DataHandleImp, DataType>& data,
InterfaceType iftype,
......
......@@ -68,18 +68,19 @@ namespace Dune
using Super = std::stack<EntityStackEntry, std::vector<EntityStackEntry>>;
public:
explicit EntityStack (const GridImp* multiMesh)
explicit EntityStack (int maxLevel)
{
c.reserve(multiMesh->maxLevel());
c.reserve(maxLevel);
}
// return true if all levels >= l are finished, i.e. hierarchic iterators it == end
bool finished (std::size_t l = 0) const
{
bool f = true;
for (auto tmp = c[l].it; f && l < c.size(); ++l,
tmp = c[l].it)
for (auto tmp = c[l].it; f && l < c.size(); ++l) {
tmp = c[l].it;
f = f && (++tmp) == c[l].end;
}
return f;
}
......@@ -91,9 +92,9 @@ namespace Dune
/// Constructor. Stores a pointer to the grid
explicit MultiMeshIterator (const GridImp* multiMesh, int level)
: multiMesh_(multiMesh)
, entityStacks_(multiMesh->grids_.size(), EntityStack{multiMesh})
, incrementAllowed_(multiMesh->grids_.size())
, incrementAllowed_(multiMesh->size(), true)
, level_(level)
, multiEntity_(multiMesh->size())
{
for (auto const& grid : multiMesh_->grids_) {
macroIterators_.push_back(grid->levelGridView(0).template begin<0,pitype>());
......@@ -101,8 +102,11 @@ namespace Dune
}
// go to first leaf entity on all grids
for (std::size_t i = 0; i < entityStacks_.size(); ++i)
entityStacks_.reserve(multiMesh_->size());
for (std::size_t i = 0; i < multiMesh_->size(); ++i) {
entityStacks_.emplace_back((*multiMesh_)[i].maxLevel());
initialIncrement(i);
}
}
/// Constructor which create the end iterator
......@@ -146,10 +150,12 @@ namespace Dune
/// dereferencing
std::vector<HostEntity> dereference () const
{
std::vector<HostEntity> multiEntity;
for (std::size_t i = 0; i < entityStacks_.size(); ++i)
multiEntity.push_back(dereference(i));
return multiEntity;
// update entries in multiEntity that have changed
for (std::size_t i = 0; i < entityStacks_.size(); ++i) {
if (incrementAllowed_[i])
multiEntity_[i] = dereference(i);
}
return multiEntity_;
}
/// equality
......@@ -186,8 +192,10 @@ namespace Dune
// 3. go down in tree until leaf entity
for (auto child = dereference(i); !entityTest(child);
child = dereference(i))
child = dereference(i)) {
entityStack.emplace(child);
assert( entityStack.size() <= (*multiMesh_)[i].maxLevel() );
}
}
/// Return true, if all stacks with size > stack[i].size are finished
......@@ -213,16 +221,21 @@ namespace Dune
// 2. go down in tree until leaf entity
for (auto child = dereference(i); !entityTest(child);
child = dereference(i))
child = dereference(i)) {
entityStack.emplace(child);
assert( entityStack.size() <= (*multiMesh_)[i].maxLevel() );
}
}
HostEntity dereference (std::size_t i) const
{
if (entityStacks_[i].empty())
if (entityStacks_[i].empty()) {
assert(macroIterators_[i] != macroEndIterators_[i]);
return *macroIterators_[i];
else
} else {
assert(entityStacks_[i].top().it != entityStacks_[i].top().end);
return *entityStacks_[i].top().it;
}
}
bool entityTest (HostEntity const& entity)
......@@ -239,6 +252,8 @@ namespace Dune
std::vector<EntityStack> entityStacks_;
std::vector<bool> incrementAllowed_;
int level_ = -1;
mutable std::vector<HostEntity> multiEntity_;
};
} // end namespace Dune
......
......@@ -133,20 +133,20 @@ namespace Dune
// initialize 0 grids
MultiMesh () = default;
std::size_t numGrids() const
std::size_t size() const
{
return grids_.size();
}
/// Returns the i'th grid managed by this MultiMesh
HostGridType& grid (std::size_t i)
HostGridType& operator[] (std::size_t i)
{
assert(i < grids_.size());
return *grids_[i];
}
/// Returns the i'th grid managed by this MultiMesh
HostGridType const& grid (std::size_t i) const
HostGridType const& operator[] (std::size_t i) const
{
assert(i < grids_.size());
return *grids_[i];
......
#install headers
install(FILES
structuredgridbuilder.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/multimesh/utility)
......@@ -3,10 +3,6 @@
#ifndef DUNE_MULTIMESH_STRUCTURED_GRIDFACTORY_HH
#define DUNE_MULTIMESH_STRUCTURED_GRIDFACTORY_HH
/** \file
\brief A class to construct structured cube and simplex grids using the grid factory
*/
#include <algorithm>
#include <array>
#include <cstddef>
......
add_executable("testiterator" testiterator.cc)
target_link_dune_default_libraries("testiterator")
add_dune_alberta_flags(GRIDDIM 3 WORLDDIM 3 "testiterator")
if (HAVE_ALBERTA)
add_dune_alberta_flags(GRIDDIM 3 WORLDDIM 3 "testiterator")
endif (HAVE_ALBERTA)
add_executable("uggrid" uggrid.cc)
target_link_dune_default_libraries("uggrid")
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <iostream>
#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
int main(int argc, char** argv)
{
try{
// Maybe initialize MPI
Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);
std::cout << "Hello World! This is dune-multimesh." << std::endl;
if(Dune::MPIHelper::isFake)
std::cout<< "This is a sequential program." << std::endl;
else
std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size()
<<" processes!"<<std::endl;
return 0;
}
catch (Dune::Exception &e){
std::cerr << "Dune reported error: " << e << std::endl;
}
catch (...){
std::cerr << "Unknown exception thrown!" << std::endl;
}
}
......@@ -18,7 +18,7 @@
#include <dune/multimesh/mmgridfactory.hh>
#include <dune/multimesh/utility/structuredgridbuilder.hh>
#define GRID 1
#define GRID 2
using namespace Dune;
......@@ -27,9 +27,15 @@ void printGrid(Grid const& grid)
{
volatile std::size_t n = 0;
Dune::Timer t;
for (auto const& entities : elements(grid.leafGridView()))
n += grid.grid(0).leafIndexSet().index(entities[0]);
std::cout << n << "\n";
for (auto const& entities : elements(grid.leafGridView())) {
n += grid[0].leafIndexSet().index(entities[0]);
std::cout << "indices = [";
for (std::size_t i = 0; i < entities.size(); ++i) {
std::cout << (i > 0 ? ", " : "") << grid[i].leafIndexSet().index(entities[i]);
}
std::cout << "]\n";
}
std::cout << "n = " << n << "\n";
std::cout << "time: " << t.elapsed() << "\n";
}
......@@ -53,9 +59,9 @@ int main(int argc, char** argv)
FieldVector<double,3> lower_left = {-1.5, -1.5, -1.5};
FieldVector<double,3> bbox = {1.5, 1.5, 1.5};
std::array<int,3> num_elements = {16, 16, 16};
std::array<int,3> num_elements = {2, 2, 2};
using HostGrid = YaspGrid<3, EquidistantOffsetCoordinates<double,3>>;
MultiMesh<HostGrid> grid(2, lower_left, bbox, num_elements);
MultiMesh<HostGrid> grid(3, lower_left, bbox, num_elements);
#elif GRID == 2
......@@ -65,7 +71,7 @@ int main(int argc, char** argv)
using HostGrid = Dune::ALUGrid<2, 2, Dune::simplex, Dune::conforming>;
using Factory = StructuredGridBuilder<MultiMesh<HostGrid> >;
GridFactory<MultiMesh<HostGrid> > gridFactory(2);
GridFactory<MultiMesh<HostGrid> > gridFactory(3);
auto gridPtr = Factory::createSimplexGrid(gridFactory, lower_left, bbox, num_elements);
auto& grid = *gridPtr;
......@@ -75,17 +81,18 @@ int main(int argc, char** argv)
assert(argc > 1);
std::string filename = argv[1];
using HostGrid = Dune::AlbertaGrid<3,3>;
MultiMesh<HostGrid> grid(2, filename);
grid.grid(0).globalRefine(8);
grid.grid(1).globalRefine(8);
MultiMesh<HostGrid> grid(3, filename);
grid[0].globalRefine(8);
grid[1].globalRefine(8);
#endif
std::cout << "number of grids = " << grid.numGrids() << "\n";
std::cout << "number of grids = " << grid.size() << "\n";
printGrid2(grid.grid(0));
printGrid2(grid[0]);
printGrid(grid);
grid.grid(0).globalRefine(1);
printGrid2(grid.grid(0));
grid[0].globalRefine(2);
grid[1].globalRefine(1);
printGrid2(grid[0]);
printGrid(grid);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment