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 "InterfaceDiffusiveFluxIntegral.h" 11 : #include "MathFVUtils.h" 12 : #include "FaceInfo.h" 13 : 14 : #include "libmesh/remote_elem.h" 15 : #include "metaphysicl/raw_type.h" 16 : 17 : registerMooseObject("MooseApp", InterfaceDiffusiveFluxIntegral); 18 : registerMooseObject("MooseApp", ADInterfaceDiffusiveFluxIntegral); 19 : 20 : template <bool is_ad> 21 : InputParameters 22 57222 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::validParams() 23 : { 24 57222 : InputParameters params = InterfaceIntegralPostprocessor::validParams(); 25 : 26 57222 : params.addRequiredCoupledVar("variable", 27 : "The name of the variable on the primary side of the interface"); 28 57222 : params.addCoupledVar("neighbor_variable", 29 : "The name of the variable on the secondary side of the interface."); 30 57222 : params.addRequiredParam<MaterialPropertyName>( 31 : "diffusivity", "The name of the diffusivity property on the primary side of the interface"); 32 57222 : params.addParam<MaterialPropertyName>("neighbor_diffusivity", 33 : "The name of the diffusivity property on the secondary " 34 : "side of the interface. By default, the " 35 : "primary side material property name is used for the " 36 : "secondary side. Only needed for finite volume"); 37 57222 : MooseEnum interp_method("average harmonic", "harmonic"); 38 57222 : params.addParam<MooseEnum>( 39 : "coeff_interp_method", 40 : interp_method, 41 : "Switch that can select face interpolation method for diffusion coefficients."); 42 57222 : params.addClassDescription("Computes the diffusive flux on the interface."); 43 : 44 114444 : return params; 45 57222 : } 46 : 47 : template <bool is_ad> 48 84 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::InterfaceDiffusiveFluxIntegralTempl( 49 : const InputParameters & parameters) 50 : : InterfaceIntegralPostprocessor(parameters), 51 84 : _grad_u(coupledGradient("variable")), 52 84 : _u(coupledValue("variable")), 53 168 : _u_neighbor(parameters.isParamSetByUser("neighbor_variable") 54 168 : ? coupledNeighborValue("neighbor_variable") 55 84 : : coupledNeighborValue("variable")), 56 84 : _diffusion_coef( 57 84 : getGenericMaterialProperty<Real, is_ad>(getParam<MaterialPropertyName>("diffusivity"))), 58 168 : _diffusion_coef_neighbor(parameters.isParamSetByUser("neighbor_diffusivity") 59 84 : ? getGenericNeighborMaterialProperty<Real, is_ad>( 60 84 : getParam<MaterialPropertyName>("neighbor_diffusivity")) 61 84 : : getGenericNeighborMaterialProperty<Real, is_ad>( 62 252 : getParam<MaterialPropertyName>("diffusivity"))) 63 : { 64 : 65 : // Primary and secondary variable should both be of a similar variable type 66 84 : if (parameters.isParamSetByUser("neighbor_variable")) 67 210 : if ((_has_fv_vars && !getFieldVar("neighbor_variable", 0)->isFV()) || 68 140 : (!_has_fv_vars && getFieldVar("neighbor_variable", 0)->isFV())) 69 0 : mooseError("For the InterfaceDiffusiveFluxIntegral, variable and " 70 : "neighbor_variable should be of a similar variable type."); 71 : 72 84 : if (!_has_fv_vars && parameters.isParamSetByUser("coeff_interp_method")) 73 0 : paramError( 74 : "coeff_interp_method", 75 : "This parameter should not be defined for the postprocessing of finite element variables!"); 76 : 77 84 : const auto & interp_method = getParam<MooseEnum>("coeff_interp_method"); 78 84 : if (interp_method == "average") 79 14 : _coeff_interp_method = Moose::FV::InterpMethod::Average; 80 70 : else if (interp_method == "harmonic") 81 70 : _coeff_interp_method = Moose::FV::InterpMethod::HarmonicAverage; 82 84 : } 83 : 84 : template <bool is_ad> 85 : Real 86 450 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::computeQpIntegral() 87 : { 88 450 : if (_has_fv_vars) 89 : { 90 : mooseAssert(_fi, "This should never be null. If it is then something went wrong in execute()"); 91 : 92 198 : const auto normal = _fi->normal(); 93 : 94 : // Form a finite difference gradient across the interface 95 198 : Point one_over_gradient_support = _fi->elemCentroid() - _fi->neighborCentroid(); 96 198 : one_over_gradient_support /= (one_over_gradient_support * one_over_gradient_support); 97 198 : const auto gradient = (_u[_qp] - _u_neighbor[_qp]) * one_over_gradient_support; 98 : 99 : Real diffusivity; 100 198 : interpolate(_coeff_interp_method, 101 : diffusivity, 102 198 : MetaPhysicL::raw_value(_diffusion_coef[_qp]), 103 198 : MetaPhysicL::raw_value(_diffusion_coef_neighbor[_qp]), 104 198 : *_fi, 105 : true); 106 : 107 198 : return -diffusivity * MetaPhysicL::raw_value(gradient * normal); 108 : } 109 : else 110 252 : return -MetaPhysicL::raw_value(_diffusion_coef[_qp]) * _grad_u[_qp] * _normals[_qp]; 111 : } 112 : 113 : template class InterfaceDiffusiveFluxIntegralTempl<false>; 114 : template class InterfaceDiffusiveFluxIntegralTempl<true>;