Skip to content

Commit

Permalink
allow material property names to be passed to ElementMaterialSampler, c…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessecarterMOOSE committed Jan 18, 2025
1 parent b451641 commit b65eb70
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 23 deletions.
70 changes: 49 additions & 21 deletions framework/src/vectorpostprocessors/ElementMaterialSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ InputParameters
ElementMaterialSampler::validParams()
{
InputParameters params = ElementVectorPostprocessor::validParams();
params.addClassDescription("Records all Real-valued material properties of a material object on "
"quadrature points on elements at the indicated execution points.");
params.addRequiredParam<MaterialName>("material",
params.addClassDescription("Records all Real-valued material properties of a material object, "
"or Real-valued material properties of the supplied property names "
"on quadrature points on elements at the indicated execution points.");
params.addParam<MaterialName>("material",
"Material for which all properties will be recorded.");
params.addParam<std::vector<MaterialPropertyName>>("property", "Material property names that will be recorded.");
params.addParam<std::vector<dof_id_type>>(
"elem_ids",
"Subset of element IDs to print data for. If omitted, all elements will be printed.");
Expand All @@ -44,35 +46,61 @@ ElementMaterialSampler::ElementMaterialSampler(const InputParameters & parameter
_y_coords(declareVector("y")),
_z_coords(declareVector("z"))
{
auto & mat = getMaterialByName(getParam<MaterialName>("material"), true);
auto & prop_names = mat.getSuppliedItems();
if (mat.isBoundaryMaterial())
mooseError(name(), ": boundary materials (i.e. ", mat.name(), ") cannot be used");
// Check either "material" or "property" was set but not both
if (parameters.isParamSetByUser("material") && parameters.isParamSetByUser("property"))
mooseError("Setting both 'material' and 'property' is not allowed. Use one or the other.");
if (!parameters.isParamSetByUser("material") && !parameters.isParamSetByUser("property"))
mooseError("Either 'material' and 'property' needs to be set.");

// List of property names to collect
std::vector<MaterialName> prop_names;

// Get list of elements from user
if (parameters.isParamValid("elem_ids"))
{
const auto & ids = getParam<std::vector<dof_id_type>>("elem_ids");
_elem_filter = std::set<dof_id_type>(ids.begin(), ids.end());
}

// If Material is used, get all properties.
if (parameters.isParamSetByUser("material"))
{
auto & mat = getMaterialByName(getParam<MaterialName>("material"), true);
if (mat.isBoundaryMaterial())
mooseError(name(), ": boundary materials (i.e. ", mat.name(), ") cannot be used");

// check requested materials are available
for (const auto & id : ids)
// Get property names from the Material
auto & props = mat.getSuppliedItems(); // returns std::set
prop_names = std::vector<MaterialName>(props.begin(), props.end());

// Check requested materials are available
if (_elem_filter)
{
auto el = _mesh.getMesh().query_elem_ptr(id);

// We'd better have found the requested element on *some*
// processor.
bool found_elem = (el != nullptr);
this->comm().max(found_elem);

// We might not have el on this processor in a distributed mesh,
// but it should be somewhere and it ought to have a material
// defined for its subdomain
if (!found_elem || (el && !mat.hasBlocks(el->subdomain_id())))
mooseError(name(), ": material ", mat.name(), " is not defined on element ", id);
for (const auto & id : *_elem_filter)
{
auto el = _mesh.getMesh().query_elem_ptr(id);

// We'd better have found the requested element on *some*
// processor.
bool found_elem = (el != nullptr);
this->comm().max(found_elem);

// We might not have el on this processor in a distributed mesh,
// but it should be somewhere and it ought to have a material
// defined for its subdomain
if (!found_elem || (el && !mat.hasBlocks(el->subdomain_id())))
mooseError(name(), ": material ", mat.name(), " is not defined on element ", id);
}
}

} else {

// Properties supplied by user
auto & props = getParam<std::vector<MaterialPropertyName>>("property");
prop_names = std::vector<MaterialName>(props.begin(), props.end());
}

// Check properties are valid and store references
for (auto & prop : prop_names)
{
if (hasMaterialProperty<Real>(prop))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
elem_id,prop1,prop2,propt,propx,qp_id,x,y,z
0,1,2,1,0.10566243270259,0,0.10566243270259,0.10566243270259,0
0,1,2,1,0.39433756729741,1,0.39433756729741,0.10566243270259,0
0,1,2,1,0.10566243270259,2,0.10566243270259,0.39433756729741,0
0,1,2,1,0.39433756729741,3,0.39433756729741,0.39433756729741,0
1,10,20,1,0.60566243270259,0,0.60566243270259,0.10566243270259,0
1,10,20,1,0.89433756729741,1,0.89433756729741,0.10566243270259,0
1,10,20,1,0.60566243270259,2,0.60566243270259,0.39433756729741,0
1,10,20,1,0.89433756729741,3,0.89433756729741,0.39433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
elem_id,prop1,prop2,propt,propx,qp_id,x,y,z
0,1,2,2,0.10566243270259,0,0.10566243270259,0.10566243270259,0
0,1,2,2,0.39433756729741,1,0.39433756729741,0.10566243270259,0
0,1,2,2,0.10566243270259,2,0.10566243270259,0.39433756729741,0
0,1,2,2,0.39433756729741,3,0.39433756729741,0.39433756729741,0
1,10,20,2,0.60566243270259,0,0.60566243270259,0.10566243270259,0
1,10,20,2,0.89433756729741,1,0.89433756729741,0.10566243270259,0
1,10,20,2,0.60566243270259,2,0.60566243270259,0.39433756729741,0
1,10,20,2,0.89433756729741,3,0.89433756729741,0.39433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
elem_id,prop1,prop2,propt,propx,qp_id,x,y,z
0,1,2,1,0.10566243270259,0,0.10566243270259,0.10566243270259,0
0,1,2,1,0.39433756729741,1,0.39433756729741,0.10566243270259,0
0,1,2,1,0.10566243270259,2,0.10566243270259,0.39433756729741,0
0,1,2,1,0.39433756729741,3,0.39433756729741,0.39433756729741,0
1,10,20,1,0.60566243270259,0,0.60566243270259,0.10566243270259,0
1,10,20,1,0.89433756729741,1,0.89433756729741,0.10566243270259,0
1,10,20,1,0.60566243270259,2,0.60566243270259,0.39433756729741,0
1,10,20,1,0.89433756729741,3,0.89433756729741,0.39433756729741,0
2,1,2,1,0.10566243270259,0,0.10566243270259,0.60566243270259,0
2,1,2,1,0.39433756729741,1,0.39433756729741,0.60566243270259,0
2,1,2,1,0.10566243270259,2,0.10566243270259,0.89433756729741,0
2,1,2,1,0.39433756729741,3,0.39433756729741,0.89433756729741,0
3,10,20,1,0.60566243270259,0,0.60566243270259,0.60566243270259,0
3,10,20,1,0.89433756729741,1,0.89433756729741,0.60566243270259,0
3,10,20,1,0.60566243270259,2,0.60566243270259,0.89433756729741,0
3,10,20,1,0.89433756729741,3,0.89433756729741,0.89433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
elem_id,prop1,prop2,propt,propx,qp_id,x,y,z
0,1,2,2,0.10566243270259,0,0.10566243270259,0.10566243270259,0
0,1,2,2,0.39433756729741,1,0.39433756729741,0.10566243270259,0
0,1,2,2,0.10566243270259,2,0.10566243270259,0.39433756729741,0
0,1,2,2,0.39433756729741,3,0.39433756729741,0.39433756729741,0
1,10,20,2,0.60566243270259,0,0.60566243270259,0.10566243270259,0
1,10,20,2,0.89433756729741,1,0.89433756729741,0.10566243270259,0
1,10,20,2,0.60566243270259,2,0.60566243270259,0.39433756729741,0
1,10,20,2,0.89433756729741,3,0.89433756729741,0.39433756729741,0
2,1,2,2,0.10566243270259,0,0.10566243270259,0.60566243270259,0
2,1,2,2,0.39433756729741,1,0.39433756729741,0.60566243270259,0
2,1,2,2,0.10566243270259,2,0.10566243270259,0.89433756729741,0
2,1,2,2,0.39433756729741,3,0.39433756729741,0.89433756729741,0
3,10,20,2,0.60566243270259,0,0.60566243270259,0.60566243270259,0
3,10,20,2,0.89433756729741,1,0.89433756729741,0.60566243270259,0
3,10,20,2,0.60566243270259,2,0.60566243270259,0.89433756729741,0
3,10,20,2,0.89433756729741,3,0.89433756729741,0.89433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
elem_id,prop1,prop2,propt,qp_id,x,y,z
0,1,2,1,0,0.10566243270259,0.10566243270259,0
0,1,2,1,1,0.39433756729741,0.10566243270259,0
0,1,2,1,2,0.10566243270259,0.39433756729741,0
0,1,2,1,3,0.39433756729741,0.39433756729741,0
1,1,2,1,0,0.60566243270259,0.10566243270259,0
1,1,2,1,1,0.89433756729741,0.10566243270259,0
1,1,2,1,2,0.60566243270259,0.39433756729741,0
1,1,2,1,3,0.89433756729741,0.39433756729741,0
2,1,2,1,0,0.10566243270259,0.60566243270259,0
2,1,2,1,1,0.39433756729741,0.60566243270259,0
2,1,2,1,2,0.10566243270259,0.89433756729741,0
2,1,2,1,3,0.39433756729741,0.89433756729741,0
3,1,2,1,0,0.60566243270259,0.60566243270259,0
3,1,2,1,1,0.89433756729741,0.60566243270259,0
3,1,2,1,2,0.60566243270259,0.89433756729741,0
3,1,2,1,3,0.89433756729741,0.89433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
elem_id,prop1,prop2,propt,qp_id,x,y,z
0,1,2,2,0,0.10566243270259,0.10566243270259,0
0,1,2,2,1,0.39433756729741,0.10566243270259,0
0,1,2,2,2,0.10566243270259,0.39433756729741,0
0,1,2,2,3,0.39433756729741,0.39433756729741,0
1,1,2,2,0,0.60566243270259,0.10566243270259,0
1,1,2,2,1,0.89433756729741,0.10566243270259,0
1,1,2,2,2,0.60566243270259,0.39433756729741,0
1,1,2,2,3,0.89433756729741,0.39433756729741,0
2,1,2,2,0,0.10566243270259,0.60566243270259,0
2,1,2,2,1,0.39433756729741,0.60566243270259,0
2,1,2,2,2,0.10566243270259,0.89433756729741,0
2,1,2,2,3,0.39433756729741,0.89433756729741,0
3,1,2,2,0,0.60566243270259,0.60566243270259,0
3,1,2,2,1,0.89433756729741,0.60566243270259,0
3,1,2,2,2,0.60566243270259,0.89433756729741,0
3,1,2,2,3,0.89433756729741,0.89433756729741,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[Mesh]
[gen]
type = GeneratedMeshGenerator
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 2
ny = 2
[]
[]

[Variables]
[./u]
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Materials]
[mat1]
type = GenericFunctionMaterial
prop_names = 'prop1 prop2 propt'
prop_values = '1 2 t'
[]
[]

[Executioner]
type = Transient
num_steps = 2
dt = 1.0
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[VectorPostprocessors]
[props]
type = ElementMaterialSampler
property = 'prop1 prop2 propt'
execute_on = 'initial timestep_end'
[]
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[Mesh]
[gen]
type = GeneratedMeshGenerator
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 2
ny = 2
[]
[left]
type = ParsedSubdomainMeshGenerator
input = gen
combinatorial_geometry = 'x < 0.5'
block_id = 1
block_name = LEFT_SIDE
[]
[right]
type = ParsedSubdomainMeshGenerator
input = left
combinatorial_geometry = 'x > 0.5'
block_id = 2
block_name = RIGHT_SIDE
[]
[]

[Variables]
[./u]
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Materials]
[mat1]
type = GenericFunctionMaterial
prop_names = 'prop1 prop2 propt propx'
prop_values = '1 2 t x'
block = 1
[]
[mat2]
type = GenericFunctionMaterial
prop_names = 'prop1 prop2 propt propx'
prop_values = '10 20 t x'
block = 2
[]
[]

[Executioner]
type = Transient
num_steps = 2
dt = 1.0
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[VectorPostprocessors]
[props]
type = ElementMaterialSampler
property = 'prop1 prop2 propt propx'
execute_on = 'initial timestep_end'
[]
[]

[Outputs]
csv = true
[]
Loading

0 comments on commit b65eb70

Please sign in to comment.