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
region.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: 2006-02-24
7 
8  Copyright (C) 2006 EPFL
9  Copyright (C) 2008 Université de Grenoble 1 (Joseph Fourier)
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef __Region_H
31 #define __Region_H 1
32 
33 #include <boost/lambda/lambda.hpp>
34 #include <boost/lambda/bind.hpp>
35 
37 #include <feel/feeldiscr/mesh.hpp>
38 #include <feel/feeldiscr/functionspace.hpp>
39 
40 
41 namespace Feel
42 {
43 namespace lambda = boost::lambda;
48 template<typename SpaceType, typename Expr>
49 typename SpaceType::element_type
50 region( boost::shared_ptr<SpaceType> const& space,
51  Expr const& expr )
52 {
53  BOOST_STATIC_ASSERT( SpaceType::fe_type::nOrder == 0 );
54  typedef typename SpaceType::element_type element_type;
55  element_type v( space, "field" );
56  VLOG(1) << "[region] saving region with pid:\n";
57  int pid = space->mesh()->comm().rank();
58  VLOG(1) << "[region] saving region with pid: " << pid << "\n";
59  auto it = space->mesh()->beginElementWithProcessId( pid );
60  auto en = space->mesh()->endElementWithProcessId( pid );
61  VLOG(1) << "[region] nb elements in region: " << std::distance( it, en ) << "\n";
62  for ( ; it != en; ++it )
63  {
64  size_type dof_id = boost::get<0>( space->dof()->localToGlobal( it->id(),0, 0 ) );
65 
66  if ( dof_id >= v.firstLocalIndex() &&
67  dof_id < v.lastLocalIndex() )
68  v ( dof_id ) = expr( *it );
69  }
70 
71  return v;
72 }
73 struct Region
74 {
75  virtual ~Region() {}
76 };
77 
82 template<typename SpaceType, typename Expr>
83 typename SpaceType::element_type
84 regionv( boost::shared_ptr<SpaceType> const& space,
85  Expr const& expr )
86 {
87  BOOST_STATIC_ASSERT( SpaceType::fe_type::nOrder == 0 );
88  typedef typename SpaceType::element_type element_type;
89  element_type v( space, "field" );
90 
91  int pid = space->mesh()->comm().rank();
92  typename SpaceType::mesh_type::element_const_iterator it = space->mesh()->beginElementWithProcessId( pid );
93  typename SpaceType::mesh_type::element_const_iterator en = space->mesh()->endElementWithProcessId( pid );
94 
95  for ( ; it != en; ++it )
96  {
97  size_type dof_id = boost::get<0>( space->dof()->localToGlobal( it->id(),0, 0 ) );
98 
99  if ( dof_id >= v.firstLocalIndex() &&
100  dof_id < v.lastLocalIndex() )
101  v ( dof_id ) = expr( *it ).value();
102  }
103 
104  return v;
105 }
106 
111 template<typename SpaceType>
112 typename SpaceType::element_type
113 regionProcess( boost::shared_ptr<SpaceType> const& space )
114 {
115  return region( space, lambda::bind( &SpaceType::mesh_type::element_type::processId, lambda::_1 ) );
116 
117 }
118 
122 struct RegionProcess : public Region
123 {
124  template<typename SpaceType>
125  typename SpaceType::element_type
126  apply( boost::shared_ptr<SpaceType> const& space )
127  {
128  return regionProcess( space );
129  }
130 };
131 
136 template<typename SpaceType>
137 typename SpaceType::element_type
138 regionMarker( boost::shared_ptr<SpaceType> const& space )
139 {
140  return region( space, lambda::bind( &SpaceType::mesh_type::element_type::marker, lambda::_1 ) );
141 
142 }
146 struct RegionMarkre : public Region
147 {
148  template<typename SpaceType>
149  typename SpaceType::element_type
150  apply( boost::shared_ptr<SpaceType> const& space )
151  {
152  return regionMarker( space );
153  }
154 };
155 
160 template<typename SpaceType>
161 typename SpaceType::element_type
162 regionMarker2( boost::shared_ptr<SpaceType> const& space )
163 {
164  return region( space, lambda::bind( &SpaceType::mesh_type::element_type::marker2, lambda::_1 ) );
165 
166 }
167 
171 struct RegionMarker2 : public Region
172 {
173  template<typename SpaceType>
174  typename SpaceType::element_type
175  apply( boost::shared_ptr<SpaceType> const& space )
176  {
177  return regionMarker2( space );
178  }
179 };
180 
185 template<typename SpaceType>
186 typename SpaceType::element_type
187 regionMarker3( boost::shared_ptr<SpaceType> const& space )
188 {
189  return region( space, lambda::bind( &SpaceType::mesh_type::element_type::marker3, lambda::_1 ) );
190 
191 }
192 
196 struct RegionMarker3 : public Region
197 {
198  template<typename SpaceType>
199  typename SpaceType::element_type
200  apply( boost::shared_ptr<SpaceType> const& space )
201  {
202  return regionMarker3( space );
203  }
204 };
205 
206 } // Feel
207 
208 #endif /* __Region_H */

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