https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
46
47void
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
58void
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)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Function class that reads in a list of (x,y) value pairs representing a point-wise defined function s...
void buildCoarsenedGrid()
Builds the coarse linear interpolation from the fine raw data.
void initialSetup() override
Needed to process data loaded from user objects that are not available at construction.
CoarsenedPiecewiseLinear(const InputParameters &parameters)
static InputParameters validParams()
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
std::vector< Real > _raw_x
raw function data as read
std::vector< Real > _raw_y
Base class for functions which provides a piecewise continuous linear interpolation of an (x,...
void buildInterpolation(const bool extrap=false)
Builds the linear interpolation object from the x/y data.
static InputParameters validParams()
bool _interpolation_created
Whether the interpolation has been created.
void initialSetup() override
Needed to load data from user objects that are not available at construction.
bool isRawDataLoaded() const
Returns whether the raw data has been loaded already.
std::vector< FunctionNode > FunctionNodeList
FunctionNodeList douglasPeucker(const FunctionNodeList &, libMesh::Real epsilon)
Generate a pruned function node list using the Ramer-Douglas-Peucker algorithm.