https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
LinearFVGradientInterface Class Reference

Registration, update, and allocation logic for linear finite-volume cell gradients. More...

#include <LinearFVGradientInterface.h>

Inheritance diagram for LinearFVGradientInterface:
[legend]

Classes

struct  LinearFVGradientContainer
 Gradient values for all variables using the same gradient method. More...
 

Public Member Functions

 LinearFVGradientInterface (SystemBase &sys)
 
const FVGradientMethodresolveFVGradientMethod (const GradientMethodName &method_name)
 Resolve a named gradient method, constructing a built-in method when needed.
 
LinearFVGradientReader registerFVGradient (unsigned int variable_number, const FVGradientMethod &method)
 Register a variable for gradient values produced by a method object.
 

Protected Types

using GradientContainer = LinearFVGradientReader::GradientContainer
 One vector per spatial component of a cell-centered gradient field.
 

Protected Member Functions

void computeGradients ()
 Compute and finalize all registered linear FV gradient fields.
 
void updateFVGradient (const LinearFVGradientReader &reader)
 Update a registered gradient reader explicitly.
 
void rebuildLinearFVGradientStorage ()
 Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.
 
bool hasLinearFVGradients () const
 Whether any linear finite-volume gradient fields have been registered to this object.
 
void initializeContainer (GradientContainer &container) const
 Allocate one zeroed vector per spatial component for gradient storage.
 
LinearFVGradientContainercomputeLinearFVGradientContainer (const FVGradientMethod &method)
 Compute replacement field values for a registered gradient method.
 
void finalizeLinearFVGradientContainer (LinearFVGradientContainer &container)
 Replace the current gradient storage with the freshly computed new gradients.
 

Protected Attributes

SystemBase_sys
 Reference to the system object.
 
std::unordered_map< const FVGradientMethod *, LinearFVGradientContainer_linear_fv_gradient_container_by_method
 Gradient containers keyed by the method object that produces them.
 

Detailed Description

Registration, update, and allocation logic for linear finite-volume cell gradients.

This interface should be inherited by system classes that may own linear finite-volume variables

Definition at line 38 of file LinearFVGradientInterface.h.

Member Typedef Documentation

◆ GradientContainer

One vector per spatial component of a cell-centered gradient field.

Definition at line 63 of file LinearFVGradientInterface.h.

Constructor & Destructor Documentation

◆ LinearFVGradientInterface()

LinearFVGradientInterface::LinearFVGradientInterface ( SystemBase sys)
inline
Parameters
sysSystem that owns registered linear finite-volume gradient fields.

Definition at line 44 of file LinearFVGradientInterface.h.

44: _sys(sys) {}
SystemBase & _sys
Reference to the system object.

Member Function Documentation

◆ computeGradients()

void LinearFVGradientInterface::computeGradients ( )
protected

Compute and finalize all registered linear FV gradient fields.

Definition at line 77 of file LinearFVGradientInterface.C.

78{
80 return;
81
82 auto * const perf_graph_interface = dynamic_cast<PerfGraphInterface *>(&_sys);
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);
89
90 // Keep current values unchanged until every replacement has been computed so boundary
91 // conditions consistently use gradients from the previous update.
92 // BCs may use cell gradients to compute the boundary face value, which is itself used to
93 // compute cell gradients
94 for (auto & method_container_pair : _linear_fv_gradient_container_by_method)
95 computeLinearFVGradientContainer(*method_container_pair.first);
96
97 for (auto & method_container_pair : _linear_fv_gradient_container_by_method)
98 finalizeLinearFVGradientContainer(method_container_pair.second);
99}
void finalizeLinearFVGradientContainer(LinearFVGradientContainer &container)
Replace the current gradient storage with the freshly computed new gradients.
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.
Interface for objects interacting with the PerfGraph.
Scope guard for starting and stopping timing for a node.
Definition PerfGuard.h:26

Referenced by AuxiliarySystem::compute().

◆ computeLinearFVGradientContainer()

LinearFVGradientInterface::LinearFVGradientContainer & LinearFVGradientInterface::computeLinearFVGradientContainer ( const FVGradientMethod method)
protected

Compute replacement field values for a registered gradient method.

Parameters
methodGradient method used to compute the replacement values.
Returns
Method container whose replacement values were computed.

Definition at line 148 of file LinearFVGradientInterface.C.

149{
150 auto & container = libmesh_map_find(_linear_fv_gradient_container_by_method, &method);
151
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.");
158
159 method.computeGradient(_sys, container.next_values, container.variable_numbers);
160
161 return container;
162}
void computeGradient(SystemBase &system, GradientContainer &gradient, const std::unordered_set< unsigned int > &variable_numbers) const
Compute the final gradient values for the requested variables.

Referenced by computeGradients(), and updateFVGradient().

◆ finalizeLinearFVGradientContainer()

void LinearFVGradientInterface::finalizeLinearFVGradientContainer ( LinearFVGradientContainer container)
protected

Replace the current gradient storage with the freshly computed new gradients.

Parameters
containerMethod container whose gradient values should be finalized.

Definition at line 165 of file LinearFVGradientInterface.C.

166{
167 mooseAssert(container.next_values.size() == container.values.size(),
168 "Next and current gradient containers must have the same size.");
169 container.values.swap(container.next_values);
170}

Referenced by computeGradients(), and updateFVGradient().

◆ hasLinearFVGradients()

bool LinearFVGradientInterface::hasLinearFVGradients ( ) const
protected

Whether any linear finite-volume gradient fields have been registered to this object.

Definition at line 132 of file LinearFVGradientInterface.C.

133{
135}

Referenced by AuxiliarySystem::compute(), and rebuildLinearFVGradientStorage().

◆ initializeContainer()

void LinearFVGradientInterface::initializeContainer ( GradientContainer container) const
protected

Allocate one zeroed vector per spatial component for gradient storage.

Parameters
containerComponent-vector container to rebuild.

Definition at line 138 of file LinearFVGradientInterface.C.

139{
140 container.clear();
141 mooseAssert(_sys.currentSolution(),
142 "Current solution must exist before building FV gradient storage.");
143 for (unsigned int i = 0; i < _sys.mesh().dimension(); ++i)
144 container.push_back(_sys.currentSolution()->zero_clone());
145}
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
MooseMesh & mesh()
Definition SystemBase.h:100
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0

Referenced by rebuildLinearFVGradientStorage().

◆ rebuildLinearFVGradientStorage()

void LinearFVGradientInterface::rebuildLinearFVGradientStorage ( )
protected

Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.

Definition at line 173 of file LinearFVGradientInterface.C.

174{
175 for (auto & method_container_pair : _linear_fv_gradient_container_by_method)
176 {
177 method_container_pair.second.values.clear();
178 method_container_pair.second.next_values.clear();
179 }
180
182 return;
183
184 for (auto & method_container_pair : _linear_fv_gradient_container_by_method)
185 {
186 initializeContainer(method_container_pair.second.values);
187 initializeContainer(method_container_pair.second.next_values);
188 }
189}
void initializeContainer(GradientContainer &container) const
Allocate one zeroed vector per spatial component for gradient storage.
bool hasLinearFVGradients() const
Whether any linear finite-volume gradient fields have been registered to this object.

Referenced by AuxiliarySystem::AuxiliarySystem(), LinearSystem::initialSetup(), AuxiliarySystem::reinit(), and LinearSystem::reinit().

◆ registerFVGradient()

LinearFVGradientReader LinearFVGradientInterface::registerFVGradient ( unsigned int  variable_number,
const FVGradientMethod method 
)

Register a variable for gradient values produced by a method object.

Parameters
variable_numberVariable number whose gradient should be stored.
methodGradient method that computes the field values.

Definition at line 52 of file LinearFVGradientInterface.C.

54{
55 auto * const variable =
56 dynamic_cast<MooseVariableFieldBase *>(_sys.variableWarehouse().getVariable(variable_number));
57 if (!variable)
58 mooseError("Linear FV gradients were requested for variable number ",
59 variable_number,
60 " on system '",
61 _sys.name(),
62 "', but no field variable with that number exists on the system.");
63
64 auto & container = _linear_fv_gradient_container_by_method[&method];
65 container.variable_numbers.insert(variable_number);
66
67 if (container.values.empty() && _sys.currentSolution())
68 initializeContainer(container.values);
69
70 if (container.next_values.empty() && _sys.currentSolution())
71 initializeContainer(container.next_values);
72
73 return LinearFVGradientReader(_sys, container.values, method, variable_number);
74}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Read-only view of one variable's cell-centered linear finite-volume gradient values.
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual const std::string & name() const
const VariableWarehouse & variableWarehouse(THREAD_ID tid=0) const
Definition SystemBase.h:775
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.

◆ resolveFVGradientMethod()

const FVGradientMethod & LinearFVGradientInterface::resolveFVGradientMethod ( const GradientMethodName &  method_name)

Resolve a named gradient method, constructing a built-in method when needed.

Parameters
method_nameName of the gradient method to retrieve.
Returns
Gradient method associated with the supplied name.

Definition at line 26 of file LinearFVGradientInterface.C.

27{
28 auto & fe_problem = _sys.feProblem();
29
30 if (!fe_problem.hasFVGradientMethod(method_name))
31 {
32 if (method_name == "green-gauss")
33 {
34 auto params = fe_problem.getMooseApp().getFactory().getValidParams("FVGreenGaussGradient");
35 fe_problem.addFVGradientMethod("FVGreenGaussGradient", method_name, params);
36 }
37 else if (method_name == "green-gauss-venkatakrishnan")
38 {
39 auto params = fe_problem.getMooseApp().getFactory().getValidParams("FVGreenGaussGradient");
40 params.set<MooseEnum>("limiter") = "venkatakrishnan";
41 fe_problem.addFVGradientMethod("FVGreenGaussGradient", method_name, params);
42 }
43 }
44
45 if (!fe_problem.hasFVGradientMethod(method_name))
46 mooseError("Unable to find FVGradientMethod with name '", method_name, "'");
47
48 return fe_problem.getFVGradientMethod(method_name);
49}
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
FEProblemBase & feProblem()
Definition SystemBase.h:104

◆ updateFVGradient()

void LinearFVGradientInterface::updateFVGradient ( const LinearFVGradientReader reader)
protected

Update a registered gradient reader explicitly.

Parameters
readerGradient reader to update.

Definition at line 102 of file LinearFVGradientInterface.C.

103{
104 if (&reader.system() != &_sys)
105 mooseError("Requested update for a linear FV gradient field from a different system than '",
106 _sys.name(),
107 "'.");
108
109 const auto method_container_pair = _linear_fv_gradient_container_by_method.find(&reader.method());
110 if (method_container_pair != _linear_fv_gradient_container_by_method.end())
111 {
112 auto * const perf_graph_interface = dynamic_cast<PerfGraphInterface *>(&_sys);
113 mooseAssert(perf_graph_interface,
114 "LinearFVGradientInterface requires its owning system to implement "
115 "PerfGraphInterface.");
116 const auto perf_id =
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);
120
121 auto & container = computeLinearFVGradientContainer(reader.method());
123 return;
124 }
125
126 mooseError("Requested update for an unregistered linear FV gradient field on system '",
127 _sys.name(),
128 "'.");
129}
const FVGradientMethod & method() const
Method object that produces the stored values.
const SystemBase & system() const
System whose DOF map indexes the stored values.

Member Data Documentation

◆ _linear_fv_gradient_container_by_method

std::unordered_map<const FVGradientMethod *, LinearFVGradientContainer> LinearFVGradientInterface::_linear_fv_gradient_container_by_method
protected

Gradient containers keyed by the method object that produces them.

Definition at line 119 of file LinearFVGradientInterface.h.

Referenced by computeGradients(), computeLinearFVGradientContainer(), hasLinearFVGradients(), rebuildLinearFVGradientStorage(), and updateFVGradient().

◆ _sys

SystemBase& LinearFVGradientInterface::_sys
protected

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