Skip to content

Commit

Permalink
Address comments (idaholab#14220)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Dec 6, 2019
1 parent edac05e commit a65861b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PiecewiseLinear
# CoarsenedPiecewiseLinear

!syntax description /Functions/CoarsenedPiecewiseLinear

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

!syntax description /VectorPostprocessors/PiecewiseFunctionTabulate

This object can be used to check the function generated by a
[`CoarsenedPiecewiseLinear`](/CoarsenedPiecewiseLinear.md) function.
This object can be used to check the function generated by a 2D piecewise
defined function, such as

- [`PiecewiseConstant`](/PiecewiseConstant.md)
- [`PiecewiseLinear`](/PiecewiseLinear.md)
- [`CoarsenedPiecewiseLinear`](/CoarsenedPiecewiseLinear.md).

!syntax parameters /VectorPostprocessors/PiecewiseFunctionTabulate

Expand Down
5 changes: 4 additions & 1 deletion framework/include/functions/CoarsenedPiecewiseLinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ template <>
InputParameters validParams<CoarsenedPiecewiseLinear>();

/**
* Perform a point reduction of the tabulated data upon initialization.
* Function class that reads in a list of (x,y) value pairs representing a pointwise defined
* function sililar to PiecewiseLinear. In addition this Function object performs a point reduction
* of the tabulated data upon initialization resulting in the evaluation of a simplified function
* with fewer data points.
*/
class CoarsenedPiecewiseLinear : public PiecewiseLinearBase
{
Expand Down
4 changes: 2 additions & 2 deletions framework/include/functions/PiecewiseBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ InputParameters validParams<PiecewiseBase>();

/**
* Function base which provides a piecewise approximation to a provided
* (x,y) point data set. Derived classes which control the order
* (x,y) point data set. Derived classes, which control the order
* (constant, linear) of the approximation and how the (x,y) data set
* is generated. should be used directly,
* is generated, should be used directly.
*/
class PiecewiseBase : public Function
{
Expand Down
20 changes: 2 additions & 18 deletions framework/include/functions/PiecewiseLinearBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,18 @@ template <>
InputParameters validParams<PiecewiseLinearBase>();

/**
* Function which provides a piecewise continuous linear interpolation
* of a provided (x,y) point data set.
* Base class for functions which provides a piecewise continuous linear
* interpolation of an (x,y) point data set.
*/
class PiecewiseLinearBase : public PiecewiseBase
{
public:
PiecewiseLinearBase(const InputParameters & parameters);

virtual void initialSetup() override;

/**
* Get the value of the function (based on time only)
* \param t The time
* \param pt The point in space (x,y,z) (unused)
* \return The value of the function at the specified time
*/
virtual Real value(Real t, const Point & pt) const override;

/**
* Get the time derivative of the function (based on time only)
* \param t The time
* \param pt The point in space (x,y,z) (unused)
* \return The time derivative of the function at the specified time
*/
virtual Real timeDerivative(Real t, const Point & pt) const override;

virtual Real integral() const override;

virtual Real average() const override;

protected:
Expand Down
16 changes: 14 additions & 2 deletions framework/include/utils/PointReduction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ namespace PointReduction
typedef std::pair<Real, Real> FunctionNode;
typedef std::vector<FunctionNode> FunctionNodeList;

/// compute the perpendicular distance of a point from a line defined by begin and end points
/**
* compute the perpendicular distance of a point P from a line defined by begin
* and end points.
*
* @param point The (x,y) point P
* @param begin The first (x,y) point defining the line to compute the distance to
* @param end The second (x,y) point defining the line to compute the distance to
*/
Real perpendicularDistance(const FunctionNode & point,
const FunctionNode & begin,
const FunctionNode & end);

/// return a pruned function node list using the Ramer-Douglas-Peucker algorithm
/**
* Generate a pruned function node list using the Ramer-Douglas-Peucker algorithm.
*
* @param list An ordered (by x) list of (x,y) points defining a pointwise defined function.
* @param epsilon The Ramer-Douglas-Peucker tolerance parameter for coarsening.
*/
FunctionNodeList douglasPeucker(const FunctionNodeList &, Real epsilon);

} // namespace PointReduction
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class PiecewiseFunctionTabulate : public GeneralVectorPostprocessor
virtual void finalize() override {}

protected:
/// The piecewise function to tabulate
const PiecewiseBase * _piecewise_function;

/// function argument (x) column
VectorPostprocessorValue & _x_col;

/// function value (x) column
VectorPostprocessorValue & _y_col;
};
6 changes: 4 additions & 2 deletions framework/src/utils/PointReduction.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "PointReduction.h"
#include "MooseUtils.h"
#include "MooseError.h"

#include <algorithm>
Expand Down Expand Up @@ -35,7 +36,8 @@ perpendicularDistance(const FunctionNode & node,
const Real y2 = end.second;

const Real denom = std::sqrt(sqr(y2 - y1) + sqr(x2 - x1));
mooseAssert(denom > 0, "Line begin and end points bust not be the same");
mooseAssert(MooseUtils::absoluteFuzzyGreaterThan(denom, 0.0),
"Line begin and end points must not be the same");

return std::abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) / denom;
}
Expand All @@ -47,7 +49,7 @@ douglasPeuckerRecurse(const FunctionNodeList & list,
std::size_t begin,
std::size_t end)
{
// Find the point with the maximum distance
// Find the point with the maximum distance from the line defined by begin and end
Real dmax = 0.0;
std::size_t index = 0;

Expand Down
2 changes: 1 addition & 1 deletion test/tests/functions/coarsened_piecewise_linear/tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
type = 'CSVDiff'
input = 'coarsened_piecewise_linear.i'
csvdiff = 'coarsened_piecewise_linear_vpp_F_0000.csv'
requirement = "The Function system shall include an object that creates a function based on x- and y-data pairs and returns an explicit value from the supplied data when queried (i.e., linear interpolation is not performed)."
requirement = "The Function system shall include an object that creates a function based on x- and y-data pairs, reduces the number of data points based on a user supplied cut-off and returns a linearly interpolated value from the coarsened data."
prereq = 'prepare_data'
[../]
[]

0 comments on commit a65861b

Please sign in to comment.