Skip to content

Commit

Permalink
Address comments, add tolerance (idaholab#6389)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed May 4, 2016
1 parent a05209c commit f729e85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 8 additions & 1 deletion modules/phase_field/include/postprocessors/FindValueOnLine.h
Expand Up @@ -17,7 +17,11 @@ template<>
InputParameters validParams<FindValueOnLine>();

/**
* Finds a secific value along a line through a bisection search/
* Find a specific target value along a sampling line. The variable values along
* the line should change monotonically. The target value is searched using a
* bisection algorithm.
* The Postprocessor reports the distance from the start_point along the line
* between start_point and end_point.
*/
class FindValueOnLine : public GeneralPostprocessor, public Coupleable
{
Expand Down Expand Up @@ -45,6 +49,9 @@ class FindValueOnLine : public GeneralPostprocessor, public Coupleable
/// search depth
const unsigned int _depth;

/// tolerance for comparison to the target value
const Real _tol;

/// coupled variable
MooseVariable * _coupled_var;

Expand Down
15 changes: 11 additions & 4 deletions modules/phase_field/src/postprocessors/FindValueOnLine.C
Expand Up @@ -12,10 +12,12 @@ template<>
InputParameters validParams<FindValueOnLine>()
{
InputParameters params = validParams<GeneralPostprocessor>();
params.addParam<Point>("start_point", "Start point of the sample line.");
params.addParam<Point>("end_point", "End point of the sample line.");
params.addClassDescription("Find a specific target value along a sampling line. The variable values along the line should change monotonically. The target value is searched using a bisection algorithm.");
params.addParam<Point>("start_point", "Start point of the sampling line.");
params.addParam<Point>("end_point", "End point of the sampling line.");
params.addParam<Real>("target", "Target value to locate.");
params.addParam<unsigned int>("depth", "Number of bisections to perform.");
params.addParam<unsigned int>("depth", 30, "Maximum number of bisections to perform.");
params.addParam<Real>("tol", 1e-10, "Stop search if a value within a symmetric interval of this with around the target is found.");
params.addCoupledVar("v", "Variable to inspect");
return params;
}
Expand All @@ -28,6 +30,7 @@ FindValueOnLine::FindValueOnLine(const InputParameters & parameters) :
_length((_end_point - _start_point).norm()),
_target(getParam<Real>("target")),
_depth(getParam<unsigned int>("depth")),
_tol(getParam<Real>("tol") / 2.0),
_coupled_var(getVar("v", 0)),
_position(0.0),
_mesh(_subproblem.mesh()),
Expand Down Expand Up @@ -60,6 +63,10 @@ FindValueOnLine::execute()
// sample value
Real value = getValueAtPoint(p);

// have we hit the target value yet?
if (value > _target - _tol && value < _target + _tol)
break;

// bisect
if ( (left >= _target && _target >= value)
|| (left <= _target && _target <= value))
Expand Down Expand Up @@ -103,7 +110,7 @@ FindValueOnLine::getValueAtPoint(const Point & p)
else
{
// there is no element
mooseError("No element found.");
mooseError("No element found at the current search point. Please make sure the sampling line stays inside the mesh completely.");
}
}

Expand Down

0 comments on commit f729e85

Please sign in to comment.