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

Generated by: LCOV version 1.14