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
#pragma once
// std c++ headers
#include <cmath>
#include <string>
#include <vector>
// AMDiS includes
#include "Log.hpp"
#include "Math.hpp"
namespace AMDiS
{
/**
* \ingroup Adaption
*
* \brief
* Holds adapt parameters and infos about the problem. Base class
* for AdaptInfoScal and AdaptInfoVec.
*/
class AdaptInfo
{
protected:
/** \brief
* Stores adapt infos for a scalar problem or for one component of a
* vector valued problem.
*/
class ScalContent
{
public:
/// Constructor.
explicit ScalContent(std::string prefix);
/// Sum of all error estimates
double est_sum = 0.0;
/// Sum of all time error estimates
double est_t_sum = 0.0;
/// maximal local error estimate.
double est_max = 0.0;
/// Maximum of all time error estimates
double est_t_max = 0.0;
/// factors to combine max and integral time estimate
double fac_max = 0.0, fac_sum = 1.0;
/// Tolerance for the (absolute or relative) error
double spaceTolerance = 0.0;
/// Time tolerance.
double timeTolerance = 0.0;
/// Relative time tolerance
double timeRelativeTolerance = 0.0;
/// Lower bound for the time error.
double timeErrLow = 0.0;
/// true if coarsening is allowed, false otherwise.
int coarsenAllowed = 0;
/// true if refinement is allowed, false otherwise.
int refinementAllowed = 1;
/** \brief
* parameter to tell the marking strategy how many bisections should be
* performed when an element is marked for refinement; usually the value is
* 1 or DIM
*/
int refineBisections = 1;
/** \brief
* parameter to tell the marking strategy how many bisections should
* be undone when an element is marked for coarsening; usually the value is
* 1 or DIM
*/
int coarseBisections = 1;
};
public:
/// Constructor.
AdaptInfo(std::string name_, int size = 1);
/// Destructor.
virtual ~AdaptInfo()
{
for (size_t i = 0; i < scalContents.size(); i++)
delete scalContents[i];
}
/// Resets all variables to zero (or something equivalent)
void reset();
/// Returns whether space tolerance is reached.
virtual bool spaceToleranceReached() const
{
for (size_t i = 0; i < scalContents.size(); i++)
{
if (!(scalContents[i]->est_sum < scalContents[i]->spaceTolerance))
return false;
}
return true;
}
/// Returns whether space tolerance of component i is reached.
virtual bool spaceToleranceReached(int i) const
{
if (!(scalContents[i]->est_sum < scalContents[i]->spaceTolerance))
return false;
else
return true;
}
/// Returns whether time tolerance is reached.
virtual bool timeToleranceReached() const
{
for (size_t i = 0; i < scalContents.size(); i++)
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance))
return false;
return true;
}
/// Returns whether time tolerance of component i is reached.
virtual bool timeToleranceReached(int i) const
{
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance))
return false;
else
return true;
}
/// Returns whether time error is under its lower bound.
virtual bool timeErrorLow() const
{
for (size_t i = 0; i < scalContents.size(); i++)
if (!(getTimeEstCombined(i) < scalContents[i]->timeErrLow))
return false;
return true;
}
/// Returns the time estimation as a combination
/// of maximal and integral time error
double getTimeEstCombined(size_t i) const
{
return
scalContents[i]->est_t_max * scalContents[i]->fac_max +
scalContents[i]->est_t_sum * scalContents[i]->fac_sum;
}
/// Print debug information about time error and its bound.
void printTimeErrorLowInfo() const;
/// Returns \ref spaceIteration.
int getSpaceIteration() const
{
return spaceIteration;
}
/// Sets \ref spaceIteration.
void setSpaceIteration(int it)
{
spaceIteration = it;
}
/// Returns \ref maxSpaceIteration.
int getMaxSpaceIteration() const
{
return maxSpaceIteration;
}
/// Sets \ref maxSpaceIteration.
void setMaxSpaceIteration(int it)
{
maxSpaceIteration = it;
}
/// Increments \ref spaceIteration by 1;
void incSpaceIteration()
{
spaceIteration++;
}
/// Sets \ref timestepIteration.
void setTimestepIteration(int it)
{
timestepIteration = it;
}
/// Returns \ref timestepIteration.
int getTimestepIteration() const
{
return timestepIteration;
}
/// Increments \ref timestepIteration by 1;
void incTimestepIteration()
{
timestepIteration++;
}
/// Returns \ref maxTimestepIteration.
int getMaxTimestepIteration() const
{
return maxTimestepIteration;
}
/// Sets \ref maxTimestepIteration.
void setMaxTimestepIteration(int it)
{
maxTimestepIteration = it;
}
/// Sets \ref timeIteration.
void setTimeIteration(int it)
{
timeIteration = it;
}
/// Returns \ref timeIteration.
int getTimeIteration() const
{
return timeIteration;
}
/// Increments \ref timesIteration by 1;
void incTimeIteration()
{
timeIteration++;
}
/// Returns \ref maxTimeIteration.
int getMaxTimeIteration() const
{
return maxTimeIteration;
}
/// Sets \ref maxTimeIteration.
void setMaxTimeIteration(int it)
{
maxTimeIteration = it;
}
/// Returns \ref timestepNumber.
int getTimestepNumber() const
{
return timestepNumber;
}
/// Sets \ref timestepNumber.
void setTimestepNumber(int num)
{
timestepNumber = std::min(nTimesteps, num);
}
/// Returns \ref nTimesteps.
int getNumberOfTimesteps() const
{
return nTimesteps;
}
/// Sets \ref nTimesteps.
void setNumberOfTimesteps(int num)
{
nTimesteps = std::max(0, num);
}
/// Increments \ref timestepNumber by 1;
void incTimestepNumber()
{
timestepNumber++;
}
/// Sets \ref est_sum.
void setEstSum(double e, int index)
{
scalContents[index]->est_sum = e;
}
/// Sets \ref est_max.
void setEstMax(double e, int index)
{
scalContents[index]->est_max = e;
}
/// Sets \ref est_max.
void setTimeEstMax(double e, int index)
{
scalContents[index]->est_t_max = e;
}
/// Sets \ref est_t_sum.
void setTimeEstSum(double e, int index)
{
scalContents[index]->est_t_sum = e;
}
/// Returns \ref est_sum.
double getEstSum(int index) const
{
FUNCNAME_DBG("AdaptInfo::getEstSum()");
TEST_EXIT_DBG(static_cast<size_t>(index) < scalContents.size())
("Wrong index for adaptInfo!\n");
return scalContents[index]->est_sum;
}
/// Returns \ref est_t_sum.
double getEstTSum(int index) const
{
return scalContents[index]->est_t_sum;
}
/// Returns \ref est_max.
double getEstMax(int index) const
{
FUNCNAME_DBG("AdaptInfo::getEstSum()");
TEST_EXIT_DBG(static_cast<size_t>(index) < scalContents.size())
("Wrong index for adaptInfo!\n");
return scalContents[index]->est_max;
}
/// Returns \ref est_max.
double getTimeEstMax(int index) const
{
return scalContents[index]->est_t_max;
}
/// Returns \ref est_t_sum.
double getTimeEstSum(int index) const
{
return scalContents[index]->est_t_sum;
}