field_component.h
Go to the documentation of this file.
#ifndef _RHEOLEF_FIELD_COMPONENT_H
#define _RHEOLEF_FIELD_COMPONENT_H
/* TODO: when slip B.C. or Raviart-Thomas RT H(div) approx :
uh[0] values are computed on the fly in a temporary
struct field_component {
// data:
field_basic<T,M>::iterator _start, _last;
const space_constit& _constit; // a ce niveau
field* _tmp_comp_ptr; // si necesite un temporaire
// actions:
field_component (field& uh, i_comp) {
constit = uh.get_space().get_constitution();
_constit = constit[i_comp]);
if (! constit.has_slip_bc() && ! constit.has_hdiv()) {
_tmp_comp_ptr = 0;
_star & _last : pointe dans le field uh
} else {
space Vi (_constit);
_tmp_comp_ptr = new field (Vi);
uh.compute_slip_comp (i_comp, *_tmp_comp_ptr);
_star & _last : pointe dans *_tmp_comp_ptr
}
}
~field_component () {
if (_tmp_comp_ptr) delete _tmp_comp_ptr;
}
};
*/
#include "rheolef/field.h"
#include "rheolef/field_indirect.h"
namespace rheolef {
// =========================================================================
// field_component
// =========================================================================
template<class T, class M>
class field_component {
public:
// typename:
typedef typename field_basic<T,M>::size_type size_type;
typedef T value_type;
typedef M memory_type;
typedef typename scalar_traits<T>::type scalar_type;
typedef typename float_traits<T>::type float_type;
typedef typename field_basic<T,M>::iterator iterator;
typedef typename field_basic<T,M>::const_iterator const_iterator;
// allocators:
field_component ();
field_component (field_basic<T,M>& uh, size_type i_comp);
field_component (field_component<T,M>& uh, size_type i_comp);
field_component<T,M>& operator= (const T& alpha);
template <class Expr,
class Sfinae
= typename std::enable_if<
details::is_field_expr_affine_homogeneous<Expr>::value
&& ! details::is_field_expr_v2_constant <Expr>::value
>::type>
field_component<T,M>& operator= (const Expr&);
// explicit copy cstor (avoid simple copy of the proxy; see nfem/ptst/field_comp_assign_tst.cc )
field_component<T,M>& operator= (const field_component<T,M>& expr) {
return this -> template operator=<field_component<T,M> > (expr);
}
// high-level accessors & modifiers:
field_indirect<T,M> operator[] (const geo_basic<T,M>& dom);
field_indirect<T,M> operator[] (const std::string& dom_name);
// recursive call:
field_component<T,M> operator[] (size_t i_comp);
// low-level accessors & modifiers:
const space_constitution<T,M>& get_constitution() const { return _constit; }
std::string name() const { return _constit.name(); }
geo_basic<T,M> get_geo() const { return _constit.get_geo(); }
space_basic<T,M> get_space() const { return space_basic<T,M>(_constit); }
bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
const distributor& ownership() const { return _constit.ownership(); }
const communicator& comm() const { return ownership().comm(); }
size_type ndof() const { return ownership().size(); }
size_type dis_ndof() const { return ownership().dis_size(); }
T& dof (size_type idof) { return _start [idof]; }
const T& dof (size_type idof) const { return _start [idof]; }
iterator begin_dof() { return _start; }
iterator end_dof() { return _last; }
const_iterator begin_dof() const { return const_iterator(_start); }
const_iterator end_dof() const { return const_iterator(_last); }
// advanced usage:
field_component<T,M>& proxy_assign (field_component<T,M>&& uh_comp);
friend class field_component_const<T,M>;
template<class Iterator>
static void initialize (
const space_constitution<T,M>& sup_constit,
size_type i_comp,
space_constitution<T,M>& constit,
Iterator& start,
Iterator& last);
protected:
static const size_type _unset = std::numeric_limits<size_type>::max();
// data:
space_constitution<T,M> _constit; // at this level
iterator _start;
iterator _last;
};
// =========================================================================
// field_component_const
// =========================================================================
template<class T, class M>
class field_component_const {
public:
// typename:
typedef typename field_basic<T,M>::size_type size_type;
typedef T value_type;
typedef M memory_type;
typedef typename scalar_traits<T>::type scalar_type;
typedef typename float_traits<T>::type float_type;
typedef typename field_basic<T,M>::const_iterator const_iterator;
// allocators:
field_component_const ();
field_component_const (const field_basic<T,M>& uh, size_type i_comp);
field_component_const (const field_component<T,M>& uh_comp);
const space_constitution<T,M>& get_constitution() const { return _constit; }
std::string name() const { return _constit.name(); }
const distributor& ownership() const { return _constit.ownership(); }
const communicator& comm() const { return ownership().comm(); }
geo_basic<T,M> get_geo() const { return _constit.get_geo(); }
space_basic<T,M> get_space() const { return space_basic<T,M>(_constit); }
bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
size_type ndof() const { return ownership().size(); }
size_type dis_ndof() const { return ownership().dis_size(); }
const T& dof (size_type idof) const { return _start [idof]; }
const_iterator begin_dof() const { return const_iterator(_start); }
const_iterator end_dof() const { return const_iterator(_last); }
// advanced usage:
field_component_const<T,M>& proxy_assign (const field_component_const<T,M>& uh_comp);
protected:
static const size_type _unset = std::numeric_limits<size_type>::max();
// data:
space_constitution<T,M> _constit; // at this level
const_iterator _start;
const_iterator _last;
private:
field_component_const<T,M>& operator= (const field_component_const<T,M>& uh_comp);
};
// =========================================================================
// inlined
// =========================================================================
template<class T, class M>
inline
field_component<T,M>::field_component()
: _constit(),
_start(),
_last()
{
}
template<class T, class M>
inline
field_component_const<T,M>::field_component_const()
: _constit(),
_start(),
_last()
{
}
template<class T, class M>
template<class Iterator>
void
field_component<T,M>::initialize (
const space_constitution<T,M>& sup_constit,
size_type i_comp,
space_constitution<T,M>& constit,
Iterator& start,
Iterator& last)
{
if (sup_constit.is_hierarchical()) {
size_type n_comp = sup_constit.size();
check_macro (i_comp < n_comp,
"field component index "<<i_comp<<" is out of range [0:"<<n_comp<<"[");
size_type shift = 0;
for (size_type j_comp = 0; j_comp < i_comp; j_comp++) {
shift += sup_constit [j_comp].ndof();
}
constit = sup_constit [i_comp];
size_type sz = constit.ndof();
start += shift;
last += shift + sz;
} else {
size_type n_comp = sup_constit.get_basis().size();
check_macro (i_comp < n_comp,
"field component index "<<i_comp<<" is out of range [0:"<<n_comp<<"[");
constit = space_constitution<T,M>(sup_constit.get_geo(), sup_constit.get_basis()[i_comp].name());
start += i_comp;
last += i_comp + n_comp*constit.ndof();
start.set_increment (n_comp);
last.set_increment (n_comp);
}
}
template<class T, class M>
field_component<T,M>::field_component (field_basic<T,M>& uh, size_type i_comp)
: _constit(),
_start(uh.begin_dof()),
_last(uh.begin_dof())
{
initialize (uh.get_space().get_constitution(), i_comp, _constit, _start, _last);
}
template<class T, class M>
field_component_const<T,M>::field_component_const (const field_basic<T,M>& uh, size_type i_comp)
: _constit(),
_start(uh.begin_dof()),
_last(uh.begin_dof())
{
field_component<T,M>::initialize (uh.get_space().get_constitution(), i_comp, _constit, _start, _last);
}
template<class T, class M>
field_component<T,M>::field_component (field_component<T,M>& uh, size_type i_comp)
: _constit(),
_start(uh._start),
_last(uh._last)
{
initialize (uh._constit, i_comp, _constit, _start, _last);
}
template<class T, class M>
inline
field_component_const<T,M>::field_component_const (const field_component<T,M>& uh_comp)
: _constit (uh_comp.get_constitution()),
_start(uh_comp.begin_dof()),
_last(uh_comp.end_dof())
{
}
template<class T, class M>
inline
field_component_const<T,M>&
field_component_const<T,M>::operator= (const field_component_const<T,M>& uh_comp)
{
// avoided at compile time: is private
fatal_macro ("try to assign const field in field[i_comp] = field[j_comp]");
return *this;
}
template<class T, class M>
inline
field_component_const<T,M>&
field_component_const<T,M>::proxy_assign (const field_component_const<T,M>& uh_comp)
{
_constit = uh_comp.get_constitution();
_start = uh_comp.begin_dof();
_last = uh_comp.end_dof();
return *this;
}
template<class T, class M>
inline
field_component<T,M>&
field_component<T,M>::proxy_assign (field_component<T,M>&& uh_comp)
{
_constit = uh_comp.get_constitution();
_start = uh_comp.begin_dof();
_last = uh_comp.end_dof();
return *this;
}
template<class T, class M>
inline
field_component<T,M>
field_basic<T,M>::operator[] (size_type i_comp)
{
dis_dof_indexes_requires_update();
return field_component<T,M> (*this, i_comp);
}
template<class T, class M>
inline
field_component<T,M>
field_component<T,M>::operator[] (size_t i_comp)
{
return field_component<T,M> (*this, i_comp);
}
template<class T, class M>
inline
field_component_const<T,M>
field_basic<T,M>::operator[] (size_type i_comp) const
{
return field_component_const<T,M> (*this, i_comp);
}
template<class T, class M>
inline
field_component<T,M>&
field_component<T,M>::operator= (const T& alpha)
{
std::fill (begin_dof(), end_dof(), alpha);
return *this;
}
#ifdef TODO
// TODO: as: field vh; din >> vh ; uh[i_comp] = vh;
template <class T, class M>
inline
idiststream& operator >> (odiststream& ids, field_basic<T,M>& u);
#endif // TODO
template <class T, class M>
odiststream& operator << (odiststream& ods, const field_component<T,M>& uh_comp)
{
return ods << field_basic<T,M>(uh_comp);
}
template <class T, class M>
inline
odiststream& operator << (odiststream& ods, const field_component_const<T,M>& uh_comp)
{
return ods << field_basic<T,M>(uh_comp);
}
// =========================================================================
// uh[0]["boundary"] = alpha;
// => field_component & field_indirect together
// =========================================================================
template <class T, class M>
inline
field_indirect<T,M>::field_indirect (field_component<T,M>& uh_comp, const geo_basic<T,M>& dom)
: _V(uh_comp.get_space()),
_W(dom, _V.get_basis().name()),
_dom(dom),
_indirect(_V.build_indirect_array (_W, _dom.name())),
_val(uh_comp.begin_dof())
{
}
template <class T, class M>
inline
field_indirect<T,M>
field_component<T,M>::operator[] (const geo_basic<T,M>& dom)
{
return field_indirect<T,M> (*this, dom);
}
template <class T, class M>
inline
field_indirect<T,M>
field_component<T,M>::operator[] (const std::string& dom_name)
{
return field_indirect<T,M> (*this, get_geo().operator[](dom_name));
}
} // namespace rheolef
#endif // _RHEOLEF_FIELD_COMPONENT_H
rheolef::field_component_const::get_constitution
const space_constitution< T, M > & get_constitution() const
Definition: field_component.h:160
rheolef::field_component::comm
const communicator & comm() const
Definition: field_component.h:112
rheolef::field_component::initialize
static void initialize(const space_constitution< T, M > &sup_constit, size_type i_comp, space_constitution< T, M > &constit, Iterator &start, Iterator &last)
Definition: field_component.h:206
rheolef::geo_basic< T, M >
rheolef::field_basic::iterator
Definition: field.h:427
rheolef::field_component::dis_ndof
size_type dis_ndof() const
Definition: field_component.h:114
rheolef::field_basic::get_space
const space_type & get_space() const
Definition: field.h:300
rheolef::field_component::_constit
space_constitution< T, M > _constit
Definition: field_component.h:135
rheolef::space_constitution::ndof
size_type ndof() const
Definition: space_constitution.h:412
rheolef::field_component::begin_dof
iterator begin_dof()
Definition: field_component.h:117
rheolef::begin_dof
const_iterator begin_dof() const
Definition: field_expr_recursive.h:569
bdf::alpha
Float alpha[pmax+1][pmax+1]
Definition: bdf.icc:28
mkgeo_ball.expr
expr
Definition: mkgeo_ball.sh:361
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef::space_constitution::is_hierarchical
bool is_hierarchical() const
Definition: space_constitution.h:432
rheolef::distributor::comm
const communicator_type & comm() const
Definition: distributor.h:145
rheolef::field_component::ownership
const distributor & ownership() const
Definition: field_component.h:111
rheolef::field_component::float_type
float_traits< T >::type float_type
Definition: field_component.h:70
rheolef::field_component_const::size_type
field_basic< T, M >::size_type size_type
Definition: field_component.h:148
rheolef::details::is_field_expr_affine_homogeneous
Definition: field.h:229
rheolef::field_component_const::get_space
space_basic< T, M > get_space() const
Definition: field_component.h:165
rheolef::field_component::have_homogeneous_space
bool have_homogeneous_space(space_basic< T, M > &Xh) const
Definition: field_component.h:110
rheolef::field_component_const::comm
const communicator & comm() const
Definition: field_component.h:163
rheolef::field_component_const::have_homogeneous_space
bool have_homogeneous_space(space_basic< T, M > &Xh) const
Definition: field_component.h:166
rheolef::field_component_const
Definition: field.h:207
rheolef::space_basic
the finite element space
Definition: space.h:352
rheolef::distributor
see the distributor page for the full documentation
Definition: distributor.h:62
rheolef::field_component::proxy_assign
field_component< T, M > & proxy_assign(field_component< T, M > &&uh_comp)
Definition: field_component.h:290
rheolef::field_component::scalar_type
scalar_traits< T >::type scalar_type
Definition: field_component.h:69
rheolef::field_component::_last
iterator _last
Definition: field_component.h:137
rheolef::field_component::dof
T & dof(size_type idof)
Definition: field_component.h:115
rheolef::field_component::size_type
field_basic< T, M >::size_type size_type
Definition: field_component.h:66
rheolef::field_component::dof
const T & dof(size_type idof) const
Definition: field_component.h:116
rheolef::field_component_const::dis_ndof
size_type dis_ndof() const
Definition: field_component.h:168
rheolef::field_component_const::const_iterator
field_basic< T, M >::const_iterator const_iterator
Definition: field_component.h:153
rheolef::field_component_const::_start
const_iterator _start
Definition: field_component.h:179
rheolef::space_constitution::get_basis
const basis_basic< T > & get_basis() const
Definition: space_constitution.h:418
rheolef::field_component::iterator
field_basic< T, M >::iterator iterator
Definition: field_component.h:71
rheolef::field_component_const::float_type
float_traits< T >::type float_type
Definition: field_component.h:152
rheolef::field_indirect::field_indirect
field_indirect(field_basic< T, M > &uh, const geo_basic< T, M > &dom)
Definition: field_indirect.h:53
rheolef::field_component_const::name
std::string name() const
Definition: field_component.h:161
rheolef::field_indirect
Definition: field.h:204
rheolef::field_component::get_geo
geo_basic< T, M > get_geo() const
Definition: field_component.h:108
rheolef::field_component::_start
iterator _start
Definition: field_component.h:136
rheolef::field_component_const::_unset
static const size_type _unset
Definition: field_component.h:176
rheolef::field_component::value_type
T value_type
Definition: field_component.h:67
rheolef::space_constitution::size
size_type size() const
Definition: space_constitution.h:455
rheolef::type
rheolef::std type
rheolef::field_basic
Definition: field_expr_utilities.h:38
rheolef::field_component::memory_type
M memory_type
Definition: field_component.h:68
rheolef::field_component::begin_dof
const_iterator begin_dof() const
Definition: field_component.h:119
rheolef::field_component_const::ndof
size_type ndof() const
Definition: field_component.h:167
rheolef::field_component
Definition: field.h:206
fatal_macro
#define fatal_macro(message)
Definition: dis_macros.h:33
rheolef::details::is_field_expr_v2_constant
Definition: field.h:217
rheolef::field_component_const::scalar_type
scalar_traits< T >::type scalar_type
Definition: field_component.h:151
rheolef::operator>>
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:88
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::float_traits::type
T type
Definition: Float.h:94
rheolef::field_component::end_dof
const_iterator end_dof() const
Definition: field_component.h:120
rheolef::distributor::dis_size
size_type dis_size() const
global and local sizes
Definition: distributor.h:207
rheolef::field_component_const::proxy_assign
field_component_const< T, M > & proxy_assign(const field_component_const< T, M > &uh_comp)
Definition: field_component.h:280
rheolef::field_component_const::ownership
const distributor & ownership() const
Definition: field_component.h:162
u
Definition: leveque.h:25
rheolef::space_constitution::get_geo
const geo_basic< T, M > & get_geo() const
Definition: space_constitution.h:416
rheolef::field_component_const::dof
const T & dof(size_type idof) const
Definition: field_component.h:169
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
rheolef::field_component_const::_last
const_iterator _last
Definition: field_component.h:180
rheolef::field_component_const::begin_dof
const_iterator begin_dof() const
Definition: field_component.h:170
rheolef::field_component::get_space
space_basic< T, M > get_space() const
Definition: field_component.h:109
rheolef::field_component::operator=
field_component< T, M > & operator=(const T &alpha)
Definition: field_component.h:322
rheolef::field_component::_unset
static const size_type _unset
Definition: field_component.h:133
rheolef::scalar_traits::type
T type
Definition: point.h:324
rheolef::field_component::operator[]
field_indirect< T, M > operator[](const geo_basic< T, M > &dom)
Definition: field_component.h:362
rheolef::field_component_const::field_component_const
field_component_const()
Definition: field_component.h:197
rheolef::field_component_const::value_type
T value_type
Definition: field_component.h:149
rheolef::field_component::ndof
size_type ndof() const
Definition: field_component.h:113
rheolef::field_basic::operator[]
field_indirect< T, M > operator[](const geo_basic< T, M > &dom)
Definition: field_indirect.h:158
get_geo
void get_geo(istream &in, my_geo &omega)
Definition: field2gmsh_pos.cc:126
rheolef::field_component_const::memory_type
M memory_type
Definition: field_component.h:150
rheolef::field_component::get_constitution
const space_constitution< T, M > & get_constitution() const
Definition: field_component.h:106
rheolef::field_component::name
std::string name() const
Definition: field_component.h:107
rheolef::operator<<
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
rheolef::field_basic::const_iterator
Definition: field.h:518
rheolef::field_component::const_iterator
field_basic< T, M >::const_iterator const_iterator
Definition: field_component.h:72
rheolef::field_component_const::get_geo
geo_basic< T, M > get_geo() const
Definition: field_component.h:164
mkgeo_contraction.name
name
Definition: mkgeo_contraction.sh:133
rheolef::field_component::end_dof
iterator end_dof()
Definition: field_component.h:118
M
Expr1::memory_type M
Definition: vec_expr_v2.h:385
rheolef::distributor::size
size_type size(size_type iproc) const
Definition: distributor.h:163
rheolef::space_constitution
Definition: space_constitution.h:32
rheolef::field_basic::size_type
std::size_t size_type
Definition: field.h:239
rheolef::field_component_const::end_dof
const_iterator end_dof() const
Definition: field_component.h:171
rheolef::field_component::field_component
field_component()
Definition: field_component.h:189
T
Expr1::float_type T
Definition: field_expr.h:218
rheolef::field_component_const::_constit
space_constitution< T, M > _constit
Definition: field_component.h:178