https://mooseframework.inl.gov
KokkosExtraIDIntegralVectorPostprocessor.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 
14 #include "MooseMesh.h"
15 
17 {
18  template <typename T>
20 
21  template <typename T>
23 
25 
26 public:
29 
30  virtual void initialSetup() override;
31  virtual void initialize() override;
32  virtual void compute() override;
33  virtual void finalize() override;
34 
35  template <typename Derived>
36  KOKKOS_FUNCTION void join(Real * result, const Real * source) const;
37  template <typename Derived>
38  KOKKOS_FUNCTION void init(Real * result) const;
39  template <typename Derived>
40  KOKKOS_FUNCTION void reduce(Datum & datum, Real * result) const;
41  template <typename Derived>
42  KOKKOS_FUNCTION void execute(Datum & datum) const;
43 
44 protected:
46  const MooseMesh & _mesh;
48  const bool _average;
52  const unsigned int _nvar;
54  const unsigned int _nprop;
56  const std::vector<MaterialPropertyName> _prop_names;
58  const std::vector<ExtraElementIDName> _extra_id;
60  const unsigned int _n_extra_id;
62  std::unordered_map<dof_id_type, dof_id_type> _unique_vpp_id_map;
74  std::vector<VectorPostprocessorValue *> _extra_ids;
78  static constexpr unsigned int _cache_size = 10;
79 };
80 
81 template <typename Derived>
82 KOKKOS_FUNCTION void
83 KokkosExtraIDIntegralVectorPostprocessor::join(Real * result, const Real * source) const
84 {
85  auto size = _vector_size * (_nvar + _nprop + _average);
86 
87  for (decltype(size) i = 0; i < size; ++i)
88  result[i] += source[i];
89 }
90 
91 template <typename Derived>
92 KOKKOS_FUNCTION void
94 {
95  auto size = _vector_size * (_nvar + _nprop + _average);
96 
97  for (decltype(size) i = 0; i < size; ++i)
98  result[i] = 0;
99 }
100 
101 template <typename Derived>
102 KOKKOS_FUNCTION void
104 {
105  const auto ipos = _unique_vpp_ids[datum.subdomain()](datum.elemID());
106  const auto & var = _var_values.variable();
107  const auto subdomain = datum.subdomain();
108 
109  Real sum[_cache_size] = {0};
110  Real vol = 0;
111 
112  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
113  {
114  const auto JxW = datum.JxW(qp);
115 
116  unsigned int i = 0;
117 
118  for (unsigned int ivar = 0; ivar < _nvar; ++ivar, ++i)
119  if (kokkosSystem(var.sys(ivar)).isVariableActive(var.var(ivar), subdomain))
120  sum[i] += JxW * _var_values(datum, qp, ivar);
121 
122  for (unsigned int iprop = 0; iprop < _nprop; ++iprop, ++i)
123  sum[i] += JxW * _props[iprop](datum, qp);
124 
125  vol += JxW;
126  }
127 
128  for (unsigned int i = 0; i < _nvar + _nprop; ++i)
129  result[ipos + i * _vector_size] += sum[i];
130 
131  if (_average)
132  result[ipos + (_nvar + _nprop) * _vector_size] += vol;
133 }
134 
135 template <typename Derived>
136 KOKKOS_FUNCTION void
138 {
139  const auto ipos = _unique_vpp_ids[datum.subdomain()](datum.elemID());
140  const auto & var = _var_values.variable();
141  const auto subdomain = datum.subdomain();
142 
143  Real sum[_cache_size] = {0};
144  Real vol = 0;
145 
146  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
147  {
148  const auto JxW = datum.JxW(qp);
149 
150  unsigned int i = 0;
151 
152  for (unsigned int ivar = 0; ivar < _nvar; ++ivar, ++i)
153  if (kokkosSystem(var.sys(ivar)).isVariableActive(var.var(ivar), subdomain))
154  sum[i] += JxW * _var_values(datum, qp, ivar);
155 
156  for (unsigned int iprop = 0; iprop < _nprop; ++iprop, ++i)
157  sum[i] += JxW * _props[iprop](datum, qp);
158 
159  vol += JxW;
160  }
161 
162  for (unsigned int i = 0; i < _nvar + _nprop; ++i)
163  Kokkos::atomic_add(&_integrals[i][ipos], sum[i]);
164 
165  if (_average)
166  Kokkos::atomic_add(&_volumes[ipos], vol);
167 }
const unsigned int _nprop
Number of material properties to be integrated.
std::vector< VectorPostprocessorValue * > _extra_ids
Vectors holding extra IDs.
The Kokkos array class.
Definition: KokkosArray.h:64
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
Array< Array< Real > > _integrals
Vectors holding integrals over extra IDs.
static InputParameters validParams()
virtual void compute() override
Compute this user object.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
VariableValue _var_values
Quadrature point values of coupled MOOSE variables.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const std::vector< MaterialPropertyName > _prop_names
Name of material properties.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< ExtraElementIDName > _extra_id
Extra IDs in use.
const bool _average
Whether or not to compute volume average.
Array< MaterialProperty< Real > > _props
Material properties to be integrated.
Array< Real > _volumes
Vector holding the volume of extra IDs.
KOKKOS_FUNCTION ContiguousElementID elemID() const
Get the contiguous element ID.
Definition: KokkosDatum.h:89
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:118
static constexpr unsigned int _cache_size
Sum cache size.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:93
KOKKOS_FUNCTION const System & kokkosSystem(unsigned int sys) const
Get the const reference of a Kokkos system.
Definition: KokkosSystem.h:792
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
const unsigned int _nvar
Number of variables to be integrated.
The Kokkos wrapper classes for MOOSE-like variable value access.
virtual void finalize() override
Finalize.
KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const
Get the contiguous subdomain ID.
Definition: KokkosDatum.h:103
VariableValueTempl< false > VariableValue
KOKKOS_FUNCTION void reduce(Datum &datum, Real *result) const
KokkosExtraIDIntegralVectorPostprocessor(const InputParameters &parameters)
KOKKOS_FUNCTION const Variable & variable() const
Get the Kokkos variable.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::unordered_map< dof_id_type, dof_id_type > _unique_vpp_id_map
Map of element IDs to parsed vpp ids.
Array< Array< dof_id_type > > _unique_vpp_ids
Map of contiguous element IDs to parsed vpp ids for device.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:311
const unsigned int _n_extra_id
Number of extra IDs in use.
The Kokkos material property class.
KOKKOS_FUNCTION void join(Real *result, const Real *source) const
uint8_t dof_id_type