Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
riesz.h
Go to the documentation of this file.
1#ifndef _RHEO_RIESZ_H
2#define _RHEO_RIESZ_H
23#include "rheolef/field.h"
24#include "rheolef/band.h"
25#include "rheolef/test.h"
26#include "rheolef/integrate.h"
27
28namespace rheolef {
29
30// --------------------------------------------------------------------------
31// implementation
32// --------------------------------------------------------------------------
33namespace details {
34// --------------------------------------------------------------------------
35// generic implementation
36// --------------------------------------------------------------------------
37// scalar-valued function
38template <class T, class M, class Geo, class Function>
39field_basic<T,M>
41 const space_basic<T,M>& Xh,
42 const Function& f,
43 const quadrature_option& qopt,
44 const Geo& dom,
45 std::false_type)
46{
48 return integrate (dom, f*v, qopt);
49}
50// vector-valued function
51template <class T, class M, class Geo, class Function>
54 const space_basic<T,M>& Xh,
55 const Function& f,
56 const quadrature_option& qopt,
57 const Geo& dom,
58 std::true_type)
59{
61 return integrate (dom, dot(f,v), qopt);
62}
63// --------------------------------------------------------------------------
64// switch between compile-time return type:
65// --------------------------------------------------------------------------
66template <class T, class M, class Geo, class Function>
69 const space_basic<T,M>& Xh,
70 const Function& f,
71 const quadrature_option& qopt,
72 const Geo& dom,
73 const T&)
74{
75 return riesz_function_internal (Xh, f, qopt, dom, std::false_type());
76}
77template <class T, class M, class Geo, class Function>
80 const space_basic<T,M>& Xh,
81 const Function& f,
82 const quadrature_option& qopt,
83 const Geo& dom,
84 const point_basic<T>&)
85{
86 return riesz_function_internal (Xh, f, qopt, dom, std::true_type());
87}
88template <class T, class M, class Geo, class Function>
91 const space_basic<T,M>& Xh,
92 const Function& f,
93 const quadrature_option& qopt,
94 const Geo& dom,
96{
97 if (Xh.valued_tag() == space_constant::scalar) {
98 return riesz_function_internal (Xh, f, qopt, dom, std::false_type());
99 } else {
100 return riesz_function_internal (Xh, f, qopt, dom, std::true_type());
101 }
102}
103// --------------------------------------------------------------------------
104// f: switch between constant or function
105// --------------------------------------------------------------------------
106// f is a function:
107template <class T, class M, class Geo, class Function>
108typename
109std::enable_if<
110 is_field_function<Function>::value
112>::type
114 const space_basic<T,M>& Xh,
115 const Function& f,
116 const quadrature_option& qopt,
117 const Geo& dom,
118 std::false_type)
119{
121 return riesz_tag2 (Xh, f, qopt, dom, result_type());
122}
123// f is an expression
124template <class T, class M, class Geo, class Function>
125typename
126std::enable_if<
127 ! is_field_function<Function>::value
129>::type
131 const space_basic<T,M>& Xh,
132 const Function& f,
133 const quadrature_option& qopt,
134 const Geo& dom,
135 std::false_type)
136{
137 using result_type = typename Function::result_type;
138 return riesz_tag2 (Xh, f, qopt, dom, result_type());
139}
140// f is a constant:
141// thanks to a wrapper class, we go to the first case
142template <class T, class M, class Geo, class Constant>
145 const space_basic<T,M>& Xh,
146 const Constant& value,
147 const quadrature_option& qopt,
148 const Geo& dom,
149 std::true_type)
150{
151 typedef typename field_basic<T,M>::float_type float_type;
152 typedef typename constant_promote<Constant>::type constant_type; // int to Float, but conserve point_basic<T> & tensor
153 return riesz_tag (Xh, f_constant<point_basic<float_type>,constant_type>(value),
154 qopt, dom, std::false_type());
155}
156
157} // namespace details
158
159/*Class:riesz
160NAME: @code{riesz} - approximate a Riesz representer
161@findex riesz
162@cindex riesz representer
163@cindex quadrature formula
164@clindex space
165@clindex field
166
167SYNOPSIS:
168 The @code{riesz} function is now obsolete: it has been now suppersetted by the @code{integrate} function
169 @pxref{integrate algorithm}.
170@example
171 template <class Expr>
172 field riesz (space, Expr expr);
173 field riesz (space, Expr expr, quadrature_option);
174 field riesz (space, Expr expr, domain);
175 field riesz (space, Expr expr, domain, quadrature_option);
176@end example
177 The domain can be also provided by its name as a string.
178 The old-fashioned code:
179NOTE:
180 The @code{riesz} function is now obsolete: it has been now suppersetted by the @code{integrate} function
181 @pxref{integrate algorithm}.
182 The old-fashioned code:
183 @example
184 field l1h = riesz (Xh, f);
185 field l2h = riesz (Xh, f, "boundary");
186 @end example
187 writes now:
188 @example
189 test v (Xh);
190 field l1h = integrate (f*v);
191 field l2h = integrate ("boundary", f*v);
192 @end example
193 The @code{riesz} function is still present in the library for backward compatibility purpose.
194DESCRIPTION:
195 Let @code{f} be any continuous function, its Riesz representer in the finite
196 element space @code{Xh} on the domain @code{Omega} is defind by:
197@example
198 /
199 |
200 dual(lh,vh) = | f(x) vh(x) dx
201 |
202 / Omega
203@end example
204 for all @code{vh} in @code{Xh}, where @code{dual} denotes the duality
205 between @code{Xh} and its dual. As @code{Xh} is a finite dimensional space,
206 its dual is identified as @code{Xh} and the duality product as the Euclidian one.
207 The Riesz representer is thus the @code{lh} field of @code{Xh} where
208 its i-th degree of freedom is:
209@example
210 /
211 |
212 dual(lh,vh) = | f(x) phi_i(x) dx
213 |
214 / Omega
215@end example
216 where phi_i is the i-th basis function in @code{Xh}.
217 The integral is evaluated by using a quadrature formula.
218 By default the quadrature formule is the Gauss one with
219 the order equal to @code{2*k-1} where $@code{k} is the polynomial degree in @code{Xh}.
220 Alternative quadrature formula and order is available
221 by passing an optional variable to riesz.
222
223@noindent
224 The function @code{riesz} implements the
225 approximation of the Riesz representer
226 by using some quadrature formula for the evaluation of the integrals.
227 Its argument can be any function, class-function or linear or nonlinear
228 expressions mixing fields and continuous functions.
229
230@cindex integrate
231@findex integrate
232EXAMPLE:
233@noindent
234 The following code compute the Riesz representant, denoted
235 by @code{lh} of f(x), and the integral of f over the domain omega:
236@example
237 Float f(const point& x);
238 ...
239 space Xh (omega_h, "P1");
240 field lh = riesz (Xh, f);
241 Float int_f = dual(lh, 1);
242@end example
243OPTIONS:
244 An optional argument specifies the quadrature formula used
245 for the computation of the integral.
246 The domain of integration is by default the mesh associated to
247 the finite element space.
248 An alternative domain @code{dom}, e.g. a part of
249 the boundary can be supplied as an extra argument.
250 This domain can be also a @code{band} associated to
251 the banded level set method.
252End: */
253
254//<riesz:
255template <class T, class M, class Function>
256inline
257field_basic<T,M>
259 const space_basic<T,M>& Xh,
260 const Function& f,
261 const quadrature_option& qopt
263//>riesz:
264{
265 return details::riesz_tag (Xh, f, qopt, Xh.get_geo(),
267}
268//<riesz:
269template <class T, class M, class Function>
270field_basic<T,M>
272 const space_basic<T,M>& Xh,
273 const Function& f,
274 const geo_basic<T,M>& dom,
275 const quadrature_option& qopt
277//>riesz:
278{
279 return details::riesz_tag (Xh, f, qopt, dom,
281}
282//<riesz:
283template <class T, class M, class Function>
284field_basic<T,M>
286 const space_basic<T,M>& Xh,
287 const Function& f,
288 std::string dom_name,
289 const quadrature_option& qopt
291//>riesz:
292{
293 const geo_basic<T,M>& omega = Xh.get_geo();
294 return riesz (Xh, f, omega[dom_name], qopt);
295}
296//<riesz:
297template <class T, class M, class Function>
298field_basic<T,M>
300 const space_basic<T,M>& Xh,
301 const Function& f,
302 const band_basic<T,M>& gh,
303 const quadrature_option& qopt
305//>riesz:
306{
307 return details::riesz_tag (Xh, f, qopt, gh,
309}
310
311}// namespace rheolef
312#endif // _RHEO_RIESZ_H
field gh(Float epsilon, Float t, const field &uh, const test &v)
typename float_traits< T >::type float_type
Definition field.h:228
generic mesh with rerefence counting
Definition geo.h:1089
see the integrate_option page for the full documentation
the finite element space
Definition space.h:382
Expr1::float_type T
Definition field_expr.h:230
std::enable_if< is_field_function< Function >::value, field_basic< T, M > >::type riesz_tag(const space_basic< T, M > &Xh, const Function &f, const quadrature_option &qopt, const Geo &dom, std::false_type)
Definition riesz.h:113
rheolef::details::is_vec dot
field_basic< T, M > riesz_tag2(const space_basic< T, M > &Xh, const Function &f, const quadrature_option &qopt, const Geo &dom, const T &)
Definition riesz.h:68
field_basic< T, M > riesz_function_internal(const space_basic< T, M > &Xh, const Function &f, const quadrature_option &qopt, const Geo &dom, std::false_type)
Definition riesz.h:40
This file is part of Rheolef.
field_basic< T, M > riesz(const space_basic< T, M > &Xh, const Function &f, const quadrature_option &qopt=quadrature_option())
Definition riesz.h:258
std::enable_if< details::is_field_expr_v2_nonlinear_arg< Expr >::value &&!is_undeterminated< Result >::value, Result >::type integrate(const geo_basic< T, M > &omega, const Expr &expr, const integrate_option &iopt, Result dummy=Result())
see the integrate page for the full documentation
Definition integrate.h:211
Definition cavity_dg.h:29
helper for generic field value_type: T, point_basic<T> or tensor_basic<T>