https://mooseframework.inl.gov
NestedDivision.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 #include "NestedDivision.h"
11 #include "FEProblemBase.h"
12 #include "libmesh/elem.h"
13 
15 
18 {
20  params.addClassDescription("Divide the mesh using nested divisions objects");
21  params.addRequiredParam<std::vector<MeshDivisionName>>("divisions", "Nested divisions");
22  return params;
23 }
24 
26 {
27  for (const auto & div_name : getParam<std::vector<MeshDivisionName>>("divisions"))
28  _divisions.push_back(&_fe_problem->getMeshDivision(div_name));
29  if (_divisions.size() == 0)
30  paramError("divisions", "You cannot pass an empty vector of divisions");
32 }
33 
34 void
36 {
37  auto tot_divs = 1;
38  _num_divs.resize(_divisions.size());
39 
40  for (const auto i : index_range(_divisions))
41  {
42  _num_divs[i] = _divisions[i]->getNumDivisions();
43  tot_divs *= _num_divs[i];
44  if (_num_divs[i] == 0)
45  mooseError("Nested division '", _divisions[i]->name(), "' has zero bins");
46  }
47  setNumDivisions(tot_divs);
48 
49  // If any division does not cover the entire mesh, nested will have the same holes
50  // in its coverage of the mesh
51  _mesh_fully_indexed = true;
52  for (const auto division : _divisions)
53  if (!division->coversEntireMesh())
54  {
55  _mesh_fully_indexed = false;
56  break;
57  }
58 }
59 
60 unsigned int
61 NestedDivision::divisionIndex(const Elem & elem) const
62 {
63  unsigned int index = 0;
64  unsigned int running_product = 1;
65  const auto N_divs = _divisions.size();
66  for (const auto i : index_range(_divisions))
67  {
68  index += _divisions[N_divs - 1 - i]->divisionIndex(elem) * running_product;
69  running_product *= _num_divs[N_divs - 1 - i];
70  }
71  return index;
72 }
73 
74 unsigned int
75 NestedDivision::divisionIndex(const Point & pt) const
76 {
77  unsigned int index = 0;
78  unsigned int running_product = 1;
79  const auto N_divs = _divisions.size();
80  for (const auto i : index_range(_divisions))
81  {
82  index += _divisions[N_divs - 1 - i]->divisionIndex(pt) * running_product;
83  running_product *= _num_divs[N_divs - 1 - i];
84  }
85  return index;
86 }
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:384
registerMooseObject("MooseApp", NestedDivision)
std::vector< unsigned int > _num_divs
Vector of the number of divisions for each nested division.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Divides the mesh based on nested divisions.
Base class for MeshDivision objects.
Definition: MeshDivision.h:35
MeshDivision & getMeshDivision(const std::string &name, const THREAD_ID tid=0) const
Get a MeshDivision.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
static InputParameters validParams()
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index...
Definition: MeshDivision.h:77
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
Definition: MeshDivision.h:65
NestedDivision(const InputParameters &parameters)
const FEProblemBase *const _fe_problem
Pointer to the problem, needed to retrieve pointers to various objects.
Definition: MeshDivision.h:71
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
static InputParameters validParams()
Class constructor.
Definition: MeshDivision.C:14
auto index_range(const T &sizable)
std::vector< const MeshDivision * > _divisions
Vector of nested divisions. Indexing is more and more &#39;inner&#39; as we progress in the vector...