https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElementCentroidPositions.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
13
16{
18 params.addClassDescription("Positions of element centroids.");
20
21 // Element centroids could be sorted by XYZ or by id. Default to not sorting
22 params.set<bool>("auto_sort") = false;
23 // Gathered locally, should be broadcast on every process
24 params.set<bool>("auto_broadcast") = true;
25
26 return params;
27}
28
30 : Positions(parameters), BlockRestrictable(this), _mesh(_subproblem.mesh())
31{
32 // Mesh is ready at construction
33 initialize();
34 // Trigger synchronization as the initialization is distributed
35 finalize();
36}
37
38void
40{
42
43 // By default, initialize should be called on meshChanged()
44 // Gathering of positions is local, reporter system makes sure to make it global
45 if (blockRestricted())
46 {
47 _positions_2d.resize(numBlocks());
48 unsigned int b_index = 0;
49 for (const auto & sub_id : blockIDs())
50 {
51 for (const auto & elem : _mesh.getMesh().active_local_subdomain_elements_ptr_range(sub_id))
52 {
53 auto centroid = elem->true_centroid();
54 _positions.emplace_back(centroid);
55 _positions_2d[b_index].emplace_back(centroid);
56 }
57 b_index += 1;
58 }
59 }
60 else
61 {
62 _positions.resize(_mesh.getMesh().n_active_local_elem());
63 unsigned int i = 0;
64 for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
65 _positions[i++] = elem->true_centroid();
66 }
67 _initialized = true;
68}
registerMooseObject("MooseApp", ElementCentroidPositions)
An interface that restricts an object to subdomains via the 'blocks' input parameter.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
unsigned int numBlocks() const
Return the number of blocks for this object.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
static InputParameters validParams()
Positions from centroids of elements in the mesh.
virtual void initialize() override
In charge of computing / loading the positions.
ElementCentroidPositions(const InputParameters &parameters)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
Positions objects are under the hood Reporters.
Definition Positions.h:21
std::vector< std::vector< Point > > _positions_2d
2D storage for all the positions
Definition Positions.h:95
void clearPositions()
Clear all positions vectors.
Definition Positions.C:154
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition Positions.h:92
static InputParameters validParams()
Definition Positions.C:15
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition Positions.C:220
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition Positions.h:116
MeshBase & mesh