keller_details.h
Go to the documentation of this file.
#ifndef _RHEOLEF_KELLER_DETAILS_H
#define _RHEOLEF_KELLER_DETAILS_H
#include "rheolef/pair_with_linear_algebra.h"
namespace rheolef { namespace details {
// -----------------
// reset
// -----------------
template<class T>
void reset (T& x) { x = 0; }
template<class T>
void reset (std::valarray<T>& x) {
for (size_t i = 0; i < x.size(); ++i) reset(x[i]);
}
template<class T1, class T2>
void reset (pair_with_linear_algebra<T1,T2>& x)
{
reset (x.first);
reset (x.second);
}
// -----------------
// max_abs
// -----------------
template<class T>
T max_abs (const T& x) { return abs(x); }
template<class T>
T max_abs (const field_basic<T>& x) { return x.max_abs(); }
template<class T>
typename field_basic<T>::float_type
max_abs (const std::valarray<field_basic<T> >& x) {
typename field_basic<T>::float_type value = 0;
for (size_t i = 0; i < x.size(); ++i) {
value = std::max(value, x[i].max_abs());
}
return value;
}
// -----------------
// unknown_size
// -----------------
template<class T>
size_t get_unknown (const T& x) { return 1; }
template<class T>
size_t
unknown_size (const field_basic<T>& x) { return x.u().size(); }
template<class T>
size_t
unknown_size (const std::valarray<field_basic<T> >& x) {
size_t n = 0;
for (size_t i = 0; i < x.size(); ++i) {
n += x[i].u().size();
}
return n;
}
// -----------------
// get_unknown part
// -----------------
template<class T>
T get_unknown (const T& x) { return x; }
template<class T>
T get_unknown (const T& x, const distributor&) { return x; }
template<class T>
vec<T> get_unknown (const field_basic<T>& x) { return x.u(); }
template<class T>
vec<T> get_unknown (const field_basic<T>& x, const distributor&) { return x.u(); }
template<class T>
vec<T> get_unknown (const std::valarray<field_basic<T> >& x, const distributor& ownership) {
vec<T> y (ownership, T(0));
for (size_t i = 0, start = 0; i < x.size(); ++i) {
std::copy (x[i].u().begin(), x[i].u().end(), y.begin()+start);
start += x[i].u().size();
}
return y;
}
template<class T>
vec<T> get_unknown (const std::valarray<field_basic<T> >& x) {
if (x.size() == 0) return vec<T>();
size_t n = 0, dis_n = 0;
for (size_t i = 0; i < x.size(); ++i) {
n += x[i].u().size();
dis_n += x[i].u().dis_size();
}
communicator comm = x[0].u().ownership().comm();
distributor ownership (dis_n, comm, n);
return get_unknown (x, ownership);
}
// -----------------
// set_unknown part
// -----------------
template<class T>
void set_unknown (T& x, const T& value) { x = value; }
template<class T>
void set_unknown (field_basic<T>& x, const vec<T>& value) {
// value.size == x.size+1 on one proc
size_t size = x.u().size();
std::copy (value.begin(), value.begin() + size, x.set_u().begin());
}
template<class T>
void set_unknown (std::valarray<field_basic<T> >& x, const vec<T>& value) {
size_t start = 0;
for (size_t i = 0; i < x.size(); ++i) {
size_t last = start + x[i].u().size();
std::copy (value.begin() + start, value.begin() + last, x[i].set_u().begin());
start = last;
}
}
}} // namespace rheolef::details
#endif // _RHEOLEF_KELLER_DETAILS_H
rheolef::distributor
see the distributor page for the full documentation
Definition: distributor.h:62
rheolef::field_basic
Definition: field.h:235
rheolef::field_basic::max_abs
T max_abs() const
Definition: field.h:731
rheolef::field_basic::set_u
vec< T, M > & set_u()
Definition: field.h:312
rheolef::field_basic::u
const vec< T, M > & u() const
Definition: field.h:310
rheolef::field_basic::float_type
typename float_traits< T >::type float_type
Definition: field.h:245
rheolef::vec
see the vec page for the full documentation
Definition: vec.h:79
rheolef::value
rheolef::std value
T
Expr1::float_type T
Definition: field_expr.h:261
mkgeo_ball.n
int n
Definition: mkgeo_ball.sh:150
rheolef::details::reset
void reset(T &x)
Definition: keller_details.h:31
rheolef::details::get_unknown
size_t get_unknown(const T &x)
Definition: keller_details.h:65
rheolef::details::max_abs
T max_abs(const T &x)
Definition: keller_details.h:47
rheolef::details::unknown_size
size_t unknown_size(const field_basic< T > &x)
Definition: keller_details.h:69
rheolef::details::set_unknown
void set_unknown(T &x, const T &value)
Definition: keller_details.h:119
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::details::pair_with_linear_algebra
Definition: pair_with_linear_algebra.h:27
u
Float u(const point &x)
Definition: transmission_error.cc:26