13 #include "libmesh/elem.h" 14 #include "libmesh/mesh_refinement.h" 24 params.
addClassDescription(
"Mesh generator which refines one or more blocks in an existing mesh");
26 params.
addRequiredParam<std::vector<SubdomainName>>(
"block",
"The list of blocks to be refined");
29 "Minimum amount of times to refine each block, corresponding to their index in 'block'");
31 "enable_neighbor_refinement",
33 "Toggles whether neighboring level one elements should be refined or not. Defaults to true. " 34 "False may lead to unsupported mesh non-conformality without great care.");
36 "max_element_volume", 1e8,
"If elements are above that size, they will be refined more");
43 _input(getMesh(
"input")),
44 _block(getParam<
std::vector<SubdomainName>>(
"block")),
45 _refinement(getParam<
std::vector<unsigned
int>>(
"refinement")),
46 _enable_neighbor_refinement(getParam<bool>(
"enable_neighbor_refinement")),
47 _max_element_volume(getParam<
Real>(
"max_element_volume"))
50 paramError(
"refinement",
"The blocks and refinement parameter vectors should be the same size");
53 std::unique_ptr<MeshBase>
57 const auto block_ids =
61 std::set<SubdomainID> mesh_blocks;
62 _input->subdomain_ids(mesh_blocks);
64 for (std::size_t i = 0; i < block_ids.size(); ++i)
68 getParam<std::vector<SubdomainName>>(
"block")[i],
69 "' was not found within the mesh");
71 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
74 if (
max > 0 && !
mesh->is_replicated() && !
mesh->is_prepared())
77 mesh->prepare_for_use();
81 if (
max > 0 && !mesh_ptr->is_replicated() && !mesh_ptr->is_prepared())
84 mesh_ptr->prepare_for_use();
87 bool found_element_to_refine =
true;
88 bool refined_on_size =
false;
89 while (found_element_to_refine)
91 found_element_to_refine =
false;
92 for (
auto bid : block_ids)
93 for (
auto & elem : mesh_ptr->active_subdomain_elements_ptr_range(bid))
96 elem->set_refinement_flag(Elem::REFINE);
97 found_element_to_refine =
true;
100 mesh_ptr->comm().max(found_element_to_refine);
102 if (found_element_to_refine)
108 refined_on_size =
true;
112 if (refined_on_size ||
max > 0)
113 mesh_ptr->set_isnt_prepared();
118 std::unique_ptr<MeshBase>
120 std::unique_ptr<MeshBase> & mesh,
121 std::vector<unsigned int> refinement,
123 unsigned int ref_step)
127 for (std::size_t i = 0; i < block_ids.size(); i++)
129 if (refinement[i] > 0 && refinement[i] > ref_step)
131 for (
const auto & elem :
mesh->active_subdomain_elements_ptr_range(block_ids[i]))
132 elem->set_refinement_flag(Elem::REFINE);
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.
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
virtual std::unique_ptr< MeshBase > recursive_refine(const std::vector< subdomain_id_type > block_ids, std::unique_ptr< MeshBase > &mesh, const std::vector< unsigned int > refinement, const unsigned int max, unsigned int ref_step=0)
The actual function refining the blocks.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
auto max(const L &left, const R &right)
RefineBlockGenerator(const InputParameters ¶meters)
std::unique_ptr< MeshBase > & _input
Input mesh to refine.
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
const std::vector< unsigned int > _refinement
The amount of times to refine each block, corresponding to their index in 'block'.
const Real _max_element_volume
maximum element size over which elements are refined
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
const std::vector< SubdomainName > _block
List of block(s) to refine.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
unsigned char & face_level_mismatch_limit()
const bool _enable_neighbor_refinement
Toggles whether neighboring level one elements should be refined or not. Defaults to true...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", RefineBlockGenerator)
MeshGenerators are objects that can modify or add to an existing mesh.
void ErrorVector unsigned int
static InputParameters validParams()
MeshGenerator for refining one or more blocks.