libMesh
remote_elem.C
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 // Local includes
21 #include "libmesh/remote_elem.h"
22 #include "libmesh/libmesh_singleton.h"
23 #include "libmesh/threads.h"
24 
25 
26 
27 namespace
28 {
29 using namespace libMesh;
30 
31 typedef Threads::spin_mutex RemoteElemMutex;
32 RemoteElemMutex remote_elem_mtx;
33 
34 
35 // Class to be dispatched by Singleton::setup()
36 // to create the \p RemoteElem singleton.
37 // While this actual object has file-level static
38 // scope and will be initialized before main(),
39 // importantly the setup() method will not be invoked
40 // until after main().
41 class RemoteElemSetup : public Singleton::Setup
42 {
43  void setup ()
44  {
46  }
47 } remote_elem_setup;
48 }
49 
50 
51 
52 namespace libMesh
53 {
54 
55 // Pointer to singleton Remote Element (to be created in
56 // libMesh::init()
58 
59 
61 {
62  RemoteElemMutex::scoped_lock lock(remote_elem_mtx);
63 
64  remote_elem = libmesh_nullptr;
65 }
66 
67 
68 
70 {
71  if (remote_elem != libmesh_nullptr)
72  return *remote_elem;
73 
74  RemoteElemMutex::scoped_lock lock(remote_elem_mtx);
75 
76  // check again - object could have been created while waiting
77  // for the lock to acquire!
78  if (remote_elem == libmesh_nullptr)
79  remote_elem = new RemoteElem;
80 
81  return *remote_elem;
82 }
83 
84 
85 } // namespace libMesh
In parallel meshes where a ghost element has neighbors which do not exist on the local processor...
Definition: remote_elem.h:44
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
The libMesh namespace provides an interface to certain functionality in the library.
static const Elem & create()
Return a reference to the global RemoteElem singleton object.
Definition: remote_elem.C:69
virtual ~RemoteElem()
Destructor.
Definition: remote_elem.C:60
Abstract base class for runtime singleton setup.
void setup(EquationSystems &systems, Mesh &mesh, GetPot &args)
const RemoteElem * remote_elem
Definition: remote_elem.C:57