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

Initial commit

parents
# We require version CMake version 3.1 to prevent issues
# with dune_enable_all_packages and older CMake versions.
cmake_minimum_required(VERSION 3.1)
project(dune-multimesh CXX)
if(NOT (dune-common_DIR OR dune-common_ROOT OR
"${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*"))
string(REPLACE ${CMAKE_PROJECT_NAME} dune-common dune-common_DIR
${PROJECT_BINARY_DIR})
endif()
#find dune-common and set the module path
find_package(dune-common REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules"
${dune-common_MODULE_PATH})
#include the dune macros
include(DuneMacros)
# start a dune project with information from dune.module
dune_project()
dune_enable_all_packages()
add_subdirectory(src)
add_subdirectory(dune)
add_subdirectory(doc)
add_subdirectory(cmake/modules)
# finalize the dune project, e.g. generating config.h etc.
finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
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!
set(modules "DuneMultimeshMacros.cmake")
install(FILES ${modules} DESTINATION ${DUNE_INSTALL_MODULEDIR})
# File for module specific CMake tests.
/* begin dune-multimesh
put the definitions for config.h specific to
your project here. Everything above will be
overwritten
*/
/* begin private */
/* Name of package */
#define PACKAGE "@DUNE_MOD_NAME@"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "@DUNE_MAINTAINER@"
/* Define to the full name of this package. */
#define PACKAGE_NAME "@DUNE_MOD_NAME@"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "@DUNE_MOD_NAME@ @DUNE_MOD_VERSION@"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "@DUNE_MOD_NAME@"
/* Define to the home page for this package. */
#define PACKAGE_URL "@DUNE_MOD_URL@"
/* Define to the version of this package. */
#define PACKAGE_VERSION "@DUNE_MOD_VERSION@"
/* end private */
/* Define to the version of dune-multimesh */
#define DUNE_MULTIMESH_VERSION "@DUNE_MULTIMESH_VERSION@"
/* Define to the major version of dune-multimesh */
#define DUNE_MULTIMESH_VERSION_MAJOR @DUNE_MULTIMESH_VERSION_MAJOR@
/* Define to the minor version of dune-multimesh */
#define DUNE_MULTIMESH_VERSION_MINOR @DUNE_MULTIMESH_VERSION_MINOR@
/* Define to the revision of dune-multimesh */
#define DUNE_MULTIMESH_VERSION_REVISION @DUNE_MULTIMESH_VERSION_REVISION@
/* end dune-multimesh
Everything below here will be overwritten
*/
add_subdirectory("doxygen")
# shortcut for creating the Doxyfile.in and Doxyfile
add_doxygen_target()
# This file contains local changes to the doxygen configuration
# please us '+=' to add file/directories to the lists
# The INPUT tag can be used to specify the files and/or directories that contain
# documented source files. You may enter file names like "myfile.cpp" or
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT += @top_srcdir@/dune/
# see e.g. dune-grid for the examples of mainpage and modules
# INPUT += @srcdir@/mainpage \
# @srcdir@/modules
# The EXCLUDE tag can be used to specify files and/or directories that should
# excluded from the INPUT source files. This way you can easily exclude a
# subdirectory from a directory tree whose root is specified with the INPUT tag.
# EXCLUDE += @top_srcdir@/dune/multimesh/test
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
# the \include command).
# EXAMPLE_PATH += @top_srcdir@/src
# The IMAGE_PATH tag can be used to specify one or more files or
# directories that contain image that are included in the documentation (see
# the \image command).
# IMAGE_PATH += @top_srcdir@/dune/multimesh/pics
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@
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
Libs: -L${libdir}
Cflags: -I${includedir}
################################
# Dune module information file #
################################
#Name of the module
Module: dune-multimesh
Version: 0.1
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-common dune-geometry dune-grid
Suggests: dune-uggrid dune-alugrid dune-foamgrid
add_subdirectory(multimesh)
#install headers
install(FILES multimesh.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/multimesh)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_ENTITYSEED_HH
#define DUNE_MULTIMESH_ENTITYSEED_HH
/**
* \file
* \brief The MultiMeshEntitySeed class
*/
namespace Dune
{
/**
* \brief The EntitySeed class provides the minimal information needed to restore an Entity using the grid.
* \ingroup MultiMesh
*
*/
template <int codim, class GridImp>
class MultiMeshEntitySeed
{
protected:
// Entity type of the hostgrid
typedef typename GridImp::HostGridType::Traits::template Codim<codim>::Entity HostEntity;
// 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.
*/
MultiMeshEntitySeed()
{}
/**
* \brief Create EntitySeed from hostgrid Entity
*
* We call hostEntity.seed() directly in the constructor
* of MultiMeshEntitySeed to allow for return value optimization.
*/
MultiMeshEntitySeed (const HostEntity& hostEntity, std::size_t gridIdx)
: hostEntitySeed_(hostEntity.seed())
, gridIdx_(gridIdx)
{}
/// Get stored HostEntitySeed
const HostEntitySeed& hostEntitySeed() const
{
return hostEntitySeed_;
}
/// Check whether it is safe to create an Entity from this Seed
bool isValid() const
{
return hostEntitySeed_.isValid();
}
/// Return the index of the grid the entity belongs to
std::size_t gridIndex() const
{
return gridIdx_;
}
private:
HostEntitySeed hostEntitySeed_;
std::size_t gridIdx_;
};
} // end namespace Dune
#endif // DUNE_MULTIMESH_ENTITYSEED_HH
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_GRIDFACTORY_HH
#define DUNE_MULTIMESH_GRIDFACTORY_HH
/** \file
* \brief Specialization of the generic GridFactory for MultiMesh
*/
#include <memory>
#include <vector>
#include <dune/grid/common/gridfactory.hh>
#include "multimesh.hh"
namespace Dune
{
/** \brief specialization of the generic GridFactory for MultiMesh
* \ingroup GridFactory
*/
template <class HostGrid>
class GridFactory<MultiMesh<HostGrid> >
: public GridFactoryInterface<MultiMesh<HostGrid> >
{
public:
/// Type of grid this factory is for
using Grid = MultiMesh<HostGrid>;
/// Type of (scalar) coordinates
using ctype = typename Grid::ctype;
/// dimension of the grid
static const int dimension = Grid::dimension;
/// dimension of the world
static const int dimensionworld = Grid::dimensionworld;
using LocalCoordinate = FieldVector<ctype, dimension>;
using GlobalCoordinate = FieldVector<ctype, dimensionworld>;
using BoundarySegment = Dune::BoundarySegment<dimension, dimensionworld>;
using ElementParametrization = VirtualFunction<LocalCoordinate,GlobalCoordinate>
public:
/// \brief Constructor
/**
* \param[in] n The number of grids to construct
* \param[in] args Additional parameters passed to the constructor of the hostgridfactory
**/
template <class... Args>
explicit GridFactory (std::size_t n, Args&&... args)
: gridFactories_(n, GridFactory<HostGrid>{std::forward<Args>(args)...})
{}
/// \brief insert a vertex into the macro grid
/**
* \param[in] pos position of the vertex (in world coordinates)
**/
virtual void insertVertex (const GlobalCoordinate& pos)
{
for (auto& gridFactory : gridFactories_)
gridFactory.insertVertex(pos);
}
/// \brief insert an element into the coarse grid
/**
* \param[in] type GeometryType of the new element
* \param[in] vertices indices of the element vertices
**/
virtual void insertElement (const GeometryType& type,
const std::vector<unsigned int>& vertices)
{
for (auto& gridFactory : gridFactories_)
gridFactory.insertElement(vertices);
}
/// \brief Insert a parametrized element into the coarse grid
/**
* \param[in] type The GeometryType of the new element
* \param[in] vertices The vertices of the new element, using the DUNE numbering
* \param[in] elementParametrization A function prescribing the shape of this element
**/
virtual void insertElement (const GeometryType& type,
const std::vector<unsigned int>& vertices,
const std::shared_ptr<ElementParametrization>& elementParametrization)
{
for (auto& gridFactory : gridFactories_)
gridFactory.insertElement(type, vertices, elementParametrization);
}
/// \brief insert a boundary segment into the macro grid
/**
* Only influences the ordering of the boundary segments
* \param[in] vertices vertex indices of boundary face
**/
virtual void insertBoundarySegment (const std::vector<unsigned int>& vertices) override
{
for (auto& gridFactory : gridFactories_)
gridFactory.insertBoundarySegment(vertices);
}
/** \brief insert a shaped boundary segment into the macro grid
*
* \param[in] vertices vertex indices of boundary face
* \param[in] boundarySegment geometric realization of shaped boundary
*/
virtual void insertBoundarySegment (const std::vector<unsigned int>& vertices,
const std::shared_ptr<BoundarySegment>& boundarySegment) override
{
for (auto& gridFactory : gridFactories_)
gridFactory.insertBoundarySegment(vertices, boundarySegment);
}
/// \brief finalize grid creation and hand over the grid
/**
* Create n copies of the grid and store it in unique_pointers
* inside the multimesh grid.
**/
virtual Grid* createGrid () override
{
Grid* multimesh = new Grid{};
for (auto& gridFactory : gridFactories_)
multimesh.grids_.emplace_back(gridFactory.createGrid());
return multimesh;
}
private:
std::vector<GridFactory<HostGrid> > gridFactories_;
};
} // end namespace Dune
#endif // #ifndef DUNE_MULTIMESH_GRIDFACTORY_HH
This diff is collapsed.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_ITERATOR_HH
#define DUNE_MULTIMESH_ITERATOR_HH
#include <numeric>
#include <stack>
#include <dune/common/iteratorfacades.hh>
#include <dune/grid/common/exceptions.hh>
#include <dune/grid/common/gridenums.hh>
/** \file
* \brief The MultiMeshIterator class
*/
namespace Dune
{
/** \brief Iterator over all entities of a given codimension and level of a grid.
* \ingroup MultiMesh
*/
template <int codim, PartitionIteratorType pitype, class GridImp>
class MultiMeshIterator
{
public:
template <class... Args>
MultiMeshIterator(Args&&... args)
{
DUNE_THROW(NotImplemented, "Not implemented for entity of codim != 0!");
}
int operator*() const { return 0; }
MultiMeshIterator& operator++() { return *this; }
MultiMeshIterator operator++(int) { return *this; }
bool operator!=(MultiMeshIterator const&) const { return false; }
};
// Implemented for codim 0 entities only
template <PartitionIteratorType pitype, class GridImp>
class MultiMeshIterator<0, pitype, GridImp>
: public ForwardIteratorFacade<MultiMeshIterator<0,pitype,GridImp>,
std::vector<typename GridImp::Traits::template Codim<0>::Entity>,
std::vector<typename GridImp::Traits::template Codim<0>::Entity> >
{
private:
// LevelIterator to the equivalent entity in the host grid
using HostGridLevelIterator =
typename GridImp::HostGridType::template Codim<0>::template Partition<pitype>::LevelIterator;
using HostEntity = typename GridImp::HostGridType::template Codim<0>::Entity;
struct EntityStackEntry
{
template <class It, class End>
EntityStackEntry(It&& it, End&& end)
: it(std::forward<It>(it))
, end(std::forward<End>(end))
{}
typename HostEntity::HierarchicIterator it;
typename HostEntity::HierarchicIterator end;
};
class EntityStack
: public std::stack<EntityStackEntry, std::vector<EntityStackEntry>>
{
using Super = std::stack<EntityStackEntry, std::vector<EntityStackEntry>>;
public:
explicit EntityStack(const GridImp* multiMesh)
{
c.reserve(multiMesh->maxLevel());
}
// return true of all levels >= l are finished, i.e. hierarchic iterators it == end
bool finished(std::size_t l = 0) const
{
bool f = true;
while (f && l < c.size()) {
auto tmp = c[l].it;
++tmp;
f = f && tmp == c[l].end;
++l;
}
return f;
}
protected:
using Super::c;
};
public:
/// 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())
, level_(level)
{
for (auto const& grid : multiMesh_->grids_) {
macroIterators_.push_back(grid->levelGridView(0).template begin<0,pitype>());
macroEndIterators_.push_back(grid->levelGridView(0).template end<0,pitype>());
}
// go to first leaf entity on all grids
for (std::size_t i = 0; i < entityStacks_.size(); ++i)
initialIncrement(i);
}
/// Constructor which create the end iterator
/**
* \param multiMesh Pointer to grid instance
* \param endDummy Here only to distinguish it from the other constructor
*/
MultiMeshIterator (const GridImp* multiMesh, int level, bool endDummy)
: multiMesh_(multiMesh)
, level_(level)
{
for (auto const& grid : multiMesh_->grids_) {
macroIterators_.push_back(grid->levelGridView(0).template end<0,pitype>());
macroEndIterators_.push_back(grid->levelGridView(0).template end<0,pitype>());
}
}
MultiMeshIterator (const GridImp* multiMesh)
: MultiMeshIterator{multiMesh, -1}
{}
MultiMeshIterator (const GridImp* multiMesh, bool endDummy)
: MultiMeshIterator{multiMesh, -1, endDummy}
{}
/// prefix increment
void increment ()
{
for (std::size_t i = 0; i < entityStacks_.size(); ++i)
incrementAllowed_[i] = incrementAllowed(i);
for (std::size_t i = 0; i < entityStacks_.size(); ++i) {
if (incrementAllowed_[i])
increment(i);
}
}
/// dereferencing
std::vector<HostEntity> dereference () const
{
std::vector<HostEntity> multiEntity;
for (auto const& stack : entityStacks_)
multiEntity.push_back(*stack.top().it);
return multiEntity;
}
/// equality
bool equals (const MultiMeshIterator& that) const
{
return macroIterators_ == that.macroIterators_;
}
protected:
// got to next entity in grid i
// iterator always points to a leaf entity
void increment (std::size_t i)
{
auto& entityStack = entityStacks_[i];
auto& macroIt = macroIterators_[i];
auto const& macroEnd = macroEndIterators_[i];
// 1. go up in tree or to next entity on current level until we can go down again
while (!entityStack.empty()) {
auto& top = entityStack.top();
++top.it;
if (top.it == top.end) {
entityStack.pop();
} else {
break;
}
}
// 2. if entityStack is empty, go to next macroElement
if (entityStack.empty()) {
++macroIt;
if (macroIt == macroEnd)
return;
auto entity = *macroIt;
entityStack.emplace(entity.hbegin(0), entity.hend(0));
}
// 3. go down in tree until leaf entity
for (auto child = *entityStack.top().it; !entityTest(child);
child = *entityStack.top().it) {
int childLevel = child.level() + 1;
entityStack.emplace(child.hbegin(childLevel), child.hend(childLevel));
}
}
/// Return true, if all stacks with size > stack[i].size are finished
bool incrementAllowed (std::size_t i) const
{
std::size_t size = entityStacks_[i].size();
return std::accumulate(entityStacks_.begin(), entityStacks_.end(), true,
[i,size](bool allowed, auto const& entityStack) {
return allowed && (entityStack.size() <= size || entityStack.finished(size));
});
}
// got to first leaf entity on grid i
void initialIncrement (std::size_t i)
{
auto& entityStack = entityStacks_[i];
auto& macroIt = macroIterators_[i];
auto const& macroEnd = macroEndIterators_[i];
assert( entityStack.empty() );
if (macroIt == macroEnd)
return;
// 1. push first entry to stack
auto entity = *macroIt;
entityStack.emplace(entity.hbegin(0), entity.hend(0));
// 2. go down in tree until leaf entity
for (auto child = *entityStack.top().it; !entityTest(child);
child = *entityStack.top().it) {
int childLevel = child.level() + 1;
entityStack.emplace(child.hbegin(childLevel), child.hend(childLevel));
}
}
HostEntity dereference (std::size_t i) const
{
return *entityStacks_[i].top().it;
}
bool entityTest(HostEntity const& entity)
{
return entity.level() == level_ || entity.isLeaf() || !entity.isRegular();
}
private:
const GridImp* multiMesh_;
std::vector<HostGridLevelIterator> macroIterators_;
std::vector<HostGridLevelIterator> macroEndIterators_;
std::vector<EntityStack> entityStacks_;
std::vector<bool> incrementAllowed_;
int level_ = -1;
double time1 = 0.0, time2 = 0.0, time3 = 0.0, time4 = 0.0;
};
} // end namespace Dune
#endif // DUNE_MULTIMESH_ITERATOR_HH
This diff is collapsed.
add_executable("testiterator" testiterator.cc)
target_link_dune_default_libraries("testiterator")
// -*- 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;
}
}
// -*- 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
#include <dune/common/timer.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/multimesh/multimesh.hh>