https://mooseframework.inl.gov
BoundaryElemIntegrityCheckThread.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 
10 // MOOSE includes
12 #include "AuxiliarySystem.h"
13 #include "NonlinearSystemBase.h"
14 #include "FEProblemBase.h"
15 #include "SideUserObject.h"
16 #include "MooseMesh.h"
17 #include "IntegratedBCBase.h"
19 
20 #include "libmesh/threads.h"
21 #include "libmesh/elem.h"
22 #include "libmesh/mesh_base.h"
23 
24 #include <vector>
25 
27  FEProblemBase & fe_problem, const TheWarehouse::Query & query)
28  : _fe_problem(fe_problem),
29  _aux_sys(fe_problem.getAuxiliarySystem()),
30  _elem_aux(_aux_sys.elemAuxWarehouse()),
31  _elem_vec_aux(_aux_sys.elemVectorAuxWarehouse()),
32  _elem_array_aux(_aux_sys.elemArrayAuxWarehouse()),
33  _query(query)
34 {
35 }
36 
37 // Splitting Constructor
40  : _fe_problem(x._fe_problem),
41  _aux_sys(x._aux_sys),
42  _elem_aux(x._elem_aux),
43  _elem_vec_aux(x._elem_vec_aux),
44  _elem_array_aux(x._elem_array_aux),
45  _query(x._query)
46 {
47 }
48 
49 void
51 {
52  ParallelUniqueId puid;
53  const auto tid = puid.id;
54 
55  for (const auto & belem : range)
56  {
57  const Elem * elem = belem->_elem;
58  const auto boundary_id = belem->_bnd_id;
59  const auto side = belem->_side;
60 
61  // We can distribute work just as the actual execution code will
62  if (elem->processor_id() != _fe_problem.processor_id())
63  return;
64 
65  auto & mesh = _fe_problem.mesh();
66 
67  const auto & bnd_name = mesh.getBoundaryName(boundary_id);
68 
69  // uo check
70  std::vector<SideUserObject *> objs;
71  _query.clone()
72  .condition<AttribThread>(tid)
73  .condition<AttribInterfaces>(Interfaces::SideUserObject)
74  .condition<AttribBoundaries>(boundary_id, true)
75  .queryInto(objs);
76  for (const auto & uo : objs)
77  if (uo->checkVariableBoundaryIntegrity())
78  {
79  auto leftover_vars = uo->checkAllVariables(*elem);
80  if (!leftover_vars.empty())
81  {
82  const auto neighbor = elem->neighbor_ptr(side);
83  const bool upwind_elem = !neighbor || elem->id() < neighbor->id();
84  const Elem * lower_d_elem =
85  upwind_elem ? mesh.getLowerDElem(elem, side)
86  : mesh.getLowerDElem(neighbor, neighbor->which_neighbor_am_i(elem));
87  if (lower_d_elem)
88  leftover_vars = uo->checkVariables(*lower_d_elem, leftover_vars);
89  }
90  boundaryIntegrityCheckError(*uo, leftover_vars, bnd_name);
91  }
92 
93  auto check = [elem, boundary_id, &bnd_name, tid, &mesh, side](const auto & warehouse)
94  {
95  if (!warehouse.hasBoundaryObjects(boundary_id, tid))
96  return;
97 
98  const auto & bnd_objects = warehouse.getBoundaryObjects(boundary_id, tid);
99  for (const auto & bnd_object : bnd_objects)
100  // Skip if this object uses geometric search because coupled variables may be defined on
101  // paired boundaries instead of the boundary this elem is on
102  if (!bnd_object->requiresGeometricSearch() && bnd_object->checkVariableBoundaryIntegrity())
103  {
104  // First check the higher-dimensional element
105  auto leftover_vars = bnd_object->checkAllVariables(*elem);
106  if (!leftover_vars.empty())
107  {
108  const auto neighbor = elem->neighbor_ptr(side);
109  const bool upwind_elem = !neighbor || elem->id() < neighbor->id();
110  const Elem * lower_d_elem =
111  upwind_elem ? mesh.getLowerDElem(elem, side)
112  : mesh.getLowerDElem(neighbor, neighbor->which_neighbor_am_i(elem));
113  if (lower_d_elem)
114  leftover_vars = bnd_object->checkVariables(*lower_d_elem, leftover_vars);
115  }
116 
117  boundaryIntegrityCheckError(*bnd_object, leftover_vars, bnd_name);
118  }
119  };
120 
121  check(_elem_aux);
124  for (const auto i : make_range(_fe_problem.numNonlinearSystems()))
126  }
127 }
128 
129 void
131 {
132 }
133 
134 void
136  const std::set<MooseVariableFieldBase *> & variables,
137  const BoundaryName & boundary_name)
138 {
139  if (variables.empty())
140  return;
141 
142  std::vector<std::string> names;
143  names.reserve(variables.size());
144  for (const auto * const var : variables)
145  names.push_back(var->name());
146 
147  mooseError("'",
148  object.name(),
149  "' of type '",
150  object.type(),
151  "' depends on variable(s) '",
152  MooseUtils::join(names, ","),
153  "'. However, that variable does not appear to be defined on (all of) boundary '",
154  boundary_name,
155  "'.");
156 }
std::string name(const ElemQuality q)
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
Definition: MooseUtils.h:142
BoundaryElemIntegrityCheckThread(FEProblemBase &fe_problem, const TheWarehouse::Query &query)
void join(const BoundaryElemIntegrityCheckThread &)
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
Definition: TheWarehouse.h:208
void boundaryIntegrityCheckError(const MooseObject &object, const std::set< MooseVariableFieldBase *> &variables, const BoundaryName &boundary_name)
Compose boundary restricted error message for the provided object, variables, and boundary_name if th...
virtual std::size_t numNonlinearSystems() const override
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const TheWarehouse::Query & _query
A warehouse query that we will use to obtain user objects for boundary variable dependency integrity ...
MeshBase & mesh
MooseObjectTagWarehouse< IntegratedBCBase > & getIntegratedBCWarehouse()
void operator()(const ConstBndElemRange &range)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const ExecuteMooseObjectWarehouse< AuxKernel > & _elem_aux
Elemental auxiliary kernels acting on standard field variables.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
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
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
FEProblemBase & _fe_problem
the finite element (or volume) problem
const ExecuteMooseObjectWarehouse< VectorAuxKernel > & _elem_vec_aux
Elemental auxiliary kernels acting on vector field variables.
query_obj query
const ExecuteMooseObjectWarehouse< ArrayAuxKernel > & _elem_array_aux
Elemental auxiliary kernels acting on array field variables.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:284
processor_id_type processor_id() const
Result check(std::string requirements, const Registry &capabilities)
Checks if a set of requirements is satisified by the given capability registry.