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 12394 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::validParams() 23 : { 24 12394 : InputParameters params = InterfaceIntegralPostprocessor::validParams(); 25 : 26 49576 : params.addRequiredCoupledVar("variable", 27 : "The name of the variable on the primary side of the interface"); 28 49576 : params.addCoupledVar("neighbor_variable", 29 : "The name of the variable on the secondary side of the interface."); 30 49576 : params.addRequiredParam<MaterialPropertyName>( 31 : "diffusivity", "The name of the diffusivity property on the primary side of the interface"); 32 49576 : 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 49576 : MooseEnum interp_method("average harmonic", "harmonic"); 38 49576 : params.addParam<MooseEnum>( 39 : "coeff_interp_method", 40 : interp_method, 41 : "Switch that can select face interpolation method for diffusion coefficients."); 42 12394 : params.addClassDescription("Computes the diffusive flux on the interface."); 43 : 44 24788 : return params; 45 12394 : } 46 : 47 : template <bool is_ad> 48 78 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::InterfaceDiffusiveFluxIntegralTempl( 49 : const InputParameters & parameters) 50 : : InterfaceIntegralPostprocessor(parameters), 51 78 : _grad_u(coupledGradient("variable")), 52 234 : _u(coupledValue("variable")), 53 78 : _u_neighbor(parameters.isParamSetByUser("neighbor_variable") 54 286 : ? coupledNeighborValue("neighbor_variable") 55 104 : : coupledNeighborValue("variable")), 56 78 : _diffusion_coef( 57 234 : getGenericMaterialProperty<Real, is_ad>(getParam<MaterialPropertyName>("diffusivity"))), 58 156 : _diffusion_coef_neighbor(parameters.isParamSetByUser("neighbor_diffusivity") 59 78 : ? getGenericNeighborMaterialProperty<Real, is_ad>( 60 78 : getParam<MaterialPropertyName>("neighbor_diffusivity")) 61 78 : : getGenericNeighborMaterialProperty<Real, is_ad>( 62 390 : getParam<MaterialPropertyName>("diffusivity"))) 63 : { 64 : 65 : // Primary and secondary variable should both be of a similar variable type 66 156 : if (parameters.isParamSetByUser("neighbor_variable")) 67 273 : if ((_has_fv_vars && !getFieldVar("neighbor_variable", 0)->isFV()) || 68 182 : (!_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 130 : 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 156 : const auto & interp_method = getParam<MooseEnum>("coeff_interp_method"); 78 78 : if (interp_method == "average") 79 13 : _coeff_interp_method = Moose::FV::InterpMethod::Average; 80 65 : else if (interp_method == "harmonic") 81 65 : _coeff_interp_method = Moose::FV::InterpMethod::HarmonicAverage; 82 78 : } 83 : 84 : template <bool is_ad> 85 : Real 86 400 : InterfaceDiffusiveFluxIntegralTempl<is_ad>::computeQpIntegral() 87 : { 88 400 : if (_has_fv_vars) 89 : { 90 : mooseAssert(_fi, "This should never be null. If it is then something went wrong in execute()"); 91 : 92 176 : const auto normal = _fi->normal(); 93 : 94 : // Form a finite difference gradient across the interface 95 176 : Point one_over_gradient_support = _fi->elemCentroid() - _fi->neighborCentroid(); 96 176 : one_over_gradient_support /= (one_over_gradient_support * one_over_gradient_support); 97 176 : const auto gradient = (_u[_qp] - _u_neighbor[_qp]) * one_over_gradient_support; 98 : 99 : Real diffusivity; 100 176 : interpolate(_coeff_interp_method, 101 : diffusivity, 102 176 : MetaPhysicL::raw_value(_diffusion_coef[_qp]), 103 176 : MetaPhysicL::raw_value(_diffusion_coef_neighbor[_qp]), 104 176 : *_fi, 105 : true); 106 : 107 176 : return -diffusivity * MetaPhysicL::raw_value(gradient * normal); 108 : } 109 : else 110 224 : return -MetaPhysicL::raw_value(_diffusion_coef[_qp]) * _grad_u[_qp] * _normals[_qp]; 111 : } 112 : 113 : template class InterfaceDiffusiveFluxIntegralTempl<false>; 114 : template class InterfaceDiffusiveFluxIntegralTempl<true>;