www.mooseframework.org
AllLocalDofIndicesThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
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 
27  std::vector<std::string> vars,
28  bool include_semilocal)
29  : ParallelObject(problem.comm()),
30  _problem(problem),
31  _sys(nullptr),
32  _include_semilocal(include_semilocal)
33 {
34  for (unsigned int i = 0; i < vars.size(); i++)
35  {
36  auto & var = _problem.getVariable(0, vars[i]);
37  if (_sys)
38  {
39  if (_sys != &var.sys().system())
40  mooseError("Variables passed in AllLocalDofIndicesThread must be all in the same system.");
41  }
42  else
43  _sys = &var.sys().system();
44 
45  if (var.isArray())
46  {
47  const auto & array_var = _problem.getArrayVariable(0, vars[i]);
48  for (unsigned int p = 0; p < var.count(); ++p)
49  _var_numbers.push_back(_sys->variable_number(array_var.componentName(p)));
50  }
51  else
52  _var_numbers.push_back(_sys->variable_number(vars[i]));
53  }
54 }
55 
56 // Splitting Constructor
58  Threads::split /*split*/)
59  : ParallelObject(x._problem.comm()),
60  _problem(x._problem),
61  _sys(x._sys),
62  _var_numbers(x._var_numbers),
63  _include_semilocal(x._include_semilocal)
64 {
65 }
66 
67 void
69 {
70  ParallelUniqueId puid;
71  _tid = puid.id;
72 
73  mooseAssert(_sys, "We should have a system, did you forget to specify any variable in vars?");
74  auto & dof_map = _sys->get_dof_map();
75 
76  for (const auto & elem : range)
77  {
78  std::vector<dof_id_type> dof_indices;
79 
80  dof_id_type local_dof_begin = dof_map.first_dof();
81  dof_id_type local_dof_end = dof_map.end_dof();
82 
83  // prepare variables
84  for (unsigned int i = 0; i < _var_numbers.size(); i++)
85  {
86  dof_map.dof_indices(elem, dof_indices, _var_numbers[i]);
87  for (unsigned int j = 0; j < dof_indices.size(); j++)
88  {
89  dof_id_type dof = dof_indices[j];
90 
91  if (_include_semilocal || (dof >= local_dof_begin && dof < local_dof_end))
92  _all_dof_indices.insert(dof);
93  }
94  }
95  }
96 }
97 
98 void
100 {
101  _all_dof_indices.insert(y._all_dof_indices.begin(), y._all_dof_indices.end());
102 }
103 
104 void
106 {
107  _communicator.set_union(_all_dof_indices);
108 }
void operator()(const ConstElemRange &range)
std::vector< unsigned int > _var_numbers
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
void join(const AllLocalDofIndicesThread &y)
StoredRange< MeshBase::const_element_iterator, const Elem *> ConstElemRange
Grab all the (possibly semi)local dof indices for the variables passed in, in the system passed in...
std::set< dof_id_type > _all_dof_indices
virtual ArrayMooseVariable & getArrayVariable(const THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested ArrayMooseVariable which may be in any system...
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const =0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
const bool _include_semilocal
Whether to include semilocal dof indices.
AllLocalDofIndicesThread(SubProblem &problem, std::vector< std::string > vars, bool include_semilocal=false)
uint8_t dof_id_type