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 : #include "LinearFVAdvectionDiffusionExtrapolatedBC.h" 11 : 12 : registerMooseObject("MooseApp", LinearFVAdvectionDiffusionExtrapolatedBC); 13 : 14 : InputParameters 15 7040 : LinearFVAdvectionDiffusionExtrapolatedBC::validParams() 16 : { 17 7040 : InputParameters params = LinearFVAdvectionDiffusionBC::validParams(); 18 14080 : params.addClassDescription( 19 : "Adds a boundary condition which calculates the face values and face gradients assuming one " 20 : "or two term expansions from the cell centroid. This kernel is only compatible " 21 : "with advection-diffusion problems."); 22 14080 : params.addParam<bool>( 23 : "use_two_term_expansion", 24 14080 : false, 25 : "If an approximate linear expansion should be used to compute the face value."); 26 7040 : return params; 27 0 : } 28 : 29 459 : LinearFVAdvectionDiffusionExtrapolatedBC::LinearFVAdvectionDiffusionExtrapolatedBC( 30 459 : const InputParameters & parameters) 31 : : LinearFVAdvectionDiffusionBC(parameters), 32 918 : _two_term_expansion(getParam<bool>("use_two_term_expansion")) 33 : { 34 459 : if (_two_term_expansion) 35 359 : _var.computeCellGradients(); 36 459 : } 37 : 38 : Real 39 1115550 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValue() const 40 : { 41 : // We allow internal boundaries too so we need to check which side we are on 42 1115550 : const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM 43 1115550 : ? _current_face_info->elemInfo() 44 0 : : _current_face_info->neighborInfo(); 45 1115550 : const auto state = determineState(); 46 : 47 : // By default we approximate the boundary value with the neighboring cell value 48 1115550 : auto boundary_value = _var.getElemValue(*elem_info, state); 49 : 50 : // If we request linear extrapolation, we add the gradient term as well 51 1115550 : if (_two_term_expansion) 52 929826 : boundary_value += _var.gradSln(*elem_info, state) * computeCellToFaceVector(); 53 : 54 1115550 : return boundary_value; 55 : } 56 : 57 : Real 58 0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryNormalGradient() const 59 : { 60 : // By default we assume that the face value is the same as the cell center value so we 61 : // have a zero gradient. 62 0 : Real normal_gradient = 0.0; 63 : 64 : // If we request linear extrapolation, we will have a gradient. We use 65 0 : if (_two_term_expansion) 66 : { 67 0 : const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM 68 0 : ? _current_face_info->elemInfo() 69 0 : : _current_face_info->neighborInfo(); 70 0 : normal_gradient = _var.gradSln(*elem_info, determineState()) * _current_face_info->normal(); 71 : } 72 0 : return normal_gradient; 73 : } 74 : 75 : Real 76 620085 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValueMatrixContribution() const 77 : { 78 620085 : return 1.0; 79 : } 80 : 81 : Real 82 620085 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValueRHSContribution() const 83 : { 84 : // If we approximate the face value with the cell value, we 85 : // don't need to add anything to the right hand side 86 620085 : Real contribution = 0.0; 87 : 88 : // If we have linear extrapolation, we chose to add the linear term to 89 : // the right hand side instead of the system matrix. 90 620085 : if (_two_term_expansion) 91 : { 92 464913 : const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM 93 464913 : ? _current_face_info->elemInfo() 94 0 : : _current_face_info->neighborInfo(); 95 464913 : contribution = _var.gradSln(*elem_info, determineState()) * computeCellToFaceVector(); 96 : } 97 : 98 620085 : return contribution; 99 : } 100 : 101 : Real 102 0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryGradientMatrixContribution() const 103 : { 104 0 : return 1.0 / computeCellToFaceDistance(); 105 : } 106 : 107 : Real 108 0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryGradientRHSContribution() const 109 : { 110 0 : return computeBoundaryValue() / computeCellToFaceDistance(); 111 : }