Commit bc2410a6 authored by Praetorius, Simon's avatar Praetorius, Simon

demo directory cleaned up

parent 232e2b2c
......@@ -14,7 +14,6 @@ set(ball src/ball.cc)
set(bunny src/bunny.cc)
set(ellipt src/ellipt.cc)
set(heat src/heat.cc)
set(navierStokes src/navierStokes.cc)
set(neumann src/neumann.cc)
set(nonlin src/nonlin.cc)
set(parametric src/parametric.cc)
......@@ -40,10 +39,6 @@ add_executable("heat" ${heat})
target_link_libraries("heat" ${BASIS_LIBS})
install(TARGETS heat RUNTIME DESTINATION bin)
add_executable("navierStokes" ${navierStokes})
target_link_libraries("navierStokes" ${BASIS_LIBS})
install(TARGETS navierStokes RUNTIME DESTINATION bin)
add_executable("neumann" ${neumann})
target_link_libraries("neumann" ${BASIS_LIBS})
install(TARGETS neumann RUNTIME DESTINATION bin)
......@@ -76,88 +71,5 @@ add_executable("vecheat" ${vecheat})
target_link_libraries("vecheat" ${BASIS_LIBS})
install(TARGETS vecheat RUNTIME DESTINATION bin)
# find tools-directory
find_path(TOOLS_DIR NAMES "baseProblem/BaseProblem.h" "misc/Helpers.h" DOC "Path to tools directory in AMDiS-trunk dir" )
if (TOOLS_DIR)
if (NOT EXISTS ${TOOLS_DIR}/misc/Helpers.h OR NOT EXISTS ${TOOLS_DIR}/baseProblems/BaseProblem.h)
message(WARNING "Wrong tools directory! Directory must contain the subdirectories 'diffuseDomain' and 'baseProblems'")
else()
include_directories(${TOOLS_DIR}/diffuseDomain)
include_directories(${TOOLS_DIR}/baseProblems)
include_directories(${TOOLS_DIR}/misc)
set(elliptBase src/elliptBaseProblem.cc)
add_executable("elliptBase" ${elliptBase})
target_link_libraries("elliptBase" ${BASIS_LIBS})
set(elliptImplicit src/elliptImplicit.cc)
add_executable("elliptImplicit" ${elliptImplicit})
target_link_libraries("elliptImplicit" ${BASIS_LIBS})
set(cahn_hilliard src/cahn_hilliard.cc ${TOOLS_DIR}/baseProblems/CahnHilliard.cc)
add_executable("cahn_hilliard" ${cahn_hilliard})
target_link_libraries("cahn_hilliard" ${BASIS_LIBS})
set(pfc src/pfc.cc ${TOOLS_DIR}/baseProblems/PhaseFieldCrystal_Base.cc ${TOOLS_DIR}/misc/Helpers.cc)
add_executable("pfc" ${pfc})
target_link_libraries("pfc" ${BASIS_LIBS})
set(drivenCavity ${TOOLS_DIR}/diffuseDomain/POperators.cc
${TOOLS_DIR}/baseProblems/CahnHilliard.cc
${TOOLS_DIR}/baseProblems/NavierStokes_TaylorHood.cc
src/chns/drivenCavity.cc)
add_executable("drivenCavity" ${drivenCavity})
target_link_libraries("drivenCavity" ${BASIS_LIBS})
include_directories(/home/spraetor/projects/src/common)
set(navierStokes ${TOOLS_DIR}/diffuseDomain/POperators.cc
# ${TOOLS_DIR}/baseProblems/NavierStokes_TaylorHood.cc
${TOOLS_DIR}/baseProblems/NavierStokes_TaylorHood_RB.cc
${TOOLS_DIR}/baseProblems/time/ExtendedRosenbrockStationary.cc
/home/spraetor/projects/src/common/GeometryTools.cc
src/navierStokes.cc)
add_executable("navierStokes" ${navierStokes})
target_link_libraries("navierStokes" ${BASIS_LIBS})
set(navierStokesDd ${TOOLS_DIR}/diffuseDomain/POperators.cc
${TOOLS_DIR}/baseProblems/NavierStokes_TaylorHood.cc
${TOOLS_DIR}/baseProblems/NavierStokesPhase_TaylorHood.cc
${TOOLS_DIR}/misc/Helpers.cc
/home/spraetor/projects/src/common/GeometryTools.cc
src/navierStokes_diffuseDomain.cc)
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.")
endif(TOOLS_DIR)
#create the output dir
# file(MAKE_DIRECTORY output)
#include "AMDiS.h"
#include "CouplingTimeInterface.h"
#include "Refinement.h"
#include "MeshFunction_Level.h"
#include "CahnHilliard.h"
#include "Views.h"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace AMDiS;
using namespace boost::posix_time;
class RefinementTimeInterface : public CouplingTimeInterface
{
public:
RefinementTimeInterface(CahnHilliard *chProb_) :
chProb(chProb_),
refFunction(NULL),
refinement(NULL)
{
addTimeInterface(chProb);
}
~RefinementTimeInterface()
{
if (refFunction)
delete refFunction;
if (refinement)
delete refinement;
}
virtual void initTimeInterface()
{
chProb->initTimeInterface();
}
/// Called at the end of each timestep.
virtual void closeTimestep(AdaptInfo *adaptInfo)
{
CouplingTimeInterface::closeTimestep(adaptInfo);
refinement->refine(2);
}
/// Set initial condition and perform initial refinement
virtual void solveInitialProblem(AdaptInfo *adaptInfo)
{
refFunction= new PhaseFieldRefinement(chProb->getMesh());
refinement= new RefinementLevelDOF(
chProb->getProblem(0)->getFeSpace(),
refFunction,
new PhaseDOFView<double>(chProb->getProblem(0)->getSolution()->getDOFVector(0)));
// initial refinement
refinement->refine(0);
// refine until interfaces is solved
for (int i = 0; i < 3; ++i) {
chProb->solveInitialProblem(adaptInfo);
refinement->refine((i < 4 ? 4 : 10));
}
CouplingTimeInterface::solveInitialProblem(adaptInfo);
}
protected:
CahnHilliard *chProb;
PhaseFieldRefinement* refFunction;
RefinementLevelDOF *refinement;
};
int main(int argc, char** argv)
{ FUNCNAME("main");
AMDiS::init(argc, argv);
CahnHilliard chProb("ch");
chProb.initialize(INIT_ALL);
RefinementTimeInterface timeInterface(&chProb);
// Adapt-Infos
AdaptInfo adaptInfo("adapt", chProb.getNumComponents());
AdaptInstationary adaptInstat("adapt", chProb, adaptInfo, timeInterface, adaptInfo);
ptime start_time = microsec_clock::local_time();
timeInterface.initTimeInterface(); // fill operators and BC
int error_code = adaptInstat.adapt();
time_duration td = microsec_clock::local_time()-start_time;
MSG("elapsed time= %d sec\n", td.total_seconds());
AMDiS::finalize();
return error_code;
};
/** \file CahnHilliardNavierStokes.h */
#ifndef CAHN_HILLIARD_NAVIER_STOKES_H
#define CAHN_HILLIARD_NAVIER_STOKES_H
// coupling structures
#include "CouplingIterationInterface.h"
#include "CouplingTimeInterface.h"
#include "CouplingProblemStat.h"
// structures for local refinement
#include "Refinement.h"
#include "MeshFunction_Level.h"
#include "POperators.h"
using namespace AMDiS;
/**
* \ingroup Problem
*
* \brief
*/
template<typename CH_Type = CahnHilliard,
typename NS_Type = NavierStokes_TaylorHood>
class CahnHilliardNavierStokes : public CouplingIterationInterface,
public CouplingTimeInterface,
public CouplingProblemStat
{
public:
CahnHilliardNavierStokes(std::string name_, CH_Type *chProb_, NS_Type *nsProb_)
: CouplingProblemStat(name_),
chProb(chProb_),
nsProb(nsProb_),
refFunction(NULL),
refinement(NULL),
sigma(0.0),
surfaceTension(0.0)
{
dow = Global::getGeo(WORLD);
Parameters::get(name + "->sigma", sigma);
surfaceTension = sigma/chProb->getEpsilon();
}
~CahnHilliardNavierStokes() {
if (refFunction != NULL)
delete refFunction;
if (refinement != NULL)
delete refinement;
}
/**
* Add the problems to the iterationInterface, timeInterface and couplingProblemStat.
* As a consequence all problem can be initialized one after another and in the
* adaption loop they are solved in rotation.
* At the end the problems are filled with operators and coupling operators as well as
* boundary conditions are added.
*
* In the adaption loop the problems are solved the same order as they are added to the
* iterationInterface in this method. This order can be changed manually in the oneIteration
* method.
**/
void initialize(AdaptInfo *adaptInfo)
{
for (size_t i = 0; i < chProb->getNumProblems(); i++)
addProblem(chProb->getProblem(i));
for (size_t i = 0; i < nsProb->getNumProblems(); i++)
addProblem(nsProb->getProblem(i));
addIterationInterface(chProb);
addIterationInterface(nsProb);
addTimeInterface(chProb);
addTimeInterface(nsProb);
CouplingProblemStat::initialize(INIT_ALL);
dim = getMesh()->getDim();
fillCouplingOperators();
// fillOperators and fillBoundaryConditions for chProb and nsProb
nsProb->initTimeInterface();
chProb->initTimeInterface();
// fillCouplingBoundaryConditions();
}
/**
* In this method the operators responsible for the coupling of all problems are defined
* and added to the problem. The access to the problems is through the baseBroblem->getProblem()
* method. All baseProblem provide FiniteElemSpaces and solution vectors.
**/
void fillCouplingOperators()
{ FUNCNAME("CahnHilliardNavierStokes::fillCouplingOperators()");
MSG("CahnHilliardNavierStokes::fillCouplingOperators()");
for (size_t i = 0; i < dow; i++) {
// < nu * d_i(c) , theta >
Operator *opNuGradC = new Operator(nsProb->getFeSpace(i), chProb->getFeSpace(0));
opNuGradC->addTerm(new VecAndPartialDerivative_ZOT(chProb->getSolution()->getDOFVector(1), chProb->getSolution()->getDOFVector(0), i));
nsProb->getProblem(0)->addVectorOperator(opNuGradC, i, &surfaceTension, &surfaceTension);
}
// < v * grad(c) , theta >
Operator *opVGradC = new Operator(chProb->getFeSpace(0), chProb->getFeSpace(0));
opVGradC->addTerm(new WorldVector_FOT(nsProb->getVelocity(), -1.0), GRD_PSI);
chProb->getProblem()->addMatrixOperator(opVGradC, 0, 0);
}
/**
* Solves the initial problems.Before this is done the mesh is refined by the Refinement-class
* This provides local refinement functions for phaseField-refinement or signed-distance-refinement.
* See MeshFunction_Level.h for some details.
**/
void solveInitialProblem(AdaptInfo *adaptInfo)
{
// meshFunction for klocal refinement around the interface of the phasefield-DOFVector
refFunction = new PhaseFieldRefinement(chProb->getMesh());
if (chProb->getDoubleWellType() == 0) {
refinement = new RefinementLevelDOF(
chProb->getFeSpace(),
refFunction,
chProb->getSolution()->getDOFVector(0)); // phaseField-DOFVector in [0,1]
} else {
refinement = new RefinementLevelDOF(
chProb->getFeSpace(),
refFunction,
new PhaseDOFView<double>(chProb->getSolution()->getDOFVector(0))); // phaseField-DOFVector in [-1,1]
}
// initial refinement
refinement->refine(0);
for (int i = 0; i < 3; i++) {
chProb->solveInitialProblem(adaptInfo); // update phaseField-DOFVector
refinement->refine((i < 4 ? 4 : 10)); // do k steps of local refinement
}
// solve all initial problems of the problems added to the CouplingTimeInterface
CouplingTimeInterface::solveInitialProblem(adaptInfo);
}
/**
* Called at the end of each timestep.
* If the phase-field has changed the mesh is updated by the refinement-method
**/
void closeTimestep(AdaptInfo *adaptInfo)
{
CouplingTimeInterface::closeTimestep(adaptInfo);
refinement->refine(2);
}
protected:
CH_Type *chProb; // CahnHilliard baseProblem
NS_Type *nsProb; // Navier-Stokes baseProblem
PhaseFieldRefinement* refFunction;
RefinementLevelDOF *refinement;
unsigned dim; // dimension of the mesh
unsigned dow; // dimension of the world
double sigma; // coupling parameter to calculate the surface tension
double surfaceTension;// := sigma/epsilon
};
#endif // CAHN_HILLIARD_NAVIER_STOKES_H
#include "AMDiS.h"
#include "CahnHilliard.h"
#include "NavierStokes_TaylorHood.h"
#include "CahnHilliardNavierStokes.h"
#include "SignedDistFunctors.h"
#include "PhaseFieldConvert.h"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace AMDiS;
using namespace boost::posix_time;
struct DrivenCavityBC : AbstractFunction<double, WorldVector<double> >
{
double operator()(const WorldVector<double> &x) const {
return std::max(0.0, 1.0 - 4.0 * sqr(x[0] - 0.5));
}
};
class CH_DrivenCavity : public CahnHilliard
{
public:
CH_DrivenCavity(std::string name_) : CahnHilliard(name_) {}
protected:
void fillBoundaryConditions()
{ FUNCNAME("CH_DrivenCavity::fillBoundaryConditions()");
// homogeneouse neumann conditions
}
};
class NS_DrivenCavity : public NavierStokes_TaylorHood
{
public:
NS_DrivenCavity(std::string name_) : NavierStokes_TaylorHood(name_) {}
protected:
void fillBoundaryConditions()
{ FUNCNAME("NS_DrivenCavity::fillBoundaryConditions()");
DOFVector<double> *zeroDOF = new DOFVector<double>(getFeSpace(0), "zero");
zeroDOF->set(0.0);
size_t dow = Global::getGeo(WORLD);
/// at rigid wall: no-slip boundary condition
for (size_t i = 0; i < dow; i++)
getProblem(0)->addDirichletBC(1, i, i, zeroDOF);
/// at upper wall: prescribed velocity
getProblem(0)->addDirichletBC(2, 0, 0, new DrivenCavityBC);
getProblem(0)->addDirichletBC(2, 1, 1, zeroDOF);
}
};
int main(int argc, char** argv)
{ FUNCNAME("main");
AMDiS::init(argc, argv);
CH_DrivenCavity chProb("ch");
NS_DrivenCavity nsProb("ns");
CahnHilliardNavierStokes<CH_DrivenCavity,NS_DrivenCavity> mainProb("main", &chProb, &nsProb);
// Adapt-Infos
AdaptInfo adaptInfo("adapt", mainProb.getNumComponents());
mainProb.initialize(&adaptInfo);
// adaption loop - solve ch-prob and ns-prob
AdaptInstationary adaptInstat("adapt", mainProb, adaptInfo, mainProb, adaptInfo);
ptime start_time = microsec_clock::local_time();
int error_code = adaptInstat.adapt();
time_duration td = microsec_clock::local_time()-start_time;
MSG("elapsed time= %d sec\n", td.total_seconds());
AMDiS::finalize();
return error_code;
};
#include "AMDiS.h"
#include "BaseProblem.h"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace AMDiS;
using namespace boost::posix_time;
// ===========================================================================
// ===== function definitions ================================================
// ===========================================================================
/// Dirichlet boundary function
class G : public AbstractFunction<double, WorldVector<double> >
{
public:
/// Implementation of AbstractFunction::operator().
double operator()(const WorldVector<double>& x) const
{
return exp(-10.0 * (x * x));
}
};
/// RHS function
class F : public AbstractFunction<double, WorldVector<double> >
{
public:
F(int degree) : AbstractFunction<double, WorldVector<double> >(degree) {}
/// Implementation of AbstractFunction::operator().
double operator()(const WorldVector<double>& x) const
{
int dow = Global::getGeo(WORLD);
double r2 = (x * x);
double ux = exp(-10.0 * r2);
return -(400.0 * r2 - 20.0 * dow) * ux;
}
};
class ElliptBase : public StandardBaseProblem
{
public:
typedef StandardBaseProblem super;
public:
ElliptBase(std::string name_) : super(name_) {}
protected:
void fillOperators()
{
// ===== create matrix operator =====
Operator *matrixOperator = new Operator(getFeSpace());
matrixOperator->addTerm(new Simple_SOT);
prob->addMatrixOperator(matrixOperator, 0, 0);
// ===== create rhs operator =====
int degree = getFeSpace()->getBasisFcts()->getDegree();
Operator *rhsOperator = new Operator(getFeSpace());
rhsOperator->addTerm(new CoordsAtQP_ZOT(new F(degree)));
prob->addVectorOperator(rhsOperator, 0);
}
void fillBoundaryCondition()
{
// ===== add boundary conditions =====
prob->addDirichletBC(1, 0, 0, new G);
}
};
// ===========================================================================
// ===== main program ========================================================
// ===========================================================================
int main(int argc, char* argv[])
{
FUNCNAME("main");
AMDiS::init(argc, argv);
// ===== create and init the scalar problem =====
ElliptBase ellipt("ellipt");
ellipt.initialize(INIT_ALL);
// === create adapt info ===
AdaptInfo adaptInfo("ellipt->adapt", ellipt.getNumComponents());
// === create adapt ===
AdaptStationary adapt("ellipt->adapt", ellipt, adaptInfo);
// ===== start adaption loop =====
ptime start_time= microsec_clock::local_time();
ellipt.initTimeInterface(); // fillOperators() and fillBoundaryCondition()
adapt.adapt();
time_duration td= microsec_clock::local_time()-start_time;
MSG("elapsed time= %f msec\n", td.total_milliseconds()/1000.0);
ellipt.writeFiles(&adaptInfo, true);
AMDiS::finalize();
}
#include "AMDiS.h"
#include "SignedDistFunctors.h"
#include "ExtendedProblemStat.h"
#include "Refinement.h"
#include "MeshFunction_Level.h"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace AMDiS;
using namespace boost::posix_time;
/**
* solve poisson-equation in domain defined by signed-dist function, using
* dirichlet boundary condition on the implicit boundary (zero level set of
* signed-dist function) and an algebraic equation in the outer domain (sign
* of the signed-dist function poisitive).
**/
// ===========================================================================
// ===== function definitions ================================================
// ===========================================================================
/// Dirichlet boundary function
class G : public AbstractFunction<double, WorldVector<double> >
{
public:
/// Implementation of AbstractFunction::operator().
double operator()(const WorldVector<double>& x) const
{
return 0.0;
}
};
// ===========================================================================
// ===== main program ========================================================
// ===========================================================================
int main(int argc, char* argv[])
{
FUNCNAME("main");
AMDiS::init(argc, argv);
// ===== create and init the scalar problem =====
ExtendedProblemStat ellipt("ellipt");
ellipt.initialize(INIT_ALL);
// === create adapt info ===
AdaptInfo adaptInfo("ellipt->adapt", ellipt.getNumComponents());
// === create adapt ===
AdaptStationary adapt("ellipt->adapt", ellipt, adaptInfo);
// ===== signedDist function that describes the geometry =====
AbstractFunction<double, WorldVector<double> > *signedDistFct = new InverseCircle(1.0);
// ===== refine mesh at interface =====
SignedDistRefinement refFunction(ellipt.getMesh());
RefinementLevelCoords2 refinement(
ellipt.getFeSpace(),
&refFunction,
signedDistFct);
refinement.refine(9);