https://mooseframework.inl.gov
KokkosNodalStatistics.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 "KokkosNodalReporter.h"
13 
15 {
16 public:
18 
20 
21  template <typename Derived>
22  KOKKOS_FUNCTION void reduce(Datum & datum, Real * result) const;
23 
24  template <typename Derived>
25  KOKKOS_FUNCTION void join(Real * result, const Real * source) const;
26  template <typename Derived>
27  KOKKOS_FUNCTION void init(Real * result) const;
28 
29 protected:
30  virtual void initialize() override;
31  virtual void finalize() override;
32 
33 private:
34  const std::string _base_name;
38  unsigned int & _number_nodes;
39 };
40 
41 template <typename Derived>
42 KOKKOS_FUNCTION void
43 KokkosNodalStatistics::reduce(Datum & datum, Real * result) const
44 {
45  // Get value to to update statistics
46  Real value = static_cast<const Derived *>(this)->computeValue(datum);
47 
48  if (result[0] < value)
49  result[0] = value;
50 
51  if (result[1] > value)
52  result[1] = value;
53 
54  // Update the total and the number to get the average when "finalizing"
55  result[2] += value;
56  result[3]++;
57 }
58 
59 template <typename Derived>
60 KOKKOS_FUNCTION void
61 KokkosNodalStatistics::join(Real * result, const Real * source) const
62 {
63  result[0] = Kokkos::max(result[0], source[0]);
64  result[1] = Kokkos::min(result[1], source[1]);
65  result[2] += source[2];
66  result[3] += source[3];
67 }
68 
69 template <typename Derived>
70 KOKKOS_FUNCTION void
71 KokkosNodalStatistics::init(Real * result) const
72 {
73  result[0] = Kokkos::Experimental::finite_min_v<Real>;
74  result[1] = Kokkos::Experimental::finite_max_v<Real>;
75  result[2] = 0;
76  result[3] = 0;
77 }
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
KOKKOS_FUNCTION void reduce(Datum &datum, Real *result) const
static InputParameters validParams()
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION void join(Real *result, const Real *source) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
auto max(const L &left, const R &right)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual void finalize() override
Finalize.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto min(const L &left, const R &right)
KOKKOS_FUNCTION void init(Real *result) const
const std::string _base_name
KokkosNodalStatistics(const InputParameters &parameters)