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 integral() const;
29 KOKKOS_FUNCTION Real average() const;
30
31private:
34};
35
36KOKKOS_FUNCTION inline Real
38{
40
41 const Real x = _has_axis ? p(_axis) : t;
42
43 const auto len = functionSize();
44 constexpr Real tolerance = 1.0e-14;
45
46 // endpoint cases
47 if ((_direction == Direction::LEFT && x < (1 + tolerance * sign(domain(0))) * domain(0)) ||
48 (_direction == Direction::RIGHT && x < (1 - tolerance * sign(domain(0))) * domain(0)) ||
50 x < (1 - tolerance * sign(domain(0))) * domain(0)) ||
52 x < (1 + tolerance * sign(domain(0))) * domain(0)))
53 return _scale_factor * range(0);
54 else if ((_direction == Direction::LEFT &&
55 x > (1 + tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
57 x > (1 - tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
59 x > (1 - tolerance * sign(domain(len - 1))) * domain(len - 1)) ||
61 x > (1 + tolerance * sign(domain(len - 1))) * domain(len - 1)))
62 return _scale_factor * range(len - 1);
63
64 for (unsigned int i = 1; i < len; ++i)
65 {
66 if (_direction == Direction::LEFT && x < (1 + tolerance * sign(domain(i))) * domain(i))
67 return _scale_factor * range(i - 1);
69 x < (1 - tolerance * sign(domain(i))) * domain(i))
70 return _scale_factor * range(i - 1);
71 else if ((_direction == Direction::RIGHT && x < (1 - tolerance * sign(domain(i))) * domain(i)))
72 return _scale_factor * range(i);
74 x < (1 + tolerance * sign(domain(i))) * domain(i)))
75 return _scale_factor * range(i);
76 }
77
78 return 0.0;
79}
80
81KOKKOS_FUNCTION inline Real
83{
84 const auto len = functionSize();
85
86 unsigned int offset = 0;
87
89 offset = 1;
90
91 Real sum = 0;
92
93 for (unsigned int i = 0; i < len - 1; ++i)
94 sum += range(i + offset) * (domain(i + 1) - domain(i));
95
96 return _scale_factor * sum;
97}
98
99KOKKOS_FUNCTION inline Real
101{
102 return integral() / (domain(functionSize() - 1) - domain(0));
103}
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 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