https://mooseframework.inl.gov
FVFluxBC.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 
10 #include "FVFluxBC.h"
11 #include "MooseVariableFV.h"
12 #include "SystemBase.h"
13 #include "Assembly.h"
14 #include "ADUtils.h"
15 
18 {
21  params.registerSystemAttributeName("FVFluxBC");
22 
23  // FVFluxBCs always rely on Boundary MaterialData
24  params.set<Moose::MaterialDataType>("_material_data_type") = Moose::BOUNDARY_MATERIAL_DATA;
25  params.set<bool>("_residual_object") = true;
26 
27  return params;
28 }
29 
31  : FVBoundaryCondition(parameters),
33  this, /*nodal=*/false, /*neighbor_nodal=*/false, /*is_fv=*/true),
35 {
37  paramError("variable",
38  "There should not be a need to specify a flux "
39  "boundary condition for an auxiliary variable.");
40 }
41 
42 void
44 {
45  _face_info = &fi;
46  _normal = fi.normal();
47  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
48 
49  // For FV flux kernels, the normal is always oriented outward from the lower-id
50  // element's perspective. But for BCs, there is only a residual
51  // contribution to one element (one side of the face). Because of this, we
52  // make an exception and orient the normal to point outward from whichever
53  // side of the face the BC's variable is defined on; we flip it if this
54  // variable is defined on the neighbor side of the face (instead of elem) since
55  // the FaceInfo normal polarity is always oriented with respect to the lower-id element.
57  _normal = -_normal;
58 }
59 
60 void
62 {
64 
66  mooseError("A FVFluxBC is being triggered on an internal face with centroid: ",
67  fi.faceCentroid());
69  mooseError("A FVFluxBC is being triggered on a face which does not connect to a block ",
70  "with the relevant finite volume variable. Its centroid: ",
71  fi.faceCentroid());
72 
74 
75  // This could be an "internal" boundary - one created by variable block
76  // restriction where the var is only defined on one side of the face. We
77  // need to make sure that we add the residual contribution to the correct
78  // side - the one where the variable is defined.
83 
84  _local_re(0) = r;
86 }
87 
88 void
90 {
91  computeJacobian(fi);
92 }
93 
94 void
96 {
97  _face_info = &fi;
98  _normal = fi.normal();
99  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
100 
101  // For FV flux kernels, the normal is always oriented outward from the lower-id
102  // element's perspective. But for BCs, there is only a Jacobian
103  // contribution to one element (one side of the face). Because of this, we
104  // make an exception and orient the normal to point outward from whichever
105  // side of the face the BC's variable is defined on; we flip it if this
106  // variable is defined on the neighbor side of the face (instead of elem) since
107  // the FaceInfo normal polarity is always oriented with respect to the lower-id element.
109  _normal = -_normal;
110 
111  ADReal r = fi.faceArea() * fi.faceCoord() * computeQpResidual();
112 
113  const auto & dof_indices = (_face_type == FaceInfo::VarFaceNeighbors::ELEM)
114  ? _var.dofIndices()
116 
117  mooseAssert(dof_indices.size() == 1, "We're currently built to use CONSTANT MONOMIALS");
118 
119  addResidualsAndJacobian(_assembly, std::array<ADReal, 1>{{r}}, dof_indices, _var.scalingFactor());
120 }
121 
123 FVFluxBC::elemArg(const bool correct_skewness) const
124 {
125  return {&_face_info->elem(), correct_skewness};
126 }
127 
129 FVFluxBC::neighborArg(const bool correct_skewness) const
130 {
131  return {_face_info->neighborPtr(), correct_skewness};
132 }
virtual const std::vector< dof_id_type > & dofIndicesNeighbor() const final
Get neighbor DOF indices for currently selected element.
const FaceInfo * _face_info
Holds information for the face we are currently examining.
void computeResidualAndJacobian(const FaceInfo &fi) override
Compute the residual and Jacobian on the supplied face.
Definition: FVFluxBC.C:89
FaceInfo::VarFaceNeighbors _face_type
The variable face type.
Definition: FVFluxBC.h:60
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the provided d...
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
Moose::ElemArg neighborArg(bool correct_skewness=false) const
Definition: FVFluxBC.C:129
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
static InputParameters validParams()
Definition: FVFluxBC.C:17
unsigned int number() const
Get variable number coming from libMesh.
Base class for creating new types of boundary conditions.
const Elem & elem() const
Definition: FaceInfo.h:85
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:740
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition: FaceInfo.h:75
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Assembly & _assembly
Reference to assembly.
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:100
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseVariableFV< Real > & _var
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition: FaceInfo.h:68
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:42
FVFluxBC(const InputParameters &parameters)
Definition: FVFluxBC.C:30
Real faceArea() const
Returns the face area of face id.
Definition: FaceInfo.h:64
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:37
const Elem * neighborPtr() const
Definition: FaceInfo.h:88
void updateCurrentFace(const FaceInfo &fi)
Update internal structures (normal, face type, etc) for the given face.
Definition: FVFluxBC.C:43
ADRealVectorValue _normal
Definition: FVFluxBC.h:47
A structure that is used to evaluate Moose functors logically at an element/cell center.
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:72
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1158
void prepareVectorTagNeighbor(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual the according to active tags for DG and interface kernels...
const std::set< SubdomainID > EMPTY_BLOCK_IDS
Definition: MooseTypes.h:732
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
This interface is designed for DGKernel, InternalSideUserObject, InterfaceUserObject, where material properties on a side of both its primary side (face) and its secondary side (neighbor) all required.
Moose::ElemArg elemArg(bool correct_skewness=false) const
Definition: FVFluxBC.C:123
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
static InputParameters validParams()
SystemBase & sys()
Get the system this variable is part of.
void computeJacobian(const FaceInfo &fi) override
Compute the jacobian on the supplied face.
Definition: FVFluxBC.C:95
virtual ADReal computeQpResidual()=0
void computeResidual(const FaceInfo &fi) override
Compute the residual on the supplied face.
Definition: FVFluxBC.C:61
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
virtual const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
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