https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
ComputeLinearFVGreenGaussGradientFaceThread Class Reference

The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation can be computed as follows: More...

#include <ComputeLinearFVGreenGaussGradientFaceThread.h>

Public Types

using FaceInfoRange = StoredRange< MooseMesh::const_face_info_iterator, const FaceInfo * >
 

Public Member Functions

 ComputeLinearFVGreenGaussGradientFaceThread (FEProblemBase &fe_problem, SystemBase &system, std::vector< std::unique_ptr< NumericVector< Number > > > &temporary_gradient, const std::unordered_set< unsigned int > &gradient_variables, const FVGreenGaussGradient &gradient_method)
 Class constructor.
 
 ComputeLinearFVGreenGaussGradientFaceThread (ComputeLinearFVGreenGaussGradientFaceThread &x, Threads::split split)
 Splitting constructor.
 
void operator() (const FaceInfoRange &range)
 Operator which is used to execute the thread over a certain iterator range.
 
void join (const ComputeLinearFVGreenGaussGradientFaceThread &y)
 Join threads at the end of the execution.
 

Protected Attributes

FEProblemBase & _fe_problem
 Reference to the problem.
 
const unsigned int _dim
 The dimension of the domain.
 
SystemBase & _system
 The system wrapper this thread operates on.
 
const libMesh::System & _libmesh_system
 Reference to the libMesh system backing the wrapper system.
 
const unsigned int _system_number
 Global system number (the number of this system in the libmesh equation system)
 
THREAD_ID _tid
 Thread ID.
 
MooseLinearVariableFV< Real > * _current_var
 Pointer to the current variable.
 
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
 Cache for the temporary gradient being built.
 
const std::unordered_set< unsigned int > & _gradient_variables
 Indices of the variables this producer should compute gradients for.
 
const FVGreenGaussGradient & _gradient_method
 Method providing the two Green-Gauss values on an internal face.
 

Detailed Description

The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation can be computed as follows:

\nabla u \approx \frac{1}{V_C} \sum_f u_f\vec{S}_f,

where V_C denotes the volume of the cell, f is a face iterator, while u_f and \vec{S}_f are the face value of the variable and surface area vector (the product of the surface area and normals), respectively. This object carries out the summation part over the faces (\sum_f u_f\vec{S}_f).

Definition at line 38 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Member Typedef Documentation

◆ FaceInfoRange

Constructor & Destructor Documentation

◆ ComputeLinearFVGreenGaussGradientFaceThread() [1/2]

ComputeLinearFVGreenGaussGradientFaceThread::ComputeLinearFVGreenGaussGradientFaceThread ( FEProblemBase &  fe_problem,
SystemBase &  system,
std::vector< std::unique_ptr< NumericVector< Number > > > &  temporary_gradient,
const std::unordered_set< unsigned int > &  gradient_variables,
const FVGreenGaussGradient &  gradient_method 
)

Class constructor.

Parameters
fe_problemReference to the problem
systemThe system which contains variables that need gradients.
temporary_gradientScratch storage for gradients being assembled.
gradient_methodMethod that supplies internal-face values.

Definition at line 17 of file ComputeLinearFVGreenGaussGradientFaceThread.C.

23 : _fe_problem(fe_problem),
25 _system(system),
26 _libmesh_system(system.system()),
28 _temporary_gradient(temporary_gradient),
29 _gradient_variables(gradient_variables),
30 _gradient_method(gradient_method)
31{
32}
const unsigned int _system_number
Global system number (the number of this system in the libmesh equation system)
const std::unordered_set< unsigned int > & _gradient_variables
Indices of the variables this producer should compute gradients for.
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
Cache for the temporary gradient being built.
const FVGreenGaussGradient & _gradient_method
Method providing the two Green-Gauss values on an internal face.
SystemBase & _system
The system wrapper this thread operates on.
const libMesh::System & _libmesh_system
Reference to the libMesh system backing the wrapper system.
virtual MooseMesh & mesh() override
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition MooseMesh.C:2983
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
unsigned int number() const

◆ ComputeLinearFVGreenGaussGradientFaceThread() [2/2]

ComputeLinearFVGreenGaussGradientFaceThread::ComputeLinearFVGreenGaussGradientFaceThread ( ComputeLinearFVGreenGaussGradientFaceThread &  x,
Threads::split  split 
)

Splitting constructor.

Parameters
xReference to the other bodies
splitThe thread split

Definition at line 34 of file ComputeLinearFVGreenGaussGradientFaceThread.C.

37 _dim(x._dim),
41 // This will be the vector we work on since the old gradient might still be needed
42 // to compute extrapolated boundary conditions for example.
46{
47}

Member Function Documentation

◆ join()

void ComputeLinearFVGreenGaussGradientFaceThread::join ( const ComputeLinearFVGreenGaussGradientFaceThread &  y)

Join threads at the end of the execution.

Parameters
yReference to the other bodies

Definition at line 168 of file ComputeLinearFVGreenGaussGradientFaceThread.C.

170{
171}

◆ operator()()

void ComputeLinearFVGreenGaussGradientFaceThread::operator() ( const FaceInfoRange &  range)

Operator which is used to execute the thread over a certain iterator range.

Parameters
rangeThe range of FaceInfos which should be computed.

Definition at line 50 of file ComputeLinearFVGreenGaussGradientFaceThread.C.

51{
53 _tid = puid.id;
54
55 unsigned int size = 0;
56
57 for (const auto & variable : _system.getVariables(_tid))
58 {
59 _current_var = dynamic_cast<MooseLinearVariableFV<Real> *>(variable);
60 if (!_current_var)
61 continue;
62
64 {
65 if (!size)
66 size = range.size();
67
68 std::vector<std::vector<Real>> temporary_values_elem(_temporary_gradient.size(),
69 std::vector<Real>(size, 0.0));
70 std::vector<std::vector<Real>> temporary_values_neighbor(_temporary_gradient.size(),
71 std::vector<Real>(size, 0.0));
72 std::vector<dof_id_type> dof_indices_elem(size, 0);
73 std::vector<dof_id_type> dof_indices_neighbor(size, 0);
74
75 {
77
78 // Iterate over all the face infos in the range
79 auto face_iterator = range.begin();
80 for (const auto & face_i : make_range(size))
81 {
82 const auto & face_info = *face_iterator;
83
84 const auto current_face_type =
85 face_info->faceType(std::make_pair(_current_var->number(), _system_number));
86
87 // First we check if this face is internal to the variable, if yes, contribute to both
88 // sides
89 if (current_face_type == FaceInfo::VarFaceNeighbors::BOTH)
90 {
91 dof_indices_elem[face_i] =
92 face_info->elemInfo()->dofIndices()[_system_number][_current_var->number()];
93 dof_indices_neighbor[face_i] =
94 face_info->neighborInfo()->dofIndices()[_system_number][_current_var->number()];
95
96 const auto face_values =
98 *face_info->elemInfo(),
99 *face_info->neighborInfo(),
101 solution_reader(dof_indices_elem[face_i]),
102 solution_reader(dof_indices_neighbor[face_i]));
103
104 const auto surface_vector =
105 face_info->normal() * face_info->faceArea() * face_info->faceCoord();
106 const auto elem_contribution = surface_vector * face_values.first;
107 const auto neighbor_contribution = -surface_vector * face_values.second;
108
109 for (const auto i : make_range(_dim))
110 {
111 temporary_values_elem[i][face_i] = elem_contribution(i);
112 temporary_values_neighbor[i][face_i] = neighbor_contribution(i);
113 }
114 }
115 // If this face is on the boundary of the block where the variable is defined, we
116 // check for boundary conditions. If we don't find any we use an automatic one-term
117 // expansion to compute the face value.
118 else if (current_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
119 current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR)
120 {
121 auto * bc_pointer =
122 _current_var->getBoundaryCondition(*face_info->boundaryIDs().begin());
123
124 if (bc_pointer)
125 bc_pointer->setupFaceData(face_info, current_face_type);
126
127 const auto * const elem_info = current_face_type == FaceInfo::VarFaceNeighbors::ELEM
128 ? face_info->elemInfo()
129 : face_info->neighborInfo();
130
131 // We have to account for cases when this face is an internal boundary and the normal
132 // points in the wrong direction
133 const auto multiplier =
134 current_face_type == FaceInfo::VarFaceNeighbors::ELEM ? 1.0 : -1.0;
135 auto & dof_id_container = current_face_type == FaceInfo::VarFaceNeighbors::ELEM
136 ? dof_indices_elem
137 : dof_indices_neighbor;
138 auto & contribution_container = current_face_type == FaceInfo::VarFaceNeighbors::ELEM
139 ? temporary_values_elem
140 : temporary_values_neighbor;
141
142 dof_id_container[face_i] =
143 elem_info->dofIndices()[_system_number][_current_var->number()];
144
145 // If we don't have a boundary condition, then it's a natural condition. We'll use a
146 // one-term expansion approximation in that case
147 const auto contribution = multiplier * face_info->normal() * face_info->faceArea() *
148 face_info->faceCoord() *
149 (bc_pointer ? bc_pointer->computeBoundaryValue()
150 : solution_reader(dof_id_container[face_i]));
151 for (const auto i : make_range(_dim))
152 contribution_container[i][face_i] = contribution(i);
153 }
154 face_iterator++;
155 }
156 }
157 for (const auto i : make_range(_dim))
158 {
159 _temporary_gradient[i]->add_vector(temporary_values_elem[i].data(), dof_indices_elem);
160 _temporary_gradient[i]->add_vector(temporary_values_neighbor[i].data(),
161 dof_indices_neighbor);
162 }
163 }
164 }
165}
MooseLinearVariableFV< Real > * _current_var
Pointer to the current variable.
virtual InternalFaceValues internalFaceValues(const FaceInfo &fi, const ElemInfo &elem_info, const ElemInfo &neighbor_info, const MooseLinearVariableFV< Real > &variable, Real elem_value, Real neighbor_value) const
Return the two Green-Gauss face values on an internal face.
void setupFaceData(const FaceInfo *face_info, const FaceInfo::VarFaceNeighbors face_type)
Set current face info.
This class provides variable solution interface for linear finite volume problems.
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
Get the boundary condition object which corresponds to the given boundary ID.
unsigned int number() const
Get variable number coming from libMesh.
A class which helps with repeated reading from a petsc vector.
std::unique_ptr< NumericVector< Number > > current_local_solution
IntRange< T > make_range(T beg, T end)

Member Data Documentation

◆ _current_var

MooseLinearVariableFV<Real>* ComputeLinearFVGreenGaussGradientFaceThread::_current_var
protected

Pointer to the current variable.

Definition at line 92 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _dim

const unsigned int ComputeLinearFVGreenGaussGradientFaceThread::_dim
protected

The dimension of the domain.

Definition at line 77 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _fe_problem

FEProblemBase& ComputeLinearFVGreenGaussGradientFaceThread::_fe_problem
protected

Reference to the problem.

Definition at line 74 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

◆ _gradient_method

const FVGreenGaussGradient& ComputeLinearFVGreenGaussGradientFaceThread::_gradient_method
protected

Method providing the two Green-Gauss values on an internal face.

Definition at line 102 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _gradient_variables

const std::unordered_set<unsigned int>& ComputeLinearFVGreenGaussGradientFaceThread::_gradient_variables
protected

Indices of the variables this producer should compute gradients for.

Definition at line 99 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _libmesh_system

const libMesh::System& ComputeLinearFVGreenGaussGradientFaceThread::_libmesh_system
protected

Reference to the libMesh system backing the wrapper system.

Definition at line 83 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _system

SystemBase& ComputeLinearFVGreenGaussGradientFaceThread::_system
protected

The system wrapper this thread operates on.

Definition at line 80 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _system_number

const unsigned int ComputeLinearFVGreenGaussGradientFaceThread::_system_number
protected

Global system number (the number of this system in the libmesh equation system)

Definition at line 86 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _temporary_gradient

std::vector<std::unique_ptr<NumericVector<Number> > >& ComputeLinearFVGreenGaussGradientFaceThread::_temporary_gradient
protected

Cache for the temporary gradient being built.

It is needed because in certain scenarios the old gradient is used while assembling the replacement gradient.

Definition at line 96 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().

◆ _tid

THREAD_ID ComputeLinearFVGreenGaussGradientFaceThread::_tid
protected

Thread ID.

Definition at line 89 of file ComputeLinearFVGreenGaussGradientFaceThread.h.

Referenced by operator()().


The documentation for this class was generated from the following files: