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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_GRIDVIEW_HH
#define DUNE_MULTIMESH_GRIDVIEW_HH
#include <dune/common/typetraits.hh>
#include <dune/common/exceptions.hh>
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/common/gridview.hh>
namespace Dune
{
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>
struct Codim
{
using Iterator = typename Grid::Traits::template Codim<cd>::template Partition<All_Partition>::LevelIterator;
using Entity = typename Grid::Traits::template Codim<cd>::Entity;
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;
};
};
enum { conforming = Capabilities::isLevelwiseConforming<Grid>::v };
};
template <class GridImp>
class MultiMeshLevelGridView
{
public:
using Traits = MultiMeshLevelGridViewTraits<GridImp>;
/** \brief type of the grid */
using Grid = typename Traits::Grid;
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> {};
enum { conforming = Traits::conforming };
public:
/// Constructor. Stores a pointer to the grid
MultiMeshLevelGridView (const Grid& multiMesh, int level)
: multiMesh_(&multiMesh)
, level_(level)
{}
/// Obtain a const reference to the underlying hierarchic grid
const Grid& grid () const
{
assert( multiMesh_ );
return *multiMesh_;
}
const HostGrid& grid (std::size_t i) const
{
return multiMesh_->grid(i);
}
/// Obtain the level-indexSet
const IndexSet& indexSet (std::size_t idx) const
{
return grid(idx).levelIndexSet(level_);
}
const IndexSet& indexSet () const
{
assert(false && "Should be called on the i'th grid: indexSet(i)");
return grid(0).levelIndexSet(level_);
}
/// Obtain number of entities in a given codimension
int size (std::size_t idx, int codim) const
{
return grid(idx).size(level_, codim);
}
int size (int codim) const
{
assert(false && "Should be called on the i'th grid: size(i, codim)");
return grid(0).size(level_, codim);
}
/// Obtain number of entities with a given geometry type
int size (std::size_t idx, const GeometryType& type) const
{
return grid(idx).size( level_, type );
}
int size (const GeometryType& type) const
{
assert(false && "Should be called on the i'th grid: size(i, type)");
return grid(0).size( level_, type );
}
/// Obtain begin iterator for this view
template <int cd, PartitionIteratorType pit = All_Partition>
typename Codim<cd>::template Partition<pit>::Iterator begin () const
{
assert(cd == 0 && "Implemented for codim == 0 only");
return grid().template lbegin<cd, pit>(level_);
}
/// Obtain end iterator for this view
template <int cd, PartitionIteratorType pit = All_Partition>
typename Codim<cd>::template Partition<pit>::Iterator end () const
{
assert(cd == 0 && "Implemented for codim == 0 only");
return grid().template lend<cd, pit>(level_);
}
/// Obtain begin intersection iterator with respect to this view
IntersectionIterator ibegin (const typename Codim<0>::Entity& entity) const
{
return entity.impl().ilevelbegin();
}
/// Obtain end intersection iterator with respect to this view
IntersectionIterator iend (const typename Codim<0>::Entity& entity) const
{
return entity.impl().ilevelend();
}
/// Obtain collective communication object
const CollectiveCommunication& comm () const
{
return grid().comm();
}
/// Return size of the overlap region for a given codim on the grid view.
int overlapSize (int codim) const
{
return grid().overlapSize(level_, codim);
}
/// Return size of the ghost region for a given codim on the grid view.
int ghostSize (int codim) const
{
return grid().ghostSize(level_, codim);
}
/** communicate data on this view */
template <class DataHandleImp, class DataType>
void communicate (CommDataHandleIF<DataHandleImp, DataType>& data,
InterfaceType iftype,
CommunicationDirection dir) const
{