forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add piecewise constant by block regular material, as some users ne…
…ed it
- Loading branch information
Showing
10 changed files
with
200 additions
and
20 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
framework/include/materials/PiecewiseConstantByBlockMaterial.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "Material.h" | ||
|
||
#include <unordered_map> | ||
|
||
template <bool is_ad> | ||
class PiecewiseConstantByBlockMaterialTempl : public Material | ||
{ | ||
public: | ||
PiecewiseConstantByBlockMaterialTempl(const InputParameters & parameters); | ||
static InputParameters validParams(); | ||
|
||
protected: | ||
virtual void computeQpProperties() override; | ||
|
||
private: | ||
GenericMaterialProperty<Real, is_ad> & _prop; | ||
std::unordered_map<SubdomainID, Real> _sub_id_to_prop; | ||
}; | ||
|
||
typedef PiecewiseConstantByBlockMaterialTempl<false> PiecewiseConstantByBlockMaterial; | ||
typedef PiecewiseConstantByBlockMaterialTempl<true> ADPiecewiseConstantByBlockMaterial; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
framework/src/materials/PiecewiseConstantByBlockMaterial.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//* 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 "PiecewiseConstantByBlockMaterial.h" | ||
|
||
registerMooseObject("MooseApp", PiecewiseConstantByBlockMaterial); | ||
registerMooseObject("MooseApp", ADPiecewiseConstantByBlockMaterial); | ||
|
||
template <bool is_ad> | ||
InputParameters | ||
PiecewiseConstantByBlockMaterialTempl<is_ad>::validParams() | ||
{ | ||
auto params = Material::validParams(); | ||
params.addClassDescription("Computes a property value on a per-subdomain basis"); | ||
// Somehow min gcc doesn't know the type of params here | ||
params.template addRequiredParam<MaterialPropertyName>("prop_name", | ||
"The name of the property to declare"); | ||
params.template addRequiredParam<std::map<std::string, Real>>( | ||
"subdomain_to_prop_value", "Map from subdomain to property value"); | ||
return params; | ||
} | ||
|
||
template <bool is_ad> | ||
PiecewiseConstantByBlockMaterialTempl<is_ad>::PiecewiseConstantByBlockMaterialTempl( | ||
const InputParameters & params) | ||
: Material(params), _prop(declareGenericProperty<Real, is_ad>("prop_name")) | ||
{ | ||
for (const auto & map_pr : getParam<std::map<std::string, Real>>("subdomain_to_prop_value")) | ||
_sub_id_to_prop.emplace(std::make_pair(_mesh.getSubdomainID(map_pr.first), map_pr.second)); | ||
} | ||
|
||
template <bool is_ad> | ||
void | ||
PiecewiseConstantByBlockMaterialTempl<is_ad>::computeQpProperties() | ||
{ | ||
if (!_bnd) | ||
{ | ||
mooseAssert(_current_elem, | ||
"We should be on a block which means we should definitely have a current element"); | ||
auto it = _sub_id_to_prop.find(_current_elem->subdomain_id()); | ||
mooseAssert(it != _sub_id_to_prop.end(), | ||
"Block restriction must match the subdomain names passed in the " | ||
"subdomain_to_prop_value parameter"); | ||
_prop[_qp] = it->second; | ||
|
||
return; | ||
} | ||
|
||
if (_current_elem) | ||
{ | ||
_face_info = _mesh.faceInfo(_current_elem, _current_side); | ||
if (!_face_info) | ||
{ | ||
const Elem * const neighbor = _current_elem->neighbor_ptr(_current_side); | ||
mooseAssert(neighbor, "Should be non-null"); | ||
const auto neighbor_side = neighbor->which_neighbor_am_i(_current_elem); | ||
_face_info = _mesh.faceInfo(neighbor, neighbor_side); | ||
mooseAssert(_face_info, "We need to have retrieved something."); | ||
} | ||
mooseAssert(_current_elem->build_side_ptr(_current_side)->vertex_average() == | ||
_face_info->faceCentroid(), | ||
"Making sure we're in the right place"); | ||
auto it = _sub_id_to_prop.find(_current_elem->subdomain_id()); | ||
if (it == _sub_id_to_prop.end()) | ||
{ | ||
// We may be a ghosted material | ||
const bool current_elem_is_fi_elem = _current_elem == &_face_info->elem(); | ||
const Elem * const other_elem_to_try = | ||
current_elem_is_fi_elem ? _face_info->neighborPtr() : &_face_info->elem(); | ||
mooseAssert(other_elem_to_try, "This should be non-null"); | ||
it = _sub_id_to_prop.find(other_elem_to_try->subdomain_id()); | ||
mooseAssert(it != _sub_id_to_prop.end(), | ||
"Block restriction must match the subdomain names passed in the " | ||
"subdomain_to_prop_value parameter"); | ||
} | ||
_prop[_qp] = it->second; | ||
return; | ||
} | ||
|
||
mooseAssert(_face_info, | ||
"We must have set a face info object in order for the PiecewiseConstantByBlockMaterial " | ||
"class to work on faces"); | ||
|
||
// We must be off the domain | ||
auto it = _sub_id_to_prop.find(_face_info->elem().subdomain_id()); | ||
mooseAssert(it != _sub_id_to_prop.end(), | ||
"Block restriction must match the subdomain names passed in the " | ||
"subdomain_to_prop_value parameter"); | ||
_prop[_qp] = it->second; | ||
} | ||
|
||
template class PiecewiseConstantByBlockMaterialTempl<false>; | ||
template class PiecewiseConstantByBlockMaterialTempl<true>; |
Binary file removed
BIN
-31.4 KB
test/tests/materials/piecewise_by_block_functor_material/gold/test_out.e
Binary file not shown.
10 changes: 0 additions & 10 deletions
10
test/tests/materials/piecewise_by_block_functor_material/tests
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+33.1 KB
test/tests/materials/piecewise_by_block_material/gold/test_functor_out.e
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[Mesh] | ||
[gen] | ||
type = GeneratedMeshGenerator | ||
dim = 1 | ||
nx = 10 | ||
xmax = 2 | ||
[] | ||
[subdomain1] | ||
input = gen | ||
type = SubdomainBoundingBoxGenerator | ||
bottom_left = '1.0 0 0' | ||
block_id = 1 | ||
top_right = '2.0 1.0 0' | ||
[] | ||
[] | ||
|
||
[AuxVariables] | ||
[u] | ||
type = MooseVariableFVReal | ||
[] | ||
[] | ||
|
||
[AuxKernels] | ||
[to_var] | ||
type = ADMaterialRealAux | ||
variable = 'u' | ||
property = coeff | ||
[] | ||
[] | ||
|
||
[Materials] | ||
[coeff_mat] | ||
type = ADPiecewiseConstantByBlockMaterial | ||
prop_name = 'coeff' | ||
subdomain_to_prop_value = '0 4 | ||
1 2' | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
[] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Tests] | ||
issues = '#16758' | ||
[regular] | ||
type = Exodiff | ||
input = test.i | ||
exodiff = test_out.e | ||
requirement = 'The system shall provide a material object that can, for a single material property, map subdomain IDs to a possibly discontinuous property value.' | ||
design = 'PiecewiseConstantByBlockMaterial.md' | ||
[] | ||
[functor] | ||
type = Exodiff | ||
input = test_functor.i | ||
exodiff = test_functor_out.e | ||
requirement = 'The system shall provide a material object that can, for a single functor material property, map subdomain IDs to different functors.' | ||
design = 'PiecewiseByBlockFunctorMaterial.md' | ||
[] | ||
[] |