Skip to content

Commit

Permalink
Added MooseMesh::getBlocksMaxDimension()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahansel committed Apr 25, 2023
1 parent cf41d7d commit fe3f50a
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework/include/base/MooseApp.h
Expand Up @@ -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; }

Expand Down
7 changes: 6 additions & 1 deletion framework/include/mesh/MooseMesh.h
Expand Up @@ -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.
*/
Expand All @@ -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<SubdomainName> & blocks) const;

/**
* Returns a vector of boundary IDs for the requested element on the
* requested side.
Expand Down
12 changes: 12 additions & 0 deletions framework/src/mesh/MooseMesh.C
Expand Up @@ -2500,6 +2500,18 @@ MooseMesh::effectiveSpatialDimension() const
return 1;
}

unsigned int
MooseMesh::getBlocksMaxDimension(const std::vector<SubdomainName> & blocks) const
{
unsigned short dim = 0;
const auto subdomain_ids = getSubdomainIDs(blocks);
const std::set<SubdomainID> 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<BoundaryID>
MooseMesh::getBoundaryIDs(const Elem * const elem, const unsigned short int side) const
{
Expand Down
32 changes: 32 additions & 0 deletions 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<SubdomainName> _blocks;
};
31 changes: 31 additions & 0 deletions 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<std::vector<SubdomainName>>("block", "The list of subdomain names");
return params;
}

BlocksMaxDimensionPostprocessor::BlocksMaxDimensionPostprocessor(const InputParameters & parameters)
: GeneralPostprocessor(parameters), _blocks(getParam<std::vector<SubdomainName>>("block"))
{
}

Real
BlocksMaxDimensionPostprocessor::getValue()
{
return getMooseApp().actionWarehouse().mesh()->getBlocksMaxDimension(_blocks);
}
146 changes: 146 additions & 0 deletions 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'
[]
@@ -0,0 +1,2 @@
time,dim_1d,dim_1d_2d,dim_1d_2d_3d
0,1,2,3
12 changes: 12 additions & 0 deletions 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.'
[]
[]

0 comments on commit fe3f50a

Please sign in to comment.