https://mooseframework.inl.gov
FlipSidesetGenerator.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 
10 #include "FlipSidesetGenerator.h"
11 
12 #include "CastUniquePointer.h"
13 
15 
18 {
20  params.addClassDescription("A Mesh Generator which flips a given sideset");
21  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
22  params.addRequiredParam<BoundaryName>("boundary", "The sideset (boundary) that will be flipped");
23  return params;
24 }
25 
27  : MeshGenerator(parameters),
28  _input(getMesh("input")),
29  _sideset_name(getParam<BoundaryName>("boundary"))
30 {
31 }
32 
33 std::unique_ptr<MeshBase>
35 {
36  // get boundary info
37  BoundaryInfo & boundary_info = _input->get_boundary_info();
38  // get id of the input sideset
39  const auto sideset_id = boundary_info.get_id_by_name(_sideset_name);
40 
41  // Throw an error if the sideset doesn't exist
42  if (sideset_id == libMesh::BoundaryInfo::invalid_id)
43  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  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  for (const auto & [old_elem, id_pair] : sideset_map)
52  {
53  boundary_id_type boundary_id = std::get<1>(id_pair);
54  if (boundary_id == sideset_id)
55  {
56  const auto old_side_id = std::get<0>(id_pair);
57  const auto old_elem_id = old_elem->id();
58  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  if (!new_elem)
62  mooseError("elem " + std::to_string(old_elem_id) +
63  " does not have a neighbor through side " + std::to_string(old_side_id) +
64  " therefore it cannot be flipped");
65 
66  const auto new_side_id = new_elem->which_neighbor_am_i(old_elem);
67  boundary_info.remove_side(old_elem, old_side_id, sideset_id);
68  boundary_info.add_side(new_elem, new_side_id, sideset_id);
69  }
70  }
71  return dynamic_pointer_cast<MeshBase>(_input);
72 }
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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
static InputParameters validParams()
registerMooseObject("MooseApp", FlipSidesetGenerator)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
FlipSidesetGenerator(const InputParameters &parameters)
const BoundaryName _sideset_name
Name of the sideset to flip.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
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...
int8_t boundary_id_type
std::unique_ptr< MeshBase > & _input
Input mesh the operation will be applied to.
static const boundary_id_type invalid_id
MeshGenerator for flipping a sideset.
static InputParameters validParams()
Definition: MeshGenerator.C:23
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32