Commit 4a51c82c authored by Praetorius, Simon's avatar Praetorius, Simon

initial commit of dune-amdis module

parents
Pipeline #88 skipped
cmake_minimum_required(VERSION 2.8.12)
project(amdis 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)
MAKE_FLAGS flags passed to make
An example options file might look like this:
#use this options to autogen, configure and make if no other options are given
CMAKE_FLAGS=" \
-DCMAKE_CXX_COMPILER=g++-4.9 \
-DCMAKE_CXX_FLAGS='-Wall -pedantic' \
-DCMAKE_INSTALL_PREFIX=/install/path" #Force g++-4.9 and set compiler flags
MAKE_FLAGS=install #Per default run make install instead of simply make
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!
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@
Name: @PACKAGE_NAME@
Version: @VERSION@
Description: amdis module
URL: http://dune-project.org/
Requires: dune-common dune-geometry dune-localfunctions dune-istl dune-typetree dune-grid dune-functions
Libs: -L${libdir}
Cflags: -I${includedir}
# File for module specific CMake tests.
set(modules "AmdisMacros.cmake")
install(FILES ${modules} DESTINATION ${DUNE_INSTALL_MODULEDIR})
/* begin amdis
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 amdis */
#define AMDIS_VERSION "@AMDIS_VERSION@"
/* Define to the major version of amdis */
#define AMDIS_VERSION_MAJOR @AMDIS_VERSION_MAJOR@
/* Define to the minor version of amdis */
#define AMDIS_VERSION_MINOR @AMDIS_VERSION_MINOR@
/* Define to the revision of amdis */
#define AMDIS_VERSION_REVISION @AMDIS_VERSION_REVISION@
/* end amdis
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/amdis/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/amdis/pics
################################
# Dune module information file #
################################
#Name of the module
Module: amdis
Version: 0.1
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-common dune-geometry dune-localfunctions dune-istl dune-typetree dune-grid dune-functions
add_subdirectory(amdis)
#install headers
install(FILES amdis.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/amdis)
#ifndef AMDIS_HH
#define AMDIS_HH
// add your classes here
#endif // AMDIS_HH
#include "AdaptInfo.hpp"
// std c++ headers
#include <string>
#include <iostream>
#include "Initfile.hpp"
namespace AMDiS
{
AdaptInfo::ScalContent::ScalContent(std::string prefix)
{
Parameters::get(prefix + "->tolerance", spaceTolerance);
Parameters::get(prefix + "->time tolerance", timeTolerance);
Parameters::get(prefix + "->time relative tolerance", timeRelativeTolerance);
Parameters::get(prefix + "->coarsen allowed", coarsenAllowed);
Parameters::get(prefix + "->refinement allowed", refinementAllowed);
Parameters::get(prefix + "->refine bisections", refineBisections);
Parameters::get(prefix + "->coarsen bisections", coarseBisections);
Parameters::get(prefix + "->sum factor", fac_sum);
Parameters::get(prefix + "->max factor", fac_max);
if (timeTolerance == 0.0 && timeRelativeTolerance == 0.0)
timeTolerance = 1.0;
timeErrLow = timeTolerance * 0.3;
}
AdaptInfo::AdaptInfo(std::string name_, int size)
: name(name_),
scalContents(size)
{
// init();
Parameters::get(name + "->start time", startTime);
time = startTime;
Parameters::get(name + "->timestep", timestep);
Parameters::get(name + "->end time", endTime);
Parameters::get(name + "->max iteration", maxSpaceIteration);
Parameters::get(name + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name + "->max time iteration", maxTimeIteration);
Parameters::get(name + "->min timestep", minTimestep);
Parameters::get(name + "->max timestep", maxTimestep);
Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name + "->time tolerance", globalTimeTolerance);
for (int i = 0; i < size; i++)
{
scalContents[i] = new ScalContent(name + "[" + std::to_string(i) + "]");
}
}
void AdaptInfo::setScalContents(int newSize)
{
int oldSize = static_cast<int>(scalContents.size());
if (newSize > oldSize)
{
scalContents.resize(newSize);
for (int i = oldSize; i < newSize; i++)
scalContents[i] =
new ScalContent(name + "[" + std::to_string(i) + "]");
}
}
void AdaptInfo::printTimeErrorLowInfo() const
{
for (size_t i = 0; i < scalContents.size(); i++)
{
std::cout << " Time error estimate ["<<i<<"] = "
<< getTimeEstCombined(i) << "\n"
<< " Time error estimate sum ["<<i<<"] = "
<< scalContents[i]->est_t_sum << "\n"
<< " Time error estimate max ["<<i<<"] = "
<< scalContents[i]->est_t_max << "\n"
<< " Time error low bound ["<<i<<"] = "
<< scalContents[i]->timeErrLow << "\n"
<< " Time error high bound ["<<i<<"] = "
<< scalContents[i]->timeTolerance << "\n";
}
}
void AdaptInfo::reset()
{
spaceIteration = -1;
timestepIteration = 0;
timeIteration = 0;
time = 0.0;
timestep = 0.0;
timestepNumber = 0;
solverIterations = 0;
solverResidual = 0.0;
Parameters::get(name + "->timestep", timestep);
lastProcessedTimestep=timestep;
}
} // end namespace AMDiS
This diff is collapsed.
#pragma once
#include <cassert>
#include <tuple>
namespace AMDiS
{
template <int I>
using int_ = std::integral_constant<int, I>;
template <bool B>
using bool_ = std::integral_constant<bool, B>;
template <class T>
using IdxPairList = std::map< std::pair<int, int>, std::list<std::shared_ptr<T> > >;
template <class T>
using IdxList = std::map< int, std::list<std::shared_ptr<T> > >;
namespace Impl
{
// add arg to repeated constructor argument list
template <class Tuple, size_t n, class Arg, class... Args>
Tuple construct_tuple_aux(int_<n>, Arg&& arg, Args&&... args)
{
return construct_tuple_aux<Tuple>(int_<n-1>(),
std::forward<Arg>(arg), std::forward<Arg>(arg), std::forward<Args>(args)...);
}
template <class Tuple, class... Args>
Tuple construct_tuple_aux(int_<1>, Args&&... args)
{
static_assert(std::tuples_size<Tuple>::value == sizeof...(args),
"Nr. of argument != tuple-size");
return {std::forward<Args>(args)...};
}
template <class Tuple, class... Args>
Tuple construct_tuple_aux(int_<0>, Args&&... args)
{
static_assert(std::tuples_size<Tuple>::value == 0,
"Construction of empty tuples with empty argument list only!");
return {};
}
} // end namespace Impl
// construct a tuple with each element constructed by the same argument arg.
template <class Tuple, class Arg>
Tuple construct_tuple(Arg&& arg)
{
return Impl::construct_tuple_aux<Tuple>(int_<std::tuples_size<Tuple>::value>(),
std::forward<Arg>(arg));
}
} // end namespace AMDiS
add_executable("amdis" amdis.cc)
target_link_dune_default_libraries("amdis")
#pragma once
#include <functional>
#include <type_traits>
#include <vector>
#include <dune/functions/common/functionconcepts.hh>
namespace AMDiS
{
template <class WorldVector>
class DirichletBC
{
public:
template <class Predicate, class Values,
class = std::enable_if_t< Functions::Concept::isFunction<Predicate, bool(WorldVector)>() &&
Functions::Concept::isFunction<Values, double(WorldVector)>() > >
DirichletBC(Predicate&& predicate, Values&& values)
: predicate(std::forward<Predicate>(predicate))
, values(std::forward<Values>(values)
{}
template <class RowFeSpace, class ColFeSpace, class DOFMatrix, class DOFVector>
void init(bool apply,
RowFeSpace const& rowFeSpace,
ColFeSpace const& colFeSpace,
DOFMatrix* matrix,
DOFVector* rhs,
DOFVector* solution);
template <class RowFeSpace, class ColFeSpace, class DOFMatrix, class DOFVector>
void finish(bool apply,
RowFeSpace const& rowFeSpace,
ColFeSpace const& colFeSpace,
DOFMatrix* matrix,
DOFVector* rhs,
DOFVector* solution);
private:
std::function<bool(WorldVector)> predicate;
std::function<double(WorldVector)> values;
bool initialized = false;
std::vector<char> dirichletNodes;
};
} // end namespace AMDiS
#include "DirichletBC.inc.hpp"
#pragma once
#include <dune/functions/functionspacebases/interpolate.hh>
namespace AMDiS
{
template <class RowFeSpace, class ColFeSpace, class DOFMatrix, class DOFVector>
void DirichletBC<WorldVector>::init(bool apply,
RowFeSpace const& rowFeSpace,
ColFeSpace const& colFeSpace,
DOFMatrix* matrix,
DOFVector* rhs,
DOFVector* solution)
{
using Dune::Functions::interpolate;
if (!initialized)
interpolate(rowFeSpace, dirichletNodes, predicate);
}
template <class RowFeSpace, class ColFeSpace, class DOFMatrix, class DOFVector>
void DirichletBC<WorldVector>::finish(bool apply,
RowFeSpace const& rowFeSpace,
ColFeSpace const& colFeSpace,
DOFMatrix* matrix,
DOFVector* rhs,
DOFVector* solution)
{
using Dune::Functions::interpolate;
assert( initialized );
// loop over the matrix rows
for (size_t i = 0; i < stiffnessMatrix.N(); ++i) {
if (dirichletNodes[i]) {
auto cIt = (*matrix)[i].begin();
auto cEndIt = (*matrix)[i].end();
// loop over nonzero matrix entries in current row
for (; cIt != cEndIt; ++cIt)
*cIt = (apply && i == cIt.index()) ? 1.0 : 0.0;
}
}
if (apply) {
interpolate(rowFeSpace, *rhs, values, dirichletNodes);
interpolate(colFeSpace, *solution, values, dirichletNodes);
}
}
} // end namespace AMDiS
#pragma once
namespace AMDiS
{
/** \ingroup Common
* \brief
* The Flag class encapsulates flags which represents simple information.
* Used e.g. while mesh traversal to specify, which elements should be
* visited.
*/
class Flag
{
public:
/// Constructs a unset Flag
Flag() : flags(0) {}
/// Constructs a Flag initialized by f
Flag(const unsigned long f) : flags(f) {}
/// Copy constructor
Flag(Flag const& f) : flags(f.flags) {}
/// Compares two Flags
bool operator==(Flag const& f) const
{
return (flags == f.flags);
}
/// Compares two Flags
bool operator!=(Flag const& f) const
{
return !(f == *this);
}
/// Assignment operator
Flag& operator=(Flag const& f)
{
if (this != &f)
flags = f.flags;
return *this;
}
/// Typecast
operator bool() const
{
return isAnySet();
}
/// Set \ref flags
void setFlags(const unsigned long f)
{
flags = f;
}
/// Set \ref flags
void setFlags(Flag const& f)
{
flags = f.flags;
}
/// Sets \ref flags to \ref flags | f
void setFlag(const unsigned long f)
{
flags |= f;
}
/// Sets \ref flags to \ref flags | f.flags
void setFlag(Flag const& f)
{
flags |= f.flags;
}
/// Sets \ref flags to \ref flags & ~f
void unsetFlag(const unsigned long f)
{
flags &= ~f;
}
/// Sets \ref flags to \ref flags & ~f.flags
void unsetFlag(Flag const& f)
{
flags &= ~f.flags;
}
unsigned long getFlags() const
{
return flags;
}
/// Returns \ref flags | f.flags
Flag operator+(Flag const& f) const
{
Flag r(flags);
r.setFlag(f);
return r;
}
/// Returns \ref flags & ~f.flags
Flag operator-(Flag const& f) const
{
Flag r(flags);
r.unsetFlag(f);
return r;
}
/// Returns \ref flags | f.flags
Flag operator|(Flag const& f) const
{
Flag r(flags);
r.setFlag(f);
return r;
}
/// Returns \ref flags & f.flags
Flag operator&(Flag const& f) const
{
Flag r(flags);
r.flags &= f.flags;
return r;
}
/// Sets \ref flags to \ref flags &= f.flags
Flag operator&=(Flag const& f)
{
flags &= f.flags;
return *this;
}
/// Returns \ref flags ^ f.flags
Flag operator^(Flag const& f) const
{
Flag r(flags);
r.flags ^= f.flags;
return r;
}
/// Sets \ref flags to \ref flags & f.flags
Flag& operator|=(Flag const& f)
{
if (this != &f)
flags |= f.flags;
return *this;
}
/// Returns ~\ref flags
Flag operator~() const
{
Flag r;
r.flags = ~flags;
return r;
}
/// Checks whether all set bits of f.flags are set in \ref flags too.
bool isSet(Flag const& f) const
{
return ((flags&f.flags) == f.flags);
}
/// Returns !\ref isSet(f)
bool isUnset(Flag const& f) const
{
return !isSet(f);
}
/// Returns true if \ref flags != 0
bool isAnySet() const
{
return (flags != 0);
}
protected:
/// Internal flag representation
unsigned long flags;
};
} // end namespace AMDiS
#define AMDIS_NO_EXTERN_INITFILE
#include "Initfile.hpp"
#undef AMDIS_NO_EXTERN_INITFILE
#include <string>
#ifdef _MSC_VER
#include <io.h> // _access
#else
#include <unistd.h>
#endif
#include <boost/property_tree/json_parser.hpp>
// a parser for arithmetic expressions
#include <muParser.h>
#include "Log.hpp"
namespace AMDiS
{
/// check for file existence
inline bool file_exists(std::string const& filename)
{
#ifdef _MSC_VER
return _access(filename.c_str(), 0) == 0;
#else
return access(filename.c_str(), F_OK) == 0;
#endif
}
namespace detail
{
double mu_parser_eval(std::string const& valStr)
{
mu::Parser parser;
parser.DefineConst(_T("M_PI"), m_pi);
parser.DefineConst(_T("M_E"), m_e);
parser.SetExpr(valStr);
return parser.Eval();
}
}
Initfile* Initfile::singlett = NULL;
/// initialize singleton object an global parameters
void Initfile::init(std::string in)
{
initIntern();
singlett->read(in);
singlett->getInternalParameters();
}
/// Fill an initfile from a file with filename fn
void Initfile::read(std::string fn, bool /*force*/)
{
TEST_EXIT( file_exists(fn) )
("init-file '%s' cannot be opened for reading", fn.c_str());
using namespace boost::property_tree;
json_parser::read_json(fn, pt);
}
/// read standard values for output and information of parameter-values
void Initfile::getInternalParameters()
{
int val = 0;
get("level of information", val, 0);
msgInfo = val;
val = 1;
get("parameter information", val, 0);
paramInfo = val;
val = 0;
get("break on missing tag", val, 0);
breakOnMissingTag = val;
if (msgInfo == 0)
paramInfo = 0;
}