LCOV - code coverage report
Current view: top level - src/relationshipmanagers - ElementSideNeighborLayers.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 54 55 98.2 %
Date: 2025-07-17 01:28:37 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          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      697305 : ElementSideNeighborLayers::validParams()
      28             : {
      29      697305 :   InputParameters params = FunctorRelationshipManager::validParams();
      30             : 
      31     2091915 :   params.addRangeCheckedParam<unsigned short>(
      32             :       "layers",
      33     1394610 :       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     2091915 :   params.addParam<bool>("use_point_neighbors",
      38     1394610 :                         false,
      39             :                         "Whether to use point neighbors, which introduces additional ghosting to "
      40             :                         "that used for simple face neighbors.");
      41             : 
      42      697305 :   return params;
      43           0 : }
      44             : 
      45      313261 : ElementSideNeighborLayers::ElementSideNeighborLayers(const InputParameters & parameters)
      46             :   : FunctorRelationshipManager(parameters),
      47      313257 :     _layers(getParam<unsigned short>("layers")),
      48      626518 :     _use_point_neighbors(getParam<bool>("use_point_neighbors"))
      49             : {
      50      313257 : }
      51             : 
      52       56522 : ElementSideNeighborLayers::ElementSideNeighborLayers(const ElementSideNeighborLayers & other)
      53             :   : FunctorRelationshipManager(other),
      54       56522 :     _layers(other._layers),
      55       56522 :     _use_point_neighbors(other._use_point_neighbors)
      56             : {
      57       56522 : }
      58             : 
      59             : std::unique_ptr<GhostingFunctor>
      60       56522 : ElementSideNeighborLayers::clone() const
      61             : {
      62       56522 :   return _app.getFactory().copyConstruct(*this);
      63             : }
      64             : 
      65             : std::string
      66         133 : ElementSideNeighborLayers::getInfo() const
      67             : {
      68         133 :   std::ostringstream oss;
      69         133 :   std::string layers = _layers == 1 ? "layer" : "layers";
      70             : 
      71         133 :   oss << "ElementSideNeighborLayers (" << _layers << " " << layers << ')';
      72             : 
      73         266 :   return oss.str();
      74         133 : }
      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      572816 : ElementSideNeighborLayers::operator>=(const RelationshipManager & rhs) const
      80             : {
      81      572816 :   const auto * rm = dynamic_cast<const ElementSideNeighborLayers *>(&rhs);
      82      572816 :   if (!rm)
      83      280965 :     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      568596 :     return (_layers >= rm->_layers) && (_use_point_neighbors == rm->_use_point_neighbors) &&
      88      568596 :            baseGreaterEqual(*rm);
      89             : }
      90             : 
      91             : template <typename Functor>
      92             : void
      93       63580 : ElementSideNeighborLayers::initFunctor(Functor & functor)
      94             : {
      95       63580 :   functor.set_n_levels(_layers);
      96             : 
      97       63580 :   if (_dof_map)
      98             :   {
      99             :     // Need to see if there are periodic BCs - if so we need to dig them out
     100       55996 :     auto periodic_boundaries_ptr = _dof_map->get_periodic_boundaries();
     101             : 
     102             :     mooseAssert(periodic_boundaries_ptr, "Periodic Boundaries Pointer is nullptr");
     103             : 
     104       55996 :     functor.set_periodic_boundaries(periodic_boundaries_ptr);
     105       55996 :     functor.set_dof_coupling(_dof_map->_dof_coupling);
     106             :   }
     107       63580 : }
     108             : 
     109             : void
     110       63580 : ElementSideNeighborLayers::internalInitWithMesh(const MeshBase &)
     111             : {
     112       63580 :   if (_use_point_neighbors)
     113             :   {
     114          36 :     auto functor = std::make_unique<PointNeighborCoupling>();
     115          36 :     initFunctor(*functor);
     116          36 :     _functor = std::move(functor);
     117          36 :   }
     118             :   else
     119             :   {
     120       63544 :     auto functor = std::make_unique<DefaultCoupling>();
     121       63544 :     initFunctor(*functor);
     122       63544 :     _functor = std::move(functor);
     123       63544 :   }
     124       63580 : }
     125             : 
     126             : void
     127       78077 : ElementSideNeighborLayers::dofmap_reinit()
     128             : {
     129       78077 :   if (_dof_map)
     130             :   {
     131       78077 :     if (_use_point_neighbors)
     132          69 :       static_cast<PointNeighborCoupling *>(_functor.get())
     133          69 :           ->set_dof_coupling(_dof_map->_dof_coupling);
     134             :     else
     135       78008 :       static_cast<DefaultCoupling *>(_functor.get())->set_dof_coupling(_dof_map->_dof_coupling);
     136             :   }
     137       78077 : }

Generated by: LCOV version 1.14