LCOV - code coverage report
Current view: top level - src/meshgenerators - FlipSidesetGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 30 31 96.8 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "FlipSidesetGenerator.h"
      11             : 
      12             : #include "CastUniquePointer.h"
      13             : 
      14             : registerMooseObject("MooseApp", FlipSidesetGenerator);
      15             : 
      16             : InputParameters
      17       14313 : FlipSidesetGenerator::validParams()
      18             : {
      19       14313 :   InputParameters params = MeshGenerator::validParams();
      20       14313 :   params.addClassDescription("A Mesh Generator which flips a given sideset");
      21       14313 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      22       14313 :   params.addRequiredParam<BoundaryName>("boundary", "The sideset (boundary) that will be flipped");
      23       14313 :   return params;
      24           0 : }
      25             : 
      26          24 : FlipSidesetGenerator::FlipSidesetGenerator(const InputParameters & parameters)
      27             :   : MeshGenerator(parameters),
      28          24 :     _input(getMesh("input")),
      29          48 :     _sideset_name(getParam<BoundaryName>("boundary"))
      30             : {
      31          24 : }
      32             : 
      33             : std::unique_ptr<MeshBase>
      34          24 : FlipSidesetGenerator::generate()
      35             : {
      36             :   // get boundary info
      37          24 :   BoundaryInfo & boundary_info = _input->get_boundary_info();
      38             :   // get id of the input sideset
      39          24 :   const auto sideset_id = boundary_info.get_id_by_name(_sideset_name);
      40             : 
      41             :   // Throw an error if the sideset doesn't exist
      42          24 :   if (sideset_id == libMesh::BoundaryInfo::invalid_id)
      43           4 :     paramError("boundary", "The boundary '", _sideset_name, "' was not found");
      44             : 
      45             :   // get a copy of sideset map to avoid changing the sideset map while looping on it
      46             :   std::multimap<const Elem *, std::pair<unsigned short int, boundary_id_type>> sideset_map =
      47          20 :       boundary_info.get_sideset_map();
      48             : 
      49             :   // old_elem is the original element attached to the sideset before flipping
      50             :   // new_elem is the element attached to the sideset after flipping
      51         632 :   for (const auto & [old_elem, id_pair] : sideset_map)
      52             :   {
      53         616 :     boundary_id_type boundary_id = std::get<1>(id_pair);
      54         616 :     if (boundary_id == sideset_id)
      55             :     {
      56          44 :       const auto old_side_id = std::get<0>(id_pair);
      57          44 :       const auto old_elem_id = old_elem->id();
      58          44 :       const auto new_elem = old_elem->neighbor_ptr(old_side_id);
      59             : 
      60             :       // Throw an error if the old element doesn't have a neighbor on the old side
      61          44 :       if (!new_elem)
      62           8 :         mooseError("elem " + std::to_string(old_elem_id) +
      63           8 :                    " does not have a neighbor through side " + std::to_string(old_side_id) +
      64             :                    " therefore it cannot be flipped");
      65             : 
      66          40 :       const auto new_side_id = new_elem->which_neighbor_am_i(old_elem);
      67          40 :       boundary_info.remove_side(old_elem, old_side_id, sideset_id);
      68          40 :       boundary_info.add_side(new_elem, new_side_id, sideset_id);
      69             :     }
      70             :   }
      71          32 :   return dynamic_pointer_cast<MeshBase>(_input);
      72          16 : }

Generated by: LCOV version 1.14