https://mooseframework.inl.gov
ComputeNodalUserObjectsThread.C
Go to the documentation of this file.
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 
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
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
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  for (auto * var : uo->getWritableCoupledVariables())
93  var->insert(_aux_sys.solution());
94  }
95  }
96 
97  // Block Restricted
98  // NodalUserObjects may be block restricted, in this case by default the execute() method is
99  // called for each subdomain that the node "belongs". This may be disabled in the NodalUserObject
100  // by setting "unique_node_execute = true".
101 
102  // To enforce the unique execution this vector is populated and checked if the unique flag is
103  // enabled.
104  std::set<NodalUserObject *> computed;
105  for (const auto & block : block_ids)
106  {
107  _query.clone()
109  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
110  .condition<AttribSubdomains>(block)
111  .queryInto(objs);
112 
113  for (const auto & uo : objs)
114  if (!uo->isUniqueNodeExecute() || computed.count(uo) == 0)
115  {
116  uo->execute();
117 
118  // update the aux solution vector if writable coupled variables are used
119  if (uo->hasWritableCoupledVariables())
120  for (auto * var : uo->getWritableCoupledVariables())
121  var->insert(_aux_sys.solution());
122 
123  computed.insert(uo);
124  }
125  }
126 }
127 
128 void
130 {
131 }
132 
133 void
135 {
137  return;
138 
139  // Get all nodal UOs
140  std::vector<MooseObject *> nodal_uos;
141  _query.clone()
143  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
144  .queryInto(nodal_uos);
145 
146  if (nodal_uos.size())
147  {
148  const auto & console = _fe_problem.console();
149  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
150  console << "[DBG] Computing nodal user objects on " << execute_on << std::endl;
151  mooseDoOnce(
152  console << "[DBG] Ordering on nodes:" << std::endl;
153  console << "[DBG] - boundary restricted user objects" << std::endl;
154  console << "[DBG] - block restricted user objects" << std::endl;
155  console << "[DBG] Nodal UOs executed on each node will differ based on these restrictions"
156  << std::endl;);
157 
158  auto message = ConsoleUtils::mooseObjectVectorToString(nodal_uos);
159  message = "Order of execution:\n" + message;
160  console << ConsoleUtils::formatString(message, "[DBG]") << std::endl;
161  }
162 }
MooseMesh & mesh()
Definition: SystemBase.h:99
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:597
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:196
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:1549
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:3528
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:581
AttribBoundaries tracks all boundary IDs associated with an object.
Definition: Attributes.h:188
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
vec_type::const_iterator const_iterator
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
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override