https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CellCenteredMapFunctor.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "MooseFunctor.h"
13#include "GreenGaussGradient.h"
14#include "MathFVUtils.h"
15#include "libmesh/utility.h"
16#include "libmesh/type_tensor.h"
17#include "libmesh/compare_types.h"
18#include "libmesh/threads.h"
19
25template <typename T, typename Map>
26class CellCenteredMapFunctor : public Moose::FunctorBase<T>, public Map
27{
28public:
31 using typename Moose::FunctorBase<T>::DotType;
39
44 const std::string & name,
45 const bool extrapolated_boundary);
46
52 const std::set<SubdomainID> & sub_ids,
53 const std::string & name,
54 const bool extrapolated_boundary);
55
57 const Elem * elem,
58 const StateArg & state) const override;
59 bool hasBlocks(SubdomainID sub_id) const override;
60
64 bool hasBlocks(const Elem * elem) const;
65
66 bool supportsFaceArg() const override final { return true; }
67 bool supportsElemSideQpArg() const override final { return false; }
68
69private:
72
75 const std::set<SubdomainID> _sub_ids;
76
78
80 ValueType evaluate(const ElemArg & elem_arg, const StateArg &) const override;
81 ValueType evaluate(const ElemPointArg & elem_point, const StateArg & state) const override;
82 ValueType evaluate(const FaceArg & face, const StateArg &) const override;
83 ValueType evaluate(const ElemQpArg &, const StateArg &) const override;
84 ValueType evaluate(const ElemSideQpArg &, const StateArg &) const override;
85 ValueType evaluate(const NodeArg & elem_arg, const StateArg &) const override;
86
88 GradientType evaluateGradient(const ElemArg & elem_arg, const StateArg & state) const override;
89 GradientType evaluateGradient(const FaceArg & face, const StateArg & state) const override;
90};
91
92template <typename T, typename Map>
94 const std::string & name,
95 const bool extrapolated_boundary)
96 : Moose::FunctorBase<T>(name), _mesh(mesh), _extrapolated_boundary(extrapolated_boundary)
97{
98}
99
100template <typename T, typename Map>
102 const std::set<SubdomainID> & sub_ids,
103 const std::string & name,
104 const bool extrapolated_boundary)
105 : Moose::FunctorBase<T>(name),
106 _mesh(mesh),
107 _sub_ids(sub_ids == mesh.meshSubdomains() ? std::set<SubdomainID>() : sub_ids),
108 _extrapolated_boundary(extrapolated_boundary)
109{
110}
111
112template <typename T, typename Map>
113bool
115 const Elem *,
116 const StateArg &) const
117{
118 const bool defined_on_elem = hasBlocks(&fi.elem());
119 const bool defined_on_neighbor = hasBlocks(fi.neighborPtr());
120 const bool extrapolated = (defined_on_elem + defined_on_neighbor) == 1;
121
122 mooseAssert(defined_on_elem || defined_on_neighbor,
123 "This shouldn't be called if we aren't defined on either side.");
124 return extrapolated;
125}
126
127template <typename T, typename Map>
128bool
129CellCenteredMapFunctor<T, Map>::hasBlocks(const Elem * const elem) const
130{
131 if (!elem)
132 return false;
133
134 return hasBlocks(elem->subdomain_id());
135}
136
137template <typename T, typename Map>
138bool
140{
141 return _sub_ids.empty() || _sub_ids.count(sub_id);
142}
143
144template <typename T, typename Map>
147{
148 const Elem * const elem = elem_arg.elem;
149
150 auto it = this->find(elem->id());
151 if (it == this->end())
152 {
153 if (!_sub_ids.empty() && !_sub_ids.count(elem->subdomain_id()))
154 mooseError("Attempted to evaluate CellCenteredMapFunctor '",
155 this->functorName(),
156 "' with an element subdomain id of '",
157 elem->subdomain_id(),
158 "' but that subdomain id is not one of the subdomain ids the functor is "
159 "restricted to.");
160 else
161 mooseError("Attempted access into CellCenteredMapFunctor '",
162 this->functorName(),
163 "' with a key that does not yet exist in the map. Make sure to fill your "
164 "CellCenteredMapFunctor for all elements you will attempt to access later.");
165 }
166
167 return it->second;
168}
169
170template <typename T, typename Map>
173 const StateArg & state) const
174{
175 return (*this)(elem_point.makeElem(), state) +
176 (elem_point.point - elem_point.elem->vertex_average()) *
177 this->gradient(elem_point.makeElem(), state);
178}
179
180template <typename T, typename Map>
183{
184 const auto & fi = *face.fi;
185 mooseAssert(face.limiter_type == Moose::FV::LimiterType::CentralDifference,
186 "this implementation currently only supports linear interpolations");
187
188 const bool defined_on_elem = hasBlocks(&fi.elem());
189 const bool defined_on_neighbor = hasBlocks(fi.neighborPtr());
190 if (defined_on_elem && defined_on_neighbor)
191 return Moose::FV::linearInterpolation(*this, face, state);
192
193 if (defined_on_elem)
194 {
195 const auto elem_arg = face.makeElem();
196 const auto elem_value = (*this)(elem_arg, state);
197 if (!_extrapolated_boundary)
198 return elem_value;
199 // Two term expansion
200 return elem_value + this->gradient(elem_arg, state) * (fi.faceCentroid() - fi.elemCentroid());
201 }
202 else
203 {
204 mooseAssert(defined_on_neighbor, "We should be defined on one of the sides");
205 const auto neighbor_arg = face.makeNeighbor();
206 const auto neighbor_value = (*this)(neighbor_arg, state);
207 if (!_extrapolated_boundary)
208 return neighbor_value;
209
210 // Two term expansion
211 return neighbor_value +
212 this->gradient(neighbor_arg, state) * (fi.faceCentroid() - fi.neighborCentroid());
213 }
214}
215
216template <typename T, typename Map>
219{
220 mooseError("not implemented");
221}
222
223template <typename T, typename Map>
226{
227 mooseError("not implemented");
228}
229
230template <typename T, typename Map>
233{
234 mooseError("not implemented");
235}
236
237template <typename T, typename Map>
240 const StateArg & state) const
241{
242 return Moose::FV::greenGaussGradient(elem_arg, state, *this, _extrapolated_boundary, _mesh);
243}
244
245template <typename T, typename Map>
248{
249 return Moose::FV::greenGaussGradient(face, state, *this, _extrapolated_boundary, _mesh);
250}
subdomain_id_type SubdomainID
const double T
void mooseError(Args &&... args)
const std::string name
Definition Setup.h:21
A functor whose evaluation relies on querying a map where the keys are element ids and the values cor...
bool supportsElemSideQpArg() const override final
CellCenteredMapFunctor(const MooseMesh &mesh, const std::set< SubdomainID > &sub_ids, const std::string &name, const bool extrapolated_boundary)
Use this constructor if you want to potentially restrict this object to a specified set of subdomains...
bool supportsFaceArg() const override final
ValueType evaluate(const ElemArg &elem_arg, const StateArg &) const override
const MooseMesh & _mesh
The mesh that this functor lives on.
bool hasBlocks(SubdomainID sub_id) const override
ValueType evaluate(const ElemSideQpArg &, const StateArg &) const override
ValueType evaluate(const ElemQpArg &, const StateArg &) const override
const std::set< SubdomainID > _sub_ids
The subdomain IDs that this functor lives on.
bool hasBlocks(const Elem *elem) const
Checks whether we are defined on the provided element.
ValueType evaluate(const NodeArg &elem_arg, const StateArg &) const override
bool isExtrapolatedBoundaryFace(const FaceInfo &fi, const Elem *elem, const StateArg &state) const override
GradientType evaluateGradient(const ElemArg &elem_arg, const StateArg &state) const override
CellCenteredMapFunctor(const MooseMesh &mesh, const std::string &name, const bool extrapolated_boundary)
Use this constructor when you want the object to live everywhere on the mesh.
GradientType evaluateGradient(const FaceArg &face, const StateArg &state) const override
ValueType evaluate(const ElemPointArg &elem_point, const StateArg &state) const override
ValueType evaluate(const FaceArg &face, const StateArg &) const override
const Elem & elem() const
const Elem * neighborPtr() const
typename FunctorReturnType< T, FunctorEvaluationKind::Gradient >::type GradientType
Point vertex_average() const
MeshBase & mesh
libMesh::CompareTypes< T, T2 >::supertype linearInterpolation(const T &value1, const T2 &value2, const FaceInfo &fi, const bool one_is_elem, const InterpMethod interp_method=InterpMethod::Average)
libMesh::VectorValue< T > greenGaussGradient(const ElemArg &elem_arg, const StateArg &state_arg, const FunctorBase< T > &functor, const bool two_term_boundary_expansion, const MooseMesh &mesh, const bool force_green_gauss=false)
const libMesh::Elem * elem
ElemArg makeElem() const
libMesh::Point point
const libMesh::Elem * elem
ElemArg makeNeighbor() const
ElemArg makeElem() const
Moose::FV::LimiterType limiter_type
const FaceInfo * fi