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
fsfunctionallinear.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): Christoph Winkelmann <christoph.winkelmann@epfl.ch>
6  Date: 2006-11-16
7 
8  Copyright (C) 2006 EPFL
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 */
30 #ifndef _FSFUNCTIONALLINEAR_HPP_
31 #define _FSFUNCTIONALLINEAR_HPP_
32 
33 #include <feel/feelalg/backend.hpp>
35 #include <feel/feelvf/vf.hpp>
36 
37 namespace Feel
38 {
39 
40 // Linear functional on function space, represented by M_vector
41 template<class Space>
42 class FsFunctionalLinear : public FsFunctional<Space>
43 {
44 public:
45 
46  // -- TYPEDEFS --
47  typedef FsFunctionalLinear<Space> this_type;
48  typedef FsFunctional<Space> super_type;
49 
50  typedef Space space_type;
51 
52  typedef boost::shared_ptr<space_type> space_ptrtype;
53  typedef typename space_type::element_type element_type;
54 
55  typedef typename space_type::value_type value_type;
56 
57  typedef Backend<value_type> backend_type;
58  typedef boost::shared_ptr<backend_type> backend_ptrtype;
59 
60  typedef typename backend_type::vector_type vector_type;
61  typedef typename backend_type::vector_ptrtype vector_ptrtype;
62 
63  FsFunctionalLinear( space_ptrtype space ) :
64  super_type( space ),
65  M_backend( backend_type::build( BACKEND_PETSC ) ),
66  M_vector( M_backend->newVector( space ) ),
67  M_name( "functionallinear" )
68  {
69  }
70 
71  FsFunctionalLinear( space_ptrtype space, backend_ptrtype backend ) :
72  super_type( space ),
73  M_backend( backend ),
74  M_vector( M_backend->newVector( space ) ),
75  M_name( "functionallinear" )
76  {
77  }
78 
79  void setName( std::string name ) { M_name = name; }
80  std::string name() const { return M_name ; }
81 
82  // apply the functional
83  virtual value_type
84  operator()( const element_type& x ) const
85  {
86  M_vector->close();
87  return M_backend->dot( *M_vector, x.container() );
88  }
89 
90  // get the representation vector
91  vector_type const& container() const
92  {
93  return *M_vector;
94  }
95 
96  vector_type& container()
97  {
98  return *M_vector;
99  }
100 
101  // get the representation vector
102  virtual vector_ptrtype const& containerPtr() const
103  {
104  return M_vector;
105  }
106 
107  virtual vector_ptrtype& containerPtr()
108  {
109  return M_vector;
110  }
111 
112  virtual void containerPtr( vector_ptrtype & vector )
113  {
114  vector = M_vector;
115  }
116 
117  virtual void container( vector_type & vector )
118  {
119  vector = *M_vector;
120  }
121 
122  // fill linear functional from linear form
123  template<typename ExprT>
124  this_type& operator=( ExprT const& e )
125  {
126  form1( _test=this->space(), _vector=M_vector ) = e;
127  return *this;
128  }
129 
130  // fill linear functional from linear form
131  template<typename ExprT>
132  this_type& operator+=( ExprT const& e )
133  {
134  form1( _test=this->space(), _vector=M_vector ) += e;
135  return *this;
136  }
137 
138  void close()
139  {
140  if ( ! M_vector->closed() )
141  {
142  M_vector->close();
143  }
144  }
145 
146  void
147  add( this_type const& f )
148  {
149  M_vector->add( f.container() );
150  }
151 private:
152 
153  backend_ptrtype M_backend;
154  vector_ptrtype M_vector;
155  std::string M_name;
156 }; // class FsFunctionalLinear
157 
158 namespace detail
159 {
160 
161 template<typename Args>
162 struct compute_functionalLinear_return
163 {
164  typedef typename boost::remove_reference<typename parameter::binding<Args, tag::space>::type>::type::element_type space_type;
165 
166  typedef FsFunctionalLinear<space_type> type;
167  typedef boost::shared_ptr<FsFunctionalLinear<space_type> > ptrtype;
168 };
169 }
170 
171 BOOST_PARAMETER_FUNCTION(
172  ( typename Feel::detail::compute_functionalLinear_return<Args>::ptrtype ), // 1. return type
173  functionalLinear, // 2. name of the function template
174  tag, // 3. namespace of tag types
175  ( required
176  ( space, *( boost::is_convertible<mpl::_,boost::shared_ptr<FunctionSpaceBase> > ) )
177  ) // required
178  ( optional
179  ( backend, *, Backend<typename Feel::detail::compute_functionalLinear_return<Args>::domain_space_type::value_type>::build() )
180  ) // optionnal
181 )
182 {
183 
184  Feel::detail::ignore_unused_variable_warning( args );
185  typedef typename Feel::detail::compute_functionalLinear_return<Args>::type functional_type;
186  typedef typename Feel::detail::compute_functionalLinear_return<Args>::ptrtype functional_ptrtype;
187  return functional_ptrtype ( new functional_type( space , backend ) );
188 
189 } // functionalLinear
190 
191 } // Feel
192 
193 #endif /* _FSFUNCTIONALLINEAR_HPP_ */
Elements & operator=(Elements const &e)
Definition: elements.hpp:335

Generated on Sun Dec 22 2013 13:11:00 for Feel++ by doxygen 1.8.5