https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Attributes | List of all members
ComputeLinearFVGreenGaussGradientVolumeThread 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 <ComputeLinearFVGreenGaussGradientVolumeThread.h>

Public Types

using ElemInfoRange = StoredRange< MooseMesh::const_elem_info_iterator, const ElemInfo * >
 

Public Member Functions

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

Protected Attributes

FEProblemBase_fe_problem
 
const unsigned int _dim
 The dimension of the domain. More...
 
SystemBase_system
 The system wrapper this thread operates on. More...
 
const libMesh::System_libmesh_system
 Reference to the libmesh system. More...
 
const unsigned int _system_number
 Global system number. More...
 
THREAD_ID _tid
 Thread ID. More...
 
MooseLinearVariableFV< Real > * _current_var
 Pointer to the current variable. More...
 
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
 Cache for the temporary gradient being built. More...
 

Detailed Description

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

u {1}{V_C} u_f{n}_f,

where V_C denotes the volume of the cell, f is a face iterator, while u_f and {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 normalization with the element volumes.

Furthermore, in cylindrical coordinates, the radial value of the gradient needs to be extended with a u(r)/r value which is added in this object as well.

Definition at line 38 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Member Typedef Documentation

◆ ElemInfoRange

Constructor & Destructor Documentation

◆ ComputeLinearFVGreenGaussGradientVolumeThread() [1/2]

ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread ( FEProblemBase fe_problem,
SystemBase system,
std::vector< std::unique_ptr< NumericVector< Number >>> &  temporary_gradient 
)

Class constructor.

Parameters
fe_problemReference to the problem
systemThe system which contains variables that need gradients.
temporary_gradientScratch storage holding the gradients being assembled.

Definition at line 16 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

20  : _fe_problem(fe_problem),
22  _system(system),
23  _libmesh_system(system.system()),
25  _temporary_gradient(temporary_gradient)
26 {
27 }
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
Cache for the temporary gradient being built.
unsigned int number() const
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MooseMesh.C:3012
SystemBase & _system
The system wrapper this thread operates on.
virtual MooseMesh & mesh() override
const libMesh::System & _libmesh_system
Reference to the libmesh system.

◆ ComputeLinearFVGreenGaussGradientVolumeThread() [2/2]

ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread ( ComputeLinearFVGreenGaussGradientVolumeThread x,
Threads::split  split 
)

Splitting constructor.

Parameters
xReference to the other bodies
splitThe thread split

Definition at line 29 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

32  _dim(x._dim),
33  _system(x._system),
37 {
38 }
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
Cache for the temporary gradient being built.
SystemBase & _system
The system wrapper this thread operates on.
const libMesh::System & _libmesh_system
Reference to the libmesh system.

Member Function Documentation

◆ join()

void ComputeLinearFVGreenGaussGradientVolumeThread::join ( const ComputeLinearFVGreenGaussGradientVolumeThread y)

Join threads at the end of the execution.

Parameters
yReference to the other bodies

Definition at line 114 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

116 {
117 }

◆ operator()()

void ComputeLinearFVGreenGaussGradientVolumeThread::operator() ( const ElemInfoRange range)

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

Parameters
rangeThe range of ElemInfos which should be computed.

Definition at line 41 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

42 {
43  ParallelUniqueId puid;
44  _tid = puid.id;
45 
46  // Computing this size can be very expensive so we only want to do it once
47  unsigned int size = 0;
48 
49  for (const auto & variable : _system.getVariables(_tid))
50  {
51  _current_var = dynamic_cast<MooseLinearVariableFV<Real> *>(variable);
52  if (!_current_var)
53  continue;
54 
56  {
57  if (!size)
58  size = range.size();
59 
60  const auto rz_radial_coord = _fe_problem.mesh().getAxisymmetricRadialCoord();
61  const auto state = Moose::currentState();
62 
63  std::vector<std::vector<Real>> temporary_values(_temporary_gradient.size(),
64  std::vector<Real>(size, 0.0));
65  std::vector<dof_id_type> dof_indices(size, 0);
66  {
67  std::vector<PetscVectorReader> grad_reader;
68  for (const auto dim_index : index_range(_temporary_gradient))
69  grad_reader.emplace_back(*_temporary_gradient[dim_index]);
70 
71  // Iterate over all the elements in the range
72  auto elem_iterator = range.begin();
73  for (const auto elem_i : make_range(size))
74  {
75  const auto & elem_info = *elem_iterator;
76  if (_current_var->hasBlocks(elem_info->subdomain_id()))
77  {
78  const auto coord_type = _fe_problem.mesh().getCoordSystem(elem_info->subdomain_id());
79 
80  mooseAssert(coord_type != Moose::CoordinateSystemType::COORD_RSPHERICAL,
81  "We have not yet implemented the correct translation from gradient to "
82  "divergence for "
83  "spherical coordinates yet.");
84 
85  dof_indices[elem_i] = elem_info->dofIndices()[_system_number][_current_var->number()];
86  const auto volume = elem_info->volume() * elem_info->coordFactor();
87 
88  for (const auto dim_index : index_range(_temporary_gradient))
89  temporary_values[dim_index][elem_i] =
90  grad_reader[dim_index](dof_indices[elem_i]) / volume;
91 
92  if (coord_type == Moose::CoordinateSystemType::COORD_RZ)
93  {
94  mooseAssert(elem_info->centroid()(rz_radial_coord) != 0,
95  "Axisymmetric control volumes should not have a zero radial coordinate");
96  temporary_values[rz_radial_coord][elem_i] -=
97  _current_var->getElemValue(*elem_info, state) /
98  elem_info->centroid()(rz_radial_coord);
99  }
100  }
101  elem_iterator++;
102  }
103  }
104  for (const auto dim_index : index_range(_temporary_gradient))
105  {
106  _temporary_gradient[dim_index]->zero();
107  _temporary_gradient[dim_index]->add_vector(temporary_values[dim_index].data(), dof_indices);
108  }
109  }
110  }
111 }
const std::vector< MooseVariableFieldBase * > & getVariables(THREAD_ID tid)
Definition: SystemBase.h:752
unsigned int number() const
Get variable number coming from libMesh.
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
Cache for the temporary gradient being built.
unsigned int getAxisymmetricRadialCoord() const
Returns the desired radial direction for RZ coordinate transformation.
Definition: MooseMesh.C:4441
SystemBase & _system
The system wrapper this thread operates on.
MooseLinearVariableFV< Real > * _current_var
Pointer to the current variable.
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
Get the coordinate system type, e.g.
Definition: MooseMesh.C:4322
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
bool hasBlocks(const SubdomainID id) const override
Returns whether the functor is defined on this block.
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
Get the solution value for the provided element and seed the derivative for the corresponding dof ind...
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
virtual bool needsGradientVectorStorage() const override
Check if cell gradient computations were requested for this variable.
StateArg currentState()
auto index_range(const T &sizable)

Member Data Documentation

◆ _current_var

MooseLinearVariableFV<Real>* ComputeLinearFVGreenGaussGradientVolumeThread::_current_var
protected

Pointer to the current variable.

Definition at line 88 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _dim

const unsigned int ComputeLinearFVGreenGaussGradientVolumeThread::_dim
protected

The dimension of the domain.

Definition at line 73 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

◆ _fe_problem

FEProblemBase& ComputeLinearFVGreenGaussGradientVolumeThread::_fe_problem
protected

Definition at line 70 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _libmesh_system

const libMesh::System& ComputeLinearFVGreenGaussGradientVolumeThread::_libmesh_system
protected

Reference to the libmesh system.

Definition at line 79 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

◆ _system

SystemBase& ComputeLinearFVGreenGaussGradientVolumeThread::_system
protected

The system wrapper this thread operates on.

Definition at line 76 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _system_number

const unsigned int ComputeLinearFVGreenGaussGradientVolumeThread::_system_number
protected

Global system number.

Definition at line 82 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _temporary_gradient

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

Cache for the temporary gradient being built.

Definition at line 91 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _tid

THREAD_ID ComputeLinearFVGreenGaussGradientVolumeThread::_tid
protected

Thread ID.

Definition at line 85 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().


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