https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NodePositions.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 "NodePositions.h"
11
12#include "libmesh/parallel_algebra.h"
13
15
18{
20 params.addClassDescription("Positions of element nodes.");
23
24 // Element nodes must be sorted to remove duplicates.
25 params.suppressParameter<bool>("auto_sort");
26 params.set<bool>("auto_sort") = true;
27 // Gathered locally, should be broadcast on every process
28 params.set<bool>("auto_broadcast") = true;
29
30 return params;
31}
32
34 : Positions(parameters),
36 BoundaryRestrictable(this, true),
37 _mesh(_subproblem.mesh())
38{
39 // Mesh is ready at construction
40 initialize();
41 // Trigger synchronization as the initialization is distributed
42 finalize();
43}
44
45void
47{
49
50 // Only needed for boundary restriction
51 const BoundaryInfo * binfo = nullptr;
53 binfo = &_mesh.getMesh().get_boundary_info();
54
55 for (const auto & [node_id, elems_ids] : _mesh.nodeToElemMap())
56 {
57 const auto * const node = _mesh.queryNodePtr(node_id);
58 if (!node)
59 continue;
60
61 // Check that node is part of boundary restriction
62 if (binfo)
63 {
64 if (!binfo->get_nodeset_map().count(node))
65 continue;
66 else
67 {
68 for (const auto [_, nodeset_id] : as_range(binfo->get_nodeset_map().equal_range(node)))
69 if (hasBoundary(nodeset_id))
70 goto inRestriction;
71 }
72 continue;
73 }
74 inRestriction:
75 // Check the elements associated with the node to see if they're in the block
76 // we're block-restricting. If so, add the node to the positions vector and move
77 // on to the next node (to minimize duplicates).
78 for (const auto elem_id : elems_ids)
79 {
80 const auto e = _mesh.queryElemPtr(elem_id);
81 if (e && hasBlocks(e->subdomain_id()))
82 {
83 _positions.emplace_back(_mesh.nodeRef(node_id));
84 break;
85 }
86 }
87 }
88
89 _initialized = true;
90}
91
92void
94{
95 // Gather up the positions vector on all ranks
96 mooseAssert(initialized(false), "Positions vector has not been initialized.");
98 // The consumer/producer reporter interface can keep track of whether a reduction is needed
99 // (for example if a consumer needs replicated data, but the producer is distributed) however,
100 // we have currently made the decision that positions should ALWAYS be replicated
101 _communicator.allgather(_positions, /* identical buffer lengths = */ false);
102
103 // We always need to sort the positions as nodes on the boundary between different mesh partitions
104 // are duplicated. We sort by X, then Y, then Z, and prune the positions list.
105 std::sort(_positions.begin(), _positions.end());
106 _positions.erase(std::unique(_positions.begin(), _positions.end()), _positions.end());
107
108 // Make a KDTree with the positions
109 _positions_kd_tree = std::make_unique<KDTree>(_positions, 1);
110
111 // For now at least, we expect positions to be the same on all ranks
112 mooseAssert(comm().verify(_positions), "Positions should be the same across all MPI processes.");
113}
registerMooseObject("MooseApp", NodePositions)
An interface that restricts an object to subdomains via the 'blocks' input parameter.
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
static InputParameters validParams()
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
bool hasBoundary(const BoundaryName &name) const
Test if the supplied boundary name is valid for this object.
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
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.
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:841
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
const std::unordered_map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected.
Definition MooseMesh.C:1236
virtual Elem * queryElemPtr(const dof_id_type i)
Definition MooseMesh.C:3226
virtual const Node * queryNodePtr(const dof_id_type i) const
Definition MooseMesh.C:867
Positions from nodes of elements in the mesh.
MooseMesh & _mesh
NodePositions(const InputParameters &parameters)
virtual void initialize() override
In charge of computing / loading the positions.
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
static InputParameters validParams()
Positions objects are under the hood Reporters.
Definition Positions.h:21
bool initialized(bool initial) const
Whether the positions object has been initialized.
Definition Positions.C:262
std::unique_ptr< KDTree > _positions_kd_tree
Definition Positions.h:105
bool _need_broadcast
Whether generation of positions is distributed or not (and therefore needs a broadcast)
Definition Positions.h:108
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
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition Positions.h:116
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator
const Parallel::Communicator & comm() const
MeshBase & mesh