Line data Source code
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 : #pragma once 11 : 12 : // Moose 13 : #include "Restartable.h" 14 : #include "PerfGraphInterface.h" 15 : 16 : // Forward declarations 17 : class SubProblem; 18 : class MooseMesh; 19 : 20 : /** 21 : * Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way 22 : * around. 23 : */ 24 : class NearestNodeLocator : public Restartable, public PerfGraphInterface 25 : { 26 : public: 27 : NearestNodeLocator(SubProblem & subproblem, 28 : MooseMesh & mesh, 29 : BoundaryID boundary1, 30 : BoundaryID boundary2); 31 : 32 : ~NearestNodeLocator(); 33 : 34 : /** 35 : * This is the main method that is going to start the search. 36 : */ 37 : void findNodes(); 38 : 39 : /** 40 : * Completely redo the search from scratch. 41 : * Most likely called because of mesh adaptivity. 42 : */ 43 : void reinit(); 44 : 45 : /** 46 : * Valid to call this after findNodes() has been called to get the distance to the nearest node. 47 : */ 48 : Real distance(dof_id_type node_id); 49 : 50 : /** 51 : * Valid to call this after findNodes() has been called to get a pointer to the nearest node. 52 : */ 53 : const Node * nearestNode(dof_id_type node_id); 54 : 55 : /** 56 : * Returns the list of secondary nodes this Locator is tracking. 57 : */ 58 : std::vector<dof_id_type> & secondaryNodes() { return _secondary_nodes; } 59 : 60 : /** 61 : * Returns the NodeIdRange of secondary nodes to be used for calling threaded 62 : * functions operating on the secondary nodes. 63 : */ 64 170144 : NodeIdRange & secondaryNodeRange() { return *_secondary_node_range; } 65 : 66 : /** 67 : * Reconstructs the KDtree, updates the patch for the nodes in secondary_nodes, 68 : * and updates the closest neighbor for these nodes in nearest node info. 69 : */ 70 : void updatePatch(std::vector<dof_id_type> & secondary_nodes); 71 : 72 : /** 73 : * Updates the ghosted elements at the start of the time step for iteration 74 : * patch update strategy. 75 : */ 76 : void updateGhostedElems(); 77 : 78 : /** 79 : * Data structure used to hold nearest node info. 80 : */ 81 : class NearestNodeInfo 82 : { 83 : public: 84 : NearestNodeInfo(); 85 : 86 : const Node * _nearest_node; 87 : Real _distance; 88 : }; 89 : 90 : protected: 91 : SubProblem & _subproblem; 92 : 93 : MooseMesh & _mesh; 94 : 95 : std::unique_ptr<NodeIdRange> _secondary_node_range; 96 : 97 : public: 98 : std::map<dof_id_type, NearestNodeInfo> _nearest_node_info; 99 : 100 : BoundaryID _boundary1; 101 : BoundaryID _boundary2; 102 : 103 : bool _first; 104 : 105 : // Compute neighborhood nodes around the secondary nodes if iteration update strategy is selected. 106 : // This flag is required for (at least initial) adaptivity in parallel and is set to true on 107 : // reinit() 108 : bool _reinit_iteration; 109 : 110 : std::vector<dof_id_type> _secondary_nodes; 111 : 112 : std::map<dof_id_type, std::vector<dof_id_type>> _neighbor_nodes; 113 : 114 : // The following parameter controls the patch size that is searched for each nearest neighbor 115 : static const unsigned int _patch_size; 116 : 117 : // Contact patch update strategy 118 : const Moose::PatchUpdateType _patch_update_strategy; 119 : 120 : // The furthest through the patch that had to be searched for any node last time 121 : Real _max_patch_percentage; 122 : 123 : // The list of ghosted elements added during a time step for iteration patch update strategy 124 : std::vector<dof_id_type> _new_ghosted_elems; 125 : };