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 : #include "ElementSideNeighborLayers.h" 11 : #include "MooseMesh.h" 12 : #include "Conversion.h" 13 : #include "MooseApp.h" 14 : #include "Executioner.h" 15 : #include "FEProblemBase.h" 16 : #include "NonlinearSystem.h" 17 : 18 : #include "libmesh/default_coupling.h" 19 : #include "libmesh/point_neighbor_coupling.h" 20 : #include "libmesh/dof_map.h" 21 : 22 : using namespace libMesh; 23 : 24 : registerMooseObject("MooseApp", ElementSideNeighborLayers); 25 : 26 : InputParameters 27 767262 : ElementSideNeighborLayers::validParams() 28 : { 29 767262 : InputParameters params = FunctorRelationshipManager::validParams(); 30 : 31 3836310 : params.addRangeCheckedParam<unsigned short>( 32 : "layers", 33 1534524 : 1, 34 : "element_side_neighbor_layers>=1 & element_side_neighbor_layers<=10", 35 : "The number of additional geometric elements to make available when " 36 : "using distributed mesh. No effect with replicated mesh."); 37 1534524 : params.addParam<bool>("use_point_neighbors", 38 1534524 : false, 39 : "Whether to use point neighbors, which introduces additional ghosting to " 40 : "that used for simple face neighbors."); 41 : 42 767262 : return params; 43 0 : } 44 : 45 344906 : ElementSideNeighborLayers::ElementSideNeighborLayers(const InputParameters & parameters) 46 : : FunctorRelationshipManager(parameters), 47 344902 : _layers(getParam<unsigned short>("layers")), 48 1034710 : _use_point_neighbors(getParam<bool>("use_point_neighbors")) 49 : { 50 344902 : } 51 : 52 62709 : ElementSideNeighborLayers::ElementSideNeighborLayers(const ElementSideNeighborLayers & other) 53 : : FunctorRelationshipManager(other), 54 62709 : _layers(other._layers), 55 62709 : _use_point_neighbors(other._use_point_neighbors) 56 : { 57 62709 : } 58 : 59 : std::unique_ptr<GhostingFunctor> 60 62709 : ElementSideNeighborLayers::clone() const 61 : { 62 62709 : return _app.getFactory().copyConstruct(*this); 63 : } 64 : 65 : std::string 66 142 : ElementSideNeighborLayers::getInfo() const 67 : { 68 142 : std::ostringstream oss; 69 142 : std::string layers = _layers == 1 ? "layer" : "layers"; 70 : 71 142 : oss << "ElementSideNeighborLayers (" << _layers << " " << layers << ')'; 72 : 73 284 : return oss.str(); 74 142 : } 75 : 76 : // the LHS ("this" object) in MooseApp::addRelationshipManager is the existing RelationshipManager 77 : // object to which we are comparing the rhs to determine whether it should get added 78 : bool 79 609942 : ElementSideNeighborLayers::operator>=(const RelationshipManager & rhs) const 80 : { 81 609942 : const auto * rm = dynamic_cast<const ElementSideNeighborLayers *>(&rhs); 82 609942 : if (!rm) 83 289153 : return false; 84 : else 85 : // We use a >= comparison instead of == for _layers because if we already have more ghosting 86 : // than the new RM provides, then that's an indication that we should *not* add the new one 87 625122 : return (_layers >= rm->_layers) && (_use_point_neighbors == rm->_use_point_neighbors) && 88 625122 : baseGreaterEqual(*rm); 89 : } 90 : 91 : template <typename Functor> 92 : void 93 70360 : ElementSideNeighborLayers::initFunctor(Functor & functor) 94 : { 95 70360 : functor.set_n_levels(_layers); 96 : 97 70360 : if (_dof_map) 98 : { 99 : // Need to see if there are periodic BCs - if so we need to dig them out 100 62161 : auto periodic_boundaries_ptr = _dof_map->get_periodic_boundaries(); 101 : 102 : mooseAssert(periodic_boundaries_ptr, "Periodic Boundaries Pointer is nullptr"); 103 : 104 62161 : functor.set_periodic_boundaries(periodic_boundaries_ptr); 105 62161 : functor.set_dof_coupling(_dof_map->_dof_coupling); 106 : } 107 70360 : } 108 : 109 : void 110 70360 : ElementSideNeighborLayers::internalInitWithMesh(const MeshBase &) 111 : { 112 70360 : if (_use_point_neighbors) 113 : { 114 39 : auto functor = std::make_unique<PointNeighborCoupling>(); 115 39 : initFunctor(*functor); 116 39 : _functor = std::move(functor); 117 39 : } 118 : else 119 : { 120 70321 : auto functor = std::make_unique<DefaultCoupling>(); 121 70321 : initFunctor(*functor); 122 70321 : _functor = std::move(functor); 123 70321 : } 124 70360 : } 125 : 126 : void 127 88061 : ElementSideNeighborLayers::dofmap_reinit() 128 : { 129 88061 : if (_dof_map) 130 : { 131 88061 : if (_use_point_neighbors) 132 75 : static_cast<PointNeighborCoupling *>(_functor.get()) 133 75 : ->set_dof_coupling(_dof_map->_dof_coupling); 134 : else 135 87986 : static_cast<DefaultCoupling *>(_functor.get())->set_dof_coupling(_dof_map->_dof_coupling); 136 : } 137 88061 : }