Skip to content

Commit fa01248

Browse files
committed
Use static, singleton object to hold caching boolean
1 parent b1ca3a8 commit fa01248

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/fe/fe.h

-7
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,6 @@ class FE : public FEGenericBase<typename FEOutputType<T>::type>
793793
std::vector<Number> & nodal_soln_on_side,
794794
bool add_p_level = true);
795795

796-
/**
797-
* Whether we cache the node locations on the last
798-
* element we computed on to try to avoid calling
799-
* init_shape_functions and compute_shape_functions
800-
*/
801-
bool caching;
802-
803796
/**
804797
* An array of the node locations on the last
805798
* element we computed on

src/fe/fe.C

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "libmesh/tensor_value.h"
2828
#include "libmesh/enum_elem_type.h"
2929
#include "libmesh/quadrature_gauss.h"
30+
#include "libmesh/libmesh_singleton.h"
3031

3132
namespace {
3233
// Put this outside a templated class, so we only get 1 warning
@@ -40,14 +41,25 @@ namespace {
4041

4142
namespace libMesh
4243
{
44+
// ------------------------------------------------------------
45+
// Whether we cache the node locations on the last element we computed on
46+
// to try to avoid calling init_shape_functions and compute_shape_functions
47+
static const bool * caching = nullptr;
48+
49+
class CachingSetup: public Singleton::Setup
50+
{
51+
private:
52+
void setup() { caching = new bool(!on_command_line("--disable-caching")); }
53+
public:
54+
~CachingSetup() { caching = nullptr; }
55+
} caching_setup;
4356

4457

4558
// ------------------------------------------------------------
4659
// FE class members
4760
template <unsigned int Dim, FEFamily T>
4861
FE<Dim,T>::FE (const FEType & fet) :
4962
FEGenericBase<typename FEOutputType<T>::type> (Dim,fet),
50-
caching(!libMesh::on_command_line("--disable-caching")),
5163
last_side(INVALID_ELEM),
5264
last_edge(INVALID_ELEM)
5365
{
@@ -227,7 +239,7 @@ void FE<Dim,T>::reinit(const Elem * elem,
227239
}
228240
}
229241

230-
if (this->shapes_need_reinit() && caching && !cached_nodes_still_fit)
242+
if (this->shapes_need_reinit() && *caching && !cached_nodes_still_fit)
231243
{
232244
cached_nodes.resize(elem->n_nodes());
233245
for (auto n : elem->node_index_range())

0 commit comments

Comments
 (0)