Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
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
25namespace rheolef { namespace details {
26
27// -----------------
28// reset
29// -----------------
30template<class T>
31void reset (T& x) { x = 0; }
32
33template<class T>
34void reset (std::valarray<T>& x) {
35 for (size_t i = 0; i < x.size(); ++i) reset(x[i]);
36}
37template<class T1, class T2>
39{
40 reset (x.first);
41 reset (x.second);
42}
43// -----------------
44// max_abs
45// -----------------
46template<class T>
47T max_abs (const T& x) { return abs(x); }
48
49template<class T>
50T max_abs (const field_basic<T>& x) { return x.max_abs(); }
51
52template<class T>
54max_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// -----------------
64template<class T>
65size_t get_unknown (const T& x) { return 1; }
66
67template<class T>
68size_t
69unknown_size (const field_basic<T>& x) { return x.u().size(); }
70
71template<class T>
72size_t
73unknown_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// -----------------
83template<class T>
84T get_unknown (const T& x) { return x; }
85template<class T>
86T get_unknown (const T& x, const distributor&) { return x; }
87
88template<class T>
89vec<T> get_unknown (const field_basic<T>& x) { return x.u(); }
90template<class T>
91vec<T> get_unknown (const field_basic<T>& x, const distributor&) { return x.u(); }
92
93template<class T>
94vec<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
103template<class T>
104vec<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// -----------------
118template<class T>
119void set_unknown (T& x, const T& value) { x = value; }
120
121template<class T>
122void set_unknown (field_basic<T>& x, const vec<T>& value) {
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
128template<class T>
129void 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:69
T max_abs() const
Definition field.h:834
vec< T, M > & set_u()
Definition field.h:284
const vec< T, M > & u() const
Definition field.h:282
typename float_traits< T >::type float_type
Definition field.h:228
see the vec page for the full documentation
Definition vec.h:79
Expr1::float_type T
Definition field_expr.h:230
size_t unknown_size(const field_basic< T > &x)
size_t get_unknown(const T &x)
T max_abs(const T &x)
void set_unknown(T &x, const T &value)
This file is part of Rheolef.
Definition leveque.h:25