https://mooseframework.inl.gov
CoarsenedPiecewiseLinear.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "PointReduction.h"
12 
14 
17 {
19  params.addClassDescription("Perform a point reduction of the tabulated data upon initialization, "
20  "then evaluate using a linear interpolation.");
21  params.addRequiredParam<Real>(
22  "epsilon",
23  "Significant distance in the function below which points are considered removable noise");
24  params.addParam<Real>("y_scale",
25  1.0,
26  "Scaling factor to apply to the function nodes for the purpose of "
27  "computing distances in the Douglas-Peucker point reduction algorithm. "
28  "This permits shifting the weight between x and y-direction distances.");
29  params.addParam<Real>("x_scale",
30  1.0,
31  "Scaling factor to apply to the function nodes for the purpose of "
32  "computing distances in the Douglas-Peucker point reduction algorithm. "
33  "This permits shifting the weight between x and y-direction distances.");
34  return params;
35 }
36 
38  : PiecewiseLinearBase(parameters)
39 {
40  if (isRawDataLoaded())
41  {
44  }
45 }
46 
47 void
49 {
53  else if (!isRawDataLoaded())
54  mooseError("Data has still not been loaded at setup time. Something has gone wrong during "
55  "Function initialization, contact a developer");
56 }
57 
58 void
60 {
61  const Real x_scale = getParam<Real>("x_scale");
62  const Real y_scale = getParam<Real>("y_scale");
63  const Real epsilon = getParam<Real>("epsilon");
64 
65  // create vector of pairs
67  list.reserve(_raw_x.size());
68  for (MooseIndex(_raw_x) i = 0; i < _raw_x.size(); ++i)
69  list.emplace_back(_raw_x[i] * x_scale, _raw_y[i] * y_scale);
70 
71  // point reduction
72  _console << "Reduced size for function '" << name() << "' from " << list.size();
73  list = PointReduction::douglasPeucker(list, epsilon);
74  _console << " to " << list.size() << " points." << std::endl;
75 
76  // unpack vector of pairs
77  _raw_x.resize(list.size());
78  _raw_y.resize(list.size());
79  for (MooseIndex(list) i = 0; i < list.size(); ++i)
80  {
81  _raw_x[i] = list[i].first / x_scale;
82  _raw_y[i] = list[i].second / y_scale;
83  }
84 
86 }
registerMooseObject("MooseApp", CoarsenedPiecewiseLinear)
static InputParameters validParams()
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void initialSetup() override
Needed to process data loaded from user objects that are not available at construction.
Function class that reads in a list of (x,y) value pairs representing a point-wise defined function s...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
std::vector< Real > _raw_x
raw function data as read
Definition: PiecewiseBase.h:39
Base class for functions which provides a piecewise continuous linear interpolation of an (x...
std::vector< FunctionNode > FunctionNodeList
CoarsenedPiecewiseLinear(const InputParameters &parameters)
void buildCoarsenedGrid()
Builds the coarse linear interpolation from the fine raw data.
FunctionNodeList douglasPeucker(const FunctionNodeList &, libMesh::Real epsilon)
Generate a pruned function node list using the Ramer-Douglas-Peucker algorithm.
void initialSetup() override
Needed to load data from user objects that are not available at construction.
void buildInterpolation(const bool extrap=false)
Builds the linear interpolation object from the x/y data.
bool isRawDataLoaded() const
Returns whether the raw data has been loaded already.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
std::vector< Real > _raw_y
Definition: PiecewiseBase.h:40
bool _interpolation_created
Whether the interpolation has been created.