LCOV - code coverage report
Current view: top level - include/kokkos/materials - KokkosMaterialProperty.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 58 62 93.5 %
Date: 2025-09-22 20:01:15 Functions: 16 75 21.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "KokkosMaterialPropertyDecl.h"
      13             : 
      14             : #ifdef MOOSE_KOKKOS_SCOPE
      15             : #include "KokkosMaterialPropertyValueDecl.h"
      16             : #endif
      17             : 
      18             : #include "KokkosAssembly.h"
      19             : 
      20             : #include "MooseMesh.h"
      21             : 
      22             : namespace Moose
      23             : {
      24             : namespace Kokkos
      25             : {
      26             : 
      27             : inline void
      28        1482 : MaterialPropertyBase::init(const PropRecord & record, const StorageKey &)
      29             : {
      30        1482 :   _record = &record;
      31        1482 :   _id = record.id;
      32        1482 : }
      33             : 
      34             : template <typename T, unsigned int dimension>
      35           0 : MaterialProperty<T, dimension>::MaterialProperty(const T & value)
      36             : {
      37           0 :   _default = true;
      38           0 :   _value = value;
      39           0 : }
      40             : 
      41             : template <typename T, unsigned int dimension>
      42       99930 : MaterialProperty<T, dimension>::MaterialProperty(const MaterialProperty<T, dimension> & property)
      43             : {
      44             :   // If reference exists, copy the reference property
      45             :   // Reference can be nullptr if the property is a default or optional property
      46       99930 :   const auto & prop = property._reference ? *property._reference : property;
      47             : 
      48       99930 :   shallowCopy(prop);
      49             : 
      50       99930 :   _reference = property._reference;
      51       99930 : }
      52             : 
      53             : template <typename T, unsigned int dimension>
      54             : auto &
      55        1135 : MaterialProperty<T, dimension>::operator=(const MaterialProperty<T, dimension> & property)
      56             : {
      57        1135 :   shallowCopy(property);
      58             : 
      59        1135 :   return *this;
      60             : }
      61             : 
      62             : template <typename T, unsigned int dimension>
      63             : void
      64        1482 : MaterialProperty<T, dimension>::init(const PropRecord & record, const StorageKey & key)
      65             : {
      66        1482 :   MaterialPropertyBase::init(record, key);
      67             : 
      68        1482 :   _reference = this;
      69        1482 : }
      70             : 
      71             : #ifdef MOOSE_KOKKOS_SCOPE
      72             : template <typename T, unsigned int dimension>
      73             : void
      74         484 : MaterialProperty<T, dimension>::copy(const MaterialPropertyBase & prop, StorageKey)
      75             : {
      76         484 :   auto prop_cast = dynamic_cast<const MaterialProperty<T, dimension> *>(&prop);
      77             : 
      78             :   mooseAssert(prop_cast, "The property to copy should be of the same type and dimension.");
      79             : 
      80         968 :   for (const auto i : index_range(prop_cast->_data))
      81         484 :     if (prop_cast->_data[i].isAlloc())
      82         484 :       _data[i].deepCopy(prop_cast->_data[i]);
      83             : 
      84         484 :   _data.copyToDevice();
      85         484 : }
      86             : 
      87             : template <typename T, unsigned int dimension>
      88             : void
      89        1868 : MaterialProperty<T, dimension>::swap(MaterialPropertyBase & prop, StorageKey)
      90             : {
      91        1868 :   auto prop_cast = dynamic_cast<MaterialProperty<T, dimension> *>(&prop);
      92             : 
      93             :   mooseAssert(prop_cast, "The property to swap should be of the same type and dimension.");
      94             : 
      95        1868 :   _data.swap(prop_cast->_data);
      96        1868 : }
      97             : 
      98             : template <typename T, unsigned int dimension>
      99             : void
     100      101065 : MaterialProperty<T, dimension>::shallowCopy(const MaterialProperty<T, dimension> & property)
     101             : {
     102      101065 :   _record = property._record;
     103      101065 :   _id = property._id;
     104      101065 :   _default = property._default;
     105             : 
     106      101065 :   _reference = property._reference;
     107      101065 :   _data = property._data;
     108      101065 :   _value = property._value;
     109      101065 : }
     110             : 
     111             : template <typename T, unsigned int dimension>
     112             : void
     113        1707 : MaterialProperty<T, dimension>::allocate(const MooseMesh & mesh,
     114             :                                          const Assembly & assembly,
     115             :                                          const std::set<SubdomainID> & subdomains,
     116             :                                          const bool bnd,
     117             :                                          StorageKey)
     118             : {
     119        1707 :   if (!_data.isAlloc())
     120        1452 :     _data.create(mesh.meshSubdomains().size());
     121             : 
     122        3441 :   for (const auto subdomain : subdomains)
     123             :   {
     124        1734 :     auto sid = mesh.getKokkosMesh()->getContiguousSubdomainID(subdomain);
     125             : 
     126        1734 :     std::vector<dof_id_type> n;
     127             : 
     128        1812 :     for (unsigned int i = 0; i < dimension; ++i)
     129          78 :       n.push_back(_record->dims[i]);
     130             : 
     131        1734 :     n.push_back(bnd ? assembly.getNumFaceQps(sid) : assembly.getNumQps(sid));
     132             : 
     133        1734 :     if (!_data[sid].isAlloc())
     134        1506 :       _data[sid].createDevice(n);
     135             :   }
     136             : 
     137        1707 :   _data.copyToDevice();
     138        1707 : }
     139             : 
     140             : template <typename T, unsigned int dimension>
     141             : KOKKOS_FUNCTION MaterialPropertyValue<T, dimension>
     142    25810976 : MaterialProperty<T, dimension>::operator()(const Datum & datum, const unsigned int qp) const
     143             : {
     144    25810976 :   return MaterialPropertyValue<T, dimension>(*this, datum, qp);
     145             : }
     146             : #endif
     147             : 
     148             : template <typename T, unsigned int dimension>
     149             : void
     150         440 : propertyStore(std::ostream & stream, void * prop)
     151             : {
     152         440 :   auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
     153             : 
     154         440 :   dataStore(stream, property->_data, nullptr);
     155         440 : }
     156             : template <typename T, unsigned int dimension>
     157             : void
     158         226 : propertyLoad(std::istream & stream, void * prop)
     159             : {
     160         226 :   auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
     161             : 
     162         226 :   dataLoad(stream, property->_data, nullptr);
     163         226 : }
     164             : 
     165             : } // namespace Kokkos
     166             : } // namespace Moose

Generated by: LCOV version 1.14