diff --git a/framework/include/base/MooseApp.h b/framework/include/base/MooseApp.h index b7615a292970..a1c9c50e093a 100644 --- a/framework/include/base/MooseApp.h +++ b/framework/include/base/MooseApp.h @@ -713,7 +713,7 @@ class MooseApp : public ConsoleStreamInterface, const MooseMesh * masterMesh() const { return _master_mesh; } /** - * Returns a pointer to the master mesh + * Returns a pointer to the master displaced mesh */ const MooseMesh * masterDisplacedMesh() const { return _master_displaced_mesh; } diff --git a/framework/include/mesh/MooseMesh.h b/framework/include/mesh/MooseMesh.h index c00f72e58d26..b4fad313db54 100644 --- a/framework/include/mesh/MooseMesh.h +++ b/framework/include/mesh/MooseMesh.h @@ -158,7 +158,7 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf virtual void buildMesh() = 0; /** - * Returns MeshBase::mesh_dimsension(), (not + * Returns MeshBase::mesh_dimension(), (not * MeshBase::spatial_dimension()!) of the underlying libMesh mesh * object. */ @@ -171,6 +171,11 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf */ virtual unsigned int effectiveSpatialDimension() const; + /** + * Returns the maximum element dimension on the given blocks + */ + unsigned int getBlocksMaxDimension(const std::vector & blocks) const; + /** * Returns a vector of boundary IDs for the requested element on the * requested side. diff --git a/framework/src/mesh/MooseMesh.C b/framework/src/mesh/MooseMesh.C index b5d569909e1a..48744e908fcc 100644 --- a/framework/src/mesh/MooseMesh.C +++ b/framework/src/mesh/MooseMesh.C @@ -2500,6 +2500,18 @@ MooseMesh::effectiveSpatialDimension() const return 1; } +unsigned int +MooseMesh::getBlocksMaxDimension(const std::vector & blocks) const +{ + unsigned short dim = 0; + const auto subdomain_ids = getSubdomainIDs(blocks); + const std::set subdomain_ids_set(subdomain_ids.begin(), subdomain_ids.end()); + for (const auto & elem : getMesh().active_subdomain_set_elements_ptr_range(subdomain_ids_set)) + dim = std::max(dim, elem->dim()); + + return dim; +} + std::vector MooseMesh::getBoundaryIDs(const Elem * const elem, const unsigned short int side) const { diff --git a/test/include/postprocessors/BlocksMaxDimensionPostprocessor.h b/test/include/postprocessors/BlocksMaxDimensionPostprocessor.h new file mode 100644 index 000000000000..5cbdda340d0c --- /dev/null +++ b/test/include/postprocessors/BlocksMaxDimensionPostprocessor.h @@ -0,0 +1,32 @@ +//* This file is part of the MOOSE framework +//* https://www.mooseframework.org +//* +//* All rights reserved, see COPYRIGHT for full restrictions +//* https://github.com/idaholab/moose/blob/master/COPYRIGHT +//* +//* Licensed under LGPL 2.1, please see LICENSE for details +//* https://www.gnu.org/licenses/lgpl-2.1.html + +#pragma once + +#include "GeneralPostprocessor.h" + +/** + * Gets the mesh dimension of a list of blocks + */ +class BlocksMaxDimensionPostprocessor : public GeneralPostprocessor +{ +public: + static InputParameters validParams(); + + BlocksMaxDimensionPostprocessor(const InputParameters & parameters); + + virtual void initialize() override {} + virtual void execute() override {} + + virtual Real getValue() override; + +protected: + /// Subdomain names + std::vector _blocks; +}; diff --git a/test/src/postprocessors/BlocksMaxDimensionPostprocessor.C b/test/src/postprocessors/BlocksMaxDimensionPostprocessor.C new file mode 100644 index 000000000000..b94256e53bff --- /dev/null +++ b/test/src/postprocessors/BlocksMaxDimensionPostprocessor.C @@ -0,0 +1,31 @@ +//* This file is part of the MOOSE framework +//* https://www.mooseframework.org +//* +//* All rights reserved, see COPYRIGHT for full restrictions +//* https://github.com/idaholab/moose/blob/master/COPYRIGHT +//* +//* Licensed under LGPL 2.1, please see LICENSE for details +//* https://www.gnu.org/licenses/lgpl-2.1.html + +#include "BlocksMaxDimensionPostprocessor.h" + +registerMooseObject("MooseTestApp", BlocksMaxDimensionPostprocessor); + +InputParameters +BlocksMaxDimensionPostprocessor::validParams() +{ + InputParameters params = GeneralPostprocessor::validParams(); + params.addRequiredParam>("block", "The list of subdomain names"); + return params; +} + +BlocksMaxDimensionPostprocessor::BlocksMaxDimensionPostprocessor(const InputParameters & parameters) + : GeneralPostprocessor(parameters), _blocks(getParam>("block")) +{ +} + +Real +BlocksMaxDimensionPostprocessor::getValue() +{ + return getMooseApp().actionWarehouse().mesh()->getBlocksMaxDimension(_blocks); +} diff --git a/test/tests/mesh/blocks_max_dimension/blocks_max_dimension.i b/test/tests/mesh/blocks_max_dimension/blocks_max_dimension.i new file mode 100644 index 000000000000..416b5fd3634b --- /dev/null +++ b/test/tests/mesh/blocks_max_dimension/blocks_max_dimension.i @@ -0,0 +1,146 @@ +# This input file tests MooseMesh::getBlocksMaxDimension(), which gets the MESH +# dimension of a list of subdomain names. +# +# Note the differences between the MESH dimension and the SPATIAL dimension. +# The SPATIAL dimension just looks at the maximum coordinate dimension used: +# - Equals 3 if there is a nonzero z coordinate +# - Equals 2 if there is no nonzero z coordinate, but there is a nonzero y coordinate +# - Equals 1 if there is no nonzero y or z coordinate +# In contrast, the MESH dimension looks at the dimensionality of the elements. +# Therefore, the MESH dimension differs from the SPATIAL dimension when: +# - a 1D element has a nonzero y or z coordinate +# - a 2D element has a nonzero z coordinate +# This test will include subdomains with these cases and test different +# lists of subdomains. +# + +[Mesh] + # 1D block + [block1d_mg] + type = GeneratedMeshGenerator + dim = 1 + xmin = 0.0 + xmax = 1.0 + [] + [block1d_renumber_mg] + type = RenameBlockGenerator + input = block1d_mg + old_block = 0 + new_block = 1 + [] + [block1d_rename_mg] + type = RenameBlockGenerator + input = block1d_renumber_mg + old_block = 1 + new_block = 'block1d' + [] + [block1d_translate_mg] + type = TransformGenerator + input = block1d_rename_mg + transform = TRANSLATE + vector_value = '0 0 1.0' + [] + + # 2D block + [block2d_mg] + type = GeneratedMeshGenerator + dim = 2 + xmin = 2.0 + xmax = 3.0 + ymin = 0.0 + ymax = 1.0 + boundary_id_offset = 10 + [] + [block2d_renumber_mg] + type = RenameBlockGenerator + input = block2d_mg + old_block = 0 + new_block = 2 + [] + [block2d_rename_mg] + type = RenameBlockGenerator + input = block2d_renumber_mg + old_block = 2 + new_block = 'block2d' + [] + [boundary2d_rename_mg] + type = RenameBoundaryGenerator + input = block2d_rename_mg + old_boundary = 'left right bottom top' + new_boundary = 'left2d right2d bottom2d top2d' + [] + [block2d_translate_mg] + type = TransformGenerator + input = boundary2d_rename_mg + transform = TRANSLATE + vector_value = '0 0 1.0' + [] + + # 3D block + [block3d_mg] + type = GeneratedMeshGenerator + dim = 3 + xmin = 4.0 + xmax = 5.0 + ymin = 0.0 + ymax = 1.0 + zmin = 0.0 + zmax = 1.0 + boundary_id_offset = 20 + [] + [block3d_renumber_mg] + type = RenameBlockGenerator + input = block3d_mg + old_block = 0 + new_block = 3 + [] + [block3d_rename_mg] + type = RenameBlockGenerator + input = block3d_renumber_mg + old_block = 3 + new_block = 'block3d' + [] + [boundary3d_rename_mg] + type = RenameBoundaryGenerator + input = block3d_rename_mg + old_boundary = 'left right bottom top back front' + new_boundary = 'left3d right3d bottom3d top3d back3d front3d' + [] + + # combine blocks + [combiner_mg] + type = CombinerGenerator + inputs = 'block1d_translate_mg block2d_translate_mg boundary3d_rename_mg' + [] +[] + +[Postprocessors] + [dim_1d] + type = BlocksMaxDimensionPostprocessor + block = 'block1d' + execute_on = 'INITIAL' + [] + [dim_1d_2d] + type = BlocksMaxDimensionPostprocessor + block = 'block1d block2d' + execute_on = 'INITIAL' + [] + [dim_1d_2d_3d] + type = BlocksMaxDimensionPostprocessor + block = 'block1d block2d block3d' + execute_on = 'INITIAL' + [] +[] + +[Executioner] + type = Steady +[] + +[Problem] + solve = false +[] + +[Outputs] + csv = true + execute_on = 'INITIAL' +[] diff --git a/test/tests/mesh/blocks_max_dimension/gold/blocks_max_dimension_out.csv b/test/tests/mesh/blocks_max_dimension/gold/blocks_max_dimension_out.csv new file mode 100644 index 000000000000..b1472219637d --- /dev/null +++ b/test/tests/mesh/blocks_max_dimension/gold/blocks_max_dimension_out.csv @@ -0,0 +1,2 @@ +time,dim_1d,dim_1d_2d,dim_1d_2d_3d +0,1,2,3 diff --git a/test/tests/mesh/blocks_max_dimension/tests b/test/tests/mesh/blocks_max_dimension/tests new file mode 100644 index 000000000000..1bce583d6c36 --- /dev/null +++ b/test/tests/mesh/blocks_max_dimension/tests @@ -0,0 +1,12 @@ +[Tests] + issues = '#23794' + design = 'Mesh/index.md' + [test] + type = CSVDiff + input = 'blocks_max_dimension.i' + csvdiff = 'blocks_max_dimension_out.csv' + recover = false # no solve + + requirement = 'The system shall get the correct mesh dimension for a list of subdomains.' + [] +[]