libMesh
sync_refinement_flags.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_SYNC_REFINEMENT_FLAGS_H
21 #define LIBMESH_SYNC_REFINEMENT_FLAGS_H
22 
23 // Local includes
24 #include "libmesh/libmesh_config.h"
25 
26 // Only compile these functions if the user requests AMR support
27 #ifdef LIBMESH_ENABLE_AMR
28 
29 // libMesh includes
30 #include "libmesh/elem.h"
31 #include "libmesh/mesh_base.h"
32 
33 // C++ includes
34 #include <vector>
35 
36 namespace libMesh {
37 
39 {
40  typedef unsigned char datum;
41  typedef Elem::RefinementState (Elem::*get_a_flag)() const;
42  typedef void (Elem::*set_a_flag)(const Elem::RefinementState);
43 
45  get_a_flag _getter,
46  set_a_flag _setter) :
47  mesh(_mesh), parallel_consistent(true),
48  get_flag(_getter), set_flag(_setter) {}
49 
54  // References to pointers to member functions segfault?
55  // get_a_flag & get_flag;
56  // set_a_flag & set_flag;
57 
58  // Find the refinement flag on each requested element
59  void gather_data (const std::vector<dof_id_type> & ids,
60  std::vector<datum> & flags) const
61  {
62  flags.resize(ids.size());
63 
64  for (std::size_t i=0; i != ids.size(); ++i)
65  {
66  // Look for this element in the mesh
67  // We'd better find every element we're asked for
68  Elem & elem = mesh.elem_ref(ids[i]);
69 
70  // Return the element's refinement flag
71  flags[i] = (elem.*get_flag)();
72  }
73  }
74 
75  void act_on_data (const std::vector<dof_id_type> & ids,
76  std::vector<datum> & flags)
77  {
78  for (std::size_t i=0; i != ids.size(); ++i)
79  {
80  Elem & elem = mesh.elem_ref(ids[i]);
81 
82  datum old_flag = (elem.*get_flag)();
83  datum & new_flag = flags[i];
84 
85  if (old_flag != new_flag)
86  {
87  // It's possible for foreign flags to be (temporarily) more
88  // conservative than our own, such as when a refinement in
89  // one of the foreign processor's elements is mandated by a
90  // refinement in one of our neighboring elements it can see
91  // which was mandated by a refinement in one of our
92  // neighboring elements it can't see
93  // libmesh_assert (!(new_flag != Elem::REFINE &&
94  // old_flag == Elem::REFINE));
95  //
96  (elem.*set_flag)
97  (static_cast<Elem::RefinementState>(new_flag));
98  parallel_consistent = false;
99  }
100  }
101  }
102 };
103 
104 
105 
106 } // namespace libMesh
107 
108 
109 #endif // LIBMESH_ENABLE_AMR
110 
111 #endif // LIBMESH_SYNC_REFINEMENT_FLAGS_H
Elem::RefinementState(Elem::* get_a_flag)() const
void(Elem::* set_a_flag)(const Elem::RefinementState)
void act_on_data(const std::vector< dof_id_type > &ids, std::vector< datum > &flags)
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
RefinementState
Enumeration of possible element refinement states.
Definition: elem.h:1125
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:68
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:490
SyncRefinementFlags(MeshBase &_mesh, get_a_flag _getter, set_a_flag _setter)
void gather_data(const std::vector< dof_id_type > &ids, std::vector< datum > &flags) const