www.mooseframework.org
ComputeNodalUserObjectsThread.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 // MOOSE includes
13 #include "FEProblem.h"
14 #include "MooseMesh.h"
15 #include "NodalUserObject.h"
16 #include "AuxiliarySystem.h"
17 
18 #include "libmesh/threads.h"
19 
21 
23  const TheWarehouse::Query & query)
24  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
25  _query(query),
26  _aux_sys(fe_problem.getAuxiliarySystem())
27 {
28 }
29 
30 // Splitting Constructor
32  Threads::split split)
33  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
34  _query(x._query),
35  _aux_sys(x._aux_sys)
36 {
37 }
38 
40 
41 void
43 {
44  std::vector<NodalUserObject *> objs;
45  _query.clone()
47  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
48  .queryInto(objs);
49 
50  std::set<TagID> needed_vector_tags;
51  for (const auto obj : objs)
52  {
53  auto & vector_tags = obj->getFEVariableCoupleableVectorTags();
54  needed_vector_tags.insert(vector_tags.begin(), vector_tags.end());
55  }
57 }
58 
59 void
60 ComputeNodalUserObjectsThread::onNode(ConstNodeRange::const_iterator & node_it)
61 {
62  const Node * node = *node_it;
63 
64  const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
65  if (_block_ids != block_ids)
66  {
67  _block_ids.clear();
68  _block_ids.insert(block_ids.begin(), block_ids.end());
70  }
71 
73 
74  std::vector<NodalUserObject *> objs;
75 
76  // Boundary Restricted
77  std::vector<BoundaryID> nodeset_ids;
78  _fe_problem.mesh().getMesh().get_boundary_info().boundary_ids(node, nodeset_ids);
79  for (const auto & bnd : nodeset_ids)
80  {
81  _query.clone()
83  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
84  .condition<AttribBoundaries>(bnd, true)
85  .queryInto(objs);
86  for (const auto & uo : objs)
87  {
88  uo->execute();
89 
90  // update the aux solution vector if writable coupled variables are used
91  if (uo->hasWritableCoupledVariables())
92  {
93  Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
94  for (auto * var : uo->getWritableCoupledVariables())
95  var->insert(_aux_sys.solution());
96  }
97  }
98  }
99 
100  // Block Restricted
101  // NodalUserObjects may be block restricted, in this case by default the execute() method is
102  // called for each subdomain that the node "belongs". This may be disabled in the NodalUserObject
103  // by setting "unique_node_execute = true".
104 
105  // To enforce the unique execution this vector is populated and checked if the unique flag is
106  // enabled.
107  std::set<NodalUserObject *> computed;
108  for (const auto & block : block_ids)
109  {
110  _query.clone()
112  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
113  .condition<AttribSubdomains>(block)
114  .queryInto(objs);
115 
116  for (const auto & uo : objs)
117  if (!uo->isUniqueNodeExecute() || computed.count(uo) == 0)
118  {
119  uo->execute();
120 
121  // update the aux solution vector if writable coupled variables are used
122  if (uo->hasWritableCoupledVariables())
123  {
124  Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
125  for (auto * var : uo->getWritableCoupledVariables())
126  var->insert(_aux_sys.solution());
127  }
128 
129  computed.insert(uo);
130  }
131  }
132 }
133 
134 void
136 {
137 }
138 
139 void
141 {
143  return;
144 
145  // Get all nodal UOs
146  std::vector<MooseObject *> nodal_uos;
147  _query.clone()
149  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
150  .queryInto(nodal_uos);
151 
152  if (nodal_uos.size())
153  {
154  const auto & console = _fe_problem.console();
155  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
156  console << "[DBG] Computing nodal user objects on " << execute_on << std::endl;
157  mooseDoOnce(
158  console << "[DBG] Ordering on nodes:" << std::endl;
159  console << "[DBG] - boundary restricted user objects" << std::endl;
160  console << "[DBG] - block restricted user objects" << std::endl;
161  console << "[DBG] Nodal UOs executed on each node will differ based on these restrictions"
162  << std::endl;);
163 
164  auto message = ConsoleUtils::mooseObjectVectorToString(nodal_uos);
165  message = "Order of execution:\n" + message;
166  console << ConsoleUtils::formatString(message, "[DBG]") << std::endl;
167  }
168 }
std::string mooseObjectVectorToString(const std::vector< MooseObject *> &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.
Definition: ConsoleUtils.C:438
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
Definition: TheWarehouse.h:208
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
NumericVector< Number > & solution()
Definition: SystemBase.h:176
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
static Threads::spin_mutex writable_variable_mutex
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:1280
ComputeNodalUserObjectsThread(FEProblemBase &fe_problem, const TheWarehouse::Query &query)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
Definition: ConsoleUtils.C:422
AttribBoundaries tracks all boundary IDs associated with an object.
Definition: Attributes.h:188
StoredRange< MeshBase::const_node_iterator, const Node *> ConstNodeRange
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:292
query_obj query
tbb::split split
const ConsoleStream & console() const
Return console handle.
Definition: Problem.h:48
virtual MooseMesh & mesh()
Definition: SystemBase.h:96
virtual MooseMesh & mesh() override
void join(const ComputeNodalUserObjectsThread &)
void printGeneralExecutionInformation() const override
Print information about the loop, mostly order of execution of objects.
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:284
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Called for each node.
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override