https://mooseframework.inl.gov
PiecewiseLinearFromVectorPostprocessor.C
Go to the documentation of this file.
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 
11 #include "FEProblemBase.h"
12 
15  VectorPostprocessorFunction,
16  "02/03/2024 00:00",
18 
21 {
23  params.addRequiredParam<VectorPostprocessorName>(
24  "vectorpostprocessor_name", "The name of the VectorPostprocessor that you want to use");
25  params.addRequiredParam<std::string>(
26  "argument_column",
27  "VectorPostprocessor column tabulating the abscissa of the sampled function");
28  params.addRequiredParam<std::string>("value_column",
29  "VectorPostprocessor column tabulating the "
30  "ordinate (function values) of the sampled "
31  "function");
32  params.addParam<bool>(
33  "parallel_sync",
34  true,
35  "Whether or not this Function should be synced to all processors when running in parallel.");
36 
37  MooseEnum component("x=0 y=1 z=2 time=3", "time");
38  params.addParam<MooseEnum>(
39  "component",
40  component,
41  "Component of the function evaluation point used to sample the VectorPostprocessor");
42 
43  params.addClassDescription(
44  "Provides piecewise linear interpolation of from two columns of a VectorPostprocessor");
45 
46  return params;
47 }
48 
50  const InputParameters & parameters)
51  : Function(parameters),
53  _argument_column(getVectorPostprocessorValue("vectorpostprocessor_name",
54  getParam<std::string>("argument_column"),
55  getParam<bool>("parallel_sync"))),
56  _value_column(getVectorPostprocessorValue("vectorpostprocessor_name",
57  getParam<std::string>("value_column"),
58  getParam<bool>("parallel_sync"))),
59  _component(getParam<MooseEnum>("component")),
60  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
61  _last_update(
62  {std::numeric_limits<Real>::lowest(), libMesh::invalid_uint, libMesh::invalid_uint})
63 {
64  try
65  {
66  _linear_interp = std::make_unique<LinearInterpolation>(_argument_column, _value_column);
67  }
68  catch (std::domain_error & e)
69  {
70  mooseError("In PiecewiseLinearFromVectorPostprocessor ", _name, ": ", e.what());
71  }
72 }
73 
74 Real
75 PiecewiseLinearFromVectorPostprocessor::value(Real t, const Point & p) const
76 {
77  return valueInternal(t, p);
78 }
79 
80 ADReal
82 {
83  return valueInternal(t, p);
84 }
85 
86 template <typename T, typename P>
87 T
89 {
90  if (_argument_column.empty())
91  return 0.0;
92 
93  const std::tuple<Real, unsigned int, unsigned int> now = {
95  _fe_problem.nNonlinearIterations(/*nl_sys=*/0),
96  _fe_problem.nLinearIterations(/*nl_sys=*/0)};
97 
98  if (now != _last_update)
99  {
101  _last_update = now;
102  }
103 
104  const T x = _component == 3 ? t : p(_component);
105  return _linear_interp->sample(x);
106 }
Base class for function objects.
Definition: Function.h:36
const unsigned int invalid_uint
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
Function which provides a piecewise continuous linear interpolation of a data set provided as two col...
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
PiecewiseLinearFromVectorPostprocessor(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual unsigned int nLinearIterations(const unsigned int nl_sys_num) const override
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:47
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
registerMooseObject("MooseApp", PiecewiseLinearFromVectorPostprocessor)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
registerMooseObjectRenamed("MooseApp", VectorPostprocessorFunction, "02/03/2024 00:00", PiecewiseLinearFromVectorPostprocessor)
virtual Real value(Real t, const Point &p) const override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
FEProblemBase & _fe_problem
used to get the current linear/non-linear iteration number
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::unique_ptr< LinearInterpolation > _linear_interp
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 optional parameter and a documentation string to the InputParameters object...
virtual unsigned int nNonlinearIterations(const unsigned int nl_sys_num) const override
static InputParameters validParams()
Class constructor.
Definition: Function.C:16
std::tuple< Real, unsigned int, unsigned int > _last_update
last iteration during which the linear interpolation was rebuilt