www.mooseframework.org
PiecewiseMulticonstant.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 "PiecewiseMulticonstant.h"
11 #include "GriddedData.h"
12 
14 
17 {
19 
20  MultiMooseEnum direction("left=0 right=1");
21  params.addParam<MultiMooseEnum>(
22  "direction", direction, "Direction to look to find value for each interpolation dimension.");
23 
24  params.addClassDescription(
25  "PiecewiseMulticonstant performs constant interpolation on 1D, 2D, 3D or 4D "
26  "data. The data_file specifies the axes directions and the function "
27  "values. If a point lies outside the data range, the appropriate end "
28  "value is used.");
29  return params;
30 }
31 
33  : PiecewiseMultiInterpolation(parameters), _direction(getParam<MultiMooseEnum>("direction"))
34 {
35  if (_direction.size() != _dim)
36  mooseError("Parameter direction must have a size identical to ", _dim);
37 }
38 
39 ADReal
40 PiecewiseMulticonstant::value(const ADReal & t, const ADPoint & p) const
41 {
42  // piecewise constant derivatives are zero everywhere (ignore discontinuities)
44 }
45 
46 Real
48 {
49  GridIndex left(_dim);
50  GridIndex right(_dim);
51  GridIndex arg(_dim);
52  for (unsigned int i = 0; i < _dim; ++i)
53  {
54  getNeighborIndices(_grid[i], pt[i], left[i], right[i]);
55  if (_direction.get(i) == 0)
56  arg[i] = left[i];
57  else
58  arg[i] = right[i];
59  }
60 
61  // return the point
62  return _gridded_data->evaluateFcn(arg);
63 }
64 
66 PiecewiseMulticonstant::gradient(Real, const Point &) const
67 {
68  return 0.0;
69 }
70 
71 Real
72 PiecewiseMulticonstant::timeDerivative(Real, const Point &) const
73 {
74  return 0.0;
75 }
Uses GriddedData to define data on a grid, and does linear interpolation on that data to provide func...
virtual RealGradient gradient(Real t, const Point &p) const override
Function objects can optionally provide a gradient at a point.
static InputParameters validParams()
Create new PiecewiseMultiInterpolation object.
std::unique_ptr< GriddedData > _gridded_data
object to provide function evaluations at points on the grid
virtual ADReal value(const ADReal &t, const ADPoint &p) const override
Override this to evaluate the scalar function at point (t,x,y,z), using dual numbers by default this ...
std::vector< std::vector< Real > > _grid
the grid
static InputParameters validParams()
virtual Real sample(const GridPoint &pt) const override
This does the core work.
auto raw_value(const Eigen::Map< T > &in)
Definition: ADReal.h:73
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", PiecewiseMulticonstant)
virtual Real timeDerivative(Real t, const Point &p) const override
Get the time derivative of the function.
Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size...
void getNeighborIndices(std::vector< Real > in_arr, Real x, unsigned int &lower_x, unsigned int &upper_x) const
Operates on monotonically increasing in_arr.
unsigned int _dim
dimension of the grid
DualReal ADReal
Definition: ADRealForward.h:14
Uses GriddedData to define data on a grid, and does linear interpolation on that data to provide func...
PiecewiseMulticonstant(const InputParameters &parameters)
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
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.
MultiMooseEnum _direction
direction where to look for value if interpolation order is constant
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 option parameter and a documentation string to the InputParameters object...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...