LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVGreenGaussGradientVolumeThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 48 60 80.0 %
Date: 2026-05-29 20:35:17 Functions: 2 4 50.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 "ComputeLinearFVGreenGaussGradientVolumeThread.h"
      11             : #include "LinearFVBoundaryCondition.h"
      12             : #include "SystemBase.h"
      13             : #include "PetscVectorReader.h"
      14             : #include "FEProblemBase.h"
      15             : 
      16       43577 : ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread(
      17             :     FEProblemBase & fe_problem,
      18             :     SystemBase & system,
      19       43577 :     std::vector<std::unique_ptr<NumericVector<Number>>> & temporary_gradient)
      20       43577 :   : _fe_problem(fe_problem),
      21       43577 :     _dim(_fe_problem.mesh().dimension()),
      22       43577 :     _system(system),
      23       43577 :     _libmesh_system(system.system()),
      24       43577 :     _system_number(_libmesh_system.number()),
      25       43577 :     _temporary_gradient(temporary_gradient)
      26             : {
      27       43577 : }
      28             : 
      29           0 : ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread(
      30           0 :     ComputeLinearFVGreenGaussGradientVolumeThread & x, Threads::split /*split*/)
      31           0 :   : _fe_problem(x._fe_problem),
      32           0 :     _dim(x._dim),
      33           0 :     _system(x._system),
      34           0 :     _libmesh_system(x._libmesh_system),
      35           0 :     _system_number(x._system_number),
      36           0 :     _temporary_gradient(x._temporary_gradient)
      37             : {
      38           0 : }
      39             : 
      40             : void
      41       43577 : ComputeLinearFVGreenGaussGradientVolumeThread::operator()(const ElemInfoRange & range)
      42             : {
      43       43577 :   ParallelUniqueId puid;
      44       43577 :   _tid = puid.id;
      45             : 
      46             :   // Computing this size can be very expensive so we only want to do it once
      47       43577 :   unsigned int size = 0;
      48             : 
      49       87154 :   for (const auto & variable : _system.getVariables(_tid))
      50             :   {
      51       43577 :     _current_var = dynamic_cast<MooseLinearVariableFV<Real> *>(variable);
      52       43577 :     if (!_current_var)
      53           0 :       continue;
      54             : 
      55       43577 :     if (_current_var->needsGradientVectorStorage())
      56             :     {
      57       43577 :       if (!size)
      58       43577 :         size = range.size();
      59             : 
      60       43577 :       const auto rz_radial_coord = _fe_problem.mesh().getAxisymmetricRadialCoord();
      61       43577 :       const auto state = Moose::currentState();
      62             : 
      63       43577 :       std::vector<std::vector<Real>> temporary_values(_temporary_gradient.size(),
      64       43577 :                                                       std::vector<Real>(size, 0.0));
      65       43577 :       std::vector<dof_id_type> dof_indices(size, 0);
      66             :       {
      67       43577 :         std::vector<PetscVectorReader> grad_reader;
      68      121291 :         for (const auto dim_index : index_range(_temporary_gradient))
      69       77714 :           grad_reader.emplace_back(*_temporary_gradient[dim_index]);
      70             : 
      71             :         // Iterate over all the elements in the range
      72       43577 :         auto elem_iterator = range.begin();
      73    51168815 :         for (const auto elem_i : make_range(size))
      74             :         {
      75    51125238 :           const auto & elem_info = *elem_iterator;
      76    51125238 :           if (_current_var->hasBlocks(elem_info->subdomain_id()))
      77             :           {
      78    51125238 :             const auto coord_type = _fe_problem.mesh().getCoordSystem(elem_info->subdomain_id());
      79             : 
      80             :             mooseAssert(coord_type != Moose::CoordinateSystemType::COORD_RSPHERICAL,
      81             :                         "We have not yet implemented the correct translation from gradient to "
      82             :                         "divergence for "
      83             :                         "spherical coordinates yet.");
      84             : 
      85    51125238 :             dof_indices[elem_i] = elem_info->dofIndices()[_system_number][_current_var->number()];
      86    51125238 :             const auto volume = elem_info->volume() * elem_info->coordFactor();
      87             : 
      88   153265012 :             for (const auto dim_index : index_range(_temporary_gradient))
      89   102139774 :               temporary_values[dim_index][elem_i] =
      90   102139774 :                   grad_reader[dim_index](dof_indices[elem_i]) / volume;
      91             : 
      92    51125238 :             if (coord_type == Moose::CoordinateSystemType::COORD_RZ)
      93             :             {
      94             :               mooseAssert(elem_info->centroid()(rz_radial_coord) != 0,
      95             :                           "Axisymmetric control volumes should not have a zero radial coordinate");
      96      143220 :               temporary_values[rz_radial_coord][elem_i] -=
      97      143220 :                   _current_var->getElemValue(*elem_info, state) /
      98      143220 :                   elem_info->centroid()(rz_radial_coord);
      99             :             }
     100             :           }
     101    51125238 :           elem_iterator++;
     102             :         }
     103       43577 :       }
     104      121291 :       for (const auto dim_index : index_range(_temporary_gradient))
     105             :       {
     106       77714 :         _temporary_gradient[dim_index]->zero();
     107       77714 :         _temporary_gradient[dim_index]->add_vector(temporary_values[dim_index].data(), dof_indices);
     108             :       }
     109       43577 :     }
     110             :   }
     111       43577 : }
     112             : 
     113             : void
     114           0 : ComputeLinearFVGreenGaussGradientVolumeThread::join(
     115             :     const ComputeLinearFVGreenGaussGradientVolumeThread & /*y*/)
     116             : {
     117           0 : }

Generated by: LCOV version 1.14