libMesh
sync_refinement_flags.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/int_range.h"
32 #include "libmesh/mesh_base.h"
33 
34 // C++ includes
35 #include <vector>
36 
37 namespace libMesh {
38 
40 {
41  typedef unsigned char datum;
42  typedef Elem::RefinementState (Elem::*get_a_flag)() const;
43  typedef void (Elem::*set_a_flag)(const Elem::RefinementState);
44 
46  get_a_flag _getter,
47  set_a_flag _setter) :
48  mesh(_mesh), parallel_consistent(true),
49  get_flag(_getter), set_flag(_setter) {}
50 
55  // References to pointers to member functions segfault?
56  // get_a_flag & get_flag;
57  // set_a_flag & set_flag;
58 
59  // Find the refinement flag on each requested element
60  void gather_data (const std::vector<dof_id_type> & ids,
61  std::vector<datum> & flags) const
62  {
63  flags.resize(ids.size());
64 
65  for (auto i : index_range(ids))
66  {
67  // Look for this element in the mesh
68  // We'd better find every element we're asked for
69  Elem & elem = mesh.elem_ref(ids[i]);
70 
71  // Return the element's refinement flag
72  flags[i] = (elem.*get_flag)();
73  }
74  }
75 
76  void act_on_data (const std::vector<dof_id_type> & ids,
77  const std::vector<datum> & flags)
78  {
79  for (auto i : index_range(ids))
80  {
81  Elem & elem = mesh.elem_ref(ids[i]);
82 
83  datum old_flag = (elem.*get_flag)();
84  datum new_flag = flags[i];
85 
86  if (old_flag != new_flag)
87  {
88  // It's possible for foreign flags to be (temporarily) more
89  // conservative than our own, such as when a refinement in
90  // one of the foreign processor's elements is mandated by a
91  // refinement in one of our neighboring elements it can see
92  // which was mandated by a refinement in one of our
93  // neighboring elements it can't see
94  // libmesh_assert (!(new_flag != Elem::REFINE &&
95  // old_flag == Elem::REFINE));
96  //
97  (elem.*set_flag)
98  (static_cast<Elem::RefinementState>(new_flag));
99  parallel_consistent = false;
100  }
101  }
102  }
103 };
104 
105 
106 
107 } // namespace libMesh
108 
109 
110 #endif // LIBMESH_ENABLE_AMR
111 
112 #endif // LIBMESH_SYNC_REFINEMENT_FLAGS_H
libMesh::SyncRefinementFlags::get_a_flag
Elem::RefinementState(Elem::* get_a_flag)() const
Definition: sync_refinement_flags.h:42
libMesh::SyncRefinementFlags::get_flag
get_a_flag get_flag
Definition: sync_refinement_flags.h:53
libMesh::SyncRefinementFlags::parallel_consistent
bool parallel_consistent
Definition: sync_refinement_flags.h:52
libMesh::SyncRefinementFlags
Definition: sync_refinement_flags.h:39
libMesh::SyncRefinementFlags::gather_data
void gather_data(const std::vector< dof_id_type > &ids, std::vector< datum > &flags) const
Definition: sync_refinement_flags.h:60
libMesh::MeshBase::elem_ref
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:521
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::SyncRefinementFlags::set_flag
set_a_flag set_flag
Definition: sync_refinement_flags.h:54
libMesh::Elem::RefinementState
RefinementState
Enumeration of possible element refinement states.
Definition: elem.h:1169
libMesh::SyncRefinementFlags::datum
unsigned char datum
Definition: sync_refinement_flags.h:41
libMesh::SyncRefinementFlags::act_on_data
void act_on_data(const std::vector< dof_id_type > &ids, const std::vector< datum > &flags)
Definition: sync_refinement_flags.h:76
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::SyncRefinementFlags::set_a_flag
void(Elem::* set_a_flag)(const Elem::RefinementState)
Definition: sync_refinement_flags.h:43
libMesh::SyncRefinementFlags::mesh
MeshBase & mesh
Definition: sync_refinement_flags.h:51
libMesh::SyncRefinementFlags::SyncRefinementFlags
SyncRefinementFlags(MeshBase &_mesh, get_a_flag _getter, set_a_flag _setter)
Definition: sync_refinement_flags.h:45
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100