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
functors.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-06-01
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 __Functor_H
30 #define __Functor_H 1
31 
32 #include <feel/feelalg/glas.hpp>
34 
35 namespace Feel
36 {
37 class MeshBase;
39 namespace detail
40 {
41 struct UpdateMesh
42 {
43  UpdateMesh( MeshBase const* m )
44  :
45  M_mesh( m )
46  {}
47  template<typename ElementType>
48  void operator()( ElementType& element ) const
49  {
50  element.setMesh( M_mesh );
51  }
52 private:
53  MeshBase const* M_mesh;
54 
55 };
56 
57 struct OnBoundary
58 {
59  OnBoundary( bool is_on_bdy = false )
60  :
61  M_bdy( is_on_bdy )
62  {}
63  template<typename ElementType>
64  void operator()( ElementType& element ) const
65  {
66  element.setOnBoundary( M_bdy );
67  }
68 private:
69  bool M_bdy;
70 
71 };
72 
73 struct ApplyDisplacement
74 {
75  ApplyDisplacement( uint16_type l, ublas::vector<double> const& displ )
76  :
77  M_l( l ),
78  M_displ( displ )
79  {}
80  template<typename ElementType>
81  void operator()( ElementType& elt )
82  {
83  elt.applyDisplacement( M_l, M_displ );
84  }
85  uint16_type M_l;
86  ublas::vector<double> const& M_displ;
87 
88 };
89 
90 template<typename FaceType>
91 struct UpdateFace
92 {
93  UpdateFace( FaceType const& face )
94  :
95  M_face( face )
96  {}
97  template<typename ElementType>
98  void operator()( ElementType& element ) const
99  {
100  if ( M_face.ad_first() == element.id() )
101  {
102  element.setFace( M_face.pos_first(), M_face );
103 
104  if ( M_face.isConnectedTo1() )
105  element.setNeighbor( M_face.pos_first(), M_face.ad_second(), M_face.proc_second() );
106 
107  FEELPP_ASSERT( element.facePtr( M_face.pos_first() ) )
108  ( M_face.pos_first() )
109  ( M_face.ad_first() ).error( "invalid face" );
110  }
111 
112  else if ( M_face.ad_second() == element.id() )
113  {
114  element.setFace( M_face.pos_second(), M_face );
115  element.setNeighbor( M_face.pos_second(), M_face.ad_first(), M_face.proc_first() );
116  FEELPP_ASSERT( element.facePtr( M_face.pos_second() ) )
117  ( M_face.pos_second() )
118  ( M_face.ad_second() ).error( "invalid face" );
119  }
120 
121  else
122  {
123  FEELPP_ASSERT( 0 )
124  ( M_face.ad_first() )( M_face.pos_first() )
125  ( M_face.ad_second() )( M_face.pos_second() )
126  ( element.id() ).error( "invalid face " );
127  }
128  }
129 private:
130  FaceType const& M_face;
131 
132 };
133 
134 template<typename PermutationType>
135 struct UpdateFacePermutation
136 {
137  UpdateFacePermutation( uint16_type j, PermutationType const& perm )
138  :
139  M_localfaceid( j ),
140  M_perm( perm )
141  {}
142  template<typename ElementType>
143  void operator()( ElementType& element ) const
144  {
145  element.setFacePermutation( M_localfaceid, M_perm );
146  }
147 private:
148  uint16_type M_localfaceid;
149  PermutationType const& M_perm;
150 
151 };
152 
153 template<typename ConnectionType>
154 struct UpdateFaceConnection0
155 {
156  UpdateFaceConnection0( ConnectionType const& conn )
157  :
158  M_conn( conn )
159  {}
160  template<typename FaceType>
161  void operator()( FaceType& element ) const
162  {
163  element.setConnection0( M_conn );
164  }
165 private:
166  ConnectionType const& M_conn;
167 
168 };
169 template<typename ConnectionType>
170 struct UpdateFaceConnection1
171 {
172  UpdateFaceConnection1( ConnectionType const& conn )
173  :
174  M_conn( conn )
175  {}
176  template<typename FaceType>
177  void operator()( FaceType& element ) const
178  {
179  //element.setOnBoundary( false );
180  element.setConnection1( M_conn );
181 
182  if ( ( element.element0().marker() == element.element1().marker() ) &&
183  element.marker().value() == 0 )
184  element.setMarker( element.element0().marker().value() );
185  }
186 private:
187  ConnectionType const& M_conn;
188 
189 };
190 
191 struct UpdateFaceOnBoundary
192 {
193  UpdateFaceOnBoundary( bool onbdy )
194  :
195  M_onbdy( onbdy )
196  {}
197  template<typename FaceType>
198  void operator()( FaceType& element ) const
199  {
200  element.setOnBoundary( M_onbdy );
201  }
202 private:
203  bool M_onbdy;
204 
205 };
206 
207 template<typename EdgeType>
208 struct UpdateEdge
209 {
210  UpdateEdge( uint16_type j, EdgeType const& edge )
211  :
212  M_localedgeid( j ),
213  M_edge( edge )
214  {}
215  template<typename ElementType>
216  void operator()( ElementType& element ) const
217  {
218  element.setEdge( M_localedgeid, M_edge );
219  }
220 private:
221  uint16_type M_localedgeid;
222  EdgeType const& M_edge;
223 
224 };
225 
226 template<typename PermutationType>
227 struct UpdateEdgePermutation
228 {
229  UpdateEdgePermutation( uint16_type j, PermutationType const& perm )
230  :
231  M_localedgeid( j ),
232  M_perm( perm )
233  {}
234  template<typename ElementType>
235  void operator()( ElementType& element ) const
236  {
237  element.setEdgePermutation( M_localedgeid, M_perm );
238  }
239 private:
240  uint16_type M_localedgeid;
241  PermutationType const& M_perm;
242 
243 };
244 
245 struct updateIdInOthersPartitions
246 {
247  updateIdInOthersPartitions( uint16_type pid, size_type id )
248  :
249  M_pid( pid ),
250  M_id( id )
251  {}
252  template<typename ElementType>
253  void operator()( ElementType& element )
254  {
255  element.setIdInOthersPartitions( M_pid, M_id );
256  }
257 private:
258  uint16_type M_pid;
259  size_type M_id;
260 };
261 
262 struct UpdateProcessId
263 {
264  UpdateProcessId( int pid )
265  :
266  M_pid( pid )
267  {}
268  template<typename ElementType>
269  void operator()( ElementType& element )
270  {
271  element.setProcessId( M_pid );
272  }
273 private:
274  int M_pid;
275 };
276 
277 struct UpdateMarker
278 {
279  UpdateMarker( flag_type v )
280  :
281  M_v( v )
282  {}
283 
284  template<typename ElementType>
285  void operator()( ElementType& element )
286  {
287  element.setMarker( M_v );
288  }
289 private:
290  flag_type M_v;
291 };
292 
293 
294 } // detail
296 }
297 #endif /* __Functor_H */

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