www.mooseframework.org
SmoothMeshGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "SmoothMeshGenerator.h"
11 
12 // libMesh includes
13 #include "libmesh/mesh_smoother_laplace.h"
14 #include "libmesh/unstructured_mesh.h"
15 #include "libmesh/replicated_mesh.h"
16 
17 #include "CastUniquePointer.h"
18 
20 
23 {
25 
26  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to smooth.");
27  params.addClassDescription("Utilizes a simple Laplacian based smoother to attempt to improve "
28  "mesh quality. Will not move boundary nodes or nodes along "
29  "block/subdomain boundaries");
30 
31  params.addParam<unsigned int>("iterations", 1, "The number of smoothing iterations to do.");
32 
33  return params;
34 }
35 
37  : MeshGenerator(parameters),
38  _input(getMesh("input")),
39  _iterations(getParam<unsigned int>("iterations"))
40 {
41 }
42 
43 std::unique_ptr<MeshBase>
45 {
46  std::unique_ptr<MeshBase> old_mesh = std::move(_input);
47  if (!old_mesh->is_replicated())
48  mooseError("SmoothMeshGenerator is not implemented for distributed meshes");
49 
50  auto mesh = dynamic_pointer_cast<ReplicatedMesh>(old_mesh);
51 
52  LaplaceMeshSmoother lms(static_cast<UnstructuredMesh &>(*mesh));
53 
54  lms.smooth(_iterations);
55 
56  return dynamic_pointer_cast<MeshBase>(mesh);
57 }
unsigned int _iterations
The number of smoothing passes to do.
static InputParameters validParams()
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
registerMooseObject("MooseApp", SmoothMeshGenerator)
static InputParameters validParams()
Definition: MeshGenerator.C:23
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
SmoothMeshGenerator(const InputParameters &parameters)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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 option parameter and a documentation string to the InputParameters object...
MeshGenerator for doing mesh smoothing.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
void ErrorVector unsigned int