https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVGradientReader.C
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
11#include "FEProblemBase.h"
12#include "FVGradientMethod.h"
13#include "SystemBase.h"
15#include "MooseError.h"
16#include "ElemInfo.h"
17#include "FaceInfo.h"
18#include "MathFVUtils.h"
19
20#include "libmesh/numeric_vector.h"
21
23 const GradientContainer & components,
24 const FVGradientMethod & method,
25 const unsigned int variable_number)
26 : _sys(sys),
27 _system_number(sys.number()),
28 _components(components),
29 _method(method),
30 _variable_number(variable_number)
31{
32}
33
34Real
35LinearFVGradientReader::component(const ElemInfo & elem_info, const unsigned int index) const
36{
37 mooseAssert(index < _components.size(), "Gradient component index out of range.");
38
39 return (*_components[index])(elem_info.dofIndices()[_system_number][_variable_number]);
40}
41
42RealVectorValue
44{
45 RealVectorValue value;
46
47 for (const auto component_index : make_range(elem_info.elem()->dim()))
48 value(component_index) = component(elem_info, component_index);
49
50 return value;
51}
52
53RealVectorValue
55{
56 const auto face_type = fi.faceType(std::make_pair(_variable_number, _system_number));
57 mooseAssert(face_type != FaceInfo::VarFaceNeighbors::NEITHER,
58 "Gradient requested on a face where the variable is defined on neither side.");
59
60 const bool var_defined_on_elem = (face_type == FaceInfo::VarFaceNeighbors::BOTH) ||
62 const auto * const elem_one = var_defined_on_elem ? fi.elemInfo() : fi.neighborInfo();
63 const auto * const elem_two = var_defined_on_elem ? fi.neighborInfo() : fi.elemInfo();
64
65 const auto elem_one_grad = gradient(*elem_one);
66
67 if (face_type == FaceInfo::VarFaceNeighbors::BOTH)
68 {
69 mooseAssert(elem_two, "Face type indicates BOTH but neighbor information is missing.");
70 const auto elem_two_grad = gradient(*elem_two);
71 return Moose::FV::linearInterpolation(elem_one_grad, elem_two_grad, fi, var_defined_on_elem);
72 }
73 else
74 return elem_one_grad;
75}
Class used for caching additional information for elements such as the volume and centroid.
Definition ElemInfo.h:26
const Elem * elem() const
Definition ElemInfo.h:34
const std::vector< std::vector< dof_id_type > > & dofIndices() const
Definition ElemInfo.h:39
Base class for linear finite-volume cell-gradient methods.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
Returns which side(s) the given variable-system number pair is defined on for this face.
Definition FaceInfo.h:229
const ElemInfo * elemInfo() const
Definition FaceInfo.h:89
const ElemInfo * neighborInfo() const
Definition FaceInfo.h:90
LinearFVGradientReader(const SystemBase &sys, const GradientContainer &components, const FVGradientMethod &method, unsigned int variable_number)
Real component(const ElemInfo &elem_info, unsigned int index) const
Read one gradient component at an element.
const GradientContainer & _components
Component vectors keyed by spatial direction.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > GradientContainer
One vector per spatial component of the cell-centered gradient.
RealVectorValue gradient(const ElemInfo &elem_info) const
Read the full gradient at an element.
const unsigned int _variable_number
Variable number whose gradients are read by this object.
const unsigned int _system_number
System number cached for hot lookups (from faces to dofs).
Base class for a system (of equations)
Definition SystemBase.h:87
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)
A simple linear interpolation of values between cell centers to a cell face.