forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created PPs to determine min/max/average of a material property
Closes idaholab#14648
- Loading branch information
1 parent
d0a0644
commit 70e5886
Showing
12 changed files
with
404 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
framework/doc/content/source/postprocessors/ElementAverageMaterialProperty.md
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,9 @@ | ||
# ElementAverageMaterialProperty | ||
|
||
This post-processor computes the average of a material property over a domain. | ||
|
||
!syntax parameters /Postprocessors/ElementAverageMaterialProperty | ||
|
||
!syntax inputs /Postprocessors/ElementAverageMaterialProperty | ||
|
||
!syntax children /Postprocessors/ElementAverageMaterialProperty |
10 changes: 10 additions & 0 deletions
10
framework/doc/content/source/postprocessors/ElementExtremeMaterialProperty.md
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,10 @@ | ||
# ElementExtremeMaterialProperty | ||
|
||
This post-processor computes the minimum or maximum of a material property from | ||
all quadrature points in a domain. | ||
|
||
!syntax parameters /Postprocessors/ElementExtremeMaterialProperty | ||
|
||
!syntax inputs /Postprocessors/ElementExtremeMaterialProperty | ||
|
||
!syntax children /Postprocessors/ElementExtremeMaterialProperty |
34 changes: 34 additions & 0 deletions
34
framework/include/postprocessors/ElementAverageMaterialProperty.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,34 @@ | ||
//* 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 "ElementIntegralMaterialProperty.h" | ||
|
||
class ElementAverageMaterialProperty; | ||
|
||
/** | ||
* Computes the average of a material property over a volume. | ||
*/ | ||
class ElementAverageMaterialProperty : public ElementIntegralMaterialProperty | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ElementAverageMaterialProperty(const InputParameters & parameters); | ||
|
||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual Real getValue() override; | ||
virtual void threadJoin(const UserObject & y) override; | ||
|
||
protected: | ||
/// Domain volume | ||
Real _volume; | ||
}; |
50 changes: 50 additions & 0 deletions
50
framework/include/postprocessors/ElementExtremeMaterialProperty.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,50 @@ | ||
//* 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 "ElementPostprocessor.h" | ||
|
||
class ElementExtremeMaterialProperty; | ||
|
||
/// Determines the minimum or maximum of a material property over a volume. | ||
class ElementExtremeMaterialProperty : public ElementPostprocessor | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
/// Type of extreme value to compute | ||
enum ExtremeType | ||
{ | ||
MAX, | ||
MIN | ||
}; | ||
|
||
ElementExtremeMaterialProperty(const InputParameters & parameters); | ||
|
||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual Real getValue() override; | ||
virtual void threadJoin(const UserObject & y) override; | ||
|
||
protected: | ||
virtual void computeQpValue(); | ||
|
||
/// Material property for which to find extreme | ||
const MaterialProperty<Real> & _mat_prop; | ||
|
||
/// Type of extreme value to compute | ||
ExtremeType _type; | ||
|
||
/// Extreme value | ||
Real _value; | ||
|
||
/// Current quadrature point | ||
unsigned int _qp; | ||
}; |
61 changes: 61 additions & 0 deletions
61
framework/src/postprocessors/ElementAverageMaterialProperty.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,61 @@ | ||
//* 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 "ElementAverageMaterialProperty.h" | ||
|
||
registerMooseObject("MooseApp", ElementAverageMaterialProperty); | ||
|
||
InputParameters | ||
ElementAverageMaterialProperty::validParams() | ||
{ | ||
InputParameters params = ElementIntegralMaterialProperty::validParams(); | ||
params.addClassDescription("Computes the average of a material property over a volume."); | ||
return params; | ||
} | ||
|
||
ElementAverageMaterialProperty::ElementAverageMaterialProperty(const InputParameters & parameters) | ||
: ElementIntegralMaterialProperty(parameters), _volume(0.0) | ||
{ | ||
} | ||
|
||
void | ||
ElementAverageMaterialProperty::initialize() | ||
{ | ||
ElementIntegralMaterialProperty::initialize(); | ||
|
||
_volume = 0.0; | ||
} | ||
|
||
void | ||
ElementAverageMaterialProperty::execute() | ||
{ | ||
ElementIntegralMaterialProperty::execute(); | ||
|
||
_volume += _current_elem_volume; | ||
} | ||
|
||
Real | ||
ElementAverageMaterialProperty::getValue() | ||
{ | ||
const Real integral = ElementIntegralMaterialProperty::getValue(); | ||
|
||
gatherSum(_volume); | ||
|
||
return integral / _volume; | ||
} | ||
|
||
void | ||
ElementAverageMaterialProperty::threadJoin(const UserObject & y) | ||
{ | ||
ElementIntegralMaterialProperty::threadJoin(y); | ||
|
||
const ElementAverageMaterialProperty & pps = | ||
static_cast<const ElementAverageMaterialProperty &>(y); | ||
_volume += pps._volume; | ||
} |
115 changes: 115 additions & 0 deletions
115
framework/src/postprocessors/ElementExtremeMaterialProperty.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,115 @@ | ||
//* 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 "ElementExtremeMaterialProperty.h" | ||
|
||
#include <algorithm> | ||
#include <limits> | ||
|
||
registerMooseObject("MooseApp", ElementExtremeMaterialProperty); | ||
|
||
InputParameters | ||
ElementExtremeMaterialProperty::validParams() | ||
{ | ||
InputParameters params = ElementPostprocessor::validParams(); | ||
|
||
params.addRequiredParam<MaterialPropertyName>("mat_prop", | ||
"Material property for which to find extreme"); | ||
MooseEnum type_options("max=0 min=1"); | ||
params.addRequiredParam<MooseEnum>("value_type", | ||
type_options, | ||
"Type of extreme value to return: 'max' " | ||
"returns the maximum value and 'min' returns " | ||
"the minimum value."); | ||
|
||
params.addClassDescription( | ||
"Determines the minimum or maximum of a material property over a volume."); | ||
|
||
return params; | ||
} | ||
|
||
ElementExtremeMaterialProperty::ElementExtremeMaterialProperty(const InputParameters & parameters) | ||
: ElementPostprocessor(parameters), | ||
|
||
_mat_prop(getMaterialProperty<Real>("mat_prop")), | ||
_type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")), | ||
_value(_type == 0 ? -std::numeric_limits<Real>::max() : std::numeric_limits<Real>::max()), | ||
_qp(0) | ||
{ | ||
} | ||
|
||
void | ||
ElementExtremeMaterialProperty::initialize() | ||
{ | ||
switch (_type) | ||
{ | ||
case MAX: | ||
_value = -std::numeric_limits<Real>::max(); // start w/ the min | ||
break; | ||
|
||
case MIN: | ||
_value = std::numeric_limits<Real>::max(); // start w/ the max | ||
break; | ||
} | ||
} | ||
|
||
void | ||
ElementExtremeMaterialProperty::execute() | ||
{ | ||
for (_qp = 0; _qp < _qrule->n_points(); _qp++) | ||
computeQpValue(); | ||
} | ||
|
||
void | ||
ElementExtremeMaterialProperty::computeQpValue() | ||
{ | ||
switch (_type) | ||
{ | ||
case MAX: | ||
_value = std::max(_value, _mat_prop[_qp]); | ||
break; | ||
|
||
case MIN: | ||
_value = std::min(_value, _mat_prop[_qp]); | ||
break; | ||
} | ||
} | ||
|
||
Real | ||
ElementExtremeMaterialProperty::getValue() | ||
{ | ||
switch (_type) | ||
{ | ||
case MAX: | ||
gatherMax(_value); | ||
break; | ||
case MIN: | ||
gatherMin(_value); | ||
break; | ||
} | ||
|
||
return _value; | ||
} | ||
|
||
void | ||
ElementExtremeMaterialProperty::threadJoin(const UserObject & y) | ||
{ | ||
const ElementExtremeMaterialProperty & pps = | ||
static_cast<const ElementExtremeMaterialProperty &>(y); | ||
|
||
switch (_type) | ||
{ | ||
case MAX: | ||
_value = std::max(_value, pps._value); | ||
break; | ||
case MIN: | ||
_value = std::min(_value, pps._value); | ||
break; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ests/postprocessors/element_average_material_property/element_average_material_property.i
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,45 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 1 | ||
nx = 4 | ||
xmin = 0 | ||
xmax = 1 | ||
[] | ||
|
||
[Functions] | ||
[./fn] | ||
type = PiecewiseConstant | ||
axis = x | ||
x = '0 0.25 0.50 0.75' | ||
y = '5 2 3 6' | ||
[../] | ||
[] | ||
|
||
[Materials] | ||
[./mat] | ||
type = GenericFunctionMaterial | ||
prop_names = 'mat_prop' | ||
prop_values = 'fn' | ||
[../] | ||
[] | ||
|
||
[Postprocessors] | ||
[./avg] | ||
type = ElementAverageMaterialProperty | ||
mat_prop = mat_prop | ||
execute_on = 'INITIAL' | ||
[../] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Outputs] | ||
csv = true | ||
execute_on = 'INITIAL' | ||
[] |
2 changes: 2 additions & 0 deletions
2
...ocessors/element_average_material_property/gold/element_average_material_property_out.csv
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,2 @@ | ||
time,avg | ||
0,4 |
12 changes: 12 additions & 0 deletions
12
test/tests/postprocessors/element_average_material_property/tests
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,12 @@ | ||
[Tests] | ||
design = 'ElementAverageMaterialProperty.md' | ||
issues = '#14648' | ||
|
||
[./test_average] | ||
type = 'CSVDiff' | ||
input = 'element_average_material_property.i' | ||
csvdiff = 'element_average_material_property_out.csv' | ||
|
||
requirement = 'The system shall compute the the average value of a material property over the domain.' | ||
[../] | ||
[] |
52 changes: 52 additions & 0 deletions
52
...ests/postprocessors/element_extreme_material_property/element_extreme_material_property.i
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,52 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 1 | ||
nx = 4 | ||
xmin = 0 | ||
xmax = 1 | ||
[] | ||
|
||
[Functions] | ||
[./fn] | ||
type = PiecewiseConstant | ||
axis = x | ||
x = '0 0.25 0.50 0.75' | ||
y = '5 2 3 4' | ||
[../] | ||
[] | ||
|
||
[Materials] | ||
[./mat] | ||
type = GenericFunctionMaterial | ||
prop_names = 'mat_prop' | ||
prop_values = 'fn' | ||
[../] | ||
[] | ||
|
||
[Postprocessors] | ||
[./min] | ||
type = ElementExtremeMaterialProperty | ||
mat_prop = mat_prop | ||
value_type = min | ||
execute_on = 'INITIAL' | ||
[../] | ||
[./max] | ||
type = ElementExtremeMaterialProperty | ||
mat_prop = mat_prop | ||
value_type = max | ||
execute_on = 'INITIAL' | ||
[../] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Outputs] | ||
csv = true | ||
execute_on = 'INITIAL' | ||
[] |
Oops, something went wrong.