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#include "Conversion.h"
20
21#include "libmesh/numeric_vector.h"
22
24 const GradientStateContainer & state_values,
25 const FVGradientMethod & method,
26 const unsigned int variable_number)
27 : _sys(sys),
28 _system_number(sys.number()),
29 _state_values(state_values),
30 _method(method),
31 _variable_number(variable_number)
32{
33 mooseAssert(!_state_values.empty(), "Gradient state storage must contain a current state.");
34}
35
36Real
37LinearFVGradientReader::component(const ElemInfo & elem_info, const unsigned int index) const
38{
39 return component(elem_info, index, Moose::currentState());
40}
41
47
50{
51 return stateComponents(state);
52}
53
56{
57 mooseAssert(!_state_values.empty(), "Gradient state storage must contain a current state.");
58
60 mooseError("Linear FV gradient state ",
61 state.state,
62 " with iteration type '",
64 "' was requested for variable '",
66 "'",
67 " on system '",
68 _sys.name(),
69 "' using gradient method '",
70 _method.name(),
71 "'. Only time iteration states are supported for non-current gradients.");
72
73 if (state.state >= _state_values.size())
74 mooseError("Linear FV gradient state ",
75 state.state,
76 " with iteration type '",
78 "' was requested for variable '",
80 "'",
81 " on system '",
82 _sys.name(),
83 "' using gradient method '",
84 _method.name(),
85 "', but the maximum allocated state is ",
86 _state_values.size() - 1,
87 ".");
88
89 return _state_values[state.state];
90}
91
92Real
94 const unsigned int index,
95 const Moose::StateArg & state) const
96{
97 const auto & components = stateComponents(state);
98 mooseAssert(index < components.size(), "Gradient component index out of range.");
99 mooseAssert(components[index], "Gradient component vector must be initialized.");
100
101 return (*components[index])(elem_info.dofIndices()[_system_number][_variable_number]);
102}
103
104RealVectorValue
106{
107 return gradient(elem_info, Moose::currentState());
108}
109
110RealVectorValue
111LinearFVGradientReader::gradient(const ElemInfo & elem_info, const Moose::StateArg & state) const
112{
113 RealVectorValue value;
114
115 for (const auto component_index : make_range(elem_info.elem()->dim()))
116 value(component_index) = component(elem_info, component_index, state);
117
118 return value;
119}
120
121RealVectorValue
123{
124 return gradient(fi, Moose::currentState());
125}
126
127RealVectorValue
129{
130 const auto face_type = fi.faceType(std::make_pair(_variable_number, _system_number));
131 mooseAssert(face_type != FaceInfo::VarFaceNeighbors::NEITHER,
132 "Gradient requested on a face where the variable is defined on neither side.");
133
134 const bool var_defined_on_elem = (face_type == FaceInfo::VarFaceNeighbors::BOTH) ||
136 const auto * const elem_one = var_defined_on_elem ? fi.elemInfo() : fi.neighborInfo();
137 const auto * const elem_two = var_defined_on_elem ? fi.neighborInfo() : fi.elemInfo();
138
139 const auto elem_one_grad = gradient(*elem_one, state);
140
141 if (face_type == FaceInfo::VarFaceNeighbors::BOTH)
142 {
143 mooseAssert(elem_two, "Face type indicates BOTH but neighbor information is missing.");
144 const auto elem_two_grad = gradient(*elem_two, state);
145 return Moose::FV::linearInterpolation(elem_one_grad, elem_two_grad, fi, var_defined_on_elem);
146 }
147 else
148 return elem_one_grad;
149}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
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
const GradientContainer & stateComponents(const Moose::StateArg &state) const
Validate and select the component vectors for a solution state.
const GradientContainer & components() const
Access the underlying component vectors keyed by spatial direction.
const GradientStateContainer & _state_values
Gradient fields indexed by solution time state.
Real component(const ElemInfo &elem_info, unsigned int index) const
Read one gradient component at an element.
std::vector< GradientContainer > GradientStateContainer
Gradient fields indexed by solution time state.
const FVGradientMethod & _method
Method object that produces the stored values.
LinearFVGradientReader(const SystemBase &sys, const GradientStateContainer &state_values, const FVGradientMethod &method, unsigned int variable_number)
std::vector< 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 SystemBase & _sys
System the variable belongs to.
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).
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Base class for a system (of equations)
Definition SystemBase.h:87
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:89
virtual const std::string & name() const
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.
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:65
StateArg currentState()
State argument for evaluating functors.
SolutionIterationType iteration_type
The solution iteration type, e.g. time or nonlinear.
unsigned int state
The state.