LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVGreenGaussGradientVolumeThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33358 (34476d) with base 4fcf7b Lines: 48 60 80.0 %
Date: 2026-07-17 19:50:30 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       43637 : ComputeLinearFVGreenGaussGradientVolumeThread::ComputeLinearFVGreenGaussGradientVolumeThread(
      17             :     FEProblemBase & fe_problem,
      18             :     SystemBase & system,
      19       43637 :     std::vector<std::unique_ptr<NumericVector<Number>>> & temporary_gradient)
      20       43637 :   : _fe_problem(fe_problem),
      21       43637 :     _dim(_fe_problem.mesh().dimension()),
      22       43637 :     _system(system),
      23       43637 :     _libmesh_system(system.system()),
      24       43637 :     _system_number(_libmesh_system.number()),
      25       43637 :     _temporary_gradient(temporary_gradient)
      26             : {
      27       43637 : }
      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       43637 : ComputeLinearFVGreenGaussGradientVolumeThread::operator()(const ElemInfoRange & range)
      42             : {
      43       43637 :   ParallelUniqueId puid;
      44       43637 :   _tid = puid.id;
      45             : 
      46             :   // Computing this size can be very expensive so we only want to do it once
      47       43637 :   unsigned int size = 0;
      48             : 
      49       87274 :   for (const auto & variable : _system.getVariables(_tid))
      50             :   {
      51       43637 :     _current_var = dynamic_cast<MooseLinearVariableFV<Real> *>(variable);
      52       43637 :     if (!_current_var)
      53           0 :       continue;
      54             : 
      55       43637 :     if (_current_var->needsGradientVectorStorage())
      56             :     {
      57       43637 :       if (!size)
      58       43637 :         size = range.size();
      59             : 
      60       43637 :       const auto rz_radial_coord = _fe_problem.mesh().getAxisymmetricRadialCoord();
      61       43637 :       const auto state = Moose::currentState();
      62             : 
      63       43637 :       std::vector<std::vector<Real>> temporary_values(_temporary_gradient.size(),
      64       43637 :                                                       std::vector<Real>(size, 0.0));
      65       43637 :       std::vector<dof_id_type> dof_indices(size, 0);
      66             :       {
      67       43637 :         std::vector<PetscVectorReader> grad_reader;
      68      121471 :         for (const auto dim_index : index_range(_temporary_gradient))
      69       77834 :           grad_reader.emplace_back(*_temporary_gradient[dim_index]);
      70             : 
      71             :         // Iterate over all the elements in the range
      72       43637 :         auto elem_iterator = range.begin();
      73    51177059 :         for (const auto elem_i : make_range(size))
      74             :         {
      75    51133422 :           const auto & elem_info = *elem_iterator;
      76    51133422 :           if (_current_var->hasBlocks(elem_info->subdomain_id()))
      77             :           {
      78    51133422 :             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    51133422 :             dof_indices[elem_i] = elem_info->dofIndices()[_system_number][_current_var->number()];
      86    51133422 :             const auto volume = elem_info->volume() * elem_info->coordFactor();
      87             : 
      88   153289564 :             for (const auto dim_index : index_range(_temporary_gradient))
      89   102156142 :               temporary_values[dim_index][elem_i] =
      90   102156142 :                   grad_reader[dim_index](dof_indices[elem_i]) / volume;
      91             : 
      92    51133422 :             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    51133422 :           elem_iterator++;
     102             :         }
     103       43637 :       }
     104      121471 :       for (const auto dim_index : index_range(_temporary_gradient))
     105             :       {
     106       77834 :         _temporary_gradient[dim_index]->zero();
     107       77834 :         _temporary_gradient[dim_index]->add_vector(temporary_values[dim_index].data(), dof_indices);
     108             :       }
     109       43637 :     }
     110             :   }
     111       43637 : }
     112             : 
     113             : void
     114           0 : ComputeLinearFVGreenGaussGradientVolumeThread::join(
     115             :     const ComputeLinearFVGreenGaussGradientVolumeThread & /*y*/)
     116             : {
     117           0 : }

Generated by: LCOV version 1.14