Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 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 "LinearFVAdvectionDiffusionScalarSymmetryBC.h" 11 : 12 : registerMooseObject("MooseApp", LinearFVAdvectionDiffusionScalarSymmetryBC); 13 : 14 : InputParameters 15 3277 : LinearFVAdvectionDiffusionScalarSymmetryBC::validParams() 16 : { 17 3277 : InputParameters params = LinearFVAdvectionDiffusionBC::validParams(); 18 6554 : params.addClassDescription("Adds a symmetry boundary condition for a scalar quantity."); 19 6554 : params.addParam<bool>( 20 : "use_two_term_expansion", 21 6554 : false, 22 : "If an approximate linear expansion should be used to compute the face value."); 23 3277 : return params; 24 0 : } 25 : 26 108 : LinearFVAdvectionDiffusionScalarSymmetryBC::LinearFVAdvectionDiffusionScalarSymmetryBC( 27 108 : const InputParameters & parameters) 28 : : LinearFVAdvectionDiffusionBC(parameters), 29 216 : _two_term_expansion(getParam<bool>("use_two_term_expansion")) 30 : { 31 108 : if (_two_term_expansion) 32 78 : _var.computeCellGradients(); 33 108 : } 34 : 35 : Real 36 22602 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryValue() const 37 : { 38 : // We allow internal boundaries too so we need to check which side we are on 39 22602 : const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM 40 22602 : ? _current_face_info->elemInfo() 41 0 : : _current_face_info->neighborInfo(); 42 22602 : const auto state = determineState(); 43 : 44 : // By default we approximate the boundary value with the neighboring cell value 45 22602 : auto boundary_value = _var.getElemValue(*elem_info, state); 46 : 47 : // If we request linear extrapolation, we add the gradient term as well. We make sure 48 : // that the zero normal gradient is respected (by subtracting the normal component). 49 22602 : if (_two_term_expansion) 50 : { 51 20184 : const auto cell_gradient = _var.gradSln(*elem_info, state); 52 20184 : const auto & normal = _current_face_info->normal(); 53 20184 : const auto d_cf = computeCellToFaceVector(); 54 : 55 20184 : const auto correction_vector = (d_cf - (d_cf * normal) * normal); 56 20184 : boundary_value += cell_gradient * correction_vector; 57 : } 58 : 59 22602 : return boundary_value; 60 : } 61 : 62 : Real 63 0 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryNormalGradient() const 64 : { 65 : // We don't have this on a symmetry plane 66 0 : return 0.0; 67 : } 68 : 69 : Real 70 4098 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryValueMatrixContribution() const 71 : { 72 : // No matter if we have a one-term or two-term expansion we will always 73 : // have a contribution to the matrix 74 4098 : return 1.0; 75 : } 76 : 77 : Real 78 4098 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryValueRHSContribution() const 79 : { 80 : // If we request linear extrapolation, we add the gradient term to the right hand 81 : // side. 82 4098 : if (_two_term_expansion) 83 : { 84 : // We allow internal boundaries too so we need to check which side we are on 85 4098 : const auto & elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM 86 4098 : ? _current_face_info->elemInfo() 87 0 : : _current_face_info->neighborInfo(); 88 4098 : const auto state = determineState(); 89 : 90 4098 : const auto & d_cf = computeCellToFaceVector(); 91 4098 : const auto & normal = _current_face_info->normal(); 92 4098 : const auto correction_vector = (d_cf - (d_cf * normal) * normal); 93 4098 : const auto & cell_gradient = _var.gradSln(*elem_info, state); 94 : 95 4098 : return cell_gradient * correction_vector; 96 : } 97 : 98 0 : return 0.0; 99 : } 100 : 101 : Real 102 7209 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryGradientMatrixContribution() const 103 : { 104 : // Nothing to add here, considering that we have a symmetry condition 105 7209 : return 0.0; 106 : } 107 : 108 : Real 109 7209 : LinearFVAdvectionDiffusionScalarSymmetryBC::computeBoundaryGradientRHSContribution() const 110 : { 111 : // Nothing to add here, considering that we have a symmetry condition 112 7209 : return 0.0; 113 : }