Commit 3d473c40 authored by Praetorius, Simon's avatar Praetorius, Simon

extensions and tools directory sorted

parent 3a2fe034
......@@ -335,6 +335,45 @@ if(ENABLE_BDDCML)
endif(ENABLE_BDDCML)
if(ENABLE_EXTENSIONS)
find_path(EXTENSIONS_DIR NAMES ${SOURCE_DIR}/../../extensions/Helpers.h DOC "Path to AMDiS extensions.")
if (EXTENSIONS_DIR)
if (NOT EXISTS ${EXTENSIONS_DIR}/Helpers.h OR NOT EXISTS ${EXTENSIONS_DIR}/base_problems/BaseProblem.h)
message(FATAL_ERROR "Wrong extensions directory! Directory must contain the 'Helpers.h' and the subdirectory 'base_problems'")
else()
SET(EXTENSIONS_SRC
${EXTENSIONS_DIR}/Helpers.cc
${EXTENSIONS_DIR}/BackgroundMesh.cc
${EXTENSIONS_DIR}/GeometryTools.cc
${EXTENSIONS_DIR}/POperators.cc
${EXTENSIONS_DIR}/time/ExtendedRosenbrockStationary.cc
${EXTENSIONS_DIR}/pugixml/src/pugixml.cpp)
list(APPEND COMPILEFLAGS "-DHAVE_EXTENSIONS=1")
if(ENABLE_BASE_PROBLEMS)
SET(BASE_PROBLEMS_SRC
${EXTENSIONS_DIR}/base_problems/CahnHilliard.cc
# ${EXTENSIONS_DIR}/base_problems/DiffuseDomainFsi.cc
${EXTENSIONS_DIR}/base_problems/LinearElasticity.cc
${EXTENSIONS_DIR}/base_problems/LinearElasticityPhase.cc
# ${EXTENSIONS_DIR}/base_problems/NavierStokes_Chorin.cc
# ${EXTENSIONS_DIR}/base_problems/NavierStokesPhase_Chorin.cc
${EXTENSIONS_DIR}/base_problems/NavierStokesPhase_TaylorHood.cc
${EXTENSIONS_DIR}/base_problems/NavierStokes_TaylorHood.cc
${EXTENSIONS_DIR}/base_problems/NavierStokes_TaylorHood_RB.cc
${EXTENSIONS_DIR}/base_problems/NavierStokes_TH_MultiPhase.cc
${EXTENSIONS_DIR}/base_problems/NavierStokes_TH_MultiPhase_RB.cc
${EXTENSIONS_DIR}/base_problems/PhaseFieldCrystal_Base.cc
# ${EXTENSIONS_DIR}/base_problems/PhaseFieldCrystal.cc
${EXTENSIONS_DIR}/base_problems/PhaseFieldCrystal_Phase.cc
${EXTENSIONS_DIR}/base_problems/PhaseFieldCrystal_RB.cc)
list(APPEND COMPILEFLAGS "-DHAVE_BASE_PROBLEMS=1")
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
SET(COMPOSITE_SOURCE_DIR ${SOURCE_DIR}/compositeFEM)
SET(COMPOSITE_FEM_SRC ${COMPOSITE_SOURCE_DIR}/CFE_Integration.cc
......@@ -361,6 +400,14 @@ list(APPEND AMDIS_INCLUDE_DIRS ${MUPARSER_SOURCE_DIR}/include)
list(APPEND AMDIS_INCLUDE_DIRS ${MTL_INCLUDE_DIR})
#include_directories(${MTL_INCLUDE_DIR})
list(APPEND AMDIS_INCLUDE_DIRS ${SOURCE_DIR})
if(ENABLE_EXTENSIONS)
list(APPEND AMDIS_INCLUDE_DIRS ${EXTENSIONS_DIR})
if(ENABLE_BASE_PROBLEMS)
list(APPEND AMDIS_INCLUDE_DIRS ${EXTENSIONS_DIR}/base_problems)
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
#include_directories(${SOURCE_DIR})
include_directories(${AMDIS_INCLUDE_DIRS})
......@@ -368,9 +415,23 @@ add_library(amdis SHARED ${AMDIS_SRC} ${PARALLEL_DOMAIN_AMDIS_SRC})
add_library(compositeFEM SHARED ${COMPOSITE_FEM_SRC})
add_library(reinit SHARED ${REINIT_SRC})
add_library(muparser SHARED ${MUPARSER_SRC})
if(ENABLE_EXTENSIONS)
add_library(extensions SHARED ${EXTENSIONS_SRC})
if(ENABLE_BASE_PROBLEMS)
add_library(base_problems SHARED ${BASE_PROBLEMS_SRC})
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
#target_link_libraries(compositeFEM amdis)
#target_link_libraries(reinit amdis)
list(APPEND AMDIS_LIBS amdis ${Boost_LIBRARIES})
if(ENABLE_EXTENSIONS)
list(APPEND AMDIS_LIBS extensions)
if(ENABLE_BASE_PROBLEMS)
list(APPEND AMDIS_LIBS base_problems)
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
if(WIN32)
list(APPEND COMPILEFLAGS "-D_SCL_SECURE_NO_WARNINGS" "-D_CRT_SECURE_NO_WARNINGS")
......@@ -428,6 +489,52 @@ FILE(GLOB HEADERS "${SOURCE_DIR}/io/*.hh")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/io)
# ========== (begin) extensions ==========================
if (ENABLE_EXTENSIONS)
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/*.h")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/)
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/*.hh")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/)
list(APPEND deb_add_dirs "include/amdis/extensions")
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/time/*.h")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/time/)
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/time/*.hh")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/time/)
list(APPEND deb_add_dirs "include/amdis/extensions/time")
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/nanoflann/*.hpp")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/nanoflann/)
list(APPEND deb_add_dirs "include/amdis/extensions/nanoflann")
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/pugixml/src/*.hpp")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/extensions/pugixml/)
list(APPEND deb_add_dirs "include/amdis/extensions/pugixml")
if(ENABLE_BASE_PROBLEMS)
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/base_problems/*.h")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/base_problems/)
FILE(GLOB HEADERS "${EXTENSIONS_DIR}/base_problems/*.hh")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/base_problems/)
list(APPEND deb_add_dirs "include/amdis/base_problems")
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
# ========== (end) extensions ==========================
FILE(GLOB HEADERS "${REINIT_SOURCE_DIR}/*.h")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/reinit)
......@@ -447,6 +554,17 @@ list(APPEND deb_add_dirs "lib/amdis")
install(TARGETS amdis compositeFEM reinit muparser
LIBRARY DESTINATION lib/amdis/ )
if (ENABLE_EXTENSIONS)
list(APPEND deb_add_dirs "lib/amdis/extensions")
install(TARGETS extensions
LIBRARY DESTINATION lib/amdis/extensions/ )
if(ENABLE_BASE_PROBLEMS)
list(APPEND deb_add_dirs "lib/amdis/extensions/base_problems")
install(TARGETS base_problems
LIBRARY DESTINATION lib/amdis/base_problems/ )
endif(ENABLE_BASE_PROBLEMS)
endif(ENABLE_EXTENSIONS)
configure_file(${AMDIS_SOURCE_DIR}/AMDISConfig.cmake.in
${AMDIS_BINARY_DIR}/AMDISConfig.cmake
@ONLY
......
......@@ -100,18 +100,6 @@ struct Diff : public BinaryAbstractFunction<T,T,T>
T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};
template<typename T>
struct L1Diff : public BinaryAbstractFunction<T,T,T>
{
T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};
template<typename T>
struct L2Diff : public BinaryAbstractFunction<T,T,T>
{
T operator()(const T &v1, const T &v2) const { return sqr(v1-v2); }
};
template<typename T>
struct Abs : public AbstractFunction<T,T>
{
......@@ -181,6 +169,18 @@ struct Norm2Sqr_comp3 : public TertiaryAbstractFunction<T,T,T,T>
T operator()(const T &v1, const T &v2, const T &v3) const { return sqr(v1)+sqr(v2)+sqr(v3); }
};
template<typename T>
struct L1Diff : public BinaryAbstractFunction<T,T,T>
{
T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};
template<typename TOut, typename T=TOut>
struct L2Diff : public BinaryAbstractFunction<TOut,T,T>
{
TOut operator()(const T &v1, const T &v2) const { return Norm2<TOut, T>()(v1-v2); }
};
template<typename T>
struct Vec1WorldVec : public AbstractFunction<WorldVector<T>,T>
{
......
......@@ -104,8 +104,11 @@ namespace AMDiS {
inline void writeCoord(boost::iostreams::filtering_ostream &file,
WorldVector<double> coord)
{
file << std::scientific;
file.precision(15);
for (int i = 0; i < Global::getGeo(WORLD); i++)
file << " " << std::scientific << coord[i];
file << " " << coord[i];
for (int i = Global::getGeo(WORLD); i < 3; i++)
file << " "<<0.0;
......@@ -115,8 +118,11 @@ namespace AMDiS {
/// Writes a world coordinate to a given file.
inline void writeCoord(std::ofstream &file, WorldVector<double> coord)
{
file << std::scientific;
file.precision(15);
for (int i = 0; i < Global::getGeo(WORLD); i++)
file << " " << std::scientific << coord[i];
file << " " << coord[i];
for (int i = Global::getGeo(WORLD); i < 3; i++)
file << " "<<0.0;
......
......@@ -251,7 +251,7 @@ namespace AMDiS {
DOFVector< std::list<WorldVector<double> > >::Iterator coordIt(dofCoords, USED_DOFS);
file << std::scientific;
file.precision(5);
file.precision(15);
// Write the values for all vertex DOFs.
for (intPointIt.reset(), valueIt.reset(), coordIt.reset();
......
......@@ -124,6 +124,31 @@ if (TOOLS_DIR)
add_executable("navierStokesDd" ${navierStokesDd})
target_link_libraries("navierStokesDd" ${BASIS_LIBS})
set(linearElasticityDd ${TOOLS_DIR}/baseProblems/LinearElasticityPhase.cc
${TOOLS_DIR}/diffuseDomain/POperators.cc
/home/spraetor/projects/src/common/GeometryTools.cc
src/linearElasticity.cc)
add_executable("linearElasticityDd" ${linearElasticityDd})
target_link_libraries("linearElasticityDd" ${BASIS_LIBS})
set(fsi ${TOOLS_DIR}/baseProblems/LinearElasticityPhase.cc
${TOOLS_DIR}/baseProblems/NavierStokes_TaylorHood.cc
${TOOLS_DIR}/baseProblems/NavierStokesPhase_TaylorHood.cc
${TOOLS_DIR}/misc/Helpers.cc
${TOOLS_DIR}/diffuseDomain/POperators.cc
/home/spraetor/projects/src/common/GeometryTools.cc
src/fsi/fluidStructureInteraction.cc)
add_executable("fsi" ${fsi})
target_link_libraries("fsi" ${BASIS_LIBS})
set(ddFsi ${TOOLS_DIR}/baseProblems/DiffuseDomainFsi.cc
${TOOLS_DIR}/misc/Helpers.cc
${TOOLS_DIR}/diffuseDomain/POperators.cc
/home/spraetor/projects/src/common/GeometryTools.cc
src/diffuseDomainFsi.cc)
add_executable("ddFsi" ${ddFsi})
target_link_libraries("ddFsi" ${BASIS_LIBS})
endif()
else()
message(WARNING "No tools directory specified! Some demos will not be build.")
......
......@@ -25,7 +25,7 @@ elasticity->space->solver: umfpack
elasticity->space->solver->symmetric strategy: 0
elasticity->space->solver->ell: 3
elasticity->space->solver->max iteration: 500
elasticity->space->solver->tolerance: 1.e-8
elasticity->space->solver->tolerance: 10% 1.e-8
elasticity->space->solver->info: 1
elasticity->space->solver->left precon: ilu
......
......@@ -2,7 +2,7 @@ dimension of world: 2
% ====================== VARIABLES ========================
output_folder: output
output_postfix: _phase
output_postfix: _phase2
mesh_name: mesh
polynomial-degree: 1
......
......@@ -42,7 +42,7 @@ ns->space->solver->symmetric strategy: 0
ns->space->solver->ell: 3
ns->space->solver->max iteration: 500
ns->space->solver->restart: 10 % only used for GMRES
ns->space->solver->tolerance: 1.e-8
ns->space->solver->tolerance: 10 %1.e-8
ns->space->solver->info: 1
ns->space->solver->left precon: ilu
......
......@@ -4,7 +4,6 @@
#define NAVIER_STOKES_H
#include "AMDiS.h"
#include "Views.h"
#include "GeometryTools.h"
struct InflowBC : AbstractFunction<double, WorldVector<double> >
......@@ -19,63 +18,18 @@ protected:
};
class Polygon : public AbstractFunction<double, WorldVector<double> >
struct MinWrapper : AbstractFunction<double, WorldVector<double> >
{
public:
Polygon(WorldVector<double> x0_, WorldVector<double> x1_, WorldVector<double> x2_, WorldVector<double> x3_)
{
vertices.push_back(x0_);
vertices.push_back(x1_);
vertices.push_back(x2_);
vertices.push_back(x3_);
vertices.push_back(x0_);
}
Polygon(std::vector<WorldVector<double> > xi_) : vertices(xi_) { }
MinWrapper(AbstractFunction<double, WorldVector<double> >* dist1_, AbstractFunction<double, WorldVector<double> >* dist2_)
: dist1(dist1_), dist2(dist2_) {}
double operator()(const WorldVector<double>& x) const
{
double result = 1.e15;
for (size_t i = 0; i < vertices.size()-1; i++)
result = std::min(result, meshconv::distance_point_line_2d(x.begin(), vertices[i].begin(), vertices[i+1].begin()));
return result * (meshconv::point_in_polygon(x.begin(), vertices) ? -1.0 : 1.0);
}
void refine(int np)
{
std::vector<WorldVector<double> > newVertices;
for (size_t i = 0; i < vertices.size()-1; i++) {
for (size_t j = 0; j < np-1; j++) {
double lambda = static_cast<double>(j)/static_cast<double>(np - 1.0);
WorldVector<double> p = lambda*vertices[i+1] + (1.0-lambda)*vertices[i];
newVertices.push_back(p);
}
}
swap(vertices, newVertices);
return std::min((*dist1)(x), (*dist2)(x));
}
void move(const DOFVector<WorldVector<double> >* velocity)
{
for (size_t i = 0; i < vertices.size()-1; i++) {
WorldVector<double> shift = evalAtPoint(*velocity, vertices[i]);
vertices[i] += shift;
}
vertices[vertices.size()-1] = vertices[0];
}
void move(AbstractFunction<WorldVector<double>, WorldVector<double> >* velocity)
{
for (size_t i = 0; i < vertices.size()-1; i++) {
WorldVector<double> shift = (*velocity)(vertices[i]);
vertices[i] += shift;
}
vertices[vertices.size()-1] = vertices[0];
}
private:
std::vector<WorldVector<double> > vertices;
AbstractFunction<double, WorldVector<double> >* dist1;
AbstractFunction<double, WorldVector<double> >* dist2;
};
#endif
......@@ -13,11 +13,21 @@ using namespace boost::posix_time;
struct BeamDisplacement1d : AbstractFunction<double, double>
{
BeamDisplacement1d(double P_, double L_, double EI_, double* time_, double tau_) : P(P_), L(L_), EI(EI_), time(time_), tau(tau_) {}
BeamDisplacement1d(double P_, double L_, double EI_, double* time_ = NULL, double* tau_ = NULL) : P(P_), L(L_), EI(EI_), time(time_), tau(tau_) {}
double operator()(const double& x) const
{
return (*time < DBL_TOL ? 0.0 : (sin(*time)-sin(*time - tau))*P*sqr(x)*(3.0*L-x)/(6.0*EI));
return (*time < DBL_TOL ? 0.0 : (sin(*time)-sin(*time - *tau))*P*sqr(x)*(3.0*L-x)/(6.0*EI));
}
void setTimePtr(double* time_)
{
time = time_;
}
void setTauPtr(double* tau_)
{
tau = tau_;
}
private:
......@@ -25,12 +35,12 @@ private:
double L;
double EI;
double* time;
double tau;
double* tau;
};
struct BeamDisplacement : AbstractFunction<WorldVector<double>, WorldVector<double> >
{
BeamDisplacement(double P, double L, double EI, double* time, double tau, WorldVector<double> fixedPoint_)
BeamDisplacement(double P, double L, double EI, WorldVector<double> fixedPoint_, double* time = NULL, double* tau = NULL)
: fct(new BeamDisplacement1d(P, L, EI, time, tau)), fixedPoint(fixedPoint_) {}
WorldVector<double> operator()(const WorldVector<double>& x) const
......@@ -39,9 +49,19 @@ struct BeamDisplacement : AbstractFunction<WorldVector<double>, WorldVector<doub
displacement[1] = (x[0] >= fixedPoint[0] ? (*fct)(x[0] - fixedPoint[0]) : 0.0);
return displacement;
}
void setTimePtr(double* time_)
{
fct->setTimePtr(time_);
}
void setTauPtr(double* tau_)
{
fct->setTauPtr(tau_);
}
private:
AbstractFunction<double, double>* fct;
BeamDisplacement1d* fct;
WorldVector<double> fixedPoint;
};
......@@ -93,14 +113,8 @@ public:
refinement->refine(10);
phaseField->interpol(new SignedDistFctToPhaseField(getEpsilon(), obstacle, -3.0));
double P = 0.1, L = 2.0, EI = 1.0;
WorldVector<double> fixedPoint; fixedPoint[0] = 2.5; fixedPoint[1] = 2.0;
Parameters::get("obstacle->P",P);
Parameters::get("obstacle->L",L);
Parameters::get("obstacle->EI",EI);
Parameters::get("obstacle->fixed point",fixedPoint);
beamDisplacement = new BeamDisplacement(P, L, EI, adaptInfo->getTimePtr(), adaptInfo->getTimestep(), fixedPoint);
beamDisplacement->setTimePtr(adaptInfo->getTimePtr());
beamDisplacement->setTauPtr(adaptInfo->getTimestepPtr());
obstacle->refine(10);
}
......@@ -112,9 +126,14 @@ protected:
AbstractFunction<double, WorldVector<double> > *zero = new AMDiS::Const<double, WorldVector<double> >(0.0);
size_t dow = Global::getGeo(WORLD);
WorldVector<double> nullVec; nullVec.set(0.0);
AbstractFunction<WorldVector<double>, WorldVector<double> > *zeroVec = new AMDiS::Const<WorldVector<double>, WorldVector<double> >(nullVec);
super::setBcFct(zeroVec);
double P = 0.1, L = 2.0, EI = 1.0;
WorldVector<double> fixedPoint; fixedPoint[0] = 2.5; fixedPoint[1] = 2.0;
Parameters::get("obstacle->P",P);
Parameters::get("obstacle->L",L);
Parameters::get("obstacle->EI",EI);
Parameters::get("obstacle->fixed point",fixedPoint);
beamDisplacement = new BeamDisplacement(P, L, EI, fixedPoint);
super::setBcFct(beamDisplacement);
super::fillBoundaryConditions();
......@@ -139,8 +158,8 @@ protected:
Parameters::get("ns->Um",Um);
/// at left wall: prescribed velocity
getProblem(0)->addDirichletBC(2, 0, 0, new InflowBC(H,Um));
getProblem(0)->addDirichletBC(2, 1, 1, zero);
// getProblem(0)->addDirichletBC(2, 0, 0, new InflowBC(H,Um));
// getProblem(0)->addDirichletBC(2, 1, 1, zero);
}
void initTimestep(AdaptInfo* adaptInfo)
......@@ -156,7 +175,7 @@ protected:
private:
DOFVector<double>* phaseField;
AbstractFunction<WorldVector<double>, WorldVector<double> >* beamDisplacement;
BeamDisplacement* beamDisplacement;
Polygon* obstacle;
SignedDistRefinement* refFunction;
......
#include "BackgroundMesh.h"
#include "VectorOperations.h" // getMin, sort, CompairPair
#include "Initfile.h"
namespace experimental {
std::map<const FiniteElemSpace*, std::pair<int, Box*> > Box::boxMap;
Box::Box(int DOW_, std::vector<int> N_)
: DOW(DOW_), N(N_), boxFilled(false)
{
min_corner.set(-1.0);
max_corner.set(1.0);
init();
}
Box::Box(int DOW_, PointType min_corner_, PointType max_corner_, std::vector<int> N_)
: DOW(DOW_),
min_corner(min_corner_),
max_corner(max_corner_),
N(N_), boxFilled(false)
{
init();
}
void Box::fillBox(const FiniteElemSpace* feSpace)
{
DOFVector<WorldVector<double> > coords(feSpace, "coords");
feSpace->getMesh()->dofCompress();
feSpace->getMesh()->getDofIndexCoords(feSpace, coords);
for (DegreeOfFreedom i = 0; i < coords.getUsedSize(); i++) {
PointType location(coords[i]);
addData(location, std::make_pair(i, location));
}
boxFilled = true;
}
void Box::clearBox()
{
boxData.clear();
}
void Box::clearBoxData()
{
for (size_t i = 0; i < boxData.size(); i++) {
boxData[i].clear();
}
}
int Box::getMaxBoxSize()
{
size_t maxSize = 0;
for (size_t i = 0; i < boxData.size(); i++) {
maxSize = std::max(maxSize, boxData[i].size());
}
return maxSize;
}
bool Box::inBox(PointType& x)
{
for (size_t i = 0; i < DOW; i++)
if (min_corner[i] > x[i] || max_corner[i] < x[i])
return false;
return true;
}
/**
*
* Ny=2
* ^----------------
* | 4 | 5 | 6 | 7 |
* ----+---+---+----
* | 0 | 1 | 2 | 3 |
* -----------------> Nx=4
**/
int Box::getBox(PointType& x)
{
std::vector<int> idx(DOW);
for (size_t i = 0; i < DOW; i++)
idx[i] = static_cast<int>((x[i]-min_corner[i])*N[i]/(max_corner[i]-min_corner[i]));
// idx[i] = static_cast<int>(floor((x[i]-min_corner[i])*N[i]/(max_corner[i]-min_corner[i])));
return idx2nr(idx);
}
bool Box::getNearestData(PointType& x, DataType& data)
{
if (!inBox(x))
return false;
int nr = getBox(x);
unsigned int n = boxData[nr].size();
// Box, in der x liegt, ist leer
if (n == 0) {
std::vector<DataType> datas;
getNearestData(x, datas, 1);
data = datas[0];
return true;
}
// suche Punkt in aktueller Box, der am nächsten zu x liegt
std::vector<double> distances;
std::vector<DataType>::iterator dataIter;
for (dataIter = boxData[nr].begin(); dataIter != boxData[nr].end(); dataIter++) {
distances.push_back(distance2(x, (*dataIter).second, DOW));