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

Shared storage and allocation logic for linear finite-volume cell gradients for variables in the system attribute of this class. More...

#include <LinearFVGradientInterface.h>

Inheritance diagram for LinearFVGradientInterface:
[legend]

Public Member Functions

 LinearFVGradientInterface (SystemBase &sys)
 
const std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & linearFVGradientContainer () const
 Access the stored raw 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.
 
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.
 
const std::unordered_set< Moose::FV::GradientLimiterType > & requestedLinearFVLimitedGradientTypes () const
 Access the limiter types requested for this system.
 

Protected Member Functions

void computeGradients ()
 Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
 
void rebuildLinearFVGradientStorage ()
 Rebuild persistent raw and temporary gradient storage after mesh/DOF changes.
 
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & temporaryLinearFVGradientContainer ()
 Return temporary storage for gradients during gradient assembly.
 
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & temporaryLinearFVLimitedGradientContainer (const Moose::FV::GradientLimiterType limiter_type)
 Return temporary storage for limited gradients during gradient assembly.
 
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & rawLinearFVLimitedGradientContainer (const Moose::FV::GradientLimiterType limiter_type)
 Access the persisted limited-gradient storage for a specific limiter.
 
const std::unordered_set< unsigned int > & requestedLinearFVLimitedGradientVariables (const Moose::FV::GradientLimiterType limiter_type) const
 Access the variable numbers that requested limited gradients for a specific limiter.
 
bool needsLinearFVGradientStorage () const
 
void initializeContainer (std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > &container) const
 

Protected Attributes

SystemBase_sys
 Reference to the system object.
 
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _temporary_gradient
 Scratch storage for raw gradients assembled during the current compute pass.
 
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _raw_grad_container
 Persisted raw cell-centered gradient components keyed by spatial direction.
 
std::unordered_set< Moose::FV::GradientLimiterType_requested_limited_gradient_types
 Set of requested limiter types for which limited gradients should be computed.
 
std::unordered_map< Moose::FV::GradientLimiterType, std::unordered_set< unsigned int > > _requested_limited_gradient_variables
 Variable numbers requesting limited gradients, keyed by limiter type.
 
std::unordered_map< Moose::FV::GradientLimiterType, std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > > _raw_limited_grad_containers
 Persisted limited gradient components keyed by limiter type.
 
std::unordered_map< Moose::FV::GradientLimiterType, std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > > _temporary_limited_gradient
 Scratch storage for limited gradients assembled during the current compute pass.
 

Detailed Description

Shared storage and allocation logic for linear finite-volume cell gradients for variables in the system attribute of this class.

Definition at line 35 of file LinearFVGradientInterface.h.

Constructor & Destructor Documentation

◆ LinearFVGradientInterface()

LinearFVGradientInterface::LinearFVGradientInterface ( SystemBase sys)
inline

Definition at line 38 of file LinearFVGradientInterface.h.

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

Member Function Documentation

◆ computeGradients()

void LinearFVGradientInterface::computeGradients ( )
protected

Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.

Definition at line 27 of file LinearFVGradientInterface.C.

28{
29 // No gradients have been requested, by now we should have set up the
30 // containers to receive the gradients. Time to early return.
31 if (_raw_grad_container.empty())
32 return;
33
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)
38 vec->zero();
39
40 auto & fe_problem = _sys.feProblem();
41 auto * const perf_graph_interface = dynamic_cast<PerfGraphInterface *>(&_sys);
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);
48
49 PARALLEL_TRY
50 {
52 FaceInfoRange face_info_range(fe_problem.mesh().ownedFaceInfoBegin(),
53 fe_problem.mesh().ownedFaceInfoEnd());
54
56 fe_problem, _sys, temporary_gradient);
57 Threads::parallel_reduce(face_info_range, gradient_face_thread);
58 }
59 fe_problem.checkExceptionAndStopSolve();
60
61 for (auto & vec : temporary_gradient)
62 vec->close();
63
64 PARALLEL_TRY
65 {
67 ElemInfoRange elem_info_range(fe_problem.mesh().ownedElemInfoBegin(),
68 fe_problem.mesh().ownedElemInfoEnd());
69
71 fe_problem, _sys, temporary_gradient);
72 Threads::parallel_reduce(elem_info_range, gradient_volume_thread);
73 }
74 fe_problem.checkExceptionAndStopSolve();
75
76 for (const auto i : index_range(_raw_grad_container))
77 temporary_gradient[i]->close();
78
79 _raw_grad_container.swap(temporary_gradient);
80
82 {
84 ElemInfoRange elem_info_range(fe_problem.mesh().ownedElemInfoBegin(),
85 fe_problem.mesh().ownedElemInfoEnd());
86
87 for (const auto limiter_type : requestedLinearFVLimitedGradientTypes())
88 {
89 if (limiter_type == Moose::FV::GradientLimiterType::None)
90 continue;
91
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)
97 vec->zero();
98
99 PARALLEL_TRY
100 {
101 ComputeLinearFVLimitedGradientThread limited_gradient_thread(
102 fe_problem,
103 _sys,
105 temporary_container,
106 limiter_type,
108 Threads::parallel_reduce(elem_info_range, limited_gradient_thread);
109 }
110 fe_problem.checkExceptionAndStopSolve();
111
112 for (auto & vec : temporary_container)
113 vec->close();
114
115 raw_container.swap(temporary_container);
116 }
117 }
118}
The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation ca...
The gradient in a volume using Green Gauss theorem and a cell-centered finite-volume approximation ca...
Compute limited cell gradients for linear FV variables.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & temporaryLinearFVLimitedGradientContainer(const Moose::FV::GradientLimiterType limiter_type)
Return temporary storage for limited gradients during gradient assembly.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & temporaryLinearFVGradientContainer()
Return temporary storage for gradients during gradient assembly.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _raw_grad_container
Persisted raw cell-centered gradient components keyed by spatial direction.
const std::unordered_set< unsigned int > & requestedLinearFVLimitedGradientVariables(const Moose::FV::GradientLimiterType limiter_type) const
Access the variable numbers that requested limited gradients for a specific limiter.
const std::unordered_set< Moose::FV::GradientLimiterType > & requestedLinearFVLimitedGradientTypes() const
Access the limiter types requested for this system.
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & rawLinearFVLimitedGradientContainer(const Moose::FV::GradientLimiterType limiter_type)
Access the persisted limited-gradient storage for a specific limiter.
Interface for objects interacting with the PerfGraph.
Scope guard for starting and stopping timing for a node.
Definition PerfGuard.h:26
FEProblemBase & feProblem()
Definition SystemBase.h:104
@ None
No gradient limiting.
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
auto index_range(const T &sizable)
const Number zero

Referenced by AuxiliarySystem::compute().

◆ initializeContainer()

void LinearFVGradientInterface::initializeContainer ( std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > &  container) const
protected

Definition at line 131 of file LinearFVGradientInterface.C.

133{
134 container.clear();
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());
139}
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(), and requestLinearFVLimitedGradients().

◆ linearFVGradientContainer()

const std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & LinearFVGradientInterface::linearFVGradientContainer ( ) const
inline

Access the stored raw cell-centered gradient components.

Returns
Raw cell-centered gradient vectors keyed by spatial direction.

Definition at line 45 of file LinearFVGradientInterface.h.

46 {
48 }

◆ linearFVLimitedGradientContainer()

const std::vector< std::unique_ptr< NumericVector< Number > > > & LinearFVGradientInterface::linearFVLimitedGradientContainer ( const Moose::FV::GradientLimiterType  limiter_type) const

Access the stored raw or limited cell-centered gradient components.

Parameters
limiter_typeThe limiter type whose gradient container is being requested.
Returns
The requested raw or limited gradient vectors ordered by spatial direction.

Definition at line 198 of file LinearFVGradientInterface.C.

200{
201 if (limiter_type == Moose::FV::GradientLimiterType::None)
202 return _raw_grad_container;
203
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 '",
207 _sys.name(),
208 "'.");
209
210 return it->second;
211}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::unordered_map< Moose::FV::GradientLimiterType, std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > > _raw_limited_grad_containers
Persisted limited gradient components keyed by limiter type.
virtual const std::string & name() const

◆ needsLinearFVGradientStorage()

bool LinearFVGradientInterface::needsLinearFVGradientStorage ( ) const
protected

Definition at line 121 of file LinearFVGradientInterface.C.

122{
123 for (const auto * const field_var : _sys.variableWarehouse().fieldVariables())
124 if (field_var->needsGradientVectorStorage())
125 return true;
126
127 return false;
128}
if(subdm)

Referenced by rebuildLinearFVGradientStorage().

◆ rawLinearFVLimitedGradientContainer()

std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & LinearFVGradientInterface::rawLinearFVLimitedGradientContainer ( const Moose::FV::GradientLimiterType  limiter_type)
inlineprotected

Access the persisted limited-gradient storage for a specific limiter.

Parameters
limiter_typeThe limiter type whose persisted storage is being accessed.
Returns
The persisted limited-gradient vectors keyed by spatial direction.

Definition at line 117 of file LinearFVGradientInterface.h.

118 {
119 return _raw_limited_grad_containers[limiter_type];
120 }

Referenced by LinearSystem::computeGradients().

◆ rebuildLinearFVGradientStorage()

void LinearFVGradientInterface::rebuildLinearFVGradientStorage ( )
protected

Rebuild persistent raw and temporary gradient storage after mesh/DOF changes.

Definition at line 142 of file LinearFVGradientInterface.C.

143{
144 _raw_grad_container.clear();
145 _temporary_gradient.clear();
148
150 return;
151
154
155 for (const auto limiter_type : _requested_limited_gradient_types)
156 {
157 if (limiter_type == Moose::FV::GradientLimiterType::None)
158 continue;
159
162 }
163}
std::unordered_map< Moose::FV::GradientLimiterType, std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > > _temporary_limited_gradient
Scratch storage for limited gradients assembled during the current compute pass.
void initializeContainer(std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > &container) const
std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > _temporary_gradient
Scratch storage for raw gradients assembled during the current compute pass.
std::unordered_set< Moose::FV::GradientLimiterType > _requested_limited_gradient_types
Set of requested limiter types for which limited gradients should be computed.

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

◆ requestedLinearFVLimitedGradientTypes()

const std::unordered_set< Moose::FV::GradientLimiterType > & LinearFVGradientInterface::requestedLinearFVLimitedGradientTypes ( ) const
inline

Access the limiter types requested for this system.

Returns
The set of limiter types whose limited gradients should be assembled. They are only assembled for the variable(s) for which they were requested not all of them

Definition at line 72 of file LinearFVGradientInterface.h.

73 {
75 }

Referenced by LinearSystem::computeGradients().

◆ requestedLinearFVLimitedGradientVariables()

const std::unordered_set< unsigned int > & LinearFVGradientInterface::requestedLinearFVLimitedGradientVariables ( const Moose::FV::GradientLimiterType  limiter_type) const
inlineprotected

Access the variable numbers that requested limited gradients for a specific limiter.

Parameters
limiter_typeThe limiter type whose request set is being accessed.
Returns
The set of variable numbers that requested the limiter.

Definition at line 128 of file LinearFVGradientInterface.h.

129 {
130 return libmesh_map_find(_requested_limited_gradient_variables, limiter_type);
131 }
std::unordered_map< Moose::FV::GradientLimiterType, std::unordered_set< unsigned int > > _requested_limited_gradient_variables
Variable numbers requesting limited gradients, keyed by limiter type.

Referenced by LinearSystem::computeGradients().

◆ requestLinearFVLimitedGradients()

void LinearFVGradientInterface::requestLinearFVLimitedGradients ( const Moose::FV::GradientLimiterType  limiter_type,
unsigned int  variable_number 
)

Request storage and assembly of limiter-specific cell gradients.

Parameters
limiter_typeThe limiter whose gradient storage should be made available.
variable_numberThe libMesh variable number requesting the limited gradients.

Definition at line 166 of file LinearFVGradientInterface.C.

168{
169 if (limiter_type == Moose::FV::GradientLimiterType::None)
170 return;
171
172 auto * const variable =
173 dynamic_cast<MooseVariableFieldBase *>(_sys.variableWarehouse().getVariable(variable_number));
174 if (!variable)
175 mooseError("Limited gradients were requested for variable number ",
176 variable_number,
177 " on system '",
178 _sys.name(),
179 "', but no field variable with that number exists on the system.");
180
181 if (!variable->needsGradientVectorStorage())
182 mooseError("Limited gradients were requested for variable '",
183 variable->name(),
184 "' on system '",
185 _sys.name(),
186 "', but regular gradients were not requested for that variable.");
187
188 _requested_limited_gradient_variables[limiter_type].insert(variable_number);
189
190 if (_requested_limited_gradient_types.insert(limiter_type).second && !_raw_grad_container.empty())
191 {
194 }
195}
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:775
MooseVariableBase * getVariable(const std::string &var_name) const
Get a variable from the warehouse.

◆ temporaryLinearFVGradientContainer()

std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & LinearFVGradientInterface::temporaryLinearFVGradientContainer ( )
inlineprotected

Return temporary storage for gradients during gradient assembly.

The returned vectors are persistent scratch storage reused across calls and swapped with the final gradient container before gradient assembly returns.

Definition at line 94 of file LinearFVGradientInterface.h.

95 {
97 }

Referenced by computeGradients().

◆ temporaryLinearFVLimitedGradientContainer()

std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & LinearFVGradientInterface::temporaryLinearFVLimitedGradientContainer ( const Moose::FV::GradientLimiterType  limiter_type)
inlineprotected

Return temporary storage for limited gradients during gradient assembly.

The returned vectors are persistent scratch storage reused across calls and swapped with the final limited-gradient container before gradient assembly returns.

Parameters
limiter_typeThe limiter type whose temporary storage is being accessed.

Definition at line 106 of file LinearFVGradientInterface.h.

107 {
108 return _temporary_limited_gradient[limiter_type];
109 }

Referenced by LinearSystem::computeGradients().

Member Data Documentation

◆ _raw_grad_container

std::vector<std::unique_ptr<libMesh::NumericVector<libMesh::Number> > > LinearFVGradientInterface::_raw_grad_container
protected

◆ _raw_limited_grad_containers

std::unordered_map<Moose::FV::GradientLimiterType, std::vector<std::unique_ptr<libMesh::NumericVector<libMesh::Number> > > > LinearFVGradientInterface::_raw_limited_grad_containers
protected

Persisted limited gradient components keyed by limiter type.

Definition at line 157 of file LinearFVGradientInterface.h.

Referenced by linearFVLimitedGradientContainer(), rawLinearFVLimitedGradientContainer(), rebuildLinearFVGradientStorage(), and requestLinearFVLimitedGradients().

◆ _requested_limited_gradient_types

std::unordered_set<Moose::FV::GradientLimiterType> LinearFVGradientInterface::_requested_limited_gradient_types
protected

Set of requested limiter types for which limited gradients should be computed.

Definition at line 148 of file LinearFVGradientInterface.h.

Referenced by rebuildLinearFVGradientStorage(), requestedLinearFVLimitedGradientTypes(), and requestLinearFVLimitedGradients().

◆ _requested_limited_gradient_variables

std::unordered_map<Moose::FV::GradientLimiterType, std::unordered_set<unsigned int> > LinearFVGradientInterface::_requested_limited_gradient_variables
protected

Variable numbers requesting limited gradients, keyed by limiter type.

Definition at line 152 of file LinearFVGradientInterface.h.

Referenced by requestedLinearFVLimitedGradientVariables(), and requestLinearFVLimitedGradients().

◆ _sys

SystemBase& LinearFVGradientInterface::_sys
protected

◆ _temporary_gradient

std::vector<std::unique_ptr<libMesh::NumericVector<libMesh::Number> > > LinearFVGradientInterface::_temporary_gradient
protected

Scratch storage for raw gradients assembled during the current compute pass.

Definition at line 142 of file LinearFVGradientInterface.h.

Referenced by rebuildLinearFVGradientStorage(), and temporaryLinearFVGradientContainer().

◆ _temporary_limited_gradient

std::unordered_map<Moose::FV::GradientLimiterType, std::vector<std::unique_ptr<libMesh::NumericVector<libMesh::Number> > > > LinearFVGradientInterface::_temporary_limited_gradient
protected

Scratch storage for limited gradients assembled during the current compute pass.

Definition at line 162 of file LinearFVGradientInterface.h.

Referenced by rebuildLinearFVGradientStorage(), requestLinearFVLimitedGradients(), and temporaryLinearFVLimitedGradientContainer().


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