18 #include "libmesh/dof_object.h" 30 const std::unordered_set<unsigned int> & requested_variables)
31 : _fe_problem(fe_problem),
32 _dim(_fe_problem.
mesh().dimension()),
34 _libmesh_system(system.system()),
35 _system_number(_libmesh_system.number()),
36 _raw_gradient(raw_gradient),
37 _limiter_type(limiter_type),
38 _requested_variables(requested_variables),
39 _temporary_limited_gradient(temporary_limited_gradient)
45 : _fe_problem(x._fe_problem),
48 _libmesh_system(x._libmesh_system),
49 _system_number(x._system_number),
50 _raw_gradient(x._raw_gradient),
51 _limiter_type(x._limiter_type),
52 _requested_variables(x._requested_variables),
53 _temporary_limited_gradient(x._temporary_limited_gradient)
66 mooseError(
"ComputeLinearFVLimitedGradientThread currently supports only the Venkatakrishnan " 69 unsigned int size = 0;
87 std::vector<Real>(size, 0.0));
88 std::vector<dof_id_type> dof_indices(size, 0);
91 std::vector<PetscVectorReader> grad_reader;
92 grad_reader.reserve(raw_grad_container.size());
93 for (
const auto dim_index :
index_range(raw_grad_container))
94 grad_reader.emplace_back(*raw_grad_container[dim_index]);
96 mooseAssert(raw_grad_container.size() >=
_dim,
97 "Raw gradient container has fewer components than mesh dimension.");
99 "Limited gradient container has fewer components than mesh dimension.");
101 auto elem_iterator = range.begin();
104 const auto & elem_info = *elem_iterator;
114 dof_indices[elem_i] = dof;
116 const Real phi_elem = solution_reader(dof);
117 Real max_value = phi_elem;
118 Real min_value = phi_elem;
121 const Elem *
const elem = elem_info->elem();
122 for (
const auto side :
make_range(elem->n_sides()))
124 const Elem *
const neighbor = elem->neighbor_ptr(side);
137 const Real phi_neighbor = solution_reader(neighbor_dof);
138 max_value =
std::max(max_value, phi_neighbor);
139 min_value =
std::min(min_value, phi_neighbor);
146 raw_grad(dim_index) = grad_reader[dim_index](dof);
149 if (
std::abs(max_value - min_value) < 1e-14)
152 temporary_values[dim_index][elem_i] = raw_grad(dim_index);
157 const Point & elem_centroid = elem_info->centroid();
159 for (
const auto side :
make_range(elem->n_sides()))
161 const Elem *
const neighbor = elem->neighbor_ptr(side);
175 const Elem *
const fi_elem = elem_has_face_info ? elem : neighbor;
176 const unsigned int fi_side =
177 elem_has_face_info ? side : neighbor->which_neighbor_am_i(elem);
180 "Missing FaceInfo for neighboring elements with centroid " +
183 " while computing limited gradients.");
185 const Point face_point = fi->faceCentroid();
187 const Real delta_face = raw_grad * (face_point - elem_centroid);
189 Real h = elem->hmin();
192 Real eps = 0.1 * (grad_mag * h) * (grad_mag * h) + 1e-20;
197 const Real rf = (delta_face >= 0.0) ?
std::abs(delta_face) / delta_max
200 const Real beta = (2.0 * rf + 1.0) / (rf * (2.0 * rf + 1.0) + 1.0);
206 temporary_values[dim_index][elem_i] = limited_grad(dim_index);
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
const std::vector< MooseVariableFieldBase * > & getVariables(THREAD_ID tid)
GradientLimiterType
Cell-gradient limiter variants used for MUSCL-style reconstructions.
bool elemHasFaceInfo(const Elem &elem, const Elem *const neighbor)
This function infers based on elements if the faceinfo between them belongs to the element or not...
int eps(unsigned int i, unsigned int j)
2D version
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
unsigned int number() const
Get variable number coming from libMesh.
const libMesh::System & _libmesh_system
Reference to the libMesh system backing the wrapper system.
ComputeLinearFVLimitedGradientThread(FEProblemBase &fe_problem, SystemBase &system, const std::vector< std::unique_ptr< NumericVector< Number >>> &raw_gradient, std::vector< std::unique_ptr< NumericVector< Number >>> &temporary_limited_gradient, const Moose::FV::GradientLimiterType limiter_type, const std::unordered_set< unsigned int > &requested_variables)
Class constructor.
Compute limited cell gradients for linear FV variables.
Base class for a system (of equations)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const std::unordered_set< unsigned int > & _requested_variables
Variable numbers that requested the current limiter.
auto max(const L &left, const R &right)
void join(const ComputeLinearFVLimitedGradientThread &y)
Join threads at the end of the execution.
const unsigned int _system_number
Global system number in the libMesh equation system.
const std::vector< const FaceInfo * > & faceInfo() const
Accessor for local FaceInfo objects.
FEProblemBase & _fe_problem
Reference to the problem.
std::vector< std::unique_ptr< NumericVector< Number > > > & _temporary_limited_gradient
Reference to the temporary limited gradient storage.
static constexpr dof_id_type invalid_id
A class which helps with repeated reading from a petsc vector.
const Moose::FV::GradientLimiterType _limiter_type
The type of the limiter we requested.
std::string stringify(const T &t)
conversion to string
void operator()(const ElemInfoRange &range)
Operator which is used to execute the thread over a certain iterator range.
const std::vector< std::vector< dof_id_type > > & dofIndices() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool hasBlocks(const SubdomainID id) const override
Returns whether the functor is defined on this block.
SystemBase & _system
The system wrapper this thread operates on.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
std::unique_ptr< NumericVector< Number > > current_local_solution
Venkatakrishnan limiter (smooth, multidimensional).
virtual bool needsGradientVectorStorage() const override
Check if cell gradient computations were requested for this variable.
const unsigned int _dim
The dimension of the domain.
StoredRange< MooseMesh::const_elem_info_iterator, const ElemInfo * > ElemInfoRange
MooseLinearVariableFV< Real > * _current_var
Pointer to the current variable we are operating on.
auto min(const L &left, const R &right)
auto index_range(const T &sizable)
const ElemInfo & elemInfo(const dof_id_type id) const
Accessor for the elemInfo object for a given element ID.
const std::vector< std::unique_ptr< NumericVector< Number > > > & _raw_gradient
Reference to the raw gradient storage used as input for limiting.