rheolef  6.5
field_component.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_FIELD_COMPONENT_H
2 #define _RHEOLEF_FIELD_COMPONENT_H
3 
4 /* TODO: when slip B.C. or Raviart-Thomas RT H(div) approx :
5  uh[0] values are computed on the fly in a temporary
6 
7 struct field_component {
8  field_basic<T,M>::iterator _start, _last;
9  const space_constit& _constit; // a ce niveau
10  field* _tmp_comp_ptr; // si necesite un temporaire
11  field_component (field& uh, i_comp) {
12  constit = uh.get_space().get_constitution();
13  _constit = constit[i_comp]);
14  if (! constit.has_slip_bc() && ! constit.has_hdiv()) {
15  _tmp_comp_ptr = 0;
16  _star & _last : pointe dans le field uh
17  } else {
18  space Vi (_constit);
19  _tmp_comp_ptr = new field (Vi);
20  uh.compute_slip_comp (i_comp, *_tmp_comp_ptr);
21  _star & _last : pointe dans *_tmp_comp_ptr
22  }
23  }
24  ~field_component () {
25  if (_tmp_comp_ptr) delete _tmp_comp_ptr;
26  }
27 };
28 */
29 
30 #include "rheolef/field.h"
31 #include "rheolef/field_indirect.h"
32 
33 namespace rheolef {
34 
35 template<class Expr> class field_expr; // forward declaration
36 
37 template<class T, class M>
38 class field_component {
39 public:
40 
41 
43  typedef T scalar_type;
44  typedef T value_type;
47 
48 
49  field_component ();
54  template<class Expr>
56  const T& operator= (const T& alpha);
57 
58 
60  field_indirect<T,M> operator[] (const std::string& dom_name);
61 
62 
63  field_component<T,M> operator[] (size_t i_comp);
64 
65 
67  std::string stamp() const { return _constit.stamp(); }
68  geo_basic<T,M> get_geo() const { return _constit.get_geo(); }
70  const distributor& ownership() const { return _constit.ownership(); }
71  const communicator& comm() const { return ownership().comm(); }
72  size_type ndof() const { return ownership().size(); }
73  size_type dis_ndof() const { return ownership().dis_size(); }
74  T& dof (size_type idof) { return _start [idof]; }
75  const T& dof (size_type idof) const { return _start [idof]; }
76  iterator begin_dof() { return _start; }
77  iterator end_dof() { return _last; }
80 
81 protected:
85 };
86 template<class T, class M>
88 public:
89 
90 
92  typedef T scalar_type;
93  typedef T value_type;
95 
96 
102  std::string stamp() const { return _constit.stamp(); }
103  const distributor& ownership() const { return _constit.ownership(); }
104  const communicator& comm() const { return ownership().comm(); }
105  geo_basic<T,M> get_geo() const { return _constit.get_geo(); }
107  size_type ndof() const { return ownership().size(); }
108  size_type dis_ndof() const { return ownership().dis_size(); }
109  const T& dof (size_type idof) const { return _start [idof]; }
112 protected:
116 };
117 template<class T, class M>
118 inline
120  : _constit(),
121  _start(),
122  _last()
123 {
124 }
125 template<class T, class M>
126 inline
128  : _constit(),
129  _start(),
130  _last()
131 {
132 }
133 template<class T, class M>
135  : _constit (uh.get_space().get_constitution() [i_comp]),
136  _start(uh.begin_dof()),
137  _last(uh.begin_dof())
138 {
139  check_macro (i_comp < uh.size(),
140  "field component index "<<i_comp<<" is out of range [0:"<<uh.size()<<"[");
141  const space_constitution<T,M>& sup_constit = uh.get_space().get_constitution();
142  size_type shift = 0;
143  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
144  shift += sup_constit [j_comp].ndof();
145  }
146  size_type sz = sup_constit [i_comp].ndof();
147  _start += shift;
148  _last += shift + sz;
149 }
150 template<class T, class M>
152  : _constit (uh.get_space().get_constitution() [i_comp]),
153  _start(uh.begin_dof()),
154  _last(uh.begin_dof())
155 {
156  check_macro (i_comp < uh.size(),
157  "field component index "<<i_comp<<" is out of range [0:"<<uh.size()<<"[");
158  const space_constitution<T,M>& sup_constit = uh.get_space().get_constitution();
159  size_type shift = 0;
160  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
161  shift += sup_constit [j_comp].ndof();
162  }
163  size_type sz = sup_constit [i_comp].ndof();
164  _start += shift;
165  _last += shift + sz;
166 }
167 template<class T, class M>
169  : _constit (),
170  _start(uh._start),
171  _last(uh._last)
172 {
173  const space_constitution<T,M>& sup_constit = uh._constit;
174  check_macro (i_comp < sup_constit.size(),
175  "field component index "<<i_comp<<" is out of range [0:"<<sup_constit.size()<<"[");
176  size_type shift = 0;
177  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
178  shift += sup_constit [j_comp].ndof();
179  }
180  _constit = sup_constit [i_comp];
181  size_type sz = _constit.ndof();
182  _start += shift;
183  _last += shift + sz;
184 }
185 template<class T, class M>
186 inline
188  : _constit (uh_comp.get_constitution()),
189  _start(uh_comp.begin_dof()),
190  _last(uh_comp.end_dof())
191 {
192 }
193 template<class T, class M>
194 inline
197 {
198  _constit = uh_comp._constit;
199  _start = uh_comp._start;
200  _last = uh_comp._last;
201  return *this;
202 }
203 template<class T, class M>
204 inline
207 {
208  _constit = uh_comp._constit;
209  _start = uh_comp._start;
210  _last = uh_comp._last;
211  return *this;
212 }
213 template<class T, class M>
214 inline
217 {
218  dis_dof_update_needed();
219  return field_component<T,M> (*this, i_comp);
220 }
221 template<class T, class M>
222 inline
225 {
226  return field_component<T,M> (*this, i_comp);
227 }
228 template<class T, class M>
229 inline
232 {
233  return field_component_const<T,M> (*this, i_comp);
234 }
235 template<class T, class M>
236 inline
239 {
240  if (stamp() == "") {
241  resize (uh_comp.get_space());
242  } else {
243  check_macro (stamp() == uh_comp.stamp(), "incompatible spaces "
244  << stamp() << " and " << uh_comp.stamp()
245  << " in field = field[i_comp]");
246  }
247  dis_dof_update_needed();
248  std::copy (uh_comp.begin_dof(), uh_comp.end_dof(), begin_dof());
249  return *this;
250 }
251 template<class T, class M>
252 inline
255 {
256  check_macro (stamp() == uh.stamp(), "incompatible spaces "
257  << stamp() << " and " << uh.stamp()
258  << " in field[i_comp] = field");
259  std::copy (uh.begin_dof(), uh.end_dof(), begin_dof());
260  return *this;
261 }
262 template<class T, class M>
263 inline
264 const T&
266 {
267  std::fill (begin_dof(), end_dof(), alpha);
268  return alpha;
269 }
270 template<class T, class M>
271 inline
274 {
275  return operator= (field_component_const<T,M>(uh_comp));
276 }
277 template<class T, class M>
278 inline
280  : _V(),
281  _u(),
282  _b(),
283  _dis_dof_update_needed(true)
284 {
285  operator= (uh_comp);
286 }
287 template<class T, class M>
288 inline
290  : _V(),
291  _u(),
292  _b(),
293  _dis_dof_update_needed(true)
294 {
295  operator= (uh_comp);
296 }
297 #ifdef TODO
298 // TODO: as: field vh; din >> vh ; uh[i_comp] = vh;
299 template <class T, class M>
300 inline
302 #endif // TODO
303 
304 template <class T, class M>
305 odiststream& operator << (odiststream& ods, const field_component<T,M>& uh_comp)
306 {
307  return ods << field_basic<T,M>(uh_comp);
308 }
309 template <class T, class M>
310 inline
311 odiststream& operator << (odiststream& ods, const field_component_const<T,M>& uh_comp)
312 {
313  return ods << field_basic<T,M>(uh_comp);
314 }
315 // => field_component & field_indirect together
316 template <class T, class M>
317 inline
319  : _V(uh_comp.get_space()),
320  _W(dom, _V.get_numbering().name()),
321  _dom(dom),
322  _indirect(_V.build_indirect_array (_W, _dom.name())),
323  _val(uh_comp.begin_dof())
324 {
325 }
326 template <class T, class M>
327 inline
330 {
331  return field_indirect<T,M> (*this, dom);
332 }
333 template <class T, class M>
334 inline
336 field_component<T,M>::operator[] (const std::string& dom_name)
337 {
338  return field_indirect<T,M> (*this, get_geo().operator[](dom_name));
339 }
340 
341 } // namespace rheolef
342 #endif // _RHEOLEF_FIELD_COMPONENT_H
343