15#include "libmesh/quadrature.h"
21 MaterialVectorPostprocessor,
29 params.
addClassDescription(
"Records all Real-valued material properties of a material object, "
30 "or Real-valued material properties of the supplied property names "
31 "on quadrature points on elements at the indicated execution points.");
32 params.
addParam<MaterialName>(
"material",
"Material for which all properties will be recorded.");
33 params.
addParam<std::vector<MaterialPropertyName>>(
34 "property",
"Material property names that will be recorded.");
35 params.
addParam<std::vector<dof_id_type>>(
37 "Subset of element IDs to print data for. If omitted, all elements will be printed.");
43 _elem_ids(declareVector(
"elem_id")),
44 _qp_ids(declareVector(
"qp_id")),
45 _x_coords(declareVector(
"x")),
46 _y_coords(declareVector(
"y")),
47 _z_coords(declareVector(
"z"))
51 mooseError(
"Setting both 'material' and 'property' is not allowed. Use one or the other.");
53 mooseError(
"Either 'material' and 'property' needs to be set.");
56 std::vector<MaterialName> prop_names;
61 const auto & ids = getParam<std::vector<dof_id_type>>(
"elem_ids");
62 _elem_filter = std::set<dof_id_type>(ids.begin(), ids.end());
69 if (mat.isBoundaryMaterial())
70 mooseError(
name(),
": boundary materials (i.e. ", mat.name(),
") cannot be used");
73 auto & props = mat.getSuppliedItems();
74 prop_names = std::vector<MaterialName>(props.begin(), props.end());
85 bool found_elem = (el !=
nullptr);
91 if (!found_elem || (el && !mat.hasBlocks(el->subdomain_id())))
92 mooseError(
name(),
": material ", mat.name(),
" is not defined on element ",
id);
100 auto & props = getParam<std::vector<MaterialPropertyName>>(
"property");
101 prop_names = std::vector<MaterialName>(props.begin(), props.end());
105 for (
auto & prop : prop_names)
107 if (hasMaterialProperty<Real>(prop))
108 _prop_refs.push_back(&getMaterialProperty<Real>(prop));
109 else if (hasMaterialProperty<unsigned int>(prop))
110 _prop_refs.push_back(&getMaterialProperty<unsigned int>(prop));
111 else if (hasMaterialProperty<int>(prop))
112 _prop_refs.push_back(&getMaterialProperty<int>(prop));
116 " is of unsupported type and skipped by ElementMaterialSampler");
147 unsigned int nqp =
_qrule->n_points();
148 for (
unsigned int qp = 0; qp < nqp; qp++)
157 for (
unsigned int i = 0; i <
_prop_names.size(); i++)
161 std::vector<Real> vals;
162 if (hasMaterialProperty<Real>(prop_name))
165 for (
unsigned int qp = 0; qp < nqp; qp++)
166 prop->push_back((*vals)[qp]);
168 else if (hasMaterialProperty<unsigned int>(prop_name))
171 for (
unsigned int qp = 0; qp < nqp; qp++)
172 prop->push_back((*vals)[qp]);
174 else if (hasMaterialProperty<int>(prop_name))
177 for (
unsigned int qp = 0; qp < nqp; qp++)
178 prop->push_back((*vals)[qp]);
202 _qp_ids.insert(
_qp_ids.end(), vpp._qp_ids.begin(), vpp._qp_ids.end());
207 for (
unsigned int i = 0; i <
_prop_vecs.size(); i++)
211 vec.insert(vec.end(), othervec.begin(), othervec.end());
219 std::vector<size_t> ind;
221 std::iota(ind.begin(), ind.end(), 0);
222 std::sort(ind.begin(),
224 [&](
size_t a,
size_t b) ->
bool
226 if (_elem_ids[a] == _elem_ids[b])
228 return _qp_ids[a] < _qp_ids[b];
238 for (
auto vec : _prop_vecs)
239 Moose::applyIndices(*vec, ind);
registerMooseObject("MooseApp", ElementMaterialSampler)
registerMooseObjectRenamed("MooseApp", MaterialVectorPostprocessor, "06/30/2025 24:00", ElementMaterialSampler)
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This postprocessor records all scalar material properties of the specified material object on specifi...
virtual void threadJoin(const UserObject &y) override
Must override.
std::optional< std::set< dof_id_type > > _elem_filter
Element ids to record material properties for.
ElementMaterialSampler(const InputParameters ¶meters)
std::vector< std::string > _prop_names
Names for every property in the material - used for determining if properties are scalar or not.
std::vector< const PropertyValue * > _prop_refs
Reference to each material property - used to retrieve the actual property values at every execution ...
void sortVecs()
Sorts all data in the VectorPostProcessorValue objects so that output from this postprocessor is orde...
VectorPostprocessorValue & _y_coords
VectorPostprocessorValue & _x_coords
Columns of quadrature point coordinates.
virtual void finalize() override
Finalize.
VectorPostprocessorValue & _elem_ids
Column of element id info.
std::vector< VectorPostprocessorValue * > _prop_vecs
Columns for each (scalar) property of the material.
virtual void execute() override
Execute method.
static InputParameters validParams()
VectorPostprocessorValue & _qp_ids
Column of quadrature point indices.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
VectorPostprocessorValue & _z_coords
const QBase *const & _qrule
const Elem *const & _current_elem
The current element pointer (available during execute())
const MooseArray< Point > & _q_point
static InputParameters validParams()
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false)
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & name() const
Get the name of the class.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
void max(const T &r, T &o, Request &req) const
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
Base class for user-specific data.
bool containsCompleteHistory() const
Return whether or not this VectorPostprocessor contains complete history.
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
const Parallel::Communicator & comm() const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void applyIndices(T &container, const std::vector< size_t > &indices)
Uses indices created by the indirectSort function to sort the given container (which must support ran...