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, const unsigned int linear_system_num)
 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...
 
const unsigned int _linear_system_number
 The number of the linear system on which this thread is acting. More...
 
const libMesh::LinearImplicitSystem_linear_system
 Reference to the linear system at libmesh level. 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...
 

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 37 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Member Typedef Documentation

◆ ElemInfoRange

Constructor & Destructor Documentation

◆ ComputeLinearFVGreenGaussGradientVolumeThread() [1/2]

ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread ( FEProblemBase fe_problem,
const unsigned int  linear_system_num 
)

Class constructor.

Parameters
fe_problemReference to the problem
linear_system_numThe number of the linear system which contains variables that need gradients.

Definition at line 16 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

18  : _fe_problem(fe_problem),
20  _linear_system_number(linear_system_num),
21  _linear_system(libMesh::cast_ref<libMesh::LinearImplicitSystem &>(
24 {
25 }
const unsigned int _linear_system_number
The number of the linear system on which this thread is acting.
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:2923
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
const libMesh::LinearImplicitSystem & _linear_system
Reference to the linear system at libmesh level.
virtual MooseMesh & mesh() override
virtual System & system() override
Get the reference to the libMesh system.
Definition: LinearSystem.h:107

◆ ComputeLinearFVGreenGaussGradientVolumeThread() [2/2]

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

Splitting constructor.

Parameters
xReference to the other bodies
splitThe thread split

Definition at line 27 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

30  _dim(x._dim),
34 {
35 }
const unsigned int _linear_system_number
The number of the linear system on which this thread is acting.
const libMesh::LinearImplicitSystem & _linear_system
Reference to the linear system at libmesh level.

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 38 of file ComputeLinearFVGreenGaussGradientVolumeThread.C.

39 {
40  ParallelUniqueId puid;
41  _tid = puid.id;
42 
43  auto & linear_system = _fe_problem.getLinearSystem(_linear_system_number);
44 
45  // This will be the vector we work on since the old gradient might still be needed
46  // to compute extrapolated boundary conditions for example.
47  auto & grad_container = linear_system.newGradientContainer();
48 
49  // Computing this size can be very expensive so we only want to do it once
50  unsigned int size = 0;
51 
52  for (const auto & variable : linear_system.getVariables(_tid))
53  {
54  _current_var = dynamic_cast<MooseLinearVariableFV<Real> *>(variable);
55  mooseAssert(_current_var,
56  "This should be a linear FV variable, did we somehow add a nonlinear variable to "
57  "the linear system?");
59  {
60  if (!size)
61  size = range.size();
62 
63  const auto rz_radial_coord = _fe_problem.mesh().getAxisymmetricRadialCoord();
64  const auto state = Moose::currentState();
65 
66  std::vector<std::vector<Real>> new_values(grad_container.size(),
67  std::vector<Real>(size, 0.0));
68  std::vector<dof_id_type> dof_indices(size, 0);
69  {
70  std::vector<PetscVectorReader> grad_reader;
71  for (const auto dim_index : index_range(grad_container))
72  grad_reader.emplace_back(*grad_container[dim_index]);
73 
74  // Iterate over all the elements in the range
75  auto elem_iterator = range.begin();
76  for (const auto elem_i : make_range(size))
77  {
78  const auto & elem_info = *elem_iterator;
79  if (_current_var->hasBlocks(elem_info->subdomain_id()))
80  {
81  const auto coord_type = _fe_problem.mesh().getCoordSystem(elem_info->subdomain_id());
82 
83  mooseAssert(coord_type != Moose::CoordinateSystemType::COORD_RSPHERICAL,
84  "We have not yet implemented the correct translation from gradient to "
85  "divergence for "
86  "spherical coordinates yet.");
87 
88  dof_indices[elem_i] = elem_info->dofIndices()[_system_number][_current_var->number()];
89  const auto volume = elem_info->volume() * elem_info->coordFactor();
90 
91  for (const auto dim_index : index_range(grad_container))
92  new_values[dim_index][elem_i] = grad_reader[dim_index](dof_indices[elem_i]) / volume;
93 
94  if (coord_type == Moose::CoordinateSystemType::COORD_RZ)
95  {
96  const auto radial_contrib = _current_var->getElemValue(*elem_info, state) /
97  elem_info->centroid()(rz_radial_coord);
98  new_values[rz_radial_coord][elem_i] += radial_contrib;
99  }
100  }
101  elem_iterator++;
102  }
103  }
104  for (const auto dim_index : index_range(grad_container))
105  {
106  grad_container[dim_index]->zero();
107  grad_container[dim_index]->add_vector(new_values[dim_index].data(), dof_indices);
108  }
109  }
110  }
111 }
unsigned int number() const
Get variable number coming from libMesh.
std::vector< std::unique_ptr< NumericVector< Number > > > & newGradientContainer()
Return a reference to the new (temporary) gradient container vectors.
Definition: LinearSystem.h:137
const unsigned int _linear_system_number
The number of the linear system on which this thread is acting.
unsigned int getAxisymmetricRadialCoord() const
Returns the desired radial direction for RZ coordinate transformation.
Definition: MooseMesh.C:4263
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:4144
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
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 85 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _dim

const unsigned int ComputeLinearFVGreenGaussGradientVolumeThread::_dim
protected

The dimension of the domain.

Definition at line 70 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

◆ _fe_problem

FEProblemBase& ComputeLinearFVGreenGaussGradientVolumeThread::_fe_problem
protected

Definition at line 67 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _linear_system

const libMesh::LinearImplicitSystem& ComputeLinearFVGreenGaussGradientVolumeThread::_linear_system
protected

Reference to the linear system at libmesh level.

Definition at line 76 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

◆ _linear_system_number

const unsigned int ComputeLinearFVGreenGaussGradientVolumeThread::_linear_system_number
protected

The number of the linear system on which this thread is acting.

Definition at line 73 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _system_number

const unsigned int ComputeLinearFVGreenGaussGradientVolumeThread::_system_number
protected

Global system number.

Definition at line 79 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().

◆ _tid

THREAD_ID ComputeLinearFVGreenGaussGradientVolumeThread::_tid
protected

Thread ID.

Definition at line 82 of file ComputeLinearFVGreenGaussGradientVolumeThread.h.

Referenced by operator()().


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