Loading...
Searching...
No Matches
field_rdof_node.h
Go to the documentation of this file.
# ifndef _RHEOLEF_FIELD_RDOF_NODE_H
# define _RHEOLEF_FIELD_RDOF_NODE_H
//
// This file is part of Rheolef.
//
// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// Rheolef is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Rheolef is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rheolef; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =========================================================================
// field_rdof: unary+- ; lambda*rdof ; binary+-
// AUTHOR: Pierre.Saramito@imag.fr
// DATE: 12 may 2020
// SUMMARY
// 1. unary node
// 1.1. unary iterator
// 1.2. unary class
// 1.3. unary operator+-
// 1.4. multiplication & division by a constant scalar
// 2. binary node
// TODO
#include "rheolef/field_rdof.h"
#include "rheolef/expression.h"
namespace rheolef {
// ============================================================================
// 1. unary node
// ============================================================================
namespace details {
// ----------------------------------------------------------------------------
// 1.1. unary iterator
// ----------------------------------------------------------------------------
template<class UnaryFunction, class InputIterator>
class field_rdof_unary_iterator {
public:
// definitions:
using iterator_category = std::forward_iterator_tag;
using size_type = std::size_t;
using value_type = typename std::iterator_traits<InputIterator>::value_type;
using reference = const value_type&;
using pointer = const value_type*;
using difference_type = std::ptrdiff_t;
using self_type = field_rdof_unary_iterator<UnaryFunction,InputIterator>;
// allocators:
field_rdof_unary_iterator() = delete;
field_rdof_unary_iterator(const UnaryFunction& f, const InputIterator& iter)
: _f(f), _iter(iter) {}
// accessors & modifiers:
value_type operator* () const { return _f(*_iter); }
value_type operator[] (size_type n) const { return _f(*(_iter + n)); }
self_type& operator++ () { ++_iter; return *this; }
self_type operator++ (int) { self_type tmp = *this; operator++(); return tmp; }
self_type& operator+= (difference_type n) { _iter += n; return *this; }
self_type operator+ (difference_type n) const { self_type tmp = *this; return tmp += n; }
// comparators:
bool operator== (const self_type& j) const { return _iter == j._iter; }
bool operator!= (const self_type& j) const { return ! operator== (j); }
protected:
// data:
UnaryFunction _f;
InputIterator _iter;
};
// ----------------------------------------------------------------------------
// 1.2. unary class
// ----------------------------------------------------------------------------
template<class UnaryFunction, class FieldRdof>
class field_rdof_unary: public field_rdof_base<field_rdof_unary<UnaryFunction,FieldRdof>> {
public:
// definitions:
using self_type = field_rdof_unary<UnaryFunction,FieldRdof>;
using base = field_rdof_base<self_type>;
using size_type = typename FieldRdof::size_type;
using scalar_type = typename FieldRdof::scalar_type;
using memory_type = typename FieldRdof::memory_type;
using float_type = typename float_traits<scalar_type>::type;
using geo_type = geo_basic<float_type,memory_type>;
using space_type = space_basic<float_type,memory_type>;
using const_iterator = field_rdof_unary_iterator<UnaryFunction,typename FieldRdof::const_iterator>;
// allocators:
field_rdof_unary (const UnaryFunction& f, const FieldRdof& expr)
: base(),
_f(f),
_expr(expr)
{}
// accessors:
const space_type& get_space() const { return _expr.get_space(); }
const_iterator begin_dof() const { return const_iterator (_f, _expr.begin_dof()); }
const_iterator end_dof() const { return const_iterator (_f, _expr.end_dof()); }
protected:
using field_rdof = typename field_wdof2rdof_traits<FieldRdof>::type;
UnaryFunction _f;
field_rdof _expr;
};
// concept:
template<class UnaryFunction, class FieldRdof>
struct is_field_rdof<field_rdof_unary<UnaryFunction,FieldRdof>>: std::true_type {};
template<class UnaryFunction, class FieldRdof>
struct field_traits<field_rdof_unary<UnaryFunction,FieldRdof>> {
using size_type = typename FieldRdof::size_type;
using scalar_type = typename FieldRdof::scalar_type;
using memory_type = typename FieldRdof::memory_type;
};
}// namespace details
// -------------------------------------------
// 1.3. unary operator+-
// -------------------------------------------
#define _RHEOLEF_make_field_rdof_unary(FUNCTION,FUNCTOR) \
template<class FieldRdof> \
typename \
std::enable_if< \
details::has_field_rdof_interface<FieldRdof>::value \
,details::field_rdof_unary<FUNCTOR,FieldRdof> \
>::type \
FUNCTION (const FieldRdof& rdof) \
{ \
return details::field_rdof_unary<FUNCTOR,FieldRdof> (FUNCTOR(), rdof); \
}
_RHEOLEF_make_field_rdof_unary (operator+, details::unary_plus)
_RHEOLEF_make_field_rdof_unary (operator-, details::negate)
#undef _RHEOLEF_make_field_rdof_unary
// ---------------------------------------------------
// 1.4. multiplication & division by a constant scalar
// ---------------------------------------------------
#define _RHEOLEF_make_field_rdof_unary_scalar_first(FUNCTION,FUNCTOR) \
template<class FieldRdof> \
typename \
std::enable_if< \
details::has_field_rdof_interface<FieldRdof>::value \
,details::field_rdof_unary<details::binder_first<FUNCTOR,typename FieldRdof::scalar_type>,FieldRdof> \
>::type \
FUNCTION (const typename FieldRdof::scalar_type& lambda, const FieldRdof& rdof) \
{ \
using A1 = details::binder_first<FUNCTOR,typename FieldRdof::scalar_type>; \
return details::field_rdof_unary<A1,FieldRdof> (A1(FUNCTOR(),lambda), rdof); \
}
#define _RHEOLEF_make_field_rdof_unary_scalar_second(FUNCTION,FUNCTOR) \
template<class FieldRdof> \
typename \
std::enable_if< \
details::has_field_rdof_interface<FieldRdof>::value \
,details::field_rdof_unary<details::binder_second<FUNCTOR,typename FieldRdof::scalar_type>,FieldRdof> \
>::type \
FUNCTION (const FieldRdof& rdof, const typename FieldRdof::scalar_type& lambda) \
{ \
using A2 = details::binder_second<FUNCTOR,typename FieldRdof::scalar_type>; \
return details::field_rdof_unary<A2,FieldRdof> (A2(FUNCTOR(),lambda), rdof); \
}
_RHEOLEF_make_field_rdof_unary_scalar_first (operator+, details::plus)
_RHEOLEF_make_field_rdof_unary_scalar_first (operator-, details::minus)
_RHEOLEF_make_field_rdof_unary_scalar_first (operator*, details::multiplies)
_RHEOLEF_make_field_rdof_unary_scalar_second(operator+, details::plus)
_RHEOLEF_make_field_rdof_unary_scalar_second(operator-, details::minus)
_RHEOLEF_make_field_rdof_unary_scalar_second(operator*, details::multiplies)
_RHEOLEF_make_field_rdof_unary_scalar_second(operator/, details::divides)
#undef _RHEOLEF_make_field_rdof_unary_scalar_first
#undef _RHEOLEF_make_field_rdof_unary_scalar_second
}// namespace rheolef
# endif /* _RHEOLEF_FIELD_RDOF_NODE_H */
rheolef::details::field_rdof_base
Definition field_rdof.h:41
rheolef::details::field_rdof_unary_iterator
Definition field_rdof_node.h:50
rheolef::details::field_rdof_unary_iterator::self_type
field_rdof_unary_iterator< UnaryFunction, InputIterator > self_type
Definition field_rdof_node.h:61
rheolef::details::field_rdof_unary_iterator::value_type
typename std::iterator_traits< InputIterator >::value_type value_type
Definition field_rdof_node.h:57
rheolef::details::field_rdof_unary_iterator::field_rdof_unary_iterator
field_rdof_unary_iterator(const UnaryFunction &f, const InputIterator &iter)
Definition field_rdof_node.h:66
rheolef::details::field_rdof_unary_iterator::pointer
const value_type * pointer
Definition field_rdof_node.h:59
rheolef::details::field_rdof_unary_iterator::operator++
self_type operator++(int)
Definition field_rdof_node.h:75
rheolef::details::field_rdof_unary_iterator::_f
UnaryFunction _f
Definition field_rdof_node.h:86
rheolef::details::field_rdof_unary_iterator::operator==
bool operator==(const self_type &j) const
Definition field_rdof_node.h:81
rheolef::details::field_rdof_unary_iterator::field_rdof_unary_iterator
field_rdof_unary_iterator()=delete
rheolef::details::field_rdof_unary_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition field_rdof_node.h:55
rheolef::details::field_rdof_unary_iterator::operator+=
self_type & operator+=(difference_type n)
Definition field_rdof_node.h:76
rheolef::details::field_rdof_unary_iterator::_iter
InputIterator _iter
Definition field_rdof_node.h:87
rheolef::details::field_rdof_unary_iterator::operator!=
bool operator!=(const self_type &j) const
Definition field_rdof_node.h:82
rheolef::details::field_rdof_unary_iterator::operator[]
value_type operator[](size_type n) const
Definition field_rdof_node.h:72
rheolef::details::field_rdof_unary_iterator::reference
const value_type & reference
Definition field_rdof_node.h:58
rheolef::details::field_rdof_unary_iterator::operator*
value_type operator*() const
Definition field_rdof_node.h:71
rheolef::details::field_rdof_unary_iterator::difference_type
std::ptrdiff_t difference_type
Definition field_rdof_node.h:60
rheolef::details::field_rdof_unary_iterator::operator+
self_type operator+(difference_type n) const
Definition field_rdof_node.h:77
rheolef::details::field_rdof_unary_iterator::size_type
std::size_t size_type
Definition field_rdof_node.h:56
rheolef::details::field_rdof_unary_iterator::operator++
self_type & operator++()
Definition field_rdof_node.h:74
rheolef::details::field_rdof_unary
Definition field_rdof_node.h:93
rheolef::details::field_rdof_unary::scalar_type
typename FieldRdof::scalar_type scalar_type
Definition field_rdof_node.h:100
rheolef::details::field_rdof_unary::_f
UnaryFunction _f
Definition field_rdof_node.h:123
rheolef::details::field_rdof_unary::end_dof
const_iterator end_dof() const
Definition field_rdof_node.h:119
rheolef::details::field_rdof_unary::begin_dof
const_iterator begin_dof() const
Definition field_rdof_node.h:118
rheolef::details::field_rdof_unary::size_type
typename FieldRdof::size_type size_type
Definition field_rdof_node.h:99
rheolef::details::field_rdof_unary::const_iterator
field_rdof_unary_iterator< UnaryFunction, typename FieldRdof::const_iterator > const_iterator
Definition field_rdof_node.h:105
rheolef::details::field_rdof_unary::field_rdof_unary
field_rdof_unary(const UnaryFunction &f, const FieldRdof &expr)
Definition field_rdof_node.h:109
rheolef::details::field_rdof_unary::self_type
field_rdof_unary< UnaryFunction, FieldRdof > self_type
Definition field_rdof_node.h:97
rheolef::details::field_rdof_unary::field_rdof
typename field_wdof2rdof_traits< FieldRdof >::type field_rdof
Definition field_rdof_node.h:122
rheolef::details::field_rdof_unary::float_type
typename float_traits< scalar_type >::type float_type
Definition field_rdof_node.h:102
rheolef::details::field_rdof_unary::memory_type
typename FieldRdof::memory_type memory_type
Definition field_rdof_node.h:101
rheolef::details::field_rdof_unary::base
field_rdof_base< self_type > base
Definition field_rdof_node.h:98
rheolef::details::field_rdof_unary::get_space
const space_type & get_space() const
Definition field_rdof_node.h:117
rheolef::details::field_rdof_unary::_expr
field_rdof _expr
Definition field_rdof_node.h:124
rheolef::geo_basic< float_type, memory_type >
rheolef::space_basic< float_type, memory_type >
_RHEOLEF_make_field_rdof_unary_scalar_second
#define _RHEOLEF_make_field_rdof_unary_scalar_second(FUNCTION, FUNCTOR)
Definition field_rdof_node.h:174
_RHEOLEF_make_field_rdof_unary
#define _RHEOLEF_make_field_rdof_unary(FUNCTION, FUNCTOR)
Definition field_rdof_node.h:142
_RHEOLEF_make_field_rdof_unary_scalar_first
#define _RHEOLEF_make_field_rdof_unary_scalar_first(FUNCTION, FUNCTOR)
Definition field_rdof_node.h:161
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
f
Definition cavity_dg.h:29
rheolef::details::field_traits< field_rdof_unary< UnaryFunction, FieldRdof > >::scalar_type
typename FieldRdof::scalar_type scalar_type
Definition field_rdof_node.h:133
rheolef::details::field_traits< field_rdof_unary< UnaryFunction, FieldRdof > >::size_type
typename FieldRdof::size_type size_type
Definition field_rdof_node.h:132
rheolef::details::field_traits< field_rdof_unary< UnaryFunction, FieldRdof > >::memory_type
typename FieldRdof::memory_type memory_type
Definition field_rdof_node.h:134
rheolef::details::field_traits
Definition field_lazy.h:265
rheolef::details::field_wdof2rdof_traits::type
FieldWdof type
Definition field_rdof.h:71
rheolef::details::is_field_rdof
Definition field_concept.h:54
rheolef::details::minus
Definition expression.h:544
rheolef::details::negate
Definition expression.h:231
rheolef::details::plus
Definition expression.h:457
rheolef::details::unary_plus
Definition expression.h:209
rheolef::float_traits::type
T type
Definition Float.h:94