Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
form.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2007-05-30
7 
8  Copyright (C) 2007 Universite Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __Form_H
30 #define __Form_H 1
31 
32 #include <feel/feelcore/parameter.hpp>
33 #include <feel/feelalg/backend.hpp>
34 #include <feel/feelalg/vector.hpp>
36 #include <feel/feelalg/backend.hpp>
37 #include <feel/feeldiscr/functionspace.hpp>
40 
41 namespace Feel
42 {
43 template<typename T> class Vector;
44 
45 //
46 // free form functions
47 //
48 template<typename X1, typename X2>
49 inline
50 vf::detail::BilinearForm<X1, X2>
51 form( boost::shared_ptr<X1> const& __X1,
52  boost::shared_ptr<X2> const& __X2,
53  boost::shared_ptr<MatrixSparse<double> > __M,
54  size_type rowstart = 0,
55  size_type colstart = 0,
56  bool init = false,
57  bool do_threshold = false,
58  typename X1::value_type threshold = type_traits<double>::epsilon(),
59  size_type pattern = Pattern::COUPLED )
60 {
61  return vf::detail::BilinearForm<X1, X2>( __X1, __X2, __M, rowstart, colstart, init, do_threshold, threshold, pattern );
62 }
63 
64 template<typename X1, typename RepType>
65 inline
66 vf::detail::LinearForm<X1, RepType, RepType>
67 form( boost::shared_ptr<X1> const& __X1,
68  boost::shared_ptr<RepType> __M,
69  size_type rowstart = 0,
70  bool init = false,
71  bool do_threshold = false,
72  typename X1::value_type threshold = type_traits<typename RepType::value_type>::epsilon() )
73 {
74  return vf::detail::LinearForm<X1, RepType, RepType>( __X1, __M, rowstart, init, do_threshold, threshold );
75 }
76 
77 
78 namespace detail
79 {
80 template <class MatrixType>
81 struct is_matrix_ptr : mpl::false_ {};
82 
83 template <class MatrixType>
84 struct is_matrix_ptr<boost::shared_ptr<MatrixType> >
85  :
86  boost::is_base_of<MatrixSparse<typename MatrixType::value_type>,
87  MatrixType>
88 {};
89 
90 template <class VectorType>
91 struct is_vector_ptr : mpl::false_ {};
92 
93 template <class VectorType>
94 struct is_vector_ptr<boost::shared_ptr<VectorType> >
95  :
96  boost::is_base_of<Vector<typename VectorType::value_type>,
97  VectorType>
98 {};
99 
100 
101 template<typename FuncSpaceType>
102 struct is_function_space_ptr : mpl::false_ {};
103 
104 template<typename FuncSpaceType>
105 struct is_function_space_ptr<boost::shared_ptr<FuncSpaceType> > : mpl::true_ {};
106 } // detail
107 
108 
110 template<typename Args>
111 struct compute_form1_return
112 {
113 #if 1
114  typedef typename boost::remove_reference<typename parameter::binding<Args, tag::test>::type>::type::element_type test_type;
115  //typedef typename boost::remove_reference<typename parameter::binding<Args, tag::vector>::type>::type::element_type vector_type;
116  typedef typename Backend<double>::vector_type vector_type;
117  typedef vf::detail::LinearForm<test_type,
118  vector_type,
119  vector_type> type;
120 #else
121  typedef typename parameter::value_type<Args, tag::test>::type test_type;
122  typedef typename parameter::value_type<Args, tag::vector>::type vector_type;
123 
124 
125  typedef vf::detail::LinearForm<test_type,vector_type,vector_type> type;
126 #endif
127 };
129 //boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> >
130 BOOST_PARAMETER_FUNCTION(
131  ( typename compute_form1_return<Args>::type ), // 1. return type
132  form1, // 2. name of the function template
133  tag, // 3. namespace of tag types
134  ( required // 4. one required parameter, and
135  ( test, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) ) )
136  ( optional // four optional parameters, with defaults
137  //( in_out( vector ), *( detail::is_vector_ptr<mpl::_> ), backend()->newVector( _test=test ) )
138  ( in_out( vector ), *, backend()->newVector( test ) )
139  ( init, *( boost::is_integral<mpl::_> ), false )
140  ( do_threshold, *( boost::is_integral<mpl::_> ), bool( false ) )
141  ( threshold, *( boost::is_floating_point<mpl::_> ), type_traits<double>::epsilon() )
142  ( rowstart, *( boost::is_integral<mpl::_> ), 0 )
143  )
144 )
145 {
146  //Feel::detail::ignore_unused_variable_warning(boost_parameter_enabler_argument);
147  Feel::detail::ignore_unused_variable_warning( args );
148  //return form( test, *vector, init, false, 1e-16 );
149  return form( test, vector, rowstart, init, do_threshold, threshold );
150 } // form
151 
152 BOOST_PARAMETER_FUNCTION(
153  ( typename compute_form1_return<Args>::type ), // 1. return type
154  lform, // 2. name of the function template
155  tag, // 3. namespace of tag types
156  ( required // 4. one required parameter, and
157  ( test, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
158  ( in_out( vector ), *(detail::is_vector_ptr<mpl::_> ) )
159  ) // required
160  ( optional // four optional parameters, with defaults
161  ( init, *( boost::is_integral<mpl::_> ), false )
162  ( do_threshold, *( boost::is_integral<mpl::_> ), bool( false ) )
163  ( threshold, *( boost::is_floating_point<mpl::_> ), type_traits<double>::epsilon() )
164  ( rowstart, *( boost::is_integral<mpl::_> ), 0 )
165  )
166 )
167 {
168  //return form( test, *vector, init, false, 1e-16 );
169  return form( test, *vector, rowstart, init, do_threshold, threshold );
170 } // form
171 
173 template<typename Args, typename T>
174 struct compute_form2_return
175 {};
176 
177 template<typename Args>
178 struct compute_form2_return<Args, mpl::false_>
179 {
180  typedef typename parameter::value_type<Args, tag::test>::type::element_type::value_type value_type;
181  typedef vf::detail::BilinearForm<typename parameter::value_type<Args, tag::test>::type::element_type,
182  typename parameter::value_type<Args, tag::trial>::type::element_type,
183  //typename parameter::value_type<Args, tag::matrix>::type::element_type,
184  VectorUblas<value_type> > type;
185 };
186 template<typename Args>
187 struct compute_form2_return<Args, mpl::true_>
188 {
189  typedef typename parameter::value_type<Args, tag::test>::type::element_type::value_type value_type;
190  typedef vf::detail::BilinearForm<typename parameter::value_type<Args, tag::test>::type::element_type,
191  typename parameter::value_type<Args, tag::test>::type::element_type,
192  //typename parameter::value_type<Args, tag::vector>::type::element_type,
193  VectorUblas<value_type> > type;
194 };
196 
197 #if 0
198 BOOST_PARAMETER_FUNCTION(
199  ( typename compute_form2_return<Args,mpl::bool_<boost::is_same<typename parameter::value_type<Args, tag::trial>::type, boost::parameter::void_>::value> >::type ), // 1. return type
200  form2, // 2. name of the function template
201  tag, // 3. namespace of tag types
202  ( required // 4. one required parameter, and
203  ( test, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
204  ( trial, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
205  ( in_out( matrix ), *(detail::is_matrix_ptr<mpl::_> ) ) ) // required
206  ( optional // four optional parameters, with defaults
207  ( init, *( boost::is_integral<mpl::_> ), false )
208  ( do_threshold, *( boost::is_integral<mpl::_> ), bool( false ) )
209  ( threshold, *( boost::is_floating_point<mpl::_> ), type_traits<double>::epsilon() )
210  ( pattern, *( boost::is_integral<mpl::_> ), size_type( Pattern::COUPLED ) )
211  ( do_threshold, *( boost::is_integral<mpl::_> ), bool( false ) )
212  ( threshold, *( boost::is_floating_point<mpl::_> ), type_traits<double>::epsilon() )
213  )
214 )
215 {
216  Feel::detail::ignore_unused_variable_warning( args );
217  //return form( test, trial, *matrix, init, false, 1e-16, pattern );
218  return form( test, trial, *matrix, init, do_threshold, threshold, pattern );
219  //return form( test, trial, *matrix, init, false, threshold, pattern );
220  //return form( test, trial, *matrix, init, false, threshold, 0 );
221 } //
222 #else
223 BOOST_PARAMETER_FUNCTION( ( typename compute_form2_return<Args,mpl::bool_<boost::is_same<typename parameter::value_type<Args, tag::trial>::type, boost::parameter::void_>::value> >::type ), // 1. return type
224  form2, // 2. name of the function template
225  tag, // 3. namespace of tag types
226  ( required // 4. one required parameter, and
227  ( test, * )
228  ( trial, * )
229  ) // required
230  (deduced
231  ( optional // four optional parameters, with defaults
232  ( init, *( boost::is_integral<mpl::_> ), false )
233  ( pattern, *( boost::is_integral<mpl::_> ), size_type( Pattern::COUPLED ) )
234  ( in_out( matrix ), *(boost::is_convertible<mpl::_, boost::shared_ptr<MatrixSparse<double>>>), backend()->newMatrix( _test=test, _trial=trial, _pattern=pattern ) )
235  ( rowstart, *( boost::is_integral<mpl::_> ), 0 )
236  ( colstart, *( boost::is_integral<mpl::_> ), 0 )
237  ) // optional
238  ) // deduced
239  )
240 {
241  Feel::detail::ignore_unused_variable_warning( args );
242  //return form( test, trial, *matrix, init, false, 1e-16, pattern );
243  //if (!matrix) matrix.reset( backend()->newMatrix( _trial=trial, _test=test ) );
244  bool do_threshold = false;
245  double threshold = 1e-16;
246  return form( test, trial, matrix, rowstart, colstart, init, do_threshold, threshold, pattern );
247  //return form( test, trial, *matrix, init, false, threshold, pattern );
248  //return form( test, trial, *matrix, init, false, threshold, 0 );
249 } //
250 
251 #endif
252 
253 #if 0
254 BOOST_PARAMETER_FUNCTION(
255  ( typename compute_form2_return<Args,mpl::bool_<boost::is_same<typename parameter::value_type<Args, tag::trial>::type, boost::parameter::void_>::value> >::type ), // 1. return type
256  blform, // 2. name of the function template
257  tag, // 3. namespace of tag types
258  ( required // 4. one required parameter, and
259  ( test, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
260  ( trial, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
261  ( in_out( matrix ), *(detail::is_matrix_ptr<mpl::_> ) ) ) // required
262  ( optional // four optional parameters, with defaults
263  ( init, *( boost::is_integral<mpl::_> ), false )
264  ( do_threshold, *( boost::is_integral<mpl::_> ), bool( false ) )
265  ( threshold, *( boost::is_floating_point<mpl::_> ), type_traits<double>::epsilon() )
266  ( pattern, *( boost::is_integral<mpl::_> ), size_type( Pattern::COUPLED ) )
267  )
268 )
269 {
270  return form( test, trial, *matrix, init, do_threshold, threshold, pattern );
271  //return form( test, trial, *matrix, init, false, 1e-16, pattern );
272 } //
273 #endif
274 
275 
276 
277 } // Feel
278 #endif /* __Form_H */

Generated on Sun Oct 20 2013 08:24:57 for Feel++ by doxygen 1.8.4