LCOV - code coverage report
Current view: top level - src/loops - AllLocalDofIndicesThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 46 47 97.9 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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 "AllLocalDofIndicesThread.h"
      11             : 
      12             : #include "FEProblem.h"
      13             : #include "ParallelUniqueId.h"
      14             : #include "NonlinearSystemBase.h"
      15             : #include "MooseVariableFE.h"
      16             : 
      17             : #include "libmesh/dof_map.h"
      18             : #include "libmesh/threads.h"
      19             : #include "libmesh/system.h"
      20             : 
      21             : #include "timpi/communicator.h"
      22             : 
      23             : #include LIBMESH_INCLUDE_UNORDERED_SET
      24             : LIBMESH_DEFINE_HASH_POINTERS
      25             : 
      26       29169 : AllLocalDofIndicesThread::AllLocalDofIndicesThread(SubProblem & problem,
      27             :                                                    std::vector<std::string> vars,
      28       29169 :                                                    bool include_semilocal)
      29             :   : ParallelObject(problem.comm()),
      30       29169 :     _problem(problem),
      31       29169 :     _sys(nullptr),
      32       29169 :     _include_semilocal(include_semilocal)
      33             : {
      34       60972 :   for (unsigned int i = 0; i < vars.size(); i++)
      35             :   {
      36       31803 :     auto & var = _problem.getVariable(0, vars[i]);
      37       31803 :     if (_sys)
      38             :     {
      39        2634 :       if (_sys != &var.sys().system())
      40           0 :         mooseError("Variables passed in AllLocalDofIndicesThread must be all in the same system.");
      41             :     }
      42             :     else
      43       29169 :       _sys = &var.sys().system();
      44             : 
      45       31803 :     if (var.isArray())
      46             :     {
      47         224 :       const auto & array_var = _problem.getArrayVariable(0, vars[i]);
      48         672 :       for (unsigned int p = 0; p < var.count(); ++p)
      49         448 :         _var_numbers.push_back(_sys->variable_number(array_var.componentName(p)));
      50             :     }
      51             :     else
      52       31579 :       _var_numbers.push_back(_sys->variable_number(vars[i]));
      53             :   }
      54       29169 : }
      55             : 
      56             : // Splitting Constructor
      57        2715 : AllLocalDofIndicesThread::AllLocalDofIndicesThread(AllLocalDofIndicesThread & x,
      58        2715 :                                                    Threads::split /*split*/)
      59        2715 :   : ParallelObject(x._problem.comm()),
      60        2715 :     _problem(x._problem),
      61        2715 :     _sys(x._sys),
      62        2715 :     _var_numbers(x._var_numbers),
      63        2715 :     _include_semilocal(x._include_semilocal)
      64             : {
      65        2715 : }
      66             : 
      67             : void
      68       31884 : AllLocalDofIndicesThread::operator()(const ConstElemRange & range)
      69             : {
      70       31884 :   ParallelUniqueId puid;
      71       31884 :   _tid = puid.id;
      72             : 
      73             :   mooseAssert(_sys, "We should have a system, did you forget to specify any variable in vars?");
      74       31884 :   auto & dof_map = _sys->get_dof_map();
      75             : 
      76     3884974 :   for (const auto & elem : range)
      77             :   {
      78     3853090 :     std::vector<dof_id_type> dof_indices;
      79             : 
      80     3853090 :     dof_id_type local_dof_begin = dof_map.first_dof();
      81     3853090 :     dof_id_type local_dof_end = dof_map.end_dof();
      82             : 
      83             :     // prepare variables
      84     7985169 :     for (unsigned int i = 0; i < _var_numbers.size(); i++)
      85             :     {
      86     4132079 :       dof_map.dof_indices(elem, dof_indices, _var_numbers[i]);
      87    10739774 :       for (unsigned int j = 0; j < dof_indices.size(); j++)
      88             :       {
      89     6607695 :         dof_id_type dof = dof_indices[j];
      90             : 
      91     6607695 :         if (_include_semilocal || (dof >= local_dof_begin && dof < local_dof_end))
      92     6556203 :           _all_dof_indices.insert(dof);
      93             :       }
      94             :     }
      95     3853090 :   }
      96       31884 : }
      97             : 
      98             : void
      99        2715 : AllLocalDofIndicesThread::join(const AllLocalDofIndicesThread & y)
     100             : {
     101        2715 :   _all_dof_indices.insert(y._all_dof_indices.begin(), y._all_dof_indices.end());
     102        2715 : }
     103             : 
     104             : void
     105         112 : AllLocalDofIndicesThread::dofIndicesSetUnion()
     106             : {
     107         112 :   _communicator.set_union(_all_dof_indices);
     108         112 : }

Generated by: LCOV version 1.14