LCOV - code coverage report
Current view: top level - src/postprocessors - HomogenizedThermalConductivity.C (source / functions) Hit Total Coverage
Test: idaholab/moose heat_transfer: #31405 (292dce) with base fef103 Lines: 55 59 93.2 %
Date: 2025-09-04 07:53:51 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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 "HomogenizedThermalConductivity.h"
      11             : #include "SubProblem.h"
      12             : #include "MooseMesh.h"
      13             : 
      14             : registerMooseObject("HeatTransferApp", HomogenizedThermalConductivity);
      15             : 
      16             : InputParameters
      17         585 : HomogenizedThermalConductivity::validParams()
      18             : {
      19         585 :   InputParameters params = ElementIntegralPostprocessor::validParams();
      20         585 :   params.addClassDescription(
      21             :       "Postprocessor for asymptotic expansion homogenization for thermal conductivity");
      22        1170 :   params.addRequiredCoupledVar(
      23             :       "chi", "The characteristic functions used for homogenization of the thermal conductivity.");
      24        1170 :   params.addRequiredParam<unsigned int>(
      25             :       "row",
      26             :       "The row index of the homogenized thermal conductivity tensor entry computed by this "
      27             :       "postprocessor.");
      28        1170 :   params.addRequiredParam<unsigned int>(
      29             :       "col",
      30             :       "The column index of the homogenized thermal conductivity tensor entry computed by this "
      31             :       "postprocessor.");
      32             : 
      33        1170 :   params.addParam<Real>("scale_factor", 1, "Scale factor");
      34        1170 :   params.addParam<MaterialPropertyName>(
      35             :       "diffusion_coefficient", "thermal_conductivity", "Property name of the diffusivity");
      36        1170 :   params.addParam<bool>(
      37        1170 :       "is_tensor", false, "True if the material property in diffusion_coefficient is a tensor");
      38         585 :   return params;
      39           0 : }
      40             : 
      41         314 : HomogenizedThermalConductivity::HomogenizedThermalConductivity(const InputParameters & parameters)
      42             :   : ElementIntegralPostprocessor(parameters),
      43         314 :     _row(getParam<unsigned int>("row")),
      44         628 :     _col(getParam<unsigned int>("col")),
      45         628 :     _scale(getParam<Real>("scale_factor")),
      46         314 :     _dim(_mesh.dimension()),
      47         314 :     _diffusion_coefficient(!getParam<bool>("is_tensor")
      48         766 :                                ? &getMaterialProperty<Real>("diffusion_coefficient")
      49             :                                : nullptr),
      50         628 :     _tensor_diffusion_coefficient(getParam<bool>("is_tensor")
      51         490 :                                       ? &getMaterialProperty<RankTwoTensor>("diffusion_coefficient")
      52         314 :                                       : nullptr)
      53             : {
      54         314 :   if (_row >= _dim)
      55           0 :     paramError("row", "Must be smaller than mesh dimension (0, 1, 2 for 1D, 2D, 3D)");
      56             : 
      57         314 :   if (_col >= _dim)
      58           0 :     paramError("col", "Must be smaller than mesh dimension (0, 1, 2 for 1D, 2D, 3D)");
      59             : 
      60         314 :   if (coupledComponents("chi") != _dim)
      61           0 :     paramError("chi", "The number of entries must be identical to the mesh dimension.");
      62             : 
      63         314 :   _grad_chi.resize(_dim);
      64        1140 :   for (unsigned int j = 0; j < _dim; ++j)
      65         826 :     _grad_chi[j] = &coupledGradient("chi", j);
      66         314 : }
      67             : 
      68             : void
      69         486 : HomogenizedThermalConductivity::initialize()
      70             : {
      71         486 :   _integral_value = 0.0;
      72         486 :   _volume = 0.0;
      73         486 : }
      74             : 
      75             : void
      76      147744 : HomogenizedThermalConductivity::execute()
      77             : {
      78      147744 :   _integral_value += computeIntegral();
      79      147744 :   _volume += _current_elem_volume;
      80      147744 : }
      81             : 
      82             : Real
      83         400 : HomogenizedThermalConductivity::getValue() const
      84             : {
      85         400 :   return _integral_value / _volume;
      86             : }
      87             : 
      88             : void
      89         400 : HomogenizedThermalConductivity::finalize()
      90             : {
      91         400 :   gatherSum(_integral_value);
      92         400 :   gatherSum(_volume);
      93         400 : }
      94             : 
      95             : void
      96          86 : HomogenizedThermalConductivity::threadJoin(const UserObject & y)
      97             : {
      98             :   const auto & pps = static_cast<const HomogenizedThermalConductivity &>(y);
      99             : 
     100          86 :   _integral_value += pps._integral_value;
     101          86 :   _volume += pps._volume;
     102          86 : }
     103             : 
     104             : Real
     105     1119744 : HomogenizedThermalConductivity::computeQpIntegral()
     106             : {
     107             :   // the _row-th row of the thermal conductivity tensor
     108             :   RealVectorValue k_row;
     109     1119744 :   if (_diffusion_coefficient)
     110     1078272 :     k_row(_row) = (*_diffusion_coefficient)[_qp];
     111             :   else
     112      124416 :     for (unsigned int j = 0; j < _dim; ++j)
     113       82944 :       k_row(j) = (*_tensor_diffusion_coefficient)[_qp](_row, j);
     114             : 
     115             :   // initialize the dchi/dx tensor, but we only use _col-th column
     116             :   RealVectorValue M_col;
     117     1119744 :   M_col(_col) = 1.0;
     118     4416768 :   for (unsigned int i = 0; i < _dim; ++i)
     119     3297024 :     M_col(i) += (*_grad_chi[_col])[_qp](i);
     120             : 
     121     1119744 :   return _scale * k_row * M_col;
     122             : }

Generated by: LCOV version 1.14