https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BoundaryLinearFVFluxIntegral.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
12#include "LinearFVFluxKernel.h"
13#include <set>
14
16
19{
21 params.addRequiredParam<std::vector<std::string>>(
22 "linearfvkernels", "List of LinearFVFluxKernels whose boundary fluxes are integrated.");
24 "Computes the side integral of selected LinearFVFluxKernel boundary flux contributions.");
25 return params;
26}
27
29 : SideIntegralPostprocessor(parameters),
30 _kernel_names(getParam<std::vector<std::string>>("linearfvkernels")),
31 _variable_number(0),
32 _system_number(0)
33{
34 _qp_integration = false;
35
36 if (_kernel_names.empty())
37 paramError("linearfvkernels", "At least one kernel must be provided.");
38}
39
40void
42{
44
45 // Kernels are constructed after postprocessors, so we fetch them here.
46 auto base_query = _fe_problem.theWarehouse()
47 .query()
48 .condition<AttribSystem>("LinearFVFluxKernel")
49 .condition<AttribThread>(_tid);
50
51 _kernel_objects.clear();
52 for (const auto & name : _kernel_names)
53 {
54 std::vector<LinearFVFluxKernel *> kernels;
55 auto query = base_query.clone();
56 query.condition<AttribName>(name).queryInto(kernels);
57 if (kernels.empty())
58 paramError("linearfvkernels",
59 "The given LinearFVFluxKernel with name '",
60 name,
61 "' was not found! This can be due to the kernel not existing in the "
62 "'LinearFVKernels' block or the kernel not inheriting from LinearFVFluxKernel.");
63
64 _kernel_objects.push_back(kernels[0]);
65 }
66
67 // Cache shared variable metadata and verify all kernels act on that same variable.
68 const auto & first_variable = _kernel_objects.front()->variable();
69 _variable_name = first_variable.name();
70 _variable_number = first_variable.number();
71 _system_number = first_variable.sys().number();
72
73 for (const auto kernel_ptr : _kernel_objects)
74 if (kernel_ptr->variable().name() != _variable_name)
75 paramError("linearfvkernels",
76 "All kernels in 'linearfvkernels' must act on the same variable name. The "
77 "kernel '",
78 kernel_ptr->name(),
79 "' acts on variable '",
80 kernel_ptr->variable().name(),
81 "', while the first kernel acts on variable '",
83 "'.");
84
85 // Postprocessors run initialSetup before variable-side BC caches are guaranteed ready,
86 // so we resolve BCs directly from the warehouse.
87 auto bc_query = _fe_problem.theWarehouse()
88 .query()
89 .condition<AttribSystem>("LinearFVBoundaryCondition")
90 .condition<AttribThread>(_tid)
91 .condition<AttribVar>(_variable_number)
92 .condition<AttribSysNum>(_system_number);
93
94 _boundary_bcs.clear();
95 for (const auto boundary_id : boundaryIDs())
96 {
97 std::vector<LinearFVBoundaryCondition *> bcs;
98 auto bc_query_copy = bc_query;
99 bc_query_copy.condition<AttribBoundaries>(std::set<BoundaryID>({boundary_id})).queryInto(bcs);
100
101 if (bcs.empty())
102 paramError("linearfvkernels",
103 "Variable '",
105 "' does not have a LinearFVBoundaryCondition on boundary '",
106 _mesh.getBoundaryName(boundary_id),
107 "'.");
108
109 if (bcs.size() > 1)
110 paramError("linearfvkernels",
111 "Variable '",
113 "' has multiple LinearFVBoundaryCondition objects on boundary '",
114 _mesh.getBoundaryName(boundary_id),
115 "', which is not currently supported.");
116
117 _boundary_bcs.emplace(boundary_id, bcs[0]);
118 }
119}
120
121Real
123{
124 mooseAssert(fi, "FaceInfo should not be null.");
125 mooseAssert(fi->boundaryIDs().size() == 1, "Expected exactly one boundary per face.");
126
127 const auto boundary_id = *fi->boundaryIDs().begin();
128 const auto face_type = fi->faceType(std::make_pair(_variable_number, _system_number));
129 if (face_type != FaceInfo::VarFaceNeighbors::ELEM &&
131 mooseError("Cannot compute boundary flux on boundary '",
132 _mesh.getBoundaryName(boundary_id),
133 "' because the variable face type is not boundary-only.");
134
135 auto * const bc = libmesh_map_find(_boundary_bcs, boundary_id);
136 bc->setupFaceData(fi, face_type);
137
138 Real flux_value = 0.0;
139 for (const auto kernel_ptr : _kernel_objects)
140 {
141 kernel_ptr->setupFaceData(fi);
142 // SideIntegralPostprocessor multiplies by geometric factors, so we just do 1 here.
143 kernel_ptr->setCurrentFaceArea(1.0);
144 flux_value += kernel_ptr->computeBoundaryFlux(*bc);
145 }
146
147 return flux_value;
148}
149
150Real
152{
153 mooseError("We should never call this function.");
154}
registerMooseObject("MooseApp", BoundaryLinearFVFluxIntegral)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
AttribBoundaries tracks all boundary IDs associated with an object.
Definition Attributes.h:190
Computes the side integral of fluxes from selected LinearFVFluxKernel objects.
unsigned int _system_number
Cached system number for all kernels (must be the same)
const std::vector< std::string > & _kernel_names
Names of the kernels whose boundary flux we want to integrate.
std::string _variable_name
Cached variable name for all kernels (must be the same)
virtual Real computeFaceInfoIntegral(const FaceInfo *fi) override
BoundaryLinearFVFluxIntegral(const InputParameters &parameters)
std::vector< LinearFVFluxKernel * > _kernel_objects
Kernel objects to integrate.
std::unordered_map< BoundaryID, LinearFVBoundaryCondition * > _boundary_bcs
Cached BC pointers on requested boundaries.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
unsigned int _variable_number
Cached variable number for all kernels (must be the same)
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
TheWarehouse & theWarehouse() const
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
Returns which side(s) the given variable-system number pair is defined on for this face.
Definition FaceInfo.h:229
const std::set< BoundaryID > & boundaryIDs() const
Const getter for every associated boundary ID.
Definition FaceInfo.h:124
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
const std::string & getBoundaryName(const BoundaryID boundary_id) const
Return the name of the boundary given the id.
Definition MooseMesh.C:1780
This postprocessor computes a surface integral of the specified variable on a sideset on the boundary...
bool _qp_integration
Whether to integrate over quadrature points or FaceInfos.
static InputParameters validParams()
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
MooseMesh & _mesh
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
const THREAD_ID _tid
Thread ID of this postprocessor.
query_obj query