Rheolef  7.2
an efficient C++ finite element environment
field_rdof_node.h
Go to the documentation of this file.
1 # ifndef _RHEOLEF_FIELD_RDOF_NODE_H
2 # define _RHEOLEF_FIELD_RDOF_NODE_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 // field_rdof: unary+- ; lambda*rdof ; binary+-
24 // AUTHOR: Pierre.Saramito@imag.fr
25 // DATE: 12 may 2020
26 
27 // SUMMARY
28 // 1. unary node
29 // 1.1. unary iterator
30 // 1.2. unary class
31 // 1.3. unary operator+-
32 // 1.4. multiplication & division by a constant scalar
33 // 2. binary node
34 // TODO
35 
36 #include "rheolef/field_rdof.h"
37 #include "rheolef/expression.h"
38 
39 namespace rheolef {
40 
41 // ============================================================================
42 // 1. unary node
43 // ============================================================================
44 namespace details {
45 // ----------------------------------------------------------------------------
46 // 1.1. unary iterator
47 // ----------------------------------------------------------------------------
48 
49 template<class UnaryFunction, class InputIterator>
51 public:
52 
53 // definitions:
54 
55  using iterator_category = std::forward_iterator_tag;
56  using size_type = std::size_t;
57  using value_type = typename std::iterator_traits<InputIterator>::value_type;
58  using reference = const value_type&;
59  using pointer = const value_type*;
60  using difference_type = std::ptrdiff_t;
62 
63 // allocators:
64 
66  field_rdof_unary_iterator(const UnaryFunction& f, const InputIterator& iter)
67  : _f(f), _iter(iter) {}
68 
69 // accessors & modifiers:
70 
71  value_type operator* () const { return _f(*_iter); }
72  value_type operator[] (size_type n) const { return _f(*(_iter + n)); }
73 
74  self_type& operator++ () { ++_iter; return *this; }
75  self_type operator++ (int) { self_type tmp = *this; operator++(); return tmp; }
76  self_type& operator+= (difference_type n) { _iter += n; return *this; }
77  self_type operator+ (difference_type n) const { self_type tmp = *this; return tmp += n; }
78 
79 // comparators:
80 
81  bool operator== (const self_type& j) const { return _iter == j._iter; }
82  bool operator!= (const self_type& j) const { return ! operator== (j); }
83 
84 protected:
85 // data:
86  UnaryFunction _f;
87  InputIterator _iter;
88 };
89 // ----------------------------------------------------------------------------
90 // 1.2. unary class
91 // ----------------------------------------------------------------------------
92 template<class UnaryFunction, class FieldRdof>
93 class field_rdof_unary: public field_rdof_base<field_rdof_unary<UnaryFunction,FieldRdof>> {
94 public:
95 // definitions:
96 
99  using size_type = typename FieldRdof::size_type;
100  using scalar_type = typename FieldRdof::scalar_type;
101  using memory_type = typename FieldRdof::memory_type;
106 
107 // allocators:
108 
109  field_rdof_unary (const UnaryFunction& f, const FieldRdof& expr)
110  : base(),
111  _f(f),
112  _expr(expr)
113  {}
114 
115 // accessors:
116 
117  const space_type& get_space() const { return _expr.get_space(); }
118  const_iterator begin_dof() const { return const_iterator (_f, _expr.begin_dof()); }
119  const_iterator end_dof() const { return const_iterator (_f, _expr.end_dof()); }
120 
121 protected:
123  UnaryFunction _f;
125 };
126 // concept:
127 template<class UnaryFunction, class FieldRdof>
128 struct is_field_rdof<field_rdof_unary<UnaryFunction,FieldRdof>>: std::true_type {};
129 
130 template<class UnaryFunction, class FieldRdof>
131 struct field_traits<field_rdof_unary<UnaryFunction,FieldRdof>> {
132  using size_type = typename FieldRdof::size_type;
133  using scalar_type = typename FieldRdof::scalar_type;
134  using memory_type = typename FieldRdof::memory_type;
135 };
136 
137 }// namespace details
138 // -------------------------------------------
139 // 1.3. unary operator+-
140 // -------------------------------------------
141 
142 #define _RHEOLEF_make_field_rdof_unary(FUNCTION,FUNCTOR) \
143 template<class FieldRdof> \
144 typename \
145 std::enable_if< \
146  details::has_field_rdof_interface<FieldRdof>::value \
147  ,details::field_rdof_unary<FUNCTOR,FieldRdof> \
148 >::type \
149 FUNCTION (const FieldRdof& rdof) \
150 { \
151  return details::field_rdof_unary<FUNCTOR,FieldRdof> (FUNCTOR(), rdof); \
152 }
153 
156 #undef _RHEOLEF_make_field_rdof_unary
157 
158 // ---------------------------------------------------
159 // 1.4. multiplication & division by a constant scalar
160 // ---------------------------------------------------
161 #define _RHEOLEF_make_field_rdof_unary_scalar_first(FUNCTION,FUNCTOR) \
162 template<class FieldRdof> \
163 typename \
164 std::enable_if< \
165  details::has_field_rdof_interface<FieldRdof>::value \
166  ,details::field_rdof_unary<details::binder_first<FUNCTOR,typename FieldRdof::scalar_type>,FieldRdof> \
167 >::type \
168 FUNCTION (const typename FieldRdof::scalar_type& lambda, const FieldRdof& rdof) \
169 { \
170  using A1 = details::binder_first<FUNCTOR,typename FieldRdof::scalar_type>; \
171  return details::field_rdof_unary<A1,FieldRdof> (A1(FUNCTOR(),lambda), rdof); \
172 }
173 
174 #define _RHEOLEF_make_field_rdof_unary_scalar_second(FUNCTION,FUNCTOR) \
175 template<class FieldRdof> \
176 typename \
177 std::enable_if< \
178  details::has_field_rdof_interface<FieldRdof>::value \
179  ,details::field_rdof_unary<details::binder_second<FUNCTOR,typename FieldRdof::scalar_type>,FieldRdof> \
180 >::type \
181 FUNCTION (const FieldRdof& rdof, const typename FieldRdof::scalar_type& lambda) \
182 { \
183  using A2 = details::binder_second<FUNCTOR,typename FieldRdof::scalar_type>; \
184  return details::field_rdof_unary<A2,FieldRdof> (A2(FUNCTOR(),lambda), rdof); \
185 }
186 
189 _RHEOLEF_make_field_rdof_unary_scalar_first (operator*, details::multiplies)
190 _RHEOLEF_make_field_rdof_unary_scalar_second(operator+, details::plus)
192 _RHEOLEF_make_field_rdof_unary_scalar_second(operator*, details::multiplies)
193 _RHEOLEF_make_field_rdof_unary_scalar_second(operator/, details::divides)
194 #undef _RHEOLEF_make_field_rdof_unary_scalar_first
195 #undef _RHEOLEF_make_field_rdof_unary_scalar_second
196 
197 }// namespace rheolef
198 # endif /* _RHEOLEF_FIELD_RDOF_NODE_H */
field::size_type size_type
Definition: branch.cc:430
self_type & operator+=(difference_type n)
typename std::iterator_traits< InputIterator >::value_type value_type
field_rdof_unary_iterator(const UnaryFunction &f, const InputIterator &iter)
bool operator==(const self_type &j) const
std::forward_iterator_tag iterator_category
bool operator!=(const self_type &j) const
value_type operator[](size_type n) const
self_type operator+(difference_type n) const
typename FieldRdof::scalar_type scalar_type
const space_type & get_space() const
const_iterator begin_dof() const
typename FieldRdof::size_type size_type
field_rdof_unary_iterator< UnaryFunction, typename FieldRdof::const_iterator > const_iterator
field_rdof_unary(const UnaryFunction &f, const FieldRdof &expr)
typename field_wdof2rdof_traits< FieldRdof >::type field_rdof
typename float_traits< scalar_type >::type float_type
typename FieldRdof::memory_type memory_type
This file is part of Rheolef.
details::minus details::plus _RHEOLEF_make_field_rdof_unary_scalar_second(operator-, details::minus) _RHEOLEF_make_field_rdof_unary_scalar_second(operator*
_RHEOLEF_make_field_rdof_unary_scalar_first(operator+, details::plus) _RHEOLEF_make_field_rdof_unary_scalar_first(operator-
_RHEOLEF_make_field_rdof_unary(operator+, details::unary_plus) _RHEOLEF_make_field_rdof_unary(operator-
Definition: cavity_dg.h:29