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++)
210 auto & othervec = *vpp._prop_vecs[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 std::optional< std::set< dof_id_type > > _elem_filter
Element ids to record material properties for.
VectorPostprocessorValue & _qp_ids
Column of quadrature point indices.
virtual void finalize() override
Finalize.
VectorPostprocessorValue & _x_coords
Columns of quadrature point coordinates.
const MooseArray< Point > & _q_point
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
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...
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
const Parallel::Communicator & comm() const
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...
virtual const std::string & name() const
Get the name of the class.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
bool containsCompleteHistory() const
Return whether or not this VectorPostprocessor contains complete history.
VectorPostprocessorValue & _y_coords
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
ElementMaterialSampler(const InputParameters ¶meters)
This postprocessor records all scalar material properties of the specified material object on specifi...
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
virtual void execute() override
Execute method.
registerMooseObject("MooseApp", ElementMaterialSampler)
registerMooseObjectRenamed("MooseApp", MaterialVectorPostprocessor, "06/30/2025 24:00", ElementMaterialSampler)
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false)
const QBase *const & _qrule
std::vector< std::string > _prop_names
Names for every property in the material - used for determining if properties are scalar or not...
const Elem *const & _current_elem
The current element pointer (available during execute())
void max(const T &r, T &o, Request &req) const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
static InputParameters validParams()
static InputParameters validParams()
std::vector< VectorPostprocessorValue * > _prop_vecs
Columns for each (scalar) property of the material.
virtual void threadJoin(const UserObject &y) override
Must override.
VectorPostprocessorValue & _elem_ids
Column of element id info.
Base class for user-specific data.
VectorPostprocessorValue & _z_coords