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 
15 template <>
18 {
20 
21  MultiMooseEnum direction("left=0 right=1");
22  params.addParam<MultiMooseEnum>(
23  "direction", direction, "Direction to look to find value for each interpolation dimension.");
24 
25  params.addClassDescription(
26  "PiecewiseMulticonstant performs constant interpolation on 1D, 2D, 3D or 4D "
27  "data. The data_file specifies the axes directions and the function "
28  "values. If a point lies outside the data range, the appropriate end "
29  "value is used.");
30  return params;
31 }
32 
34  : PiecewiseMultiInterpolation(parameters), _direction(getParam<MultiMooseEnum>("direction"))
35 {
36  if (_direction.size() != _dim)
37  mooseError("Parameter direction must have a size identical to ", _dim);
38 }
39 
40 Real
41 PiecewiseMulticonstant::sample(const std::vector<Real> & pt)
42 {
43  std::vector<unsigned int> left(_dim);
44  std::vector<unsigned int> right(_dim);
45  std::vector<unsigned int> arg(_dim);
46  for (unsigned int i = 0; i < _dim; ++i)
47  {
48  getNeighborIndices(_grid[i], pt[i], left[i], right[i]);
49  if (_direction.get(i) == 0)
50  arg[i] = left[i];
51  else
52  arg[i] = right[i];
53  }
54 
55  // return the point
56  return _gridded_data->evaluateFcn(arg);
57 }
std::unique_ptr< GriddedData > _gridded_data
object to provide function evaluations at points on the grid
std::vector< std::vector< Real > > _grid
the grid
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...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
registerMooseObject("MooseApp", PiecewiseMulticonstant)
void getNeighborIndices(std::vector< Real > in_arr, Real x, unsigned int &lower_x, unsigned int &upper_x)
Operates on monotonically increasing in_arr.
unsigned int _dim
dimension of the grid
InputParameters validParams< PiecewiseMulticonstant >()
InputParameters validParams< PiecewiseMultiInterpolation >()
PiecewiseMulticonstant(const InputParameters &parameters)
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
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...
virtual Real sample(const std::vector< Real > &pt) override
This does the core work.