version 3.11-dev
Loading...
Searching...
No Matches
lazyelementcache.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CVFE_LAZY_ELEMENT_CACHE_HH
13#define DUMUX_DISCRETIZATION_CVFE_LAZY_ELEMENT_CACHE_HH
14
15#include <utility>
16
17namespace Dumux::Detail::CVFE {
18
27template<class Cache, class Problem, class ElementVariables>
29{
30 using Update = void(*)(Cache&, const void*, const Problem&, const ElementVariables&);
31
32public:
37 template<class ElementDiscretization>
38 void bind(const ElementDiscretization& elemDisc)
39 {
40 elemDisc_ = &elemDisc;
41 update_ = [](Cache& cache, const void* elemDiscPtr, const Problem& problem, const ElementVariables& elemVars)
42 {
43 const auto& elemDisc = *static_cast<const ElementDiscretization*>(elemDiscPtr);
44 cache.update(problem, elemDisc.element(), elemDisc, elemVars);
45 };
46 isUpToDate_ = false;
47 }
48
50 const Cache& get(const Problem& problem, const ElementVariables& elemVars) const
51 {
52 if (!isUpToDate_)
53 {
54 update_(cache_, elemDisc_, problem, elemVars);
55 isUpToDate_ = true;
56 }
57 return cache_;
58 }
59
61 Cache& get(const Problem& problem, const ElementVariables& elemVars)
62 {
63 std::as_const(*this).get(problem, elemVars);
64 return cache_;
65 }
66
67private:
68 mutable Cache cache_;
69 mutable bool isUpToDate_ = false;
70 const void* elemDisc_ = nullptr;
71 Update update_ = nullptr;
72};
73
74} // end namespace Dumux::Detail::CVFE
75
76#endif
An element cache that is updated on its first access after binding.
Definition lazyelementcache.hh:29
void bind(const ElementDiscretization &elemDisc)
Bind to an element discretization, the cache is updated on the next access.
Definition lazyelementcache.hh:38
const Cache & get(const Problem &problem, const ElementVariables &elemVars) const
The cache, updated if this is the first access after binding.
Definition lazyelementcache.hh:50
Cache & get(const Problem &problem, const ElementVariables &elemVars)
The cache, updated if this is the first access after binding.
Definition lazyelementcache.hh:61
Definition elementinterpolationpointdatacache.hh:21