field_indirect.h
Go to the documentation of this file.
# ifndef _RHEOLEF_FIELD_INDIRECT_H
# define _RHEOLEF_FIELD_INDIRECT_H
#include "rheolef/field.h"
namespace rheolef {
// forward:
template <class T, class M>
class field_indirect_const;
// =================================================================================
// field_indirect
// as for:
// uh["left"] = value
// uh["left"] = gh
// =================================================================================
template <class T, class M = rheo_default_memory_model>
class field_indirect {
public:
// typedefs
typedef typename field_basic<T,M>::size_type size_type;
typedef T value_type;
typedef M memory_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits <scalar_type>::type float_type;
class iterator;
class const_iterator;
// allocators:
field_indirect (field_basic<T,M>& uh, const geo_basic<T,M>& dom)
: _V(uh.get_space()),
_W(),
_dom(dom),
_indirect(),
_val(uh.begin_dof())
{
if (! (_V.get_basis().option().is_restricted_to_sides()
&& _V.get_geo().map_dimension() == _dom.map_dimension() + 1)) {
_W = space_basic<T,M> (dom, _V.get_basis().name());
} else {
// restricted on a subdomain: e.g. Pkd[sides](square) => Pkd(square[interface])
// i.e. the basis should remove the "sides" option
size_type k = _V.get_basis().degree();
_W = space_basic<T,M> (dom, "P"+itos(k)+"d", _V.valued());
#ifdef TODO
// TODO: more general, by skipping "sides" in option basis: how to do that?
// something as: basis b2 = b; bopt=b.opt(); bopt.set_restr(false); b2.reset(bopt);
// space (omega,b2.name());
basis b = _V.get_basis();
basis_option bopt = b.option();
bopt.set_restricted_to_sides (false);
b.reset (bopt);
_W = space_basic<T,M> (dom, b.name()); // TODO: a cstor space(dom,basis) ?
// => fatal(../../include/rheolef/smart_pointer.h,330): no_copy functor called (illegal copy)
#endif // TODO
}
_indirect = disarray<size_type,M> (_V.build_indirect_array (_W, dom));
}
field_indirect (field_component<T,M>& uh, const geo_basic<T,M>& dom);
field_indirect<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_indirect<T,M>& operator= (const Expr&);
// explicit copy cstor (avoid simple copy of the proxy; see nfem/ptst/field_comp_assign_tst.cc )
field_indirect<T,M>& operator= (const field_indirect<T,M>& expr) {
return this -> template operator=<field_indirect<T,M> > (expr);
}
// accessors:
const distributor& ownership() const { return _indirect.ownership(); }
const communicator& comm() const { return ownership().comm(); }
size_type ndof() const { return ownership().size(); }
size_type dis_ndof() const { return ownership().dis_size(); }
std::string name() const;
const space_basic<T,M>& get_space() const { return _W; }
bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
T& dof (size_type idof) { return _val [_indirect [idof]]; }
const T& dof (size_type idof) const { return _val [_indirect [idof]]; }
iterator begin_dof();
iterator end_dof();
const_iterator begin_dof() const;
const_iterator end_dof() const;
protected:
friend class field_basic<T,M>;
friend class field_indirect_const<T,M>;
static std::string _name_internal (const space_basic<T,M>& V, const geo_basic<T,M>& dom);
// data:
space_basic<T,M> _V;
space_basic<T,M> _W;
geo_basic<T,M> _dom;
disarray<size_type,M> _indirect; // temporary
typename field_basic<T,M>::iterator _val; // iterator = reference on an external variable uh
// => cstor is protected : prevent copy outside the field class
};
template<class T, class M>
inline
field_indirect<T,M>&
field_indirect<T,M>::operator= (const T& alpha)
{
std::fill (begin_dof(), end_dof(), alpha);
return *this;
}
template<class T, class M>
inline
std::string
field_indirect<T,M>::name() const
{
return _name_internal (_V, _dom);
}
template<class T, class M>
std::string
field_indirect<T,M>::_name_internal(
const space_basic<T,M>& V,
const geo_basic<T,M>& dom)
{
// e.g. "P1(square[left]", an unique signature for field_expr<Expr> size-like checks
std::string dom_name = (dom.variant() != geo_abstract_base_rep<T>::geo_domain) ?
V.get_geo().name() + "[" + dom.name() + "]" :
dom.name();
return V.get_basis().name() + "{" + dom_name + "}";
}
template<class T, class M>
inline
field_indirect<T,M>
field_basic<T,M>::operator[] (const geo_basic<T,M>& dom)
{
dis_dof_indexes_requires_update();
return field_indirect<T,M> (*this, dom);
}
template<class T, class M>
inline
field_indirect<T,M>
field_basic<T,M>::operator[] (std::string dom_name)
{
dis_dof_indexes_requires_update();
return operator[] (get_space().get_geo().operator[] (dom_name));
}
// =================================================================================
// field_indirect::iterator
// =================================================================================
template <class T, class M>
class field_indirect<T,M>::iterator {
public:
// typedef:
typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
typedef typename vec<T,M>::size_type size_type;
typedef T value_type;
typedef T& reference;
typedef T* pointer;
typedef std::ptrdiff_t difference_type;
// allocator:
iterator (typename disarray<size_type,M>::const_iterator idof_iter, typename field_basic<T,M>::iterator val)
: _idof_iter(idof_iter), _val(val) {}
// accessors & modifiers:
T& operator* () { return _val [*_idof_iter]; }
const T& operator* () const { return _val [*_idof_iter]; }
iterator& operator++() { ++_idof_iter; return *this; }
// comparators:
bool operator== (const iterator& j) const { return _idof_iter == j._idof_iter; }
bool operator!= (const iterator& j) const { return ! operator== (j); }
protected:
// data:
typename disarray<size_type,M>::const_iterator _idof_iter;
typename field_basic<T,M>::iterator _val;
};
template<class T, class M>
inline
typename field_indirect<T,M>::iterator
field_indirect<T,M>::begin_dof()
{
return iterator (_indirect.begin(), _val);
}
template<class T, class M>
inline
typename field_indirect<T,M>::iterator
field_indirect<T,M>::end_dof()
{
return iterator (_indirect.end(), _val);
}
// =================================================================================
// field_indirect::const_iterator
// =================================================================================
template <class T, class M>
class field_indirect<T,M>::const_iterator {
public:
// typedef:
typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
typedef typename vec<T,M>::size_type size_type;
typedef T value_type;
typedef const T& reference;
typedef const T* pointer;
typedef std::ptrdiff_t difference_type;
// allocator:
const_iterator (typename disarray<size_type,M>::const_iterator idof_iter, typename field_basic<T,M>::const_iterator val)
: _idof_iter(idof_iter), _val(val) {}
// accessors & modifiers:
const T& operator* () const { return _val [*_idof_iter]; }
const_iterator& operator++() { ++_idof_iter; return *this; }
// comparators:
bool operator== (const const_iterator& j) const { return _idof_iter == j._idof_iter; }
bool operator!= (const const_iterator& j) const { return ! operator== (j); }
protected:
// data:
typename disarray<size_type,M>::const_iterator _idof_iter;
typename field_basic<T,M>::const_iterator _val;
};
template<class T, class M>
inline
typename field_indirect<T,M>::const_iterator
field_indirect<T,M>::begin_dof() const
{
return const_iterator (_indirect.begin(), _val);
}
template<class T, class M>
inline
typename field_indirect<T,M>::const_iterator
field_indirect<T,M>::end_dof() const
{
return const_iterator (_indirect.end(), _val);
}
// =================================================================================
// field_indirect_const
// as for:
// gh = uh["left"]
// =================================================================================
template <class T, class M = rheo_default_memory_model>
class field_indirect_const {
public:
//protected:
// typedefs:
typedef typename field_basic<T,M>::size_type size_type;
typedef T scalar_type;
typedef T value_type; // TODO: run-time dependent
typedef M memory_type;
class const_iterator;
// allocators:
field_indirect_const (const field_basic<T,M>& uh, const geo_basic<T,M>& dom)
: _V(uh.get_space()),
_W(dom, _V.get_basis().name()),
_dom(dom),
_indirect(_V.build_indirect_array (_W, dom)),
_val(uh.begin_dof())
{}
field_indirect_const (field_indirect<T,M> gh)
: _V(gh._V),
_W(gh._W),
_dom(gh._dom),
_indirect(gh._indirect),
_val(gh._val)
{}
// accessors:
//protected:
const distributor& ownership() const { return _indirect.ownership(); }
const communicator& comm() const { return ownership().comm(); }
size_type ndof() const { return ownership().size(); }
size_type dis_ndof() const { return ownership().dis_size(); }
std::string name() const;
space_basic<T,M> get_space() const { return _W; }
bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
const T& dof(size_type idof) const { return _val [_indirect [idof]]; }
const_iterator begin_dof() const;
const_iterator end_dof() const;
friend class field_basic<T,M>;
protected:
space_basic<T,M> _V;
space_basic<T,M> _W;
geo_basic<T,M> _dom;
disarray<size_type,M> _indirect; // temporary
typename field_basic<T,M>::const_iterator _val; // iterator = reference on an external variable uh
// thus cstor is protected to prevent copy outside the field class
};
template<class T, class M>
inline
std::string
field_indirect_const<T,M>::name() const
{
return field_indirect<T,M>::_name_internal (_V, _dom);
}
template<class T, class M>
inline
field_indirect_const<T,M>
field_basic<T,M>::operator[] (const geo_basic<T,M>& dom) const
{
return field_indirect_const<T,M> (*this, dom);
}
template<class T, class M>
inline
field_indirect_const<T,M>
field_basic<T,M>::operator[] (std::string dom_name) const
{
return operator[] (get_space().get_geo().operator[] (dom_name));
}
// =================================================================================
// field_indirect_const::const_iterator
// =================================================================================
template <class T, class M>
class field_indirect_const<T,M>::const_iterator {
public:
// typedefs:
typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
typedef typename vec<T,M>::size_type size_type;
typedef T value_type;
typedef const T& reference;
typedef const T* pointer;
typedef std::ptrdiff_t difference_type;
// allocator:
const_iterator (typename disarray<size_type,M>::const_iterator idof_iter, typename field_basic<T,M>::const_iterator val)
: _idof_iter(idof_iter), _val(val) {}
// accessors & modifiers:
const T& operator* () const { return _val [*_idof_iter]; }
const_iterator& operator++() { ++_idof_iter; return *this; }
// comparators:
bool operator== (const const_iterator& j) const { return _idof_iter == j._idof_iter; }
bool operator!= (const const_iterator& j) const { return ! operator== (j); }
protected:
// data:
typename disarray<size_type,M>::const_iterator _idof_iter;
typename field_basic<T,M>::const_iterator _val;
};
template<class T, class M>
inline
typename field_indirect_const<T,M>::const_iterator
field_indirect_const<T,M>::begin_dof() const
{
return const_iterator (_indirect.begin(), _val);
}
template<class T, class M>
inline
typename field_indirect_const<T,M>::const_iterator
field_indirect_const<T,M>::end_dof() const
{
return const_iterator (_indirect.end(), _val);
}
// =================================================================================
// io
// =================================================================================
template <class T, class M>
inline
odiststream&
operator << (odiststream& ops, const field_indirect<T,M>& uh)
{
field_basic<T,M> tmp = uh;
return tmp.put (ops);
}
template <class T, class M>
inline
odiststream&
operator << (odiststream& ops, const field_indirect_const<T,M>& uh)
{
field_basic<T,M> tmp = uh;
return tmp.put (ops);
}
}// namespace rheolef
# endif /* _RHEOLEF_FIELD_INDIRECT_H */
rheolef::field_indirect_const::const_iterator::_val
field_basic< T, M >::const_iterator _val
Definition: field_indirect.h:371
rheolef::field_indirect_const::begin_dof
const_iterator begin_dof() const
Definition: field_indirect.h:376
rheolef::field_indirect::const_iterator::operator++
const_iterator & operator++()
Definition: field_indirect.h:235
rheolef::field_indirect_const::const_iterator::const_iterator
const_iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::const_iterator val)
Definition: field_indirect.h:357
rheolef::geo_basic< T, M >
rheolef::field_basic::iterator
Definition: field.h:427
rheolef::field_indirect::ndof
size_type ndof() const
Definition: field_indirect.h:104
rheolef::operator!=
bool operator!=(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
Definition: heap_allocator.h:172
rheolef::field_indirect::iterator
Definition: field_indirect.h:175
rheolef::field_indirect::_W
space_basic< T, M > _W
Definition: field_indirect.h:122
rheolef::field_indirect_const::ndof
size_type ndof() const
Definition: field_indirect.h:301
rheolef::begin_dof
const_iterator begin_dof() const
Definition: field_expr_recursive.h:569
gh
field gh(Float epsilon, Float t, const field &uh, const test &v)
Definition: burgers_diffusion_operators.icc:37
bdf::alpha
Float alpha[pmax+1][pmax+1]
Definition: bdf.icc:28
mkgeo_ball.expr
expr
Definition: mkgeo_ball.sh:361
rheolef::field_indirect_const::memory_type
M memory_type
Definition: field_indirect.h:275
rheolef::distributor::comm
const communicator_type & comm() const
Definition: distributor.h:145
rheolef::field_indirect::dof
const T & dof(size_type idof) const
Definition: field_indirect.h:110
rheolef::field_indirect::iterator::_idof_iter
disarray< size_type, M >::const_iterator _idof_iter
Definition: field_indirect.h:199
rheolef::field_indirect_const::ownership
const distributor & ownership() const
Definition: field_indirect.h:299
rheolef::field_indirect::_indirect
disarray< size_type, M > _indirect
Definition: field_indirect.h:124
rheolef::field_indirect_const::dof
const T & dof(size_type idof) const
Definition: field_indirect.h:307
rheolef::field_indirect::const_iterator
Definition: field_indirect.h:220
rheolef::details::is_field_expr_affine_homogeneous
Definition: field.h:229
rheolef::field_indirect::have_homogeneous_space
bool have_homogeneous_space(space_basic< T, M > &Xh) const
Definition: field_indirect.h:108
rheolef::field_indirect::const_iterator::_idof_iter
disarray< size_type, M >::const_iterator _idof_iter
Definition: field_indirect.h:243
rheolef::operator*
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
Definition: csr.h:437
rheolef::field_indirect::scalar_type
scalar_traits< value_type >::type scalar_type
Definition: field_indirect.h:46
rheolef::field_indirect_const::_W
space_basic< T, M > _W
Definition: field_indirect.h:314
rheolef::field_indirect_const::const_iterator::size_type
vec< T, M >::size_type size_type
Definition: field_indirect.h:350
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::basis_option::set_restricted_to_sides
void set_restricted_to_sides(bool r=true)
Definition: basis_option.h:281
rheolef::field_indirect_const::end_dof
const_iterator end_dof() const
Definition: field_indirect.h:383
rheolef::field_indirect_const::_dom
geo_basic< T, M > _dom
Definition: field_indirect.h:315
rheolef::field_indirect::memory_type
M memory_type
Definition: field_indirect.h:45
rheolef::field_indirect_const::const_iterator::_idof_iter
disarray< size_type, M >::const_iterator _idof_iter
Definition: field_indirect.h:370
rheolef::field_indirect::_val
field_basic< T, M >::iterator _val
Definition: field_indirect.h:125
rheolef::basis_option
see the basis_option page for the full documentation
Definition: basis_option.h:93
rheolef::field_indirect::iterator::size_type
vec< T, M >::size_type size_type
Definition: field_indirect.h:179
rheolef::field_indirect_const
Definition: field.h:205
rheolef::field_indirect_const::_val
field_basic< T, M >::const_iterator _val
Definition: field_indirect.h:317
rheolef::field_indirect::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition: field_indirect.h:228
rheolef::field_indirect::iterator::reference
T & reference
Definition: field_indirect.h:181
rheolef::field_indirect::field_indirect
field_indirect(field_basic< T, M > &uh, const geo_basic< T, M > &dom)
Definition: field_indirect.h:53
rheolef::operator==
bool operator==(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
Definition: heap_allocator.h:167
rheolef::field_indirect::comm
const communicator & comm() const
Definition: field_indirect.h:103
rheolef::field_indirect_const::value_type
T value_type
Definition: field_indirect.h:274
rheolef::geo_abstract_base_rep
abstract base interface class
Definition: geo.h:248
rheolef::field_indirect::value_type
T value_type
Definition: field_indirect.h:44
rheolef::field_indirect::iterator::value_type
T value_type
Definition: field_indirect.h:180
rheolef::field_indirect::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: field_indirect.h:223
rheolef::field_indirect::const_iterator::pointer
const typedef T * pointer
Definition: field_indirect.h:227
rheolef::field_indirect
Definition: field.h:204
rheolef::field_indirect_const::const_iterator
Definition: field_indirect.h:345
rheolef::field_indirect_const::get_space
space_basic< T, M > get_space() const
Definition: field_indirect.h:304
basis
see the basis page for the full documentation
rheolef::field_indirect::_dom
geo_basic< T, M > _dom
Definition: field_indirect.h:123
rheolef::field_indirect_const::name
std::string name() const
Definition: field_indirect.h:323
rheolef::field_indirect::const_iterator::const_iterator
const_iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::const_iterator val)
Definition: field_indirect.h:230
rheolef::field_indirect_const::const_iterator::operator++
const_iterator & operator++()
Definition: field_indirect.h:362
rheolef::field_indirect::iterator::_val
field_basic< T, M >::iterator _val
Definition: field_indirect.h:200
rheolef::field_indirect::begin_dof
iterator begin_dof()
Definition: field_indirect.h:205
rheolef::field_indirect_const::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: field_indirect.h:349
rheolef::type
rheolef::std type
rheolef::field_indirect::const_iterator::reference
const typedef T & reference
Definition: field_indirect.h:226
rheolef::field_basic
Definition: field_expr_utilities.h:38
rheolef::field_indirect_const::field_indirect_const
field_indirect_const(field_indirect< T, M > gh)
Definition: field_indirect.h:288
rheolef::field_indirect_const::have_homogeneous_space
bool have_homogeneous_space(space_basic< T, M > &Xh) const
Definition: field_indirect.h:305
rheolef::field_component
Definition: field.h:206
rheolef::field_indirect::get_space
const space_basic< T, M > & get_space() const
Definition: field_indirect.h:107
rheolef::details::is_field_expr_v2_constant
Definition: field.h:217
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::float_traits::type
T type
Definition: Float.h:94
rheolef::distributor::dis_size
size_type dis_size() const
global and local sizes
Definition: distributor.h:207
rheolef::field_indirect::iterator::iterator
iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::iterator val)
Definition: field_indirect.h:185
rheolef::field_indirect::size_type
field_basic< T, M >::size_type size_type
Definition: field_indirect.h:43
rheolef::field_indirect::end_dof
iterator end_dof()
Definition: field_indirect.h:212
rheolef::field_indirect::dof
T & dof(size_type idof)
Definition: field_indirect.h:109
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
rheolef::field_indirect::iterator::difference_type
std::ptrdiff_t difference_type
Definition: field_indirect.h:183
rheolef::field_indirect::const_iterator::value_type
T value_type
Definition: field_indirect.h:225
rheolef::disarray< size_type, M >
rheolef::field_indirect_const::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition: field_indirect.h:354
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::field_indirect::operator=
field_indirect< T, M > & operator=(const T &alpha)
Definition: field_indirect.h:131
rheolef::scalar_traits::type
T type
Definition: point.h:324
rheolef::const_iterator
Definition: field_expr_recursive.h:552
rheolef::field_indirect::iterator::operator++
iterator & operator++()
Definition: field_indirect.h:191
rheolef::field_indirect_const::const_iterator::reference
const typedef T & reference
Definition: field_indirect.h:352
rheolef::field_indirect::const_iterator::size_type
vec< T, M >::size_type size_type
Definition: field_indirect.h:224
rheolef::field_indirect_const::const_iterator::pointer
const typedef T * pointer
Definition: field_indirect.h:353
rheolef::field_indirect_const::const_iterator::value_type
T value_type
Definition: field_indirect.h:351
rheolef::field_indirect::iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: field_indirect.h:178
rheolef::field_indirect_const::size_type
field_basic< T, M >::size_type size_type
Definition: field_indirect.h:272
rheolef::field_basic::operator[]
field_indirect< T, M > operator[](const geo_basic< T, M > &dom)
Definition: field_indirect.h:158
rheolef::field_indirect_const::_V
space_basic< T, M > _V
Definition: field_indirect.h:313
get_geo
void get_geo(istream &in, my_geo &omega)
Definition: field2gmsh_pos.cc:126
rheolef::field_indirect_const::scalar_type
T scalar_type
Definition: field_indirect.h:273
rheolef::field_indirect::name
std::string name() const
Definition: field_indirect.h:139
rheolef::field_indirect_const::_indirect
disarray< size_type, M > _indirect
Definition: field_indirect.h:316
rheolef::field_indirect_const::field_indirect_const
field_indirect_const(const field_basic< T, M > &uh, const geo_basic< T, M > &dom)
Definition: field_indirect.h:280
rheolef::field_indirect::dis_ndof
size_type dis_ndof() const
Definition: field_indirect.h:105
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
mkgeo_ball.tmp
tmp
Definition: mkgeo_ball.sh:380
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_indirect_const::comm
const communicator & comm() const
Definition: field_indirect.h:300
rheolef::field_indirect::const_iterator::_val
field_basic< T, M >::const_iterator _val
Definition: field_indirect.h:244
rheolef::field_indirect::ownership
const distributor & ownership() const
Definition: field_indirect.h:102
rheolef::vec::size_type
base::size_type size_type
Definition: vec.h:86
rheolef::field_indirect::_V
space_basic< T, M > _V
Definition: field_indirect.h:121
rheolef::field_indirect::float_type
float_traits< scalar_type >::type float_type
Definition: field_indirect.h:47
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::field_indirect_const::dis_ndof
size_type dis_ndof() const
Definition: field_indirect.h:302
rheolef::field_indirect::iterator::pointer
T * pointer
Definition: field_indirect.h:182
rheolef::field_basic::size_type
std::size_t size_type
Definition: field.h:239
T
Expr1::float_type T
Definition: field_expr.h:218
rheolef::field_indirect::_name_internal
static std::string _name_internal(const space_basic< T, M > &V, const geo_basic< T, M > &dom)
Definition: field_indirect.h:145