www.mooseframework.org
PiecewiseBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "PiecewiseBase.h"
11 
12 template <>
15 {
17 
18  MooseEnum axis("x=0 y=1 z=2 0=3 1=4 2=5");
19  axis.deprecate("0", "x");
20  axis.deprecate("1", "y");
21  axis.deprecate("2", "z");
22  params.addParam<MooseEnum>(
23  "axis", axis, "The axis used (x, y, or z) if this is to be a function of position");
24  return params;
25 }
26 
28  : Function(parameters), _has_axis(isParamValid("axis")), _data_set(false)
29 {
30  if (_has_axis)
31  {
32  _axis = getParam<MooseEnum>("axis");
33  if (_axis > 2)
34  _axis -= 3;
35  }
36 }
37 
38 void
40 {
41  if (!_data_set)
42  mooseError("In ", _name, ": Data has not been set");
43 }
44 
45 void
46 PiecewiseBase::setData(const std::vector<Real> & x, const std::vector<Real> & y)
47 {
48  _data_set = true;
49  // Size mismatch error
50  if (x.size() != y.size())
51  mooseError("In PiecewiseBase ", _name, ": Lengths of x and y data do not match.");
52 
53  try
54  {
55  _linear_interp = libmesh_make_unique<LinearInterpolation>(x, y);
56  }
57  catch (std::domain_error & e)
58  {
59  mooseError("In PiecewiseBase ", _name, ": ", e.what());
60  }
61 }
62 
63 Real
65 {
66  return _linear_interp->getSampleSize();
67 }
68 
69 Real
71 {
72  return _linear_interp->domain(i);
73 }
74 
75 Real
77 {
78  return _linear_interp->range(i);
79 }
virtual void initialSetup()
Gets called at the beginning of the simulation before this object is asked to do its job...
Definition: PiecewiseBase.C:39
std::unique_ptr< LinearInterpolation > _linear_interp
Definition: PiecewiseBase.h:43
Base class for function objects.
Definition: Function.h:40
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void setData(const std::vector< Real > &x, const std::vector< Real > &y)
Provides a means for explicitly setting the x and y data.
Definition: PiecewiseBase.C:46
virtual Real domain(const int i)
Definition: PiecewiseBase.C:70
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
static PetscErrorCode Vec x
virtual Real functionSize()
Definition: PiecewiseBase.C:64
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
virtual Real range(const int i)
Definition: PiecewiseBase.C:76
PiecewiseBase(const InputParameters &parameters)
Definition: PiecewiseBase.C:27
const std::string & _name
The name of this object, reference to value stored in InputParameters.
Definition: MooseObject.h:183
const bool _has_axis
Definition: PiecewiseBase.h:45
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
InputParameters validParams< PiecewiseBase >()
Definition: PiecewiseBase.C:14
InputParameters validParams< Function >()
Definition: Function.C:14