23#include "libmesh/numeric_vector.h"
30 if (!fe_problem.hasFVGradientMethod(method_name))
32 if (method_name ==
"green-gauss")
35 fe_problem.addFVGradientMethod(
"FVGreenGaussGradient", method_name, params);
37 else if (method_name ==
"green-gauss-venkatakrishnan")
39 auto params = fe_problem.getMooseApp().getFactory().getValidParams(
"FVGreenGaussGradient");
41 fe_problem.addFVGradientMethod(
"FVGreenGaussGradient", method_name, params);
45 if (!fe_problem.hasFVGradientMethod(method_name))
46 mooseError(
"Unable to find FVGradientMethod with name '", method_name,
"'");
48 return fe_problem.getFVGradientMethod(method_name);
55 auto *
const variable =
58 mooseError(
"Linear FV gradients were requested for variable number ",
62 "', but no field variable with that number exists on the system.");
65 container.variable_numbers.insert(variable_number);
83 mooseAssert(perf_graph_interface,
84 "LinearFVGradientInterface requires its owning system to implement "
85 "PerfGraphInterface.");
86 const auto perf_id = perf_graph_interface->registerTimedSection(
"LinearVariableFV_Gradients", 3);
87 mooseAssert(!
Threads::in_threads,
"PerfGraph timing cannot be used within threaded sections");
88 PerfGuard time_guard(perf_graph_interface->perfGraph(), perf_id);
105 mooseError(
"Requested update for a linear FV gradient field from a different system than '",
113 mooseAssert(perf_graph_interface,
114 "LinearFVGradientInterface requires its owning system to implement "
115 "PerfGraphInterface.");
117 perf_graph_interface->registerTimedSection(
"LinearVariableFV_Gradients", 3);
118 mooseAssert(!
Threads::in_threads,
"PerfGraph timing cannot be used within threaded sections");
119 PerfGuard time_guard(perf_graph_interface->perfGraph(), perf_id);
126 mooseError(
"Requested update for an unregistered linear FV gradient field on system '",
142 "Current solution must exist before building FV gradient storage.");
143 for (
unsigned int i = 0; i <
_sys.
mesh().dimension(); ++i)
152 mooseAssert(!container.values.empty(),
153 "Gradient storage must be initialized before gradient computation.");
154 mooseAssert(!container.next_values.empty(),
155 "Replacement gradient storage must be initialized before gradient computation.");
156 mooseAssert(container.next_values.size() == container.values.size(),
157 "Next and current gradient containers must have the same size.");
168 "Next and current gradient containers must have the same size.");
177 method_container_pair.second.values.clear();
178 method_container_pair.second.next_values.clear();
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Base class for linear finite-volume cell-gradient methods.
void computeGradient(SystemBase &system, GradientContainer &gradient, const std::unordered_set< unsigned int > &variable_numbers) const
Compute the final gradient values for the requested variables.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
void rebuildLinearFVGradientStorage()
Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.
void initializeContainer(GradientContainer &container) const
Allocate one zeroed vector per spatial component for gradient storage.
void finalizeLinearFVGradientContainer(LinearFVGradientContainer &container)
Replace the current gradient storage with the freshly computed new gradients.
SystemBase & _sys
Reference to the system object.
const FVGradientMethod & resolveFVGradientMethod(const GradientMethodName &method_name)
Resolve a named gradient method, constructing a built-in method when needed.
LinearFVGradientContainer & computeLinearFVGradientContainer(const FVGradientMethod &method)
Compute replacement field values for a registered gradient method.
std::unordered_map< const FVGradientMethod *, LinearFVGradientContainer > _linear_fv_gradient_container_by_method
Gradient containers keyed by the method object that produces them.
LinearFVGradientReader::GradientContainer GradientContainer
One vector per spatial component of a cell-centered gradient field.
bool hasLinearFVGradients() const
Whether any linear finite-volume gradient fields have been registered to this object.
void updateFVGradient(const LinearFVGradientReader &reader)
Update a registered gradient reader explicitly.
void computeGradients()
Compute and finalize all registered linear FV gradient fields.
LinearFVGradientReader registerFVGradient(unsigned int variable_number, const FVGradientMethod &method)
Register a variable for gradient values produced by a method object.
Read-only view of one variable's cell-centered linear finite-volume gradient values.
const FVGradientMethod & method() const
Method object that produces the stored values.
const SystemBase & system() const
System whose DOF map indexes the stored values.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
This class provides an interface for common operations on field variables of both FE and FV types wit...
Interface for objects interacting with the PerfGraph.
Scope guard for starting and stopping timing for a node.
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
FEProblemBase & feProblem()
virtual const std::string & name() const
const VariableWarehouse & variableWarehouse(THREAD_ID tid=0) const
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0
Gradient values for all variables using the same gradient method.
GradientContainer next_values
Replacement gradient values computed before publication.
GradientContainer values
Current gradient values read by consumers.