diff --git a/framework/src/vectorpostprocessors/ElementMaterialSampler.C b/framework/src/vectorpostprocessors/ElementMaterialSampler.C index 4adb96a7205f..95d919c2dd33 100644 --- a/framework/src/vectorpostprocessors/ElementMaterialSampler.C +++ b/framework/src/vectorpostprocessors/ElementMaterialSampler.C @@ -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("material", - "Material for which all properties will be recorded."); + 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("material", "Material for which all properties will be recorded."); + params.addParam>( + "property", "Material property names that will be recorded."); params.addParam>( "elem_ids", "Subset of element IDs to print data for. If omitted, all elements will be printed."); @@ -44,35 +46,62 @@ ElementMaterialSampler::ElementMaterialSampler(const InputParameters & parameter _y_coords(declareVector("y")), _z_coords(declareVector("z")) { - auto & mat = getMaterialByName(getParam("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.isParamValid("material") && parameters.isParamValid("property")) + mooseError("Setting both 'material' and 'property' is not allowed. Use one or the other."); + if (!parameters.isParamValid("material") && !parameters.isParamValid("property")) + mooseError("Either 'material' and 'property' needs to be set."); + + // List of property names to collect + std::vector prop_names; // Get list of elements from user if (parameters.isParamValid("elem_ids")) { const auto & ids = getParam>("elem_ids"); _elem_filter = std::set(ids.begin(), ids.end()); + } + + // If Material is used, get all properties. + if (parameters.isParamValid("material")) + { + auto & mat = getMaterialByName(getParam("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(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>("property"); + prop_names = std::vector(props.begin(), props.end()); + } + // Check properties are valid and store references for (auto & prop : prop_names) { if (hasMaterialProperty(prop)) diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0001.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0001.csv new file mode 100644 index 000000000000..0f2e1c38372a --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0001.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0002.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0002.csv new file mode 100644 index 000000000000..0e53c20bffbd --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_elem_ids_out_props_0002.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0001.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0001.csv new file mode 100644 index 000000000000..6b2ff13f61cb --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0001.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0002.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0002.csv new file mode 100644 index 000000000000..5a485962130b --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_multiple_blocks_out_props_0002.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0001.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0001.csv new file mode 100644 index 000000000000..af0e159a2361 --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0001.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0002.csv b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0002.csv new file mode 100644 index 000000000000..e3fb43bc8876 --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/gold/property_sampler_out_props_0002.csv @@ -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 diff --git a/test/tests/vectorpostprocessors/element_material_sampler/property_sampler.i b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler.i new file mode 100644 index 000000000000..a96238766f70 --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler.i @@ -0,0 +1,73 @@ +[Mesh] + allow_renumbering = false + [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 +[] diff --git a/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks.i b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks.i new file mode 100644 index 000000000000..02122333adac --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks.i @@ -0,0 +1,94 @@ +[Mesh] + allow_renumbering = false + [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 +[] diff --git a/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks_elem_ids.i b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks_elem_ids.i new file mode 100644 index 000000000000..689c5ff32153 --- /dev/null +++ b/test/tests/vectorpostprocessors/element_material_sampler/property_sampler_multiple_blocks_elem_ids.i @@ -0,0 +1,95 @@ +[Mesh] + allow_renumbering = false + [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' + elem_ids = '0 1' + execute_on = 'initial timestep_end' + [] +[] + +[Outputs] + csv = true +[] diff --git a/test/tests/vectorpostprocessors/element_material_sampler/tests b/test/tests/vectorpostprocessors/element_material_sampler/tests index 08d007c95cab..fb46af183962 100644 --- a/test/tests/vectorpostprocessors/element_material_sampler/tests +++ b/test/tests/vectorpostprocessors/element_material_sampler/tests @@ -24,9 +24,32 @@ csvdiff = 'all_elements_block_restricted_out_vpp_0001.csv all_elements_block_restricted_out_vpp_0002.csv' requirement = 'The system shall be able to output material properties calculated at quadrature ' - 'points on all active elements within the specified subdomains.' + 'points on all active elements within the specified subdomains.' + [] + [material_properties] + type = 'CSVDiff' + input = 'property_sampler.i' + csvdiff = 'property_sampler_out_props_0001.csv property_sampler_out_props_0002.csv' + + requirement = 'The system shall be able to output material properties calculated at quadrature ' + 'points, on all active elements, when supplied with the property names.' + [] + [material_properties_multiple_blocks] + type = 'CSVDiff' + input = 'property_sampler_multiple_blocks.i' + csvdiff = 'property_sampler_multiple_blocks_out_props_0001.csv property_sampler_multiple_blocks_out_props_0002.csv' + + requirement = 'The system shall be able to output material properties calculated at quadrature ' + 'points, on all active elements, when supplied with the property names defined on different blocks.' + [] + [material_properties_multiple_blocks_elem_ids] + type = 'CSVDiff' + input = 'property_sampler_multiple_blocks_elem_ids.i' + csvdiff = 'property_sampler_multiple_blocks_elem_ids_out_props_0001.csv property_sampler_multiple_blocks_elem_ids_out_props_0002.csv' + + requirement = 'The system shall be able to output material properties calculated at quadrature ' + 'points, on the given elements, when supplied with the property names defined on different blocks.' [] - [errors] requirement = 'The system shall issue an error if material output samples are attempted for ' 'elements:' @@ -53,7 +76,16 @@ cli_args = 'VectorPostprocessors/vpp/material=foo' expect_err = 'Unable to locate active object: foo' - detail = 'the material does not exist on the mesh.' + detail = 'the material does not exist on the mesh, or' + [] + + [block_restrict_property_sample] + type = 'RunException' + input = 'property_sampler_multiple_blocks.i' + cli_args = ' Materials/mat1/prop_names=prop1 Materials/mat1/prop_values=1 Materials/mat2/prop_names=prop2 Materials/mat2/prop_values=2 VectorPostprocessors/props/property=prop1' + expect_err = "Material property 'prop1', requested by 'props' is not defined on block RIGHT_SIDE" + + detail = 'the property does not exist on the block.' [] [] []