https://mooseframework.inl.gov
KokkosExtremeValueBase.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 
12 #include "KokkosDatum.h"
13 
14 class UserObject;
15 class InputParameters;
16 
17 template <typename Base>
18 class KokkosExtremeValueBase : public Base
19 {
20 public:
22 
23  KokkosExtremeValueBase(const InputParameters & parameters);
24 
25  virtual void initialize() override;
26  virtual void finalize() override;
27  virtual Real getValue() const override;
28 
29  template <typename Derived>
30  KOKKOS_FUNCTION void
31  computeExtremeValue(const unsigned int qp, Datum & datum, Real * result) const;
32  template <typename Derived>
33  KOKKOS_FUNCTION void join(Real * result, const Real * source) const;
34  template <typename Derived>
35  KOKKOS_FUNCTION void init(Real * result) const;
36 
37 protected:
41  enum class ExtremeType
42  {
43  MAX,
44  MIN,
45  MAX_ABS
46  } _type;
47 };
48 
49 template <typename Base>
50 template <typename Derived>
51 KOKKOS_FUNCTION void
53  Datum & datum,
54  Real * result) const
55 {
56  auto pv = static_cast<const Derived *>(this)->getProxyValuePair(qp, datum);
57  auto rpv = Kokkos::make_pair(result[0], result[1]);
58 
59  if ((_type == ExtremeType::MAX && pv > rpv) || (_type == ExtremeType::MIN && pv < rpv))
60  {
61  result[0] = pv.first;
62  result[1] = pv.second;
63  }
64  else if (_type == ExtremeType::MAX_ABS && Kokkos::abs(pv.first) > rpv.first)
65  {
66  result[0] = Kokkos::abs(pv.first);
67  result[1] = pv.second;
68  }
69 }
70 
71 template <typename Base>
72 template <typename Derived>
73 KOKKOS_FUNCTION void
74 KokkosExtremeValueBase<Base>::join(Real * result, const Real * source) const
75 {
76  auto rpv = Kokkos::make_pair(result[0], result[1]);
77  auto spv = Kokkos::make_pair(source[0], source[1]);
78 
79  if ((_type == ExtremeType::MAX && spv > rpv) || (_type == ExtremeType::MIN && spv < rpv))
80  {
81  result[0] = source[0];
82  result[1] = source[1];
83  }
84  else if (_type == ExtremeType::MAX_ABS && Kokkos::abs(spv.first) > rpv.first)
85  {
86  result[0] = Kokkos::abs(source[0]);
87  result[1] = source[1];
88  }
89 }
90 
91 template <typename Base>
92 template <typename Derived>
93 KOKKOS_FUNCTION void
95 {
96  if (_type == ExtremeType::MAX || _type == ExtremeType::MAX_ABS)
97  {
98  result[0] = Kokkos::Experimental::finite_min_v<Real>;
99  result[1] = Kokkos::Experimental::finite_min_v<Real>;
100  }
101  else if (_type == ExtremeType::MIN)
102  {
103  result[0] = Kokkos::Experimental::finite_max_v<Real>;
104  result[1] = Kokkos::Experimental::finite_max_v<Real>;
105  }
106 }
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:50
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
KOKKOS_FUNCTION void computeExtremeValue(const unsigned int qp, Datum &datum, Real *result) const
ExtremeType
Type of extreme value we are going to compute.
enum KokkosExtremeValueBase::ExtremeType _type
virtual Real getValue() const override
KokkosExtremeValueBase(const InputParameters &parameters)
KOKKOS_FUNCTION void init(Real *result) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
virtual void finalize() override
virtual void initialize() override
KOKKOS_FUNCTION void join(Real *result, const Real *source) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for user-specific data.
Definition: UserObject.h:19