~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to nfem/plib/field_component.h

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _RHEOLEF_FIELD_COMPONENT_H
 
2
#define _RHEOLEF_FIELD_COMPONENT_H
 
3
///
 
4
/// This file is part of Rheolef.
 
5
///
 
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
7
///
 
8
/// Rheolef is free software; you can redistribute it and/or modify
 
9
/// it under the terms of the GNU General Public License as published by
 
10
/// the Free Software Foundation; either version 2 of the License, or
 
11
/// (at your option) any later version.
 
12
///
 
13
/// Rheolef is distributed in the hope that it will be useful,
 
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
/// GNU General Public License for more details.
 
17
///
 
18
/// You should have received a copy of the GNU General Public License
 
19
/// along with Rheolef; if not, write to the Free Software
 
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
///
 
22
/// =========================================================================
 
23
 
 
24
/* TODO: when slip B.C. or Raviart-Thomas RT H(div) approx :
 
25
   uh[0] values are computed on the fly in a temporary
 
26
 
 
27
struct field_component {        
 
28
// data:
 
29
   field_basic<T,M>::iterator _start, _last;
 
30
   const space_constit&       _constit;         // a ce niveau
 
31
   field*                     _tmp_comp_ptr;    // si necesite un temporaire
 
32
// actions:
 
33
   field_component (field& uh, i_comp) {
 
34
        constit = uh.get_space().get_constitution();
 
35
        _constit = constit[i_comp]);
 
36
        if (! constit.has_slip_bc() && ! constit.has_hdiv()) {
 
37
          _tmp_comp_ptr = 0;
 
38
          _star & _last : pointe dans le field uh
 
39
        } else {
 
40
          space Vi (_constit);
 
41
          _tmp_comp_ptr = new field (Vi);
 
42
          uh.compute_slip_comp (i_comp, *_tmp_comp_ptr);
 
43
          _star & _last : pointe dans *_tmp_comp_ptr
 
44
        }
 
45
   }
 
46
   ~field_component () {
 
47
      if (_tmp_comp_ptr) delete _tmp_comp_ptr;
 
48
   }
 
49
};
 
50
*/
 
51
 
 
52
#include "rheolef/field.h"
 
53
#include "rheolef/field_indirect.h"
 
54
 
 
55
namespace rheolef {
 
56
 
 
57
template<class Expr> class field_expr; // forward declaration
 
58
 
 
59
// =========================================================================
 
60
// field_component
 
61
// =========================================================================
 
62
template<class T, class M>
 
63
class field_component {
 
64
public:
 
65
 
 
66
// typename:
 
67
 
 
68
  typedef typename field_basic<T,M>::size_type      size_type;
 
69
  typedef T                                         value_type;
 
70
  typedef typename field_basic<T,M>::iterator       iterator;
 
71
  typedef typename field_basic<T,M>::const_iterator const_iterator;
 
72
 
 
73
// allocators:
 
74
 
 
75
  field_component ();
 
76
  field_component (field_basic<T,M>&     uh, size_type i_comp);
 
77
  field_component (field_component<T,M>& uh, size_type i_comp);
 
78
  field_component<T,M>& operator= (const field_component<T,M>& uh_comp);
 
79
  field_component<T,M>& operator= (const field_basic<T,M>& uh);
 
80
  template<class Expr>
 
81
  field_component<T,M>& operator= (const field_expr<Expr>& expr);
 
82
  const T& operator= (const T& alpha);
 
83
 
 
84
// high-level accessors & modifiers:
 
85
 
 
86
  field_indirect<T,M> operator[] (const geo_basic<T,M>& dom);
 
87
  field_indirect<T,M> operator[] (const std::string&    dom_name);
 
88
 
 
89
// recursive call:
 
90
 
 
91
  field_component<T,M> operator[] (size_t i_comp);
 
92
 
 
93
// low-level accessors & modifiers:
 
94
 
 
95
  const space_constitution<T,M>& get_constitution() const { return _constit; }
 
96
  std::string stamp() const { return _constit.stamp(); }
 
97
  geo_basic<T,M>   get_geo() const { return _constit.get_geo(); }
 
98
  space_basic<T,M> get_space() const { return space_basic<T,M>(_constit); }
 
99
  const distributor& ownership() const { return _constit.ownership(); } 
 
100
  const communicator& comm() const { return ownership().comm(); }
 
101
  size_type     ndof() const { return ownership().size(); }
 
102
  size_type dis_ndof() const { return ownership().dis_size(); }
 
103
        T& dof (size_type idof)       { return _start [idof]; }
 
104
  const T& dof (size_type idof) const { return _start [idof]; }
 
105
  iterator begin_dof() { return _start; }
 
106
  iterator end_dof()   { return _last; }
 
107
  const_iterator begin_dof() const { return const_iterator(_start); }
 
108
  const_iterator end_dof() const   { return const_iterator(_last); }
 
109
 
 
110
protected:
 
111
// data:
 
112
  space_constitution<T,M>        _constit;     // at this level
 
113
  iterator                       _start;
 
114
  iterator                       _last;
 
115
};
 
116
// =========================================================================
 
117
// field_component_const
 
118
// =========================================================================
 
119
template<class T, class M>
 
120
class field_component_const {
 
121
public:
 
122
 
 
123
// typename:
 
124
 
 
125
  typedef typename field_basic<T,M>::size_type      size_type;
 
126
  typedef T                                         value_type;
 
127
  typedef typename field_basic<T,M>::const_iterator const_iterator;
 
128
 
 
129
// allocators:
 
130
 
 
131
  field_component_const ();
 
132
  field_component_const (const field_basic<T,M>& uh, size_type i_comp);
 
133
  field_component_const (const field_component<T,M>& uh_comp);
 
134
  field_component_const<T,M>& operator= (const field_component_const<T,M>& uh_comp);
 
135
  const space_constitution<T,M>& get_constitution() const { return _constit; }
 
136
  std::string stamp() const { return _constit.stamp(); }
 
137
  const distributor& ownership() const { return _constit.ownership(); } 
 
138
  const communicator& comm() const { return ownership().comm(); }
 
139
  geo_basic<T,M>   get_geo() const { return _constit.get_geo(); }
 
140
  space_basic<T,M> get_space() const { return space_basic<T,M>(_constit); }
 
141
  size_type     ndof() const { return ownership().size(); }
 
142
  size_type dis_ndof() const { return ownership().dis_size(); }
 
143
  const T& dof (size_type idof) const { return _start [idof]; }
 
144
  const_iterator begin_dof() const { return const_iterator(_start); }
 
145
  const_iterator end_dof() const   { return const_iterator(_last); }
 
146
protected:
 
147
// data:
 
148
  space_constitution<T,M>        _constit;     // at this level
 
149
  const_iterator                 _start;
 
150
  const_iterator                 _last;
 
151
};
 
152
// =========================================================================
 
153
// inlined
 
154
// =========================================================================
 
155
template<class T, class M>
 
156
inline
 
157
field_component<T,M>::field_component()
 
158
 : _constit(),
 
159
   _start(),
 
160
   _last()
 
161
{
 
162
}
 
163
template<class T, class M>
 
164
inline
 
165
field_component_const<T,M>::field_component_const()
 
166
 : _constit(),
 
167
   _start(),
 
168
   _last()
 
169
{
 
170
}
 
171
template<class T, class M>
 
172
field_component<T,M>::field_component (field_basic<T,M>& uh, size_type i_comp)
 
173
 : _constit (uh.get_space().get_constitution() [i_comp]),
 
174
   _start(uh.begin_dof()),
 
175
   _last(uh.begin_dof())
 
176
{
 
177
  check_macro (i_comp < uh.size(),
 
178
      "field component index "<<i_comp<<" is out of range [0:"<<uh.size()<<"[");
 
179
  const space_constitution<T,M>& sup_constit = uh.get_space().get_constitution();
 
180
  size_type shift = 0;
 
181
  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
 
182
    shift += sup_constit [j_comp].ndof();
 
183
  }
 
184
  size_type sz = sup_constit [i_comp].ndof();
 
185
  _start += shift;      
 
186
  _last  += shift + sz; 
 
187
}
 
188
template<class T, class M>
 
189
field_component_const<T,M>::field_component_const (const field_basic<T,M>& uh, size_type i_comp)
 
190
 : _constit (uh.get_space().get_constitution() [i_comp]),
 
191
   _start(uh.begin_dof()),
 
192
   _last(uh.begin_dof())
 
193
{
 
194
  check_macro (i_comp < uh.size(),
 
195
      "field component index "<<i_comp<<" is out of range [0:"<<uh.size()<<"[");
 
196
  const space_constitution<T,M>& sup_constit = uh.get_space().get_constitution();
 
197
  size_type shift = 0;
 
198
  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
 
199
    shift += sup_constit [j_comp].ndof();
 
200
  }
 
201
  size_type sz = sup_constit [i_comp].ndof();
 
202
  _start += shift;      
 
203
  _last  += shift + sz; 
 
204
}
 
205
template<class T, class M>
 
206
field_component<T,M>::field_component (field_component<T,M>& uh, size_type i_comp)
 
207
 : _constit (),
 
208
   _start(uh._start),
 
209
   _last(uh._last)
 
210
{
 
211
  const space_constitution<T,M>& sup_constit = uh._constit;
 
212
  check_macro (i_comp < sup_constit.size(),
 
213
      "field component index "<<i_comp<<" is out of range [0:"<<sup_constit.size()<<"[");
 
214
  size_type shift = 0;
 
215
  for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
 
216
    shift += sup_constit [j_comp].ndof();
 
217
  }
 
218
  _constit = sup_constit [i_comp];
 
219
  size_type sz = _constit.ndof();
 
220
  _start += shift;      
 
221
  _last  += shift + sz; 
 
222
}
 
223
template<class T, class M>
 
224
inline
 
225
field_component_const<T,M>::field_component_const (const field_component<T,M>& uh_comp)
 
226
 : _constit (uh_comp.get_constitution()),
 
227
   _start(uh_comp.begin_dof()),
 
228
   _last(uh_comp.end_dof())
 
229
{
 
230
}
 
231
template<class T, class M>
 
232
inline
 
233
field_component<T,M>&
 
234
field_component<T,M>::operator= (const field_component<T,M>& uh_comp)
 
235
{
 
236
  _constit = uh_comp._constit;
 
237
  _start   = uh_comp._start;
 
238
  _last    = uh_comp._last;
 
239
  return *this;
 
240
}
 
241
template<class T, class M>
 
242
inline
 
243
field_component_const<T,M>&
 
244
field_component_const<T,M>::operator= (const field_component_const<T,M>& uh_comp)
 
245
{
 
246
  _constit = uh_comp._constit;
 
247
  _start   = uh_comp._start;
 
248
  _last    = uh_comp._last;
 
249
  return *this;
 
250
}
 
251
template<class T, class M>
 
252
inline
 
253
field_component<T,M>
 
254
field_basic<T,M>::operator[] (size_type i_comp) 
 
255
{
 
256
  dis_dof_update_needed();
 
257
  return field_component<T,M> (*this, i_comp);
 
258
}
 
259
template<class T, class M>
 
260
inline
 
261
field_component<T,M>
 
262
field_component<T,M>::operator[] (size_t i_comp)
 
263
{
 
264
  return field_component<T,M> (*this, i_comp);
 
265
}
 
266
template<class T, class M>
 
267
inline
 
268
field_component_const<T,M>
 
269
field_basic<T,M>::operator[] (size_type i_comp) const
 
270
{
 
271
  return field_component_const<T,M> (*this, i_comp);
 
272
}
 
273
template<class T, class M>
 
274
inline
 
275
field_basic<T,M>&
 
276
field_basic<T,M>::operator=  (const field_component_const<T,M>& uh_comp)
 
277
{
 
278
  if (stamp() == "") {
 
279
    resize (uh_comp.get_space());
 
280
  } else {
 
281
    check_macro (stamp() == uh_comp.stamp(), "incompatible spaces "
 
282
        << stamp() << " and " << uh_comp.stamp()
 
283
        << " in field = field[i_comp]");
 
284
  }
 
285
  dis_dof_update_needed();
 
286
  std::copy (uh_comp.begin_dof(), uh_comp.end_dof(), begin_dof());
 
287
  return *this;
 
288
}
 
289
template<class T, class M>
 
290
inline
 
291
field_component<T,M>&
 
292
field_component<T,M>::operator= (const field_basic<T,M>& uh)
 
293
{
 
294
  check_macro (stamp() == uh.stamp(), "incompatible spaces "
 
295
        << stamp() << " and " << uh.stamp()
 
296
        << " in field[i_comp] = field");
 
297
  std::copy (uh.begin_dof(), uh.end_dof(), begin_dof());
 
298
  return *this;
 
299
}
 
300
template<class T, class M>
 
301
inline
 
302
const T&
 
303
field_component<T,M>::operator= (const T& alpha)
 
304
{
 
305
  std::fill (begin_dof(), end_dof(), alpha);
 
306
  return alpha;
 
307
}
 
308
template<class T, class M>
 
309
inline
 
310
field_basic<T,M>&
 
311
field_basic<T,M>::operator=  (const field_component<T,M>& uh_comp)
 
312
{
 
313
  return operator= (field_component_const<T,M>(uh_comp));
 
314
}
 
315
template<class T, class M>
 
316
inline
 
317
field_basic<T,M>::field_basic (const field_component<T,M>& uh_comp)
 
318
 : _V(),
 
319
   _u(),
 
320
   _b(),
 
321
   _dis_dof_update_needed(true)
 
322
{
 
323
  operator= (uh_comp);
 
324
}
 
325
template<class T, class M>
 
326
inline
 
327
field_basic<T,M>::field_basic (const field_component_const<T,M>& uh_comp)
 
328
 : _V(),
 
329
   _u(),
 
330
   _b(),
 
331
   _dis_dof_update_needed(true)
 
332
{
 
333
  operator= (uh_comp);
 
334
}
 
335
#ifdef TODO
 
336
// TODO: as: field vh; din >> vh ; uh[i_comp] = vh;
 
337
template <class T, class M>
 
338
inline
 
339
idiststream& operator >> (odiststream& ids, field_basic<T,M>& u);
 
340
#endif // TODO
 
341
 
 
342
template <class T, class M>
 
343
odiststream& operator << (odiststream& ods, const field_component<T,M>& uh_comp)
 
344
{
 
345
  return ods << field_basic<T,M>(uh_comp);
 
346
}
 
347
template <class T, class M>
 
348
inline
 
349
odiststream& operator << (odiststream& ods, const field_component_const<T,M>& uh_comp)
 
350
{
 
351
  return ods << field_basic<T,M>(uh_comp);
 
352
}
 
353
// =========================================================================
 
354
// uh[0]["boundary"] = alpha;
 
355
// => field_component & field_indirect together
 
356
// =========================================================================
 
357
template <class T, class M>
 
358
inline
 
359
field_indirect<T,M>::field_indirect (field_component<T,M>& uh_comp, const geo_basic<T,M>& dom)
 
360
  : _V(uh_comp.get_space()),
 
361
    _W(dom, _V.get_numbering().name()),
 
362
    _dom(dom),
 
363
    _indirect(_V.build_indirect_array (_W, _dom.name())),
 
364
    _val(uh_comp.begin_dof())
 
365
{
 
366
}
 
367
template <class T, class M>
 
368
inline
 
369
field_indirect<T,M>
 
370
field_component<T,M>::operator[] (const geo_basic<T,M>& dom)
 
371
{
 
372
  return field_indirect<T,M> (*this, dom);
 
373
}
 
374
template <class T, class M>
 
375
inline
 
376
field_indirect<T,M>
 
377
field_component<T,M>::operator[] (const std::string& dom_name)
 
378
{
 
379
  return field_indirect<T,M> (*this, get_geo().operator[](dom_name));
 
380
}
 
381
 
 
382
} // namespace rheolef
 
383
#endif // _RHEOLEF_FIELD_COMPONENT_H