22 #include "libmesh/numeric_vector.h" 31 if (_raw_grad_container.empty())
34 auto & temporary_gradient = temporaryLinearFVGradientContainer();
35 mooseAssert(temporary_gradient.size() == _raw_grad_container.size(),
36 "Temporary and raw gradient containers must have the same size.");
37 for (
auto & vec : temporary_gradient)
40 auto & fe_problem = _sys.feProblem();
42 mooseAssert(perf_graph_interface,
43 "LinearFVGradientInterface requires its owning system to implement " 44 "PerfGraphInterface.");
45 const auto perf_id = perf_graph_interface->registerTimedSection(
"LinearVariableFV_Gradients", 3);
46 mooseAssert(!
Threads::in_threads,
"PerfGraph timing cannot be used within threaded sections");
47 PerfGuard time_guard(perf_graph_interface->perfGraph(), perf_id);
52 FaceInfoRange face_info_range(fe_problem.mesh().ownedFaceInfoBegin(),
53 fe_problem.mesh().ownedFaceInfoEnd());
56 fe_problem, _sys, temporary_gradient);
59 fe_problem.checkExceptionAndStopSolve();
61 for (
auto & vec : temporary_gradient)
67 ElemInfoRange elem_info_range(fe_problem.mesh().ownedElemInfoBegin(),
68 fe_problem.mesh().ownedElemInfoEnd());
71 fe_problem, _sys, temporary_gradient);
74 fe_problem.checkExceptionAndStopSolve();
76 for (
const auto i :
index_range(_raw_grad_container))
77 temporary_gradient[i]->close();
79 _raw_grad_container.swap(temporary_gradient);
81 if (!requestedLinearFVLimitedGradientTypes().empty())
84 ElemInfoRange elem_info_range(fe_problem.mesh().ownedElemInfoBegin(),
85 fe_problem.mesh().ownedElemInfoEnd());
87 for (
const auto limiter_type : requestedLinearFVLimitedGradientTypes())
92 auto & raw_container = rawLinearFVLimitedGradientContainer(limiter_type);
93 auto & temporary_container = temporaryLinearFVLimitedGradientContainer(limiter_type);
94 mooseAssert(temporary_container.size() == raw_container.size(),
95 "Temporary and raw limited gradient containers must have the same size.");
96 for (
auto & vec : temporary_container)
107 requestedLinearFVLimitedGradientVariables(limiter_type));
110 fe_problem.checkExceptionAndStopSolve();
112 for (
auto & vec : temporary_container)
115 raw_container.swap(temporary_container);
123 for (
const auto *
const field_var : _sys.variableWarehouse().fieldVariables())
124 if (field_var->needsGradientVectorStorage())
135 mooseAssert(_sys.currentSolution(),
136 "Current solution must exist before building FV gradient storage.");
137 for (
unsigned int i = 0; i < _sys.mesh().dimension(); ++i)
138 container.push_back(_sys.currentSolution()->zero_clone());
144 _raw_grad_container.clear();
145 _temporary_gradient.clear();
146 _raw_limited_grad_containers.clear();
147 _temporary_limited_gradient.clear();
149 if (!needsLinearFVGradientStorage())
152 initializeContainer(_raw_grad_container);
153 initializeContainer(_temporary_gradient);
155 for (
const auto limiter_type : _requested_limited_gradient_types)
160 initializeContainer(_raw_limited_grad_containers[limiter_type]);
161 initializeContainer(_temporary_limited_gradient[limiter_type]);
172 auto *
const variable =
175 mooseError(
"Limited gradients were requested for variable number ",
179 "', but no field variable with that number exists on the system.");
181 if (!variable->needsGradientVectorStorage())
182 mooseError(
"Limited gradients were requested for variable '",
186 "', but regular gradients were not requested for that variable.");
188 _requested_limited_gradient_variables[limiter_type].insert(variable_number);
190 if (_requested_limited_gradient_types.insert(limiter_type).second && !_raw_grad_container.empty())
192 initializeContainer(_raw_limited_grad_containers[limiter_type]);
193 initializeContainer(_temporary_limited_gradient[limiter_type]);
197 const std::vector<std::unique_ptr<NumericVector<Number>>> &
202 return _raw_grad_container;
204 const auto it = _raw_limited_grad_containers.find(limiter_type);
205 if (it == _raw_limited_grad_containers.end())
206 mooseError(
"Limited gradient container was requested but not initialized on system '",
The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation ca...
void rebuildLinearFVGradientStorage()
Rebuild persistent raw and temporary gradient storage after mesh/DOF changes.
GradientLimiterType
Cell-gradient limiter variants used for MUSCL-style reconstructions.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation ca...
This class provides an interface for common operations on field variables of both FE and FV types wit...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Compute limited cell gradients for linear FV variables.
bool needsLinearFVGradientStorage() const
const std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & linearFVLimitedGradientContainer(const Moose::FV::GradientLimiterType limiter_type) const
Access the stored raw or limited cell-centered gradient components.
void requestLinearFVLimitedGradients(const Moose::FV::GradientLimiterType limiter_type, unsigned int variable_number)
Request storage and assembly of limiter-specific cell gradients.
void initializeContainer(std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number >>> &container) const
Scope guard for starting and stopping timing for a node.
Interface for objects interacting with the PerfGraph.
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
auto index_range(const T &sizable)
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.