https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
34void
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
52 for (const auto division : _divisions)
53 if (!division->coversEntireMesh())
54 {
55 _mesh_fully_indexed = false;
56 break;
57 }
58}
59
60unsigned int
61NestedDivision::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
74unsigned int
75NestedDivision::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}
registerMooseObject("MooseApp", NestedDivision)
MeshDivision & getMeshDivision(const std::string &name, const THREAD_ID tid=0) const
Get a MeshDivision.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
Base class for MeshDivision objects.
static InputParameters validParams()
Class constructor.
const FEProblemBase *const _fe_problem
Pointer to the problem, needed to retrieve pointers to various objects.
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:457
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:271
Divides the mesh based on nested divisions.
NestedDivision(const InputParameters &parameters)
static InputParameters validParams()
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
std::vector< const MeshDivision * > _divisions
Vector of nested divisions. Indexing is more and more 'inner' as we progress in the vector.
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
std::vector< unsigned int > _num_divs
Vector of the number of divisions for each nested division.