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 "SplineFunction.h" 11 : 12 : registerMooseObject("MooseApp", SplineFunction); 13 : 14 : InputParameters 15 14311 : SplineFunction::validParams() 16 : { 17 14311 : InputParameters params = Function::validParams(); 18 14311 : params.addClassDescription( 19 : "Define a spline function from interpolated data defined by input parameters."); 20 14311 : MooseEnum component("x=0 y=1 z=2", "x"); 21 14311 : params.addParam<MooseEnum>( 22 : "component", component, "The component of the geometry point to interpolate with"); 23 14311 : params.addRequiredParam<std::vector<Real>>("x", "The abscissa values"); 24 14311 : params.addRequiredParam<std::vector<Real>>("y", "The ordinate values"); 25 42933 : params.addParam<Real>( 26 28622 : "yp1", 1e30, "The value of the first derivative of the interpolating function at point 1"); 27 42933 : params.addParam<Real>( 28 28622 : "ypn", 1e30, "The value of the first derivative of the interpolating function at point n"); 29 : 30 28622 : return params; 31 14311 : } 32 : 33 24 : SplineFunction::SplineFunction(const InputParameters & parameters) 34 : : Function(parameters), 35 24 : _ipol(getParam<std::vector<Real>>("x"), 36 : getParam<std::vector<Real>>("y"), 37 48 : getParam<Real>("yp1"), 38 48 : getParam<Real>("ypn")), 39 48 : _component(getParam<MooseEnum>("component")) 40 : { 41 24 : } 42 : 43 : Real 44 864 : SplineFunction::value(Real /*t*/, const Point & p) const 45 : { 46 864 : return _ipol.sample(p(_component)); 47 : } 48 : 49 : ADReal 50 0 : SplineFunction::value(const ADReal & /*t*/, const ADPoint & p) const 51 : { 52 0 : return _ipol.sample(p(_component)); 53 : } 54 : 55 : RealGradient 56 1680 : SplineFunction::gradient(Real /*t*/, const Point & p) const 57 : { 58 1680 : RealGradient grad(0.0); 59 1680 : grad(0) = derivative(p); 60 1680 : return grad; 61 : } 62 : 63 : Real 64 1680 : SplineFunction::derivative(const Point & p) const 65 : { 66 1680 : return _ipol.sampleDerivative(p(_component)); 67 : } 68 : 69 : Real 70 1024 : SplineFunction::secondDerivative(const Point & p) const 71 : { 72 1024 : return _ipol.sample2ndDerivative(p(_component)); 73 : }