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

Added clamp expression

parent 49c90c0c
......@@ -182,6 +182,11 @@ list(APPEND AMDIS_SRC
${SOURCE_DIR}/ProblemStatDbg.cc
)
if (ENABLE_MPI)
enable_mpi(COMPILEFLAGS AMDIS_INCLUDE_DIRS _)
list(APPEND COMPILEFLAGS "-DHAVE_MPI=1")
endif (ENABLE_MPI)
include(amdis_parallel)
include(muparser)
......
......@@ -20,7 +20,6 @@ if (ENABLE_PARALLEL_DOMAIN)
list(APPEND COMPILEFLAGS "-DHAVE_PARALLEL_DOMAIN_AMDIS=1")
enable_mpi(COMPILEFLAGS AMDIS_INCLUDE_DIRS _)
enable_petsc(COMPILEFLAGS AMDIS_INCLUDE_DIRS _)
# add support for the zoltan library
......
......@@ -22,7 +22,6 @@ if (ENABLE_PARALLEL_DOMAIN)
target_compile_definitions(amdis_parallel INTERFACE
HAVE_PARALLEL_DOMAIN_AMDIS=1)
target_enable_mpi(amdis_parallel INTERFACE)
target_enable_petsc(amdis_parallel INTERFACE)
# add support for the zoltan library
......
......@@ -490,7 +490,7 @@ namespace AMDiS
int getDegree() const
{
return std::max(super::term1.getDegree(), super::term2.getDegree());
return std::max(super::term1.getDegree(), super::term2.getDegree())+2;
}
inline value_type operator()(const int& iq) const
......@@ -514,7 +514,7 @@ namespace AMDiS
int getDegree() const
{
return std::max(super::term1.getDegree(), super::term2.getDegree());
return std::max(super::term1.getDegree(), super::term2.getDegree())+2;
}
inline value_type operator()(const int& iq) const
......@@ -525,6 +525,69 @@ namespace AMDiS
std::string str() const { return std::string("min(") + super::term1.str() + ", " + super::term2.str() + ")"; }
};
template<typename Term1>
struct Clamp : public LazyOperatorTerm1<Term1>
{
typedef LazyOperatorTerm1<Term1> super;
typedef typename Term1::value_type value_type;
Clamp(const Term1& term1_, value_type const& lo = 0.0, value_type const& hi = 1.0)
: super(term1_)
, lo(lo)
, hi(hi)
{
assert( !(hi < lo) );
}
int getDegree() const
{
return super::term.getDegree()+2;
}
inline value_type operator()(const int& iq) const
{
value_type v = super::term(iq);
return v < lo ? lo : hi < v ? hi : v;
}
std::string str() const { return std::string("clamp(") + super::term.str() + ", " + lo + ", " << hi << ")"; }
value_type lo, hi;
};
// derivative of clamp
template<typename Term1>
struct DClamp : public LazyOperatorTerm1<Term1>
{
typedef LazyOperatorTerm1<Term1> super;
typedef typename Term1::value_type value_type;
DClamp(const Term1& term1_, value_type const& lo = 0.0, value_type const& hi = 1.0)
: super(term1_)
, lo(lo)
, hi(hi)
{
assert( !(hi < lo) );
}
int getDegree() const
{
return 2;
}
inline value_type operator()(const int& iq) const
{
value_type v = super::term(iq);
return v < lo ? value_type(0) : hi < v ? value_type(0) : value_type(1);
}
std::string str() const { return std::string("dclamp(") + super::term.str() + ", " + lo + ", " << hi << ")"; }
value_type lo, hi;
};
} // end namespace expressions
......@@ -742,6 +805,22 @@ namespace AMDiS
expressions::Atanh<Term> >::type
atanh(const Term& t) { return expressions::Atanh<Term>(t); }
//______________________________________________________________________________
// clamp between lo and hi
template<typename Term, typename T = typename Term::value_type>
inline typename boost::enable_if<
typename traits::is_expr<Term>::type,
expressions::Clamp<Term> >::type
clamp(const Term& t, T const& lo, T const& hi) { return expressions::Clamp<Term>(t, lo, hi); }
// derivative of clamp between lo and hi
template<typename Term, typename T = typename Term::value_type>
inline typename boost::enable_if<
typename traits::is_expr<Term>::type,
expressions::DClamp<Term> >::type
dclamp(const Term& t, T const& lo, T const& hi) { return expressions::DClamp<Term>(t, lo, hi); }
} // end namespace AMDiS
#endif // AMDIS_CMATH_EXPRESSION_HPP
......@@ -276,6 +276,39 @@ namespace AMDiS
template<typename Term, typename Id>
struct Diff< Id, Abs<Term> > {}; // not yet implemented
template<typename Id, typename Term, typename Direction>
class Diff< Id, Clamp<Term>, Direction >
{
typedef typename Simplify< typename Diff<Id, Term>::type >::type D;
typedef typename Simplify< typename Diff<Id, Term, Direction>::dir_type >::type D_;
public:
typedef Clamp<Term> original_type;
typedef typename Simplify< Mult<D, DClamp<Term>> >::type type;
typedef typename Simplify< Mult<D_,DClamp<Term>> >::type dir_type;
static type eval(original_type const& t)
{
return simplify(diff<Id>(t.term) * dclamp(t.term, t.lo, t.hi));
}
static dir_type eval(original_type const& t, Direction const& d)
{
return simplify(diff<Id>(t.term, d) * dclamp(t.term, t.lo, t.hi));
}
};
template<typename Id, typename Term, typename Direction>
struct Diff< Id, DClamp<Term>, Direction >
{
typedef DClamp<Term> original_type;
typedef CValue<0> type;
typedef CValue<0> dir_type;
static type eval(Term const& t) { return CValue<0>(); }
static dir_type eval(Term const& t, Direction const& d) { return CValue<0>(); }
};
} // end namespace expressions
......@@ -284,7 +317,7 @@ namespace AMDiS
namespace expressions
{
template<typename Id, int I, typename Term, typename Direction>
class Diff< Id, Pow<I, Term>,Direction >
class Diff< Id, Pow<I, Term>, Direction >
{
typedef typename Simplify< typename Diff<Id, Term>::type >::type D;
typedef typename Simplify< typename Diff<Id, Term, Direction>::dir_type >::type D_;
......
......@@ -65,6 +65,15 @@ namespace AMDiS
namespace expressions
{
/// no simplification
template<class T>
struct Simplify< RValue<T> >
{
typedef RValue<T> type;
static type eval(RValue<T> const& t) { return t; }
};
/// -(N) -> (-N)
template<int N>
struct Simplify< Negative<CValue<N> > >
......
......@@ -2,22 +2,16 @@ project("cahn_hilliard_demo")
cmake_minimum_required(VERSION 2.8)
#find_package(AMDIS REQUIRED COMPONENTS umfpack )
find_package(AMDIS REQUIRED)
if(AMDIS_FOUND)
message("amdis was found\n")
include(${AMDIS_USE_FILE})
SET(BASIS_LIBS ${AMDIS_LIBRARIES})
endif(AMDIS_FOUND)
find_package(AMDIS REQUIRED PARALLEL)
set(ch src/cahnHilliard.cc)
add_executable("ch" ${ch})
target_link_libraries("ch" ${BASIS_LIBS})
target_link_libraries("ch" AMDiS)
set(ch_dd src/cahnHilliard_dd.cc src/CahnHilliard_DD.cc)
add_executable("ch_dd" ${ch_dd})
target_link_libraries("ch_dd" ${BASIS_LIBS})
target_link_libraries("ch_dd" AMDiS)
set(ch_shell src/cahnHilliard_shell.cc)
add_executable("ch_shell" ${ch_shell})
target_link_libraries("ch_shell" ${BASIS_LIBS})
target_link_libraries("ch_shell" AMDiS)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment