Line data Source code
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 : #pragma once 11 : 12 : #include "FVKernel.h" 13 : #include "MathFVUtils.h" 14 : #include "NeighborCoupleable.h" 15 : #include "TwoMaterialPropertyInterface.h" 16 : #include "NeighborMooseVariableInterface.h" 17 : #include "NeighborCoupleableMooseVariableDependencyIntermediateInterface.h" 18 : #include "FVFaceResidualObject.h" 19 : #include "FaceArgInterface.h" 20 : 21 : class FaceInfo; 22 : 23 : /// FVFluxKernel is used for calculating residual contributions from numerical 24 : /// fluxes from surface integral terms in a finite volume discretization of a 25 : /// PDE (i.e. terms where the divergence theorem is applied). As with finite 26 : /// element kernels, all solution values and material properties must be 27 : /// indexed using the _qp member. Note that all interfaces for finite volume 28 : /// kernels are AD-based - be sure to use AD material properties and other AD 29 : /// values to maintain good jacobian/derivative quality. 30 : class FVFluxKernel : public FVKernel, 31 : public TwoMaterialPropertyInterface, 32 : public NeighborMooseVariableInterface<Real>, 33 : public NeighborCoupleableMooseVariableDependencyIntermediateInterface, 34 : public FVFaceResidualObject, 35 : public FaceArgProducerInterface 36 : { 37 : public: 38 : static InputParameters validParams(); 39 : FVFluxKernel(const InputParameters & params); 40 : 41 : void computeResidual() override; 42 : void computeJacobian() override; 43 : void computeResidualAndJacobian() override; 44 : void computeResidual(const FaceInfo & fi) override; 45 : void computeJacobian(const FaceInfo & fi) override; 46 : void computeResidualAndJacobian(const FaceInfo & fi) override; 47 : 48 4083 : const MooseVariableFV<Real> & variable() const override { return _var; } 49 : 50 : bool hasFaceSide(const FaceInfo & fi, const bool fi_elem_side) const override; 51 : 52 : protected: 53 : /// This is the primary function that must be implemented for flux kernel 54 : /// terms. Material properties will be initialized on the face - using any 55 : /// reconstructed fv variable gradients if any. Values for the solution are 56 : /// provided for both the elem and neighbor side of the face. 57 : virtual ADReal computeQpResidual() = 0; 58 : 59 : /// Calculates and returns "grad_u dot normal" on the face to be used for 60 : /// diffusive terms. If using any cross-diffusion corrections, etc. all 61 : /// those calculations will be handled for appropriately by this function. 62 : virtual ADReal gradUDotNormal(const Moose::StateArg & time, const bool correct_skewness) const; 63 : 64 : /// Kernels are called even on boundaries in case one is for a variable with 65 : /// a dirichlet BC - in which case we need to run the kernel with a 66 : /// ghost-element. This returns true if we need to run because of dirichlet 67 : /// conditions - otherwise this returns false and all jacobian/residual calcs 68 : /// should be skipped. 69 : virtual bool skipForBoundary(const FaceInfo & fi) const; 70 : 71 : const RealVectorValue & normal() const { return _normal; } 72 : 73 : MooseVariableFV<Real> & _var; 74 : 75 : const unsigned int _qp = 0; 76 : 77 : /// This is the outward unit normal vector for the face the kernel is currently 78 : /// operating on. By convention, this is set to be pointing outward from the 79 : /// face's elem element and residual calculations should keep this in mind. 80 : RealVectorValue _normal; 81 : 82 : /// This is holds meta-data for geometric information relevant to the current 83 : /// face including elem+neighbor cell centroids, cell volumes, face area, etc. 84 : const FaceInfo * _face_info = nullptr; 85 : 86 : /// The face type 87 : FaceInfo::VarFaceNeighbors _face_type; 88 : 89 : /** 90 : * Return whether the supplied face is on a boundary of this object's execution 91 : */ 92 : bool onBoundary(const FaceInfo & fi) const; 93 : 94 : /** 95 : * @return an element argument corresponding to the face info elem 96 : */ 97 : Moose::ElemArg elemArg(bool correct_skewness = false) const; 98 : 99 : /** 100 : * @return an element argument corresponding to the face info neighbor 101 : */ 102 : Moose::ElemArg neighborArg(bool correct_skewness = false) const; 103 : 104 : /** 105 : * Determine the single sided face argument when evaluating a functor on a face. 106 : * This is used to perform evaluations of material properties with the actual face values of 107 : * their dependences, rather than interpolate the material property to the boundary. 108 : * @param fi the FaceInfo for this face 109 : * @param limiter_type the limiter type, to be specified if more than the default average 110 : * interpolation is required for the parameters of the functor 111 : * @param correct_skewness whether to perform skew correction at the face 112 : */ 113 : Moose::FaceArg singleSidedFaceArg( 114 : const FaceInfo * fi = nullptr, 115 : Moose::FV::LimiterType limiter_type = Moose::FV::LimiterType::CentralDifference, 116 : bool correct_skewness = false, 117 : const Moose::StateArg * state_limiter = nullptr) const; 118 : 119 : /** 120 : * Returns whether to avoid execution on a boundary 121 : * @param fi the FaceInformation currently considered 122 : */ 123 : bool avoidBoundary(const FaceInfo & fi) const; 124 : 125 : /// Which boundaries/sidesets to force the execution of flux kernels on 126 : std::unordered_set<BoundaryID> _boundaries_to_force; 127 : 128 : private: 129 : /// Whether to force execution of flux kernels on all external boundaries 130 : const bool _force_boundary_execution; 131 : 132 : /// Which boundaries/sidesets to prevent the execution of flux kernels on 133 : std::unordered_set<BoundaryID> _boundaries_to_avoid; 134 : };