Line data Source code
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 : 10 : #include "CoarsenedPiecewiseLinear.h" 11 : #include "PointReduction.h" 12 : 13 : registerMooseObject("MooseApp", CoarsenedPiecewiseLinear); 14 : 15 : InputParameters 16 14290 : CoarsenedPiecewiseLinear::validParams() 17 : { 18 14290 : InputParameters params = PiecewiseLinearBase::validParams(); 19 14290 : params.addClassDescription("Perform a point reduction of the tabulated data upon initialization, " 20 : "then evaluate using a linear interpolation."); 21 14290 : params.addRequiredParam<Real>( 22 : "epsilon", 23 : "Significant distance in the function below which points are considered removable noise"); 24 42870 : params.addParam<Real>("y_scale", 25 28580 : 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 42870 : params.addParam<Real>("x_scale", 30 28580 : 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 14290 : return params; 35 0 : } 36 : 37 13 : CoarsenedPiecewiseLinear::CoarsenedPiecewiseLinear(const InputParameters & parameters) 38 13 : : PiecewiseLinearBase(parameters) 39 : { 40 13 : if (isRawDataLoaded()) 41 : { 42 13 : buildCoarsenedGrid(); 43 13 : _interpolation_created = true; 44 : } 45 13 : } 46 : 47 : void 48 13 : CoarsenedPiecewiseLinear::initialSetup() 49 : { 50 13 : PiecewiseTabularBase::initialSetup(); 51 13 : if (isRawDataLoaded() && !_interpolation_created) 52 0 : buildCoarsenedGrid(); 53 13 : else if (!isRawDataLoaded()) 54 0 : mooseError("Data has still not been loaded at setup time. Something has gone wrong during " 55 : "Function initialization, contact a developer"); 56 13 : } 57 : 58 : void 59 13 : CoarsenedPiecewiseLinear::buildCoarsenedGrid() 60 : { 61 13 : const Real x_scale = getParam<Real>("x_scale"); 62 13 : const Real y_scale = getParam<Real>("y_scale"); 63 13 : const Real epsilon = getParam<Real>("epsilon"); 64 : 65 : // create vector of pairs 66 13 : PointReduction::FunctionNodeList list; 67 13 : list.reserve(_raw_x.size()); 68 130013 : for (MooseIndex(_raw_x) i = 0; i < _raw_x.size(); ++i) 69 130000 : list.emplace_back(_raw_x[i] * x_scale, _raw_y[i] * y_scale); 70 : 71 : // point reduction 72 13 : _console << "Reduced size for function '" << name() << "' from " << list.size(); 73 13 : list = PointReduction::douglasPeucker(list, epsilon); 74 13 : _console << " to " << list.size() << " points." << std::endl; 75 : 76 : // unpack vector of pairs 77 13 : _raw_x.resize(list.size()); 78 13 : _raw_y.resize(list.size()); 79 156 : for (MooseIndex(list) i = 0; i < list.size(); ++i) 80 : { 81 143 : _raw_x[i] = list[i].first / x_scale; 82 143 : _raw_y[i] = list[i].second / y_scale; 83 : } 84 : 85 13 : buildInterpolation(); 86 13 : }