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 36242 : AllLocalDofIndicesThread::AllLocalDofIndicesThread(SubProblem & problem, 27 : std::vector<std::string> vars, 28 36242 : bool include_semilocal) 29 : : ParallelObject(problem.comm()), 30 36242 : _problem(problem), 31 36242 : _sys(nullptr), 32 36242 : _include_semilocal(include_semilocal) 33 : { 34 75239 : for (unsigned int i = 0; i < vars.size(); i++) 35 : { 36 38997 : auto & var = _problem.getVariable(0, vars[i]); 37 38997 : if (_sys) 38 : { 39 2755 : if (_sys != &var.sys().system()) 40 0 : mooseError("Variables passed in AllLocalDofIndicesThread must be all in the same system."); 41 : } 42 : else 43 36242 : _sys = &var.sys().system(); 44 : 45 38997 : if (var.isArray()) 46 : { 47 225 : const auto & array_var = _problem.getArrayVariable(0, vars[i]); 48 675 : for (unsigned int p = 0; p < var.count(); ++p) 49 450 : _var_numbers.push_back(_sys->variable_number(array_var.componentName(p))); 50 : } 51 : else 52 38772 : _var_numbers.push_back(_sys->variable_number(vars[i])); 53 : } 54 36242 : } 55 : 56 : // Splitting Constructor 57 3690 : AllLocalDofIndicesThread::AllLocalDofIndicesThread(AllLocalDofIndicesThread & x, 58 3690 : Threads::split /*split*/) 59 3690 : : ParallelObject(x._problem.comm()), 60 3690 : _problem(x._problem), 61 3690 : _sys(x._sys), 62 3690 : _var_numbers(x._var_numbers), 63 3690 : _include_semilocal(x._include_semilocal) 64 : { 65 3690 : } 66 : 67 : void 68 39932 : AllLocalDofIndicesThread::operator()(const ConstElemRange & range) 69 : { 70 39932 : ParallelUniqueId puid; 71 39932 : _tid = puid.id; 72 : 73 : mooseAssert(_sys, "We should have a system, did you forget to specify any variable in vars?"); 74 39932 : auto & dof_map = _sys->get_dof_map(); 75 : 76 4275602 : for (const auto & elem : range) 77 : { 78 4235670 : std::vector<dof_id_type> dof_indices; 79 : 80 4235670 : dof_id_type local_dof_begin = dof_map.first_dof(); 81 4235670 : dof_id_type local_dof_end = dof_map.end_dof(); 82 : 83 : // prepare variables 84 8752605 : for (unsigned int i = 0; i < _var_numbers.size(); i++) 85 : { 86 4516935 : dof_map.dof_indices(elem, dof_indices, _var_numbers[i]); 87 12000098 : for (unsigned int j = 0; j < dof_indices.size(); j++) 88 : { 89 7483163 : dof_id_type dof = dof_indices[j]; 90 : 91 7483163 : if (_include_semilocal || (dof >= local_dof_begin && dof < local_dof_end)) 92 7428863 : _all_dof_indices.insert(dof); 93 : } 94 : } 95 4235670 : } 96 39932 : } 97 : 98 : void 99 3690 : AllLocalDofIndicesThread::join(const AllLocalDofIndicesThread & y) 100 : { 101 3690 : _all_dof_indices.insert(y._all_dof_indices.begin(), y._all_dof_indices.end()); 102 3690 : } 103 : 104 : void 105 90 : AllLocalDofIndicesThread::dofIndicesSetUnion() 106 : { 107 90 : _communicator.set_union(_all_dof_indices); 108 90 : }