LCOV - code coverage report
Current view: top level - src/meshgenerators - BoundaryElementConversionGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 40 48 83.3 %
Date: 2026-05-29 20:35:17 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 "BoundaryElementConversionGenerator.h"
      11             : #include "MooseMeshElementConversionUtils.h"
      12             : #include "CastUniquePointer.h"
      13             : #include "MooseMeshUtils.h"
      14             : 
      15             : #include "libmesh/mesh_serializer.h"
      16             : 
      17             : registerMooseObject("MooseApp", BoundaryElementConversionGenerator);
      18             : 
      19             : InputParameters
      20        3203 : BoundaryElementConversionGenerator::validParams()
      21             : {
      22        3203 :   InputParameters params = MeshGenerator::validParams();
      23             : 
      24       12812 :   params.addParam<MeshGeneratorName>(
      25             :       "input",
      26             :       "mesh generator creating the mesh on which to create the boundary transition layer on.");
      27       12812 :   params.addRequiredParam<std::vector<BoundaryName>>(
      28             :       "boundary_names", "Boundaries that need to be converted to form a transition layer.");
      29        9609 :   params.addParam<unsigned int>(
      30             :       "conversion_element_layer_number",
      31        6406 :       1,
      32             :       "The number of layers of elements to be converted. The farthest layer of the elements from "
      33             :       "the given boundary are converted to elements compatible with the remainder of the mesh, "
      34             :       "while the other layers of elements are converted into TET4.");
      35       12812 :   params.addParam<SubdomainName>("converted_tet_element_subdomain_name_suffix",
      36             :                                  "to_tet",
      37             :                                  "The suffix to be added to the original subdomain name for the "
      38             :                                  "subdomains containing the elements converted to TET4.");
      39       12812 :   params.addParam<SubdomainName>(
      40             :       "converted_pyramid_element_subdomain_name_suffix",
      41             :       "to_pyramid",
      42             :       "The suffix to be added to the original subdomain name for the subdomains containing the "
      43             :       "elements converted to PYRAMID5.");
      44        9609 :   params.addParam<bool>("external_boundaries_checking",
      45        6406 :                         false,
      46             :                         "Whether to check if provided boundaries are external.");
      47             : 
      48        3203 :   params.addClassDescription("Convert the elements involved in a set of external boundaries to "
      49             :                              "ensure that the boundary set only contains TRI3 elements");
      50             : 
      51        3203 :   return params;
      52           0 : }
      53             : 
      54          71 : BoundaryElementConversionGenerator::BoundaryElementConversionGenerator(
      55          71 :     const InputParameters & parameters)
      56             :   : MeshGenerator(parameters),
      57          71 :     _input(getMesh("input")),
      58         142 :     _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names")),
      59         142 :     _conversion_element_layer_number(getParam<unsigned int>("conversion_element_layer_number")),
      60         213 :     _external_boundaries_checking(getParam<bool>("external_boundaries_checking"))
      61             : {
      62          71 : }
      63             : 
      64             : std::unique_ptr<MeshBase>
      65          71 : BoundaryElementConversionGenerator::generate()
      66             : {
      67          71 :   UnstructuredMesh & mesh = dynamic_cast<UnstructuredMesh &>(*_input);
      68             : 
      69          71 :   libMesh::MeshSerializer serial_mesh(mesh);
      70             : 
      71             :   // collect the subdomain ids of the original mesh
      72          71 :   std::set<subdomain_id_type> original_subdomain_ids;
      73        1775 :   for (auto elem_it = mesh.active_elements_begin(); elem_it != mesh.active_elements_end();
      74             :        elem_it++)
      75             :   {
      76        1704 :     original_subdomain_ids.emplace((*elem_it)->subdomain_id());
      77          71 :   }
      78             :   try
      79             :   {
      80          71 :     MooseMeshElementConversionUtils::transitionLayerGenerator(
      81          71 :         mesh, _boundary_names, _conversion_element_layer_number, _external_boundaries_checking);
      82             :   }
      83          15 :   catch (const MooseException & e)
      84             :   {
      85          30 :     if (((std::string)e.what()).compare("subdomain id overflow") == 0)
      86           6 :       paramError("input",
      87             :                  "Some subdomain ids of the input mesh are too large and cause overflow when "
      88             :                  "assigning new subdomain ids during element conversion. Please consider lowering "
      89             :                  "the subdomain ids using RenameBlockGenerator.");
      90          24 :     else if (((std::string)e.what()).compare(13, 8, "boundary") == 0)
      91          18 :       paramError("boundary_names", e.what());
      92             :     else
      93           6 :       paramError("input", e.what());
      94           0 :   }
      95             :   try
      96             :   {
      97         224 :     MooseMeshElementConversionUtils::assignConvertedElementsSubdomainNameSuffix(
      98             :         mesh,
      99             :         original_subdomain_ids,
     100          56 :         *original_subdomain_ids.rbegin() + 1,
     101             :         getParam<SubdomainName>("converted_tet_element_subdomain_name_suffix"),
     102             :         getParam<SubdomainName>("converted_pyramid_element_subdomain_name_suffix"));
     103             :   }
     104           0 :   catch (const std::exception & e)
     105             :   {
     106           0 :     if (((std::string)e.what()).compare(26, 4, "TET4") == 0)
     107           0 :       paramError("converted_tet_element_subdomain_name_suffix", e.what());
     108             :     else // if (((std::string)e.what()).compare(26, 7, "PYRAMID5") == 0)
     109           0 :       paramError("converted_pyramid_element_subdomain_name_suffix", e.what());
     110           0 :   }
     111             : 
     112             :   // MeshSerializer's destructor calls delete_remote_elements()
     113          56 :   if (!mesh.is_replicated())
     114           0 :     mesh.prepare_for_use();
     115             :   else
     116          56 :     mesh.unset_is_prepared();
     117             : 
     118         112 :   return std::move(_input);
     119          56 : }

Generated by: LCOV version 1.14