23 params.
addClassDescription(
"Find a specific target value along a sampling line. The variable "
24 "values along the line should change monotonically. The target value "
25 "is searched using a bisection algorithm.");
26 params.
addParam<Point>(
"start_point",
"Start point of the sampling line.");
27 params.
addParam<Point>(
"end_point",
"End point of the sampling line.");
28 params.
addParam<Real>(
"target",
"Target value to locate.");
32 "If true, stop with error if target value is not found on the line. If false, "
33 "return default_value.");
34 params.
addParam<Real>(
"default_value",
36 "Value to return if target value is not found on line and "
37 "error_if_not_found is false.");
38 params.
addParam<
unsigned int>(
"depth", 36,
"Maximum number of bisections to perform.");
42 "Stop search if a value is found that is equal to the target with this tolerance applied.");
50 _start_point(getParam<Point>(
"start_point")),
51 _end_point(getParam<Point>(
"end_point")),
52 _length((_end_point - _start_point).norm()),
53 _target(getParam<Real>(
"target")),
54 _error_if_not_found(getParam<bool>(
"error_if_not_found")),
55 _default_value(getParam<Real>(
"default_value")),
56 _depth(getParam<unsigned
int>(
"depth")),
57 _tol(getParam<Real>(
"tol")),
58 _coupled_var(*getVar(
"v", 0)),
60 _mesh(_subproblem.
mesh()),
70 _pl->enable_out_of_mesh_mode();
83 const auto error = [
this](
auto &&... message)
86 mooseError(std::scientific, std::setprecision(4), message...);
94 bool left_to_right = left < right;
96 if ((left_to_right &&
_target < left) || (!left_to_right &&
_target < right))
98 error(
"Target value ",
100 " is less than the minimum sampled value ",
101 std::min(left, right));
104 if ((left_to_right &&
_target > right) || (!left_to_right &&
_target > left))
106 error(
"Target value ",
108 " is greater than the maximum sampled value ",
109 std::max(left, right));
113 bool found_it =
false;
115 for (
unsigned int i = 0; i <
_depth; ++i)
118 s = (s_left + s_right) / 2.0;
125 if (MooseUtils::absoluteFuzzyEqual(value,
_target,
_tol))
132 if ((left_to_right &&
_target < value) || (!left_to_right &&
_target > value))
143 error(
"Target value ",
145 " not found on line within tolerance.\nLast sample: ",
147 ", difference from target: ",
158 const Elem * elem = (*_pl)(p);
160 processor_id_type elem_proc_id =
167 mooseError(
"No element found at the current search point. Please make sure the sampling line "
168 "stays inside the mesh completely.");
registerMooseObject("MooseApp", FindValueOnLine)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Real PostprocessorValue
various MOOSE typedefs
void ErrorVector unsigned int
Interface for objects that needs coupling capabilities.
Find a specific target value along a sampling line.
const Real & _default_value
value to return if target value is not found on the line and _error_if_not_found is false
static InputParameters validParams()
MooseVariable & _coupled_var
coupled variable
Real _position
detected interface location
virtual void execute() override
Execute method.
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
const bool & _error_if_not_found
boolean indicating whether to stop with an error if value is not found on the line
FindValueOnLine(const InputParameters ¶meters)
const unsigned int _depth
search depth
std::vector< Point > _point_vec
So we don't have to create and destroy the dummy vector.
const Point _start_point
line to sample along
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
MooseMesh & _mesh
The Mesh we're using.
const Real _tol
tolerance for comparison to the target value
Real getValueAtPoint(const Point &p)
const Real _target
value to find along the line
std::unique_ptr< libMesh::PointLocatorBase > _pl
helper object to locate elements containing points
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
virtual std::unique_ptr< libMesh::PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default),...
const FieldVariableValue & sln() const override
element solutions
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid)=0
void min(const T &r, T &o, Request &req) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
SubProblem & _subproblem
Reference to the Subproblem for this user object.
static constexpr processor_id_type invalid_processor_id
const Parallel::Communicator & _communicator
processor_id_type processor_id() const