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
fsfunctionallinearfree.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 -*-
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2013-04-26
7 
8  Copyright (C) 2013 Feel++ Consortium
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 2.1 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 */
30 #ifndef __FSFUNCTIONALLINEARFREE_H
31 #define __FSFUNCTIONALLINEARFREE_H 1
32 
33 #include <feel/feelalg/backend.hpp>
35 #include <feel/feelvf/vf.hpp>
36 
37 namespace Feel
38 {
39 
40 template<class Space, class ExprType>
41 class FsFunctionalLinearFree : public FsFunctionalLinear<Space>
42 {
43 public:
44 
45  typedef FsFunctionalLinearFree<Space,ExprType> this_type;
46  typedef FsFunctionalLinear<Space> super_type;
47 
48  typedef Space space_type;
49 
50  typedef boost::shared_ptr<space_type> space_ptrtype;
51  typedef typename space_type::element_type element_type;
52 
53  typedef typename space_type::value_type value_type;
54 
55  typedef Backend<value_type> backend_type;
56  typedef boost::shared_ptr<backend_type> backend_ptrtype;
57 
58  typedef typename backend_type::vector_type vector_type;
59  typedef typename backend_type::vector_ptrtype vector_ptrtype;
60 
61  typedef ExprType expr_type;
62 
63  FsFunctionalLinearFree( space_ptrtype space , expr_type expr ) :
64  super_type( space ),
65  M_backend( backend_type::build( BACKEND_PETSC ) ),
66  M_expr( expr )
67  {}
68 
69  FsFunctionalLinearFree( space_ptrtype space, backend_ptrtype backend , expr_type expr ) :
70  super_type( space ),
71  M_backend( backend ),
72  M_expr( expr )
73  {}
74 
75  //return the expression
76  expr_type expr()
77  {
78  return M_expr;
79  }
80 
81  // apply the functional
82  virtual value_type
83  operator()( const element_type& x ) const
84  {
85  auto vector = M_backend->newVector( this->space() );
86  form1( _test=this->space(),_vector=vector) = M_expr;
87  vector->close();
88 
89  return M_backend->dot( *vector, x.container() );
90  }
91 
92  //fill a vector to have the container
93  virtual void containerPtr( vector_ptrtype & vector_to_fill )
94  {
95  auto vector = M_backend->newVector( this->space() );
96  form1( _test=this->space(),_vector=vector) = M_expr;
97  vector->close();
98  vector_to_fill = vector;
99  }
100 
101  //fill a vector to have the container
102  virtual void container( vector_type & vector_to_fill )
103  {
104  auto vector = M_backend->newVector( this->space() );
105  form1( _test=this->space(),_vector=vector) = M_expr;
106  vector->close();
107 
108  vector_to_fill = *vector;
109  }
110 
111  this_type& operator=( this_type const& m )
112  {
113  M_backend = m.M_backend;
114  M_expr = m.M_expr;
115  return *this;
116  }
117 
118 
119 private:
120  backend_ptrtype M_backend;
121  expr_type M_expr;
122 };//FsFunctionalLinearFree
123 
124 
125 namespace detail
126 {
127 
128 template<typename Args>
129 struct compute_functionalLinearFree_return
130 {
131  typedef typename boost::remove_reference<typename parameter::binding<Args, tag::space>::type>::type::element_type space_type;
132  typedef typename boost::remove_reference<typename parameter::binding<Args, tag::expr>::type>::type expr_type;
133 
134  typedef FsFunctionalLinearFree<space_type, expr_type> type;
135  typedef boost::shared_ptr<FsFunctionalLinearFree<space_type,expr_type> > ptrtype;
136 };
137 }
138 
139 BOOST_PARAMETER_FUNCTION(
140  ( typename Feel::detail::compute_functionalLinearFree_return<Args>::ptrtype ), // 1. return type
141  functionalLinearFree, // 2. name of the function template
142  tag, // 3. namespace of tag types
143  ( required
144  ( space, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
145  ( expr , * )
146  ) // required
147  ( optional
148  ( backend, *, Backend<typename Feel::detail::compute_functionalLinearFree_return<Args>::space_type::value_type>::build() )
149  ) // optionnal
150 )
151 {
152 
153  Feel::detail::ignore_unused_variable_warning( args );
154  typedef typename Feel::detail::compute_functionalLinearFree_return<Args>::type functionalfree_type;
155  typedef typename Feel::detail::compute_functionalLinearFree_return<Args>::ptrtype functionalfree_ptrtype;
156  return functionalfree_ptrtype ( new functionalfree_type( space , backend , expr ) );
157 
158 } // functionalLinearFree
159 
160 }//Feel
161 
162 #endif /* _FSFUNCTIONALLINEARFREE_HPP_ */
163 

Generated on Fri Oct 25 2013 14:24:11 for Feel++ by doxygen 1.8.4