21#include "libmesh/point.h"
30 "What to sort the samples by. Options include 'x', 'y', 'z', 'id', and the name of any of "
31 "the sampled quantities (which each create a vector of the same name).");
35 params.
set<
bool>(
"_auto_broadcast") =
false;
43 : _sampler_params(parameters),
47 parameters.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")
50 _sort_by_index(
libMesh::invalid_uint),
51 _x(vpp->declareVector(
"x")),
52 _y(vpp->declareVector(
"y")),
53 _z(vpp->declareVector(
"z")),
54 _id(vpp->declareVector(
"id")),
55 _sort_by(parameters.get<
std::string>(
"sort_by"))
72 _values.reserve(variable_names.size());
74 for (
const auto & variable_name : variable_names)
85 "The 'sort_by' parameter must be one of x/y/z/id or one of the sampled variable names: " +
117 std::vector<VectorPostprocessorValue *> vec_ptrs = {{&
_x, &
_y, &
_z, &
_id}};
120 for (
auto vec_ptr : vec_ptrs)
126 "Number of samples is not what is expected.");
131 mooseAssert(ind < vec_ptr->size(),
"Trying to remove a sample that doesn't exist.");
132 vec_ptr->erase(vec_ptr->begin() + ind);
154 const std::string & var_param_name)
const
158 "Scalar variable '" + var_ptr->
name() +
"' cannot be sampled.");
159 mooseAssert(
dynamic_cast<const MooseObject *
>(
_vpp),
"Should have succeeded");
165 "' is a vector variable. Sampling those is not currently supported in the "
166 "framework. It may be supported using a dedicated object in your application. Use "
167 "'VectorVariableComponentAux' auxkernel to copy those values into a regular field "
174 "' is an array variable. Sampling those is not currently supported in the "
175 "framework. It may be supported using a dedicated object in your application. Use "
176 "'ArrayVariableComponent' auxkernel to copy those values into a regular field variable");
187 constexpr auto NUM_ID_VECTORS = 4;
189 std::vector<VectorPostprocessorValue *> vec_ptrs;
190 vec_ptrs.reserve(
_values.size() + NUM_ID_VECTORS);
197 for (
auto vec_ptr : vec_ptrs)
201 std::vector<std::size_t> sorted_indices;
214 auto vector_length = sorted_indices.size();
218 for (
const auto vec_ptr : vec_ptrs)
219 if (vec_ptr->size() != vector_length)
224 for (
auto & vec_ptr : vec_ptrs)
226 for (MooseIndex(sorted_indices) j = 0; j < sorted_indices.size(); ++j)
227 tmp_vector[j] = (*vec_ptr)[sorted_indices[j]];
230 vec_ptr->swap(tmp_vector);
249 _x.insert(
_x.end(), y.
_x.begin(), y.
_x.end());
250 _y.insert(
_y.end(), y.
_y.begin(), y.
_y.end());
251 _z.insert(
_z.end(), y.
_z.begin(), y.
_z.end());
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::vector< Real > VectorPostprocessorValue
std::array< Real, 2 > values
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const std::string & name() const
Get the name of the class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Every object that can be built by the factory should be derived from this class.
const libMesh::FEType & feType() const
Get the type of finite element object.
virtual bool isArray() const
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual bool isVector() const =0
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
std::vector< std::string > _variable_names
The variable names.
unsigned int _sort_by_index
The index for what to sort by: x=0, y=1, z=2, then sampled variables in ordered specified in the para...
std::vector< VectorPostprocessorValue * > _values
const std::string _sort_by
What to sort by.
virtual void addSample(const Point &p, const Real &id, const std::vector< Real > &values)
Call this with the value of every variable at each point you want to sample at.
VectorPostprocessorValue & _x
x coordinate of the points
VectorPostprocessorValue & _y
y coordinate of the points
const TransientBase *const _sampler_transient
Transient executioner used to determine if the last solve converged.
void setupVariables(const std::vector< std::string > &variable_names)
You MUST call this in the constructor of the child class and pass down the name of the variables.
SamplerBase(const InputParameters ¶meters, VectorPostprocessor *vpp, const libMesh::Parallel::Communicator &comm)
virtual void initialize()
Initialize the datastructures.
virtual void threadJoin(const SamplerBase &y)
Join the values.
VectorPostprocessor * _vpp
The child VectorPostprocessor.
VectorPostprocessorValue & _id
The node ID of each point.
VectorPostprocessorValue & _z
x coordinate of the points
virtual void finalize()
Finalize the values.
std::size_t _curr_num_samples
The number of samples added in the last execution.
void checkForStandardFieldVariableType(const MooseVariableFieldBase *const var_ptr, const std::string &var_param_name="variable") const
Checks whether the passed variable pointer corresponds to a regular single-valued field variable.
std::size_t _curr_total_samples
The full size of the vector since the last execution.
const libMesh::Parallel::Communicator & _comm
The communicator of the child.
std::set< std::size_t, std::greater< std::size_t > > _curr_indices
The indices of the samples in the last execution.
static InputParameters validParams()
processor_id_type rank() const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
Base class for Postprocessors that produce a vector of values.
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.
std::string stringify(const T &t)
conversion to string
void indirectSort(RandomAccessIterator beg, RandomAccessIterator end, std::vector< size_t > &b)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const unsigned int invalid_uint