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

Expressions for gradientOf(vector-values-DOFVector) and trans(matrix) added

parent 8b3e2168
This diff is collapsed.
......@@ -24,6 +24,7 @@
namespace AMDiS {
#if 0
namespace detail {
template<typename Term, typename T, typename Enable = void>
......@@ -50,6 +51,7 @@ template<typename Term>
struct GenericOperatorTerm {
typedef typename detail::GenericOperatorTerm<Term, typename Term::value_type>::type type;
};
#endif
template<typename Term>
......@@ -58,7 +60,7 @@ integrate(Term term, Mesh* mesh_)
{
typedef typename Term::value_type TOut;
typename GenericOperatorTerm<Term>::type ot(term);
GenericOperatorTerm<Term> ot(term);
std::set<const FiniteElemSpace*> feSpaces = ot.getAuxFeSpaces();
TEST_EXIT(mesh_ || !feSpaces.empty())("The Expression must contain a DOFVector or FeSpace depended value!\n");
......@@ -96,7 +98,7 @@ template<typename Term, typename Functor>
inline typename boost::enable_if<typename traits::is_expr<Term>::type, typename Term::value_type>::type
accumulate(Term term, Functor f, typename Term::value_type value0)
{
typename GenericOperatorTerm<Term>::type ot(term);
GenericOperatorTerm<Term> ot(term);
std::set<const FiniteElemSpace*> feSpaces = ot.getAuxFeSpaces();
TEST_EXIT(!feSpaces.empty())("The Expression must contain a DOFVector or FeSpace depended value!\n");
......@@ -148,7 +150,7 @@ transformDOF(Term term, DOFVector<T>* result)
DOFVector<TOut> temp(result->getFeSpace(), "temp");
DOFVector<int> assigned(result->getFeSpace(), "assigned");
typename GenericOperatorTerm<Term>::type ot(term);
GenericOperatorTerm<Term> ot(term);
Mesh* mesh = result->getFeSpace()->getMesh();
const FiniteElemSpace* resultFeSpace = temp.getFeSpace();
......
......@@ -422,6 +422,35 @@ namespace AMDiS
return function_(expressions::MatComponent<typename Term::value_type>(I, J), t);
}
// transpose a matrix
// _____________________________________________________________________________
namespace expressions
{
template<typename Mat>
struct MatTranspose : public FunctorBase
{
typedef Mat result_type;
int getDegree(int d0) const { return d0; }
result_type operator()(const Mat &m) const
{
Mat result;
for (size_t r = 0; r < num_rows(m); r++)
for (size_t c = 0; c < num_cols(m); c++)
result[c][r] = m[r][c];
return result;
}
};
}
template<typename Term>
typename result_of::UnaryExpr<expressions::MatTranspose, Term, traits::is_matrix>::type
trans(const Term& t)
{
return function_(expressions::MatTranspose<typename Term::value_type>(), t);
}
}
#endif // AMDIS_VEC_FUNCTORS_HPP
......@@ -237,22 +237,46 @@ namespace AMDiS
template <typename T>
struct outer< WorldVector<T>, WorldVector<T>, tag::vector, tag::vector >
: boost::mpl::identity<WorldMatrix<T> > {};
template <typename Vector, typename Scalar>
struct outer< Vector, Scalar, tag::vector, tag::scalar >
: boost::mpl::identity<Vector> {};
template <typename Scalar, typename Vector>
struct outer< Scalar, Vector, tag::scalar, tag::vector >
: boost::mpl::identity<Vector> {};
}
template <typename T>
WorldMatrix<T>
inline outer_dispatch(const WorldVector<T>& v1, const WorldVector<T>& v2, boost::mpl::false_)
inline outer_dispatch(const WorldVector<T>& v1, const WorldVector<T>& v2, tag::vector, tag::vector)
{
WorldMatrix<T> result;
result.vecProduct(v1, v2);
return result;
}
template <typename T>
WorldMatrix<T>
inline outer(const WorldVector<T>& v1, const WorldVector<T>& v2)
template <typename Vector, typename Scalar>
Vector inline outer_dispatch(const Vector& v, const Scalar& s, tag::vector, tag::scalar)
{
Vector result(v);
result *= s;
return result;
}
template <typename Scalar, typename Vector>
Vector inline outer_dispatch(const Scalar& s, const Vector& v, tag::scalar, tag::vector)
{
return outer_dispatch(v1, v2, boost::mpl::false_());
return outer_dispatch(v, s, tag::vector(), tag::scalar());
}
template <typename T1, typename T2>
typename result_of::outer<T1, T2, typename traits::category<T1>::tag, typename traits::category<T2>::tag>::type
inline outer(const T1& v1, const T2& v2)
{
typedef typename traits::category<T1>::tag tag1_;
typedef typename traits::category<T2>::tag tag2_;
return outer_dispatch(v1, v2, tag1_(), tag2_());
}
......
......@@ -103,7 +103,7 @@ namespace AMDiS { namespace Parallel {
destroyMatrixData();
}
return 0;
return getErrorCode();
}
void PetscSolver::fillPetscMatrix(DOFMatrix* mat)
......
......@@ -126,6 +126,14 @@ namespace AMDiS {
} else if (residual >= 0.0) {
MSG("Residual norm: ||b-Ax|| = %e\n", residual);
}
if (getIterations() > 0) {
MSG("Nr. of iterations needed = %d\n", getIterations());
}
if (error_code != 0) {
MSG("ERROR-Code = %d\n", error_code);
}
// test for absolute tolerance
TEST_EXIT((isNumber(residual) && (residual < 0.0 || tolerance < 1.e-30 || residual <= tolerance))
......
......@@ -167,6 +167,14 @@ namespace AMDiS
typedef int size_type;
};
template<typename T>
struct category<WorldVector<WorldVector<T> > >
{
typedef tag::matrix tag;
typedef T value_type;
typedef int size_type;
};
template<typename T, typename Parameters>
struct category<mtl::dense2D<T, Parameters> >
{
......
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