https://mooseframework.inl.gov
ComputeLinearFVGreenGaussGradientVolumeThread.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 
12 #include "SystemBase.h"
13 #include "PetscVectorReader.h"
14 #include "FEProblemBase.h"
15 
17  FEProblemBase & fe_problem,
18  SystemBase & system,
19  std::vector<std::unique_ptr<NumericVector<Number>>> & temporary_gradient)
20  : _fe_problem(fe_problem),
21  _dim(_fe_problem.mesh().dimension()),
22  _system(system),
23  _libmesh_system(system.system()),
24  _system_number(_libmesh_system.number()),
25  _temporary_gradient(temporary_gradient)
26 {
27 }
28 
31  : _fe_problem(x._fe_problem),
32  _dim(x._dim),
33  _system(x._system),
34  _libmesh_system(x._libmesh_system),
35  _system_number(x._system_number),
36  _temporary_gradient(x._temporary_gradient)
37 {
38 }
39 
40 void
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 }
112 
113 void
116 {
117 }
const std::vector< MooseVariableFieldBase * > & getVariables(THREAD_ID tid)
Definition: SystemBase.h:752
StoredRange< MooseMesh::const_elem_info_iterator, const ElemInfo * > ElemInfoRange
unsigned int number() const
Get variable number coming from libMesh.
The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation ca...
MeshBase & mesh
Base class for a system (of equations)
Definition: SystemBase.h:85
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_gradient
Cache for the temporary gradient being built.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
unsigned int getAxisymmetricRadialCoord() const
Returns the desired radial direction for RZ coordinate transformation.
Definition: MooseMesh.C:4441
void operator()(const ElemInfoRange &range)
Operator which is used to execute the thread over a certain iterator range.
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...
void join(const ComputeLinearFVGreenGaussGradientVolumeThread &y)
Join threads at the end of the execution.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
ComputeLinearFVGreenGaussGradientVolumeThread(FEProblemBase &fe_problem, SystemBase &system, std::vector< std::unique_ptr< NumericVector< Number >>> &temporary_gradient)
Class constructor.
virtual bool needsGradientVectorStorage() const override
Check if cell gradient computations were requested for this variable.
StateArg currentState()
auto index_range(const T &sizable)