https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosPiecewiseConstant.h
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
10#pragma once
11
13#include "KokkosUtils.h"
14
19{
20public:
22
24
26
27 KOKKOS_FUNCTION Real value(Real t, Real3 p) const;
28 KOKKOS_FUNCTION Real timeDerivative(Real, Real3) const { return 0; }
29 KOKKOS_FUNCTION Real integral() const;
30 KOKKOS_FUNCTION Real average() const;
31
32private:
35};
36
37KOKKOS_FUNCTION inline Real
39{
41
42 const Real x = _has_axis ? p(_axis) : t;
43
44 const auto len = functionSize();
45 constexpr Real tolerance = 1.0e-14;
46
47 // endpoint cases
48 if ((_direction == Direction::LEFT && x < (1 + tolerance * sign(domain(0))) * domain(0)) ||
49 (_direction == Direction::RIGHT && x < (1 - tolerance * sign(domain(0))) * domain(0)) ||
51 x < (1 - tolerance * sign(domain(0))) * domain(0)) ||
53 x < (1 + tolerance * sign(domain(0))) * domain(0)))
54 return _scale_factor * range(0);
55 else if ((_direction == Direction::LEFT &&
56 x > (1 + tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
58 x > (1 - tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
60 x > (1 - tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
62 x > (1 + tolerance * sign(domain(len - 1))) * domain(len - 1)))
63 return _scale_factor * range(len - 1);
64
65 for (unsigned int i = 1; i < len; ++i)
66 {
67 if (_direction == Direction::LEFT && x < (1 + tolerance * sign(domain(i))) * domain(i))
68 return _scale_factor * range(i - 1);
70 x < (1 - tolerance * sign(domain(i))) * domain(i))
71 return _scale_factor * range(i - 1);
72 else if ((_direction == Direction::RIGHT && x < (1 - tolerance * sign(domain(i))) * domain(i)))
73 return _scale_factor * range(i);
75 x < (1 + tolerance * sign(domain(i))) * domain(i)))
76 return _scale_factor * range(i);
77 }
78
79 return 0.0;
80}
81
82KOKKOS_FUNCTION inline Real
84{
85 const auto len = functionSize();
86
87 unsigned int offset = 0;
88
90 offset = 1;
91
92 Real sum = 0;
93
94 for (unsigned int i = 0; i < len - 1; ++i)
95 sum += range(i + offset) * (domain(i + 1) - domain(i));
96
97 return _scale_factor * sum;
98}
99
100KOKKOS_FUNCTION inline Real
102{
103 return integral() / (domain(functionSize() - 1) - domain(0));
104}
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
KOKKOS_FUNCTION Real range(const unsigned int i) const
KOKKOS_FUNCTION Real domain(const unsigned int i) const
KOKKOS_FUNCTION dof_id_type functionSize() const
Function which provides a piecewise constant interpolation of a provided (x,y) point data set.
enum KokkosPiecewiseConstant::Direction _direction
KokkosPiecewiseConstant(const InputParameters &parameters)
KOKKOS_FUNCTION Real average() const
Direction
Enum for which direction to apply values.
KOKKOS_FUNCTION Real integral() const
KOKKOS_FUNCTION Real timeDerivative(Real, Real3) const
KOKKOS_FUNCTION Real value(Real t, Real3 p) const
static InputParameters validParams()
Piecewise tabular base class which provides a piecewise approximation to a provided (x,...
Moose::Kokkos::Scalar< const Real > _scale_factor
function value scale factor
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
unsigned int _axis
if _has_axis is true point component to use as function argument, otherwise use t
KOKKOS_INLINE_FUNCTION T sign(T x)
Returns the sign of a value.
Definition KokkosUtils.h:26
Vector3< Real > Real3
Definition KokkosTypes.h:32
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real