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

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

#include <LinearFVGradientManager.h>

Inheritance diagram for LinearFVGradientManager:
[legend]

Classes

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

Public Member Functions

 LinearFVGradientManager (SystemBase &sys)
 
const FVGradientMethod & resolveFVGradientMethod (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, unsigned int oldest_state=0)
 Register a variable for gradient values produced by a method object.
 

Protected Types

using GradientContainer = LinearFVGradientReader::GradientContainer
 Non-owning view with one vector per spatial component of a cell-centered gradient field.
 
using GradientStateContainer = LinearFVGradientReader::GradientStateContainer
 Gradient fields indexed by solution time state.
 
using OwnedGradientContainer = std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > >
 Owned vectors used for the current gradient and its replacement.
 

Protected Member Functions

void computeGradients ()
 Compute and finalize all registered linear FV gradient fields.
 
void computeGradientsExcept (const LinearFVGradientReader &excluded_reader)
 Compute and finalize every registered linear FV gradient field except one method.
 
void updateFVGradient (const LinearFVGradientReader &reader)
 Update a registered gradient reader explicitly.
 
void initializeLinearFVGradientStorage ()
 Initialize private current and replacement gradient storage.
 
void initializeLinearFVGradientHistoryStorage ()
 Register named system vectors for requested historical gradient states.
 
void rebuildLinearFVGradientStorage ()
 Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.
 
void copyPreviousGradientStates (Moose::SolutionIterationType iteration_type, bool skip_current_to_old)
 Copy published gradient values into requested older states.
 
void restoreGradientStates ()
 Restore current gradients from state one after a failed timestep.
 
bool hasLinearFVGradients () const
 Whether any linear finite-volume gradient fields have been registered to this object.
 
void computeGradientsForMethods (const std::vector< const FVGradientMethod * > &gradient_methods)
 Compute and finalize the supplied registered gradient methods.
 
void initializeContainer (OwnedGradientContainer &container) const
 Allocate one zeroed vector per spatial component for gradient storage.
 
void resizeGradientStateStorage (LinearFVGradientContainer &container, unsigned int oldest_state)
 Ensure that a method container stores every requested time state.
 
void setCurrentGradientState (LinearFVGradientContainer &container) const
 Set solution state zero to the current gradient.
 
void checkRestartedGradientHistory (const FVGradientMethod &method, LinearFVGradientContainer &container)
 Validate and mark gradient history loaded during restart or recovery.
 
void initializeGradientStatesForTimeAdvance ()
 Compute and publish uninitialized gradients before their first time-state advancement.
 
LinearFVGradientContainer & computeLinearFVGradientContainer (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.
 

Static Protected Member Functions

static std::string gradientStateVectorName (const FVGradientMethod &method, unsigned int state, unsigned int component)
 Return the stable system-vector name for one old gradient component.
 

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.
 
std::vector< const FVGradientMethod * > _linear_fv_gradient_methods
 Registered gradient methods in registration order.
 

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 LinearFVGradientManager.h.

Member Typedef Documentation

◆ GradientContainer

Non-owning view with one vector per spatial component of a cell-centered gradient field.

Definition at line 65 of file LinearFVGradientManager.h.

◆ GradientStateContainer

Gradient fields indexed by solution time state.

Definition at line 68 of file LinearFVGradientManager.h.

◆ OwnedGradientContainer

Owned vectors used for the current gradient and its replacement.

Definition at line 71 of file LinearFVGradientManager.h.

Constructor & Destructor Documentation

◆ LinearFVGradientManager()

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

Definition at line 44 of file LinearFVGradientManager.h.

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

Member Function Documentation

◆ checkRestartedGradientHistory()

void LinearFVGradientManager::checkRestartedGradientHistory ( const FVGradientMethod &  method,
LinearFVGradientContainer &  container 
)
protected

Validate and mark gradient history loaded during restart or recovery.

Definition at line 270 of file LinearFVGradientManager.C.

272{
273 if (container.has_checked_restart_history)
274 return;
275
276 container.has_checked_restart_history = true;
277 if (container.state_values.size() <= 1)
278 return;
279
280 const auto & app = _sys.feProblem().getMooseApp();
281 if (!app.isRestarting() && !app.isRecovering())
282 return;
283
284 const auto & restartable_equation_systems = _sys.feProblem().getRestartableEquationSystems();
285 for (const auto state : make_range(std::size_t(1), container.state_values.size()))
286 for (const auto component : index_range(container.state_values[state]))
287 {
288 const auto vector_name = gradientStateVectorName(method, state, component);
289 for (const auto variable_number : container.variable_numbers)
290 {
291 const auto & variable = _sys.getVariable(0, variable_number);
292 if (!restartable_equation_systems.isVariableRestored(
293 _sys.name(), vector_name, variable.name()))
294 mooseError("Linear FV gradient state ",
295 state,
296 " for variable '",
297 variable.name(),
298 "' using gradient method '",
299 method.name(),
300 "' was requested on system '",
301 _sys.name(),
302 "', but vector '",
303 vector_name,
304 "' was not available in the restart data.");
305 }
306 }
307
308 container.has_initialized_history = true;
309}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
for(PetscInt i=0;i< nvars;++i)
const RestartableEquationSystems & getRestartableEquationSystems() const
Get the RestartableEquationSystems object.
static std::string gradientStateVectorName(const FVGradientMethod &method, unsigned int state, unsigned int component)
Return the stable system-vector name for one old gradient component.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:92
FEProblemBase & feProblem()
Definition SystemBase.h:104
virtual const std::string & name() const
auto index_range(const T &sizable)
IntRange< T > make_range(T beg, T end)

Referenced by initializeLinearFVGradientStorage().

◆ computeGradients()

void LinearFVGradientManager::computeGradients ( )
protected

Compute and finalize all registered linear FV gradient fields.

Definition at line 120 of file LinearFVGradientManager.C.

121{
123}
void computeGradientsForMethods(const std::vector< const FVGradientMethod * > &gradient_methods)
Compute and finalize the supplied registered gradient methods.
std::vector< const FVGradientMethod * > _linear_fv_gradient_methods
Registered gradient methods in registration order.

Referenced by AuxiliarySystem::compute().

◆ computeGradientsExcept()

void LinearFVGradientManager::computeGradientsExcept ( const LinearFVGradientReader &  excluded_reader)
protected

Compute and finalize every registered linear FV gradient field except one method.

Parameters
excluded_readerReader whose gradient method should not be updated.

Definition at line 126 of file LinearFVGradientManager.C.

127{
128 if (&excluded_reader.system() != &_sys)
129 mooseError("Cannot exclude a linear FV gradient field from a different system than '",
130 _sys.name(),
131 "'.");
132
133 auto gradient_methods = _linear_fv_gradient_methods;
134 gradient_methods.erase(
135 std::remove(gradient_methods.begin(), gradient_methods.end(), &excluded_reader.method()),
136 gradient_methods.end());
137 computeGradientsForMethods(gradient_methods);
138}
const FVGradientMethod & method() const
Method object that produces the stored values.
const SystemBase & system() const
System whose DOF map indexes the stored values.

◆ computeGradientsForMethods()

void LinearFVGradientManager::computeGradientsForMethods ( const std::vector< const FVGradientMethod * > &  gradient_methods)
protected

Compute and finalize the supplied registered gradient methods.

Parameters
gradient_methodsMethods whose gradient fields should be updated.

Definition at line 141 of file LinearFVGradientManager.C.

143{
144 if (gradient_methods.empty() || !_sys.solutionStatesInitialized())
145 return;
146
147 auto * const perf_graph_interface = dynamic_cast<PerfGraphInterface *>(&_sys);
148 mooseAssert(perf_graph_interface,
149 "LinearFVGradientManager requires its owning system to implement "
150 "PerfGraphInterface.");
151 const auto perf_id = perf_graph_interface->registerTimedSection("LinearVariableFV_Gradients", 3);
152 mooseAssert(!Threads::in_threads, "PerfGraph timing cannot be used within threaded sections");
153 PerfGuard time_guard(perf_graph_interface->perfGraph(), perf_id);
154
155 // Keep current values unchanged until every replacement has been computed so boundary
156 // conditions consistently use gradients from the previous update.
157 // BCs may use cell gradients to compute the boundary face value, which is itself used to
158 // compute cell gradients
159 for (const auto * const method : gradient_methods)
161
162 for (const auto * const method : gradient_methods)
164 libmesh_map_find(_linear_fv_gradient_container_by_method, method));
165}
LinearFVGradientContainer & computeLinearFVGradientContainer(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.
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
bool solutionStatesInitialized() const
Whether or not the solution states have been initialized via initSolutionState()
Definition SystemBase.h:929

Referenced by computeGradients(), and computeGradientsExcept().

◆ computeLinearFVGradientContainer()

LinearFVGradientManager::LinearFVGradientContainer & LinearFVGradientManager::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 312 of file LinearFVGradientManager.C.

313{
314 // Gradient requests can be registered before the current solution vector exists, so the current
315 // and replacement fields cannot always be created when the request is recorded. These fields
316 // must be zero clones of the solution vector to inherit its finalized layout and parallel type.
317 // Requests can also arrive after the normal initialization phase. Initializing immediately
318 // before computation handles both cases, while the empty checks make repeated calls harmless.
320
321 auto & container = libmesh_map_find(_linear_fv_gradient_container_by_method, &method);
322
323 mooseAssert(!container.state_values.empty(),
324 "Gradient state storage must contain a current state.");
325 mooseAssert(!container.state_values[0].empty(),
326 "Gradient storage must be initialized before gradient computation.");
327 mooseAssert(!container.next_values.empty(),
328 "Replacement gradient storage must be initialized before gradient computation.");
329 mooseAssert(container.next_values.size() == container.current_values.size(),
330 "Next and current gradient containers must have the same size.");
331
332 method.computeGradient(_sys, container.next_values, container.variable_numbers);
333
334 return container;
335}
void computeGradient(SystemBase &system, GradientContainer &gradient, const std::unordered_set< unsigned int > &variable_numbers) const
Compute the final gradient values for the requested variables.
void initializeLinearFVGradientStorage()
Initialize private current and replacement gradient storage.

Referenced by computeGradientsForMethods(), initializeGradientStatesForTimeAdvance(), and updateFVGradient().

◆ copyPreviousGradientStates()

void LinearFVGradientManager::copyPreviousGradientStates ( Moose::SolutionIterationType  iteration_type,
bool  skip_current_to_old 
)
protected

Copy published gradient values into requested older states.

Non-time histories are ignored because only time gradient states are currently stored.

Parameters
iteration_typeType of solution history being advanced.
skip_current_to_oldWhether state zero should not overwrite state one while deeper states still shift, matching the owning system's solution-state advancement.

Definition at line 397 of file LinearFVGradientManager.C.

399{
400 mooseAssert(iteration_type != Moose::SolutionIterationType::Nonlinear,
401 "Linear FV gradient storage does not support nonlinear iteration states.");
402 if (iteration_type != Moose::SolutionIterationType::Time)
403 return;
404
405 mooseAssert(!Threads::in_threads, "Linear FV gradient state copying is not thread-safe.");
407
408 for (auto & [_, container] : _linear_fv_gradient_container_by_method)
409 {
410 const auto number_of_states = container.state_values.size();
411 if (number_of_states <= 1)
412 continue;
413
414 mooseAssert(container.has_computed_gradient,
415 "Current gradient state must be initialized before advancing time states.");
416 // Mirror solution-state advancement: some restore workflows preserve state 1 by skipping the
417 // current-to-old copy while still shifting every deeper state.
418 const std::size_t stop = skip_current_to_old ? 1 : 0;
419 for (std::size_t state = number_of_states - 1; state > stop; --state)
420 copyGradient(container.state_values[state - 1], container.state_values[state]);
421 }
422}
void initializeGradientStatesForTimeAdvance()
Compute and publish uninitialized gradients before their first time-state advancement.
void stop(const char *file, int line, const char *date, const char *time)

Referenced by AuxiliarySystem::copyAdditionalStateBackwards(), and LinearSystem::copyAdditionalStateBackwards().

◆ finalizeLinearFVGradientContainer()

void LinearFVGradientManager::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 338 of file LinearFVGradientManager.C.

339{
340 mooseAssert(!container.state_values.empty(),
341 "Gradient state storage must contain a current state.");
342 mooseAssert(container.next_values.size() == container.current_values.size(),
343 "Next and current gradient containers must have the same size.");
344 container.current_values.swap(container.next_values);
345 setCurrentGradientState(container);
346
347 if (!container.has_initialized_history)
348 {
349 for (const auto state : make_range(std::size_t(1), container.state_values.size()))
350 copyGradient(container.state_values[0], container.state_values[state]);
351 container.has_initialized_history = true;
352 }
353
354 container.has_computed_gradient = true;
355}
void setCurrentGradientState(LinearFVGradientContainer &container) const
Set solution state zero to the current gradient.

Referenced by computeGradientsForMethods(), initializeGradientStatesForTimeAdvance(), and updateFVGradient().

◆ gradientStateVectorName()

std::string LinearFVGradientManager::gradientStateVectorName ( const FVGradientMethod &  method,
unsigned int  state,
unsigned int  component 
)
staticprotected

Return the stable system-vector name for one old gradient component.

Definition at line 261 of file LinearFVGradientManager.C.

264{
265 return "linear_fv_gradient_" + method.name() + "_state_" + std::to_string(state) + "_component_" +
266 std::to_string(component);
267}

Referenced by checkRestartedGradientHistory(), and initializeLinearFVGradientHistoryStorage().

◆ hasLinearFVGradients()

bool LinearFVGradientManager::hasLinearFVGradients ( ) const
protected

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

Definition at line 198 of file LinearFVGradientManager.C.

199{
201}

Referenced by AuxiliarySystem::compute().

◆ initializeContainer()

void LinearFVGradientManager::initializeContainer ( OwnedGradientContainer &  container) const
protected

Allocate one zeroed vector per spatial component for gradient storage.

Parameters
containerComponent-vector container to rebuild.

Definition at line 204 of file LinearFVGradientManager.C.

205{
206 container.clear();
207 const auto & current_solution = _sys.system().current_local_solution;
208 mooseAssert(current_solution && current_solution->initialized(),
209 "Current solution must exist before building FV gradient storage.");
210 container.resize(_sys.mesh().dimension());
211 for (auto & component : container)
212 component = current_solution->zero_clone();
213}
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition MooseMesh.C:2949
MooseMesh & mesh()
Definition SystemBase.h:100
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
std::unique_ptr< NumericVector< Number > > current_local_solution

Referenced by initializeLinearFVGradientStorage(), and AuxiliarySystem::updateFVGradient().

◆ initializeGradientStatesForTimeAdvance()

void LinearFVGradientManager::initializeGradientStatesForTimeAdvance ( )
protected

Compute and publish uninitialized gradients before their first time-state advancement.

Definition at line 385 of file LinearFVGradientManager.C.

386{
387 for (auto & [method, container] : _linear_fv_gradient_container_by_method)
388 if (container.state_values.size() > 1 && !container.has_computed_gradient)
390
391 for (auto & [_, container] : _linear_fv_gradient_container_by_method)
392 if (container.state_values.size() > 1 && !container.has_computed_gradient)
394}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD

Referenced by copyPreviousGradientStates().

◆ initializeLinearFVGradientHistoryStorage()

void LinearFVGradientManager::initializeLinearFVGradientHistoryStorage ( )
protected

Register named system vectors for requested historical gradient states.

This must run after gradient state requirements are known and before restart or recovery data is loaded, so checkpoint data can be restored into these vectors. It does not initialize the current or replacement working storage.

Definition at line 234 of file LinearFVGradientManager.C.

235{
236 for (auto & [method, container] : _linear_fv_gradient_container_by_method)
237 for (const auto state : make_range(std::size_t(1), container.state_values.size()))
238 if (container.state_values[state].empty())
239 {
240 GradientContainer state_values(_sys.mesh().dimension());
241 for (const auto component : index_range(state_values))
242 state_values[component] = &_sys.addVector(
243 gradientStateVectorName(*method, state, component), true, libMesh::GHOSTED);
244 container.state_values[state] = std::move(state_values);
245 }
246}
LinearFVGradientReader::GradientContainer GradientContainer
Non-owning view with one vector per spatial component of a cell-centered gradient field.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...

Referenced by AuxiliarySystem::AuxiliarySystem(), and LinearSystem::initSolutionState().

◆ initializeLinearFVGradientStorage()

void LinearFVGradientManager::initializeLinearFVGradientStorage ( )
protected

Initialize private current and replacement gradient storage.

This must run after the current local solution has been created and initialized, and after restart or recovery data has been loaded. At that point, it also checks if the restored historical gradient storage is set up correctly.

Definition at line 358 of file LinearFVGradientManager.C.

359{
360 for (auto & [method, container] : _linear_fv_gradient_container_by_method)
361 {
362 if (container.current_values.empty())
363 initializeContainer(container.current_values);
364 if (container.next_values.empty())
365 initializeContainer(container.next_values);
366 setCurrentGradientState(container);
367 checkRestartedGradientHistory(*method, container);
368 }
369}
void initializeContainer(OwnedGradientContainer &container) const
Allocate one zeroed vector per spatial component for gradient storage.
void checkRestartedGradientHistory(const FVGradientMethod &method, LinearFVGradientContainer &container)
Validate and mark gradient history loaded during restart or recovery.

Referenced by computeLinearFVGradientContainer(), AuxiliarySystem::initialSetup(), LinearSystem::initialSetup(), and rebuildLinearFVGradientStorage().

◆ rebuildLinearFVGradientStorage()

void LinearFVGradientManager::rebuildLinearFVGradientStorage ( )
protected

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

Definition at line 372 of file LinearFVGradientManager.C.

373{
374 for (auto & method_container_pair : _linear_fv_gradient_container_by_method)
375 {
376 method_container_pair.second.current_values.clear();
377 method_container_pair.second.next_values.clear();
378 method_container_pair.second.has_computed_gradient = false;
379 }
380
382}

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

◆ registerFVGradient()

LinearFVGradientReader LinearFVGradientManager::registerFVGradient ( unsigned int  variable_number,
const FVGradientMethod &  method,
unsigned int  oldest_state = 0 
)

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.
oldest_stateOldest time state that consumers need to read.

Definition at line 85 of file LinearFVGradientManager.C.

88{
89 auto * const variable =
90 dynamic_cast<MooseVariableFieldBase *>(_sys.variableWarehouse().getVariable(variable_number));
91 if (!variable)
92 mooseError("Linear FV gradients were requested for variable number ",
93 variable_number,
94 " on system '",
95 _sys.name(),
96 "', but no field variable with that number exists on the system.");
97
98 auto [method_container, inserted] = _linear_fv_gradient_container_by_method.try_emplace(&method);
99 if (inserted)
100 _linear_fv_gradient_methods.push_back(&method);
101 auto & container = method_container->second;
102 container.variable_numbers.insert(variable_number);
103
104 resizeGradientStateStorage(container, oldest_state);
105
106 const auto & current_solution = _sys.system().current_local_solution;
107 if (current_solution && current_solution->initialized())
108 {
109 if (container.current_values.empty())
110 initializeContainer(container.current_values);
111 if (container.next_values.empty())
112 initializeContainer(container.next_values);
113 setCurrentGradientState(container);
114 }
115
116 return LinearFVGradientReader(_sys, container.state_values, method, variable_number);
117}
void resizeGradientStateStorage(LinearFVGradientContainer &container, unsigned int oldest_state)
Ensure that a method container stores every requested time state.
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...
const VariableWarehouse & variableWarehouse(THREAD_ID tid=0) const
Definition SystemBase.h:787
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.

◆ resizeGradientStateStorage()

void LinearFVGradientManager::resizeGradientStateStorage ( LinearFVGradientContainer &  container,
unsigned int  oldest_state 
)
protected

Ensure that a method container stores every requested time state.

Parameters
containerMethod container whose state storage should be grown.
oldest_stateOldest time state that must be stored.

Definition at line 216 of file LinearFVGradientManager.C.

218{
219 const auto required_states = static_cast<std::size_t>(oldest_state) + 1;
220 const auto old_size = container.state_values.size();
221 if (required_states > old_size && _sys.solutionStatesInitialized() && oldest_state > 0)
222 mooseError("Linear FV gradient state ",
223 oldest_state,
224 " was requested on system '",
225 _sys.name(),
226 "' after solution states were initialized. Old gradient states must be requested "
227 "during setup.");
228
229 if (required_states > old_size)
230 container.state_values.resize(required_states);
231}

Referenced by AuxiliarySystem::updateFVGradient().

◆ resolveFVGradientMethod()

const FVGradientMethod & LinearFVGradientManager::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 59 of file LinearFVGradientManager.C.

60{
61 auto & fe_problem = _sys.feProblem();
62
63 if (!fe_problem.hasFVGradientMethod(method_name))
64 {
65 if (method_name == "green-gauss")
66 {
67 auto params = fe_problem.getMooseApp().getFactory().getValidParams("FVGreenGaussGradient");
68 fe_problem.addFVGradientMethod("FVGreenGaussGradient", method_name, params);
69 }
70 else if (method_name == "green-gauss-venkatakrishnan")
71 {
72 auto params = fe_problem.getMooseApp().getFactory().getValidParams("FVGreenGaussGradient");
73 params.set<MooseEnum>("limiter") = "venkatakrishnan";
74 fe_problem.addFVGradientMethod("FVGreenGaussGradient", method_name, params);
75 }
76 }
77
78 if (!fe_problem.hasFVGradientMethod(method_name))
79 mooseError("Unable to find FVGradientMethod with name '", method_name, "'");
80
81 return fe_problem.getFVGradientMethod(method_name);
82}
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:404
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55

◆ restoreGradientStates()

void LinearFVGradientManager::restoreGradientStates ( )
protected

Restore current gradients from state one after a failed timestep.

Definition at line 425 of file LinearFVGradientManager.C.

426{
427 mooseAssert(!Threads::in_threads, "Linear FV gradient state copying is not thread-safe.");
428 for (auto & [_, container] : _linear_fv_gradient_container_by_method)
429 {
430 if (container.state_values.size() <= 1)
431 continue;
432
433 mooseAssert(container.has_computed_gradient,
434 "Current gradient state must be initialized before restoration.");
435 copyGradient(container.state_values[1], container.state_values[0]);
436 copyGradient(container.state_values[0], container.next_values);
437 }
438}

Referenced by AuxiliarySystem::restoreAdditionalStates(), and LinearSystem::restoreAdditionalStates().

◆ setCurrentGradientState()

void LinearFVGradientManager::setCurrentGradientState ( LinearFVGradientContainer &  container) const
protected

Set solution state zero to the current gradient.

Definition at line 249 of file LinearFVGradientManager.C.

250{
251 mooseAssert(!container.state_values.empty(),
252 "Gradient state storage must contain a current state.");
253 auto & current_view = container.state_values[0];
254 current_view.clear();
255 current_view.reserve(container.current_values.size());
256 for (auto & component : container.current_values)
257 current_view.push_back(component.get());
258}
const Elem & get(const ElemType type_in)

Referenced by finalizeLinearFVGradientContainer(), initializeLinearFVGradientStorage(), and AuxiliarySystem::updateFVGradient().

◆ updateFVGradient()

void LinearFVGradientManager::updateFVGradient ( const LinearFVGradientReader &  reader)
protected

Update a registered gradient reader explicitly.

Parameters
readerGradient reader to update.

Definition at line 168 of file LinearFVGradientManager.C.

169{
170 if (&reader.system() != &_sys)
171 mooseError("Requested update for a linear FV gradient field from a different system than '",
172 _sys.name(),
173 "'.");
174
175 const auto method_container_pair = _linear_fv_gradient_container_by_method.find(&reader.method());
176 if (method_container_pair != _linear_fv_gradient_container_by_method.end())
177 {
178 auto * const perf_graph_interface = dynamic_cast<PerfGraphInterface *>(&_sys);
179 mooseAssert(perf_graph_interface,
180 "LinearFVGradientManager requires its owning system to implement "
181 "PerfGraphInterface.");
182 const auto perf_id =
183 perf_graph_interface->registerTimedSection("LinearVariableFV_Gradients", 3);
184 mooseAssert(!Threads::in_threads, "PerfGraph timing cannot be used within threaded sections");
185 PerfGuard time_guard(perf_graph_interface->perfGraph(), perf_id);
186
187 auto & container = computeLinearFVGradientContainer(reader.method());
189 return;
190 }
191
192 mooseError("Requested update for an unregistered linear FV gradient field on system '",
193 _sys.name(),
194 "'.");
195}

Member Data Documentation

◆ _linear_fv_gradient_container_by_method

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

◆ _linear_fv_gradient_methods

std::vector<const FVGradientMethod *> LinearFVGradientManager::_linear_fv_gradient_methods
protected

Registered gradient methods in registration order.

Definition at line 212 of file LinearFVGradientManager.h.

Referenced by computeGradients(), computeGradientsExcept(), and AuxiliarySystem::updateFVGradient().

◆ _sys

SystemBase& LinearFVGradientManager::_sys
protected

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