https://mooseframework.inl.gov
BoundaryElementConversionGenerator.C
Go to the documentation of this file.
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 
12 #include "CastUniquePointer.h"
13 #include "MooseMeshUtils.h"
14 
16 
19 {
21 
22  params.addParam<MeshGeneratorName>(
23  "input",
24  "mesh generator creating the mesh on which to create the boundary transition layer on.");
25  params.addRequiredParam<std::vector<BoundaryName>>(
26  "boundary_names", "Boundaries that need to be converted to form a transition layer.");
27  params.addParam<unsigned int>(
28  "conversion_element_layer_number",
29  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  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  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  params.addParam<bool>("external_boundaries_checking",
43  false,
44  "Whether to check if provided boundaries are external.");
45 
46  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  return params;
50 }
51 
53  const InputParameters & parameters)
54  : MeshGenerator(parameters),
55  _input(getMesh("input")),
56  _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names")),
57  _conversion_element_layer_number(getParam<unsigned int>("conversion_element_layer_number")),
58  _external_boundaries_checking(getParam<bool>("external_boundaries_checking"))
59 {
60 }
61 
62 std::unique_ptr<MeshBase>
64 {
65  auto replicated_mesh_ptr = dynamic_cast<ReplicatedMesh *>(_input.get());
66  if (!replicated_mesh_ptr)
67  paramError("input", "Input is not a replicated mesh, which is required");
68 
69  ReplicatedMesh & mesh = *replicated_mesh_ptr;
70 
71  // collect the subdomain ids of the original mesh
72  std::set<subdomain_id_type> original_subdomain_ids;
73  for (auto elem_it = mesh.active_elements_begin(); elem_it != mesh.active_elements_end();
74  elem_it++)
75  {
76  original_subdomain_ids.emplace((*elem_it)->subdomain_id());
77  }
78 
79  try
80  {
83  }
84  catch (const MooseException & e)
85  {
86  if (((std::string)e.what()).compare("subdomain id overflow") == 0)
87  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  else if (((std::string)e.what()).compare(13, 8, "boundary") == 0)
92  paramError("boundary_names", e.what());
93  else
94  paramError("input", e.what());
95  }
96 
97  try
98  {
100  mesh,
101  original_subdomain_ids,
102  *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  catch (const std::exception & e)
107  {
108  if (((std::string)e.what()).compare(26, 4, "TET4") == 0)
109  paramError("converted_tet_element_subdomain_name_suffix", e.what());
110  else // if (((std::string)e.what()).compare(26, 7, "PYRAMID5") == 0)
111  paramError("converted_pyramid_element_subdomain_name_suffix", e.what());
112  }
113 
114  return std::move(_input);
115 }
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Convert the elements involved in a set of external boundaries to ensure that the boundary set only co...
const unsigned int _conversion_element_layer_number
Number of layers of elements to be converted.
virtual const char * what() const
Get out the error message.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
BoundaryElementConversionGenerator(const InputParameters &parameters)
const bool _external_boundaries_checking
Whether to check if the provided boundaries are external.
static InputParameters validParams()
Definition: MeshGenerator.C:23
Provides a way for users to bail out of the current solve.
void assignConvertedElementsSubdomainNameSuffix(ReplicatedMesh &mesh, const std::set< subdomain_id_type > &original_subdomain_ids, const subdomain_id_type sid_shift_base, const SubdomainName &tet_suffix, const SubdomainName &pyramid_suffix)
Assign a subdomain name suffix to the converted elements created during transition layer generation...
registerMooseObject("MooseApp", BoundaryElementConversionGenerator)
const std::vector< BoundaryName > _boundary_names
The boundaries to convert the neighboring elements of.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
void ErrorVector unsigned int
void transitionLayerGenerator(ReplicatedMesh &mesh, const std::vector< BoundaryName > &boundary_names, const unsigned int conversion_element_layer_number, const bool external_boundaries_checking)
Generate a transition layer of elements with TRI3 surfaces on the given boundaries.