Rheolef  7.1
an efficient C++ finite element environment
keller_details.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_KELLER_DETAILS_H
2 #define _RHEOLEF_KELLER_DETAILS_H
23 #include "rheolef/pair_with_linear_algebra.h"
24 
25 namespace rheolef { namespace details {
26 
27 // -----------------
28 // reset
29 // -----------------
30 template<class T>
31 void reset (T& x) { x = 0; }
32 
33 template<class T>
34 void reset (std::valarray<T>& x) {
35  for (size_t i = 0; i < x.size(); ++i) reset(x[i]);
36 }
37 template<class T1, class T2>
39 {
40  reset (x.first);
41  reset (x.second);
42 }
43 // -----------------
44 // max_abs
45 // -----------------
46 template<class T>
47 T max_abs (const T& x) { return abs(x); }
48 
49 template<class T>
50 T max_abs (const field_basic<T>& x) { return x.max_abs(); }
51 
52 template<class T>
54 max_abs (const std::valarray<field_basic<T> >& x) {
55  typename field_basic<T>::float_type value = 0;
56  for (size_t i = 0; i < x.size(); ++i) {
57  value = std::max(value, x[i].max_abs());
58  }
59  return value;
60 }
61 // -----------------
62 // unknown_size
63 // -----------------
64 template<class T>
65 size_t get_unknown (const T& x) { return 1; }
66 
67 template<class T>
68 size_t
69 unknown_size (const field_basic<T>& x) { return x.u().size(); }
70 
71 template<class T>
72 size_t
73 unknown_size (const std::valarray<field_basic<T> >& x) {
74  size_t n = 0;
75  for (size_t i = 0; i < x.size(); ++i) {
76  n += x[i].u().size();
77  }
78  return n;
79 }
80 // -----------------
81 // get_unknown part
82 // -----------------
83 template<class T>
84 T get_unknown (const T& x) { return x; }
85 template<class T>
86 T get_unknown (const T& x, const distributor&) { return x; }
87 
88 template<class T>
89 vec<T> get_unknown (const field_basic<T>& x) { return x.u(); }
90 template<class T>
91 vec<T> get_unknown (const field_basic<T>& x, const distributor&) { return x.u(); }
92 
93 template<class T>
94 vec<T> get_unknown (const std::valarray<field_basic<T> >& x, const distributor& ownership) {
95  vec<T> y (ownership, T(0));
96  for (size_t i = 0, start = 0; i < x.size(); ++i) {
97  std::copy (x[i].u().begin(), x[i].u().end(), y.begin()+start);
98  start += x[i].u().size();
99  }
100  return y;
101 }
102 
103 template<class T>
104 vec<T> get_unknown (const std::valarray<field_basic<T> >& x) {
105  if (x.size() == 0) return vec<T>();
106  size_t n = 0, dis_n = 0;
107  for (size_t i = 0; i < x.size(); ++i) {
108  n += x[i].u().size();
109  dis_n += x[i].u().dis_size();
110  }
111  communicator comm = x[0].u().ownership().comm();
112  distributor ownership (dis_n, comm, n);
113  return get_unknown (x, ownership);
114 }
115 // -----------------
116 // set_unknown part
117 // -----------------
118 template<class T>
119 void set_unknown (T& x, const T& value) { x = value; }
120 
121 template<class T>
123  // value.size == x.size+1 on one proc
124  size_t size = x.u().size();
125  std::copy (value.begin(), value.begin() + size, x.set_u().begin());
126 }
127 
128 template<class T>
129 void set_unknown (std::valarray<field_basic<T> >& x, const vec<T>& value) {
130  size_t start = 0;
131  for (size_t i = 0; i < x.size(); ++i) {
132  size_t last = start + x[i].u().size();
133  std::copy (value.begin() + start, value.begin() + last, x[i].set_u().begin());
134  start = last;
135  }
136 }
137 
138 }} // namespace rheolef::details
139 #endif // _RHEOLEF_KELLER_DETAILS_H
see the distributor page for the full documentation
Definition: distributor.h:62
T max_abs() const
Definition: field.h:731
vec< T, M > & set_u()
Definition: field.h:312
const vec< T, M > & u() const
Definition: field.h:310
typename float_traits< T >::type float_type
Definition: field.h:245
see the vec page for the full documentation
Definition: vec.h:79
rheolef::std value
Expr1::float_type T
Definition: field_expr.h:261
void reset(T &x)
size_t get_unknown(const T &x)
T max_abs(const T &x)
size_t unknown_size(const field_basic< T > &x)
void set_unknown(T &x, const T &value)
This file is part of Rheolef.
Float u(const point &x)