LCOV - code coverage report
Current view: top level - include/kokkos/vectorpostprocessors - KokkosExtraIDIntegralVectorPostprocessor.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 50 50 100.0 %
Date: 2026-05-29 20:35:17 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "KokkosElementVectorPostprocessor.h"
      13             : 
      14             : #include "MooseMesh.h"
      15             : 
      16             : class KokkosExtraIDIntegralVectorPostprocessor : public Moose::Kokkos::ElementVectorPostprocessor
      17             : {
      18             :   template <typename T>
      19             :   using Array = Moose::Kokkos::Array<T>;
      20             : 
      21             :   template <typename T>
      22             :   using MaterialProperty = Moose::Kokkos::MaterialProperty<T>;
      23             : 
      24             :   using VariableValue = Moose::Kokkos::VariableValue;
      25             : 
      26             : public:
      27             :   static InputParameters validParams();
      28             :   KokkosExtraIDIntegralVectorPostprocessor(const InputParameters & parameters);
      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:
      45             :   /// MOOSE mesh
      46             :   const MooseMesh & _mesh;
      47             :   /// Whether or not to compute volume average
      48             :   const bool _average;
      49             :   /// Calculation mode
      50             :   const MooseEnum _mode;
      51             :   /// Number of variables to be integrated
      52             :   const unsigned int _nvar;
      53             :   /// Number of material properties to be integrated
      54             :   const unsigned int _nprop;
      55             :   /// Name of material properties
      56             :   const std::vector<MaterialPropertyName> _prop_names;
      57             :   /// Extra IDs in use
      58             :   const std::vector<ExtraElementIDName> _extra_id;
      59             :   /// Number of extra IDs in use
      60             :   const unsigned int _n_extra_id;
      61             :   /// Map of element IDs to parsed vpp ids
      62             :   std::unordered_map<dof_id_type, dof_id_type> _unique_vpp_id_map;
      63             :   /// Map of contiguous element IDs to parsed vpp ids for device
      64             :   Array<Array<dof_id_type>> _unique_vpp_ids;
      65             :   /// Quadrature point values of coupled MOOSE variables
      66             :   VariableValue _var_values;
      67             :   /// Material properties to be integrated
      68             :   Array<MaterialProperty<Real>> _props;
      69             :   /// Vector holding the volume of extra IDs
      70             :   Array<Real> _volumes;
      71             :   /// Vectors holding integrals over extra IDs
      72             :   Array<Array<Real>> _integrals;
      73             :   /// Vectors holding extra IDs
      74             :   std::vector<VectorPostprocessorValue *> _extra_ids;
      75             :   /// Size of the vector
      76             :   dof_id_type _vector_size;
      77             :   /// Sum cache size
      78             :   static constexpr unsigned int _cache_size = 10;
      79             : };
      80             : 
      81             : template <typename Derived>
      82             : KOKKOS_FUNCTION void
      83           5 : KokkosExtraIDIntegralVectorPostprocessor::join(Real * result, const Real * source) const
      84             : {
      85           5 :   auto size = _vector_size * (_nvar + _nprop + _average);
      86             : 
      87         777 :   for (decltype(size) i = 0; i < size; ++i)
      88         772 :     result[i] += source[i];
      89           5 : }
      90             : 
      91             : template <typename Derived>
      92             : KOKKOS_FUNCTION void
      93          40 : KokkosExtraIDIntegralVectorPostprocessor::init(Real * result) const
      94             : {
      95          40 :   auto size = _vector_size * (_nvar + _nprop + _average);
      96             : 
      97        6216 :   for (decltype(size) i = 0; i < size; ++i)
      98        6176 :     result[i] = 0;
      99          40 : }
     100             : 
     101             : template <typename Derived>
     102             : KOKKOS_FUNCTION void
     103      153600 : KokkosExtraIDIntegralVectorPostprocessor::reduce(Datum & datum, Real * result) const
     104             : {
     105      153600 :   const auto ipos = _unique_vpp_ids[datum.subdomain()](datum.elemID());
     106      153600 :   const auto & var = _var_values.variable();
     107      153600 :   const auto subdomain = datum.subdomain();
     108             : 
     109      153600 :   Real sum[_cache_size] = {0};
     110      153600 :   Real vol = 0;
     111             : 
     112      307200 :   for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     113             :   {
     114      153600 :     const auto JxW = datum.JxW(qp);
     115             : 
     116      153600 :     unsigned int i = 0;
     117             : 
     118      399360 :     for (unsigned int ivar = 0; ivar < _nvar; ++ivar, ++i)
     119      245760 :       if (kokkosSystem(var.sys(ivar)).isVariableActive(var.var(ivar), subdomain))
     120      245760 :         sum[i] += JxW * _var_values(datum, qp, ivar);
     121             : 
     122      276480 :     for (unsigned int iprop = 0; iprop < _nprop; ++iprop, ++i)
     123      122880 :       sum[i] += JxW * _props[iprop](datum, qp);
     124             : 
     125      153600 :     vol += JxW;
     126             :   }
     127             : 
     128      522240 :   for (unsigned int i = 0; i < _nvar + _nprop; ++i)
     129      368640 :     result[ipos + i * _vector_size] += sum[i];
     130             : 
     131      153600 :   if (_average)
     132       30720 :     result[ipos + (_nvar + _nprop) * _vector_size] += vol;
     133      153600 : }
     134             : 
     135             : template <typename Derived>
     136             : KOKKOS_FUNCTION void
     137      153600 : KokkosExtraIDIntegralVectorPostprocessor::execute(Datum & datum) const
     138             : {
     139      153600 :   const auto ipos = _unique_vpp_ids[datum.subdomain()](datum.elemID());
     140      153600 :   const auto & var = _var_values.variable();
     141      153600 :   const auto subdomain = datum.subdomain();
     142             : 
     143      153600 :   Real sum[_cache_size] = {0};
     144      153600 :   Real vol = 0;
     145             : 
     146      307200 :   for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     147             :   {
     148      153600 :     const auto JxW = datum.JxW(qp);
     149             : 
     150      153600 :     unsigned int i = 0;
     151             : 
     152      399360 :     for (unsigned int ivar = 0; ivar < _nvar; ++ivar, ++i)
     153      245760 :       if (kokkosSystem(var.sys(ivar)).isVariableActive(var.var(ivar), subdomain))
     154      245760 :         sum[i] += JxW * _var_values(datum, qp, ivar);
     155             : 
     156      276480 :     for (unsigned int iprop = 0; iprop < _nprop; ++iprop, ++i)
     157      122880 :       sum[i] += JxW * _props[iprop](datum, qp);
     158             : 
     159      153600 :     vol += JxW;
     160             :   }
     161             : 
     162      522240 :   for (unsigned int i = 0; i < _nvar + _nprop; ++i)
     163      368640 :     Kokkos::atomic_add(&_integrals[i][ipos], sum[i]);
     164             : 
     165      153600 :   if (_average)
     166       30720 :     Kokkos::atomic_add(&_volumes[ipos], vol);
     167      153600 : }

Generated by: LCOV version 1.14