Commit 44d12215 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

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-vtk 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(lib)
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 "DuneVtkMacros.cmake")
install(FILES ${modules} DESTINATION ${DUNE_INSTALL_MODULEDIR})
find_package(ZLIB)
set(HAVE_ZLIB ${ZLIB_FOUND})
if (${HAVE_ZLIB})
dune_register_package_flags(COMPILE_DEFINITIONS "ENABLE_ZLIB=1"
LIBRARIES "${ZLIB_LIBRARIES}"
INCLUDE_DIRS "${ZLIB_INCLUDE_DIRS}")
endif (${HAVE_ZLIB})
/* begin dune-vtk
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-vtk */
#define DUNE_VTK_VERSION "@DUNE_VTK_VERSION@"
/* Define to the major version of dune-vtk */
#define DUNE_VTK_VERSION_MAJOR @DUNE_VTK_VERSION_MAJOR@
/* Define to the minor version of dune-vtk */
#define DUNE_VTK_VERSION_MINOR @DUNE_VTK_VERSION_MINOR@
/* Define to the revision of dune-vtk */
#define DUNE_VTK_VERSION_REVISION @DUNE_VTK_VERSION_REVISION@
/* Define if you have the ZLIB library. */
#cmakedefine HAVE_ZLIB ENABLE_ZLIB
/* end dune-vtk
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/vtk/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/vtk/pics
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@
Name: @PACKAGE_NAME@
Version: @VERSION@
Description: dune-vtk module
URL: http://dune-project.org/
Requires: dune-grid dune-functions
Libs: -L${libdir}
Cflags: -I${includedir}
################################
# Dune module information file #
################################
#Name of the module
Module: dune-vtk
Version: 0.1
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-grid dune-functions
add_subdirectory(vtk)
dune_add_library("vtktypes" OBJECT
vtktypes.cc)
#install headers
install(FILES
filereader.hh
filewriter.hh
vtkfunction.hh
vtkreader.hh
vtkreader.impl.hh
vtktypes.hh
vtkwriter.hh
vtkwriter.impl.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter)
add_subdirectory(utility)
#pragma once
#include <string>
namespace Dune
{
template <class Grid>
class FileReader
{
public:
/// Virtual destructor
virtual ~FileReader() = default;
/// Reads the grid from a file with `filename` and returns a unique_ptr to the created grid.
virtual std::unique_ptr<Grid> read(std::string const& filename)
{
GridFactory<Grid> factory;
read(factory, filename);
return std::unique_ptr<Grid>{ factory.createGrid() };
}
/// Reads the grid from a file with `filename` into a grid-factory.
virtual void read(GridFactory<Grid>& factory, std::string const& filename) = 0;
};
} // end namespace Dune
#pragma once
#include <string>
namespace Dune
{
class FileWriter
{
public:
/// Virtual destructor
virtual ~FileWriter () = default;
/// Write to file given by `filename`
virtual void write (std::string const& filename) = 0;
};
} // end namespace Dune
dune_add_library("filesystem" OBJECT
filesystem.cc)
#install headers
install(FILES
enum.hh
filesystem.hh
string.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vtkwriter/utility)
#pragma once
#include <type_traits>
namespace Dune
{
template <class E, class Integer,
std::enable_if_t<std::is_enum<E>::value, int> = 0>
constexpr bool is_a(E a, Integer b)
{
return (int(a) & int(b)) != 0;
}
} // end namespace Dune
#include "filesystem.hh"
#ifdef _WIN32
#include <direct.h> // _mkdir
#define GET_CURRENT_DIR _getcwd
#else
#include <unistd.h>
#define GET_CURRENT_DIR getcwd
#endif
#include <errno.h> // errno, ENOENT, EEXIST
#include <stdio.h> // defines FILENAME_MAX
#include <sys/stat.h>
#include <sys/types.h>
#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
template <class... Args>
void inline _ignore_(Args&&...) {}
namespace Dune { namespace filesystem {
std::string path::string() const
{
if (empty())
return "";
auto it = begin();
auto result = *it;
for (++it; it != end(); ++it)
result += preferred_separator + *it;
return result;
}
void path::split(std::string p)
{
std::string separators = "/\\";
bool relative = true;
trim(p);
Dune::split(p.begin(), p.end(), separators.begin(), separators.end(),
[this,&relative](auto first, auto end)
{
auto token = std::string(first, end);
if ((!token.empty() && token != "." && token != "..") || (token.empty() && this->empty())) {
this->push_back(token);
relative = false;
} else if (token == "..") {
if (relative || this->empty()) {
this->push_back(token);
}
else {
this->pop_back();
}
}
});
}
path path::stem() const
{
auto f = filename().string();
auto pos = f.find_last_of('.');
if (f == "." || f == ".." || pos == std::string::npos)
return {f};
else
return {f.substr(0,pos)};
}
path path::extension() const
{
auto f = filename().string();
auto pos = f.find_last_of('.');
if (f == "." || f == ".." || pos == std::string::npos)
return {};
else
return {f.substr(pos)};
}
bool path::is_absolute(std::string p)
{
if (p[0] == '/')
return true;
// c:\ or z:/
if (std::isalpha(p[0]) && p[1] == ':' && (p[2] == '/' || p[2] == '\\'))
return true;
return false;
}
path& path::operator/=(path const& p)
{
insert(end(), p.begin(), p.end());
original += preferred_separator + p.original;
return *this;
}
bool path::is_file() const
{
std::string p = this->string();
struct stat info;
return stat(p.c_str(), &info) == 0 && (info.st_mode & S_IFREG) != 0;
}
bool path::is_directory() const
{
std::string p = this->string();
struct stat info;
return stat(p.c_str(), &info) == 0 && (info.st_mode & S_IFDIR) != 0;
}
path current_path()
{
char cwd_[FILENAME_MAX];
_ignore_(GET_CURRENT_DIR(cwd_, sizeof(cwd_)));
std::string cwd(cwd_);
return { trim(cwd) };
}
bool exists(path const& p)
{
return p.is_file() || p.is_directory();
}
bool create_directories(path const& p)
{
if (p.is_directory())
return true;
auto parent = p.parent_path();
if (!parent.empty() && !parent.is_directory())
create_directories(parent);
#ifdef _WIN32
int ret = _mkdir(p.string().c_str());
#else
mode_t mode = 0755;
int ret = mkdir(p.string().c_str(), mode);
#endif
if (ret == 0)
return true;
switch (errno)
{
case ENOENT:
std::cerr << "parent didn't exist. Should not happen, since parent directory created before!\n";
std::abort();
return false;
break;
case EEXIST:
return true;
break;
default:
return false;
}
}
} } // end namespace Dec
#pragma once
#include <string>
#include <vector>
#include "string.hh"
namespace Dune
{
namespace filesystem
{
// A minimalistic filesystem class
class path
: public std::vector<std::string>
{
using Super = std::vector<std::string>;
using iterator = Super::iterator;
using const_iterator = Super::const_iterator;
public:
#ifdef _WIN32
static constexpr char preferred_separator = '\\';
#else
static constexpr char preferred_separator = '/';
#endif
public:
path() = default;
// NOTE: implicit conversion is allowed here
template <class String>
path(String const& p)
: original(p)
{
split(p);
}
template <class InputIt>
path(InputIt it, InputIt end_it)
: Super(it, end_it)
{
original = this->string();
}
template <class String>
path(std::initializer_list<String> const& list)
: path(list.begin(), list.end())
{}
/// Removes filename path component
path& remove_filename()
{
this->pop_back();
return *this;
}
/// Returns the path of the parent path
path parent_path() const
{
return empty() ? path() : path(begin(), --end());
}
/// Returns filename path component
path filename() const
{
return empty() ? path() : path(back());
}
/// Returns the stem path component
path stem() const;
/// Returns the file extension path component
path extension() const;
/// Return the path as string
std::string string() const;
/// \brief Return whether a path is an absolute path.
/** In Linux, test whether the path starts with `/`, in Windows whether it starts
* with `[a-z]:\\`.
**/
static bool is_absolute(std::string p);
bool is_absolute() const { return is_absolute(original); }
bool is_relative() const { return !is_absolute(); }
/// Check whether path is a regular file
bool is_file() const;
/// Check whether path is a regular file
bool is_directory() const;
/// Lexicographically compares two paths
bool operator==(path const& p)
{
return this->string() == p.string();
}
/// Appends elements to the path
path& operator/=(path const& p);
/// output of the path
template <class CharT, class Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, path const& p)
{
out << '"' << p.string() << '"';
return out;
}
protected:
// split the path string into names separated by a `/`, remove relative directories,
// like `.` or `..`, if possible.
void split(std::string p);
private:
std::string original = "";
};
/// Test whether the path is a valid (existing and accessible) file / directory
bool exists(path const&);
/// Create directory and non existing parent directories.
bool create_directories(path const&);
/// Returns the current path
path current_path();
} // end namespace filesystem
} // end namespace Dune
#pragma once
#include <algorithm>
#include <cctype>
#include <locale>
#include <string>
namespace Dune
{
/// convert all characters in a string to upper case
inline std::string to_upper(std::string input)
{
for (auto& c : input)
c = toupper(c);
return input;
}
/// convert