https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
26public:
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
44protected:
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;
76 dof_id_type _vector_size;
78 static constexpr unsigned int _cache_size = 10;
79};
80
81template <typename Derived>
82KOKKOS_FUNCTION void
83KokkosExtraIDIntegralVectorPostprocessor::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
91template <typename Derived>
92KOKKOS_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
101template <typename Derived>
102KOKKOS_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
135template <typename Derived>
136KOKKOS_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}
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const bool _average
Whether or not to compute volume average.
Array< Array< dof_id_type > > _unique_vpp_ids
Map of contiguous element IDs to parsed vpp ids for device.
static constexpr unsigned int _cache_size
Sum cache size.
VariableValue _var_values
Quadrature point values of coupled MOOSE variables.
virtual void finalize() override
Finalize.
Array< MaterialProperty< Real > > _props
Material properties to be integrated.
KOKKOS_FUNCTION void join(Real *result, const Real *source) const
Array< Array< Real > > _integrals
Vectors holding integrals over extra IDs.
virtual void compute() override
Compute this user object.
const unsigned int _n_extra_id
Number of extra IDs in use.
const std::vector< ExtraElementIDName > _extra_id
Extra IDs in use.
const unsigned int _nprop
Number of material properties to be integrated.
Array< Real > _volumes
Vector holding the volume of extra IDs.
const unsigned int _nvar
Number of variables to be integrated.
const std::vector< MaterialPropertyName > _prop_names
Name of material properties.
static InputParameters validParams()
KokkosExtraIDIntegralVectorPostprocessor(const InputParameters &parameters)
std::vector< VectorPostprocessorValue * > _extra_ids
Vectors holding extra IDs.
KOKKOS_FUNCTION void reduce(Datum &datum, Real *result) const
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
std::unordered_map< dof_id_type, dof_id_type > _unique_vpp_id_map
Map of element IDs to parsed vpp ids.
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
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
The Kokkos array class.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
The Kokkos material property class.
KOKKOS_FUNCTION ContiguousElementID elemID() const
Get the contiguous element ID.
Definition KokkosDatum.h:52
KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const
Get the contiguous subdomain ID.
Definition KokkosDatum.h:91
The Kokkos wrapper classes for MOOSE-like variable value access.
KOKKOS_FUNCTION const Variable & variable() const
Get the Kokkos variable.
VariableValueTempl< false > VariableValue