LCOV - code coverage report
Current view: top level - include/kokkos/materials - KokkosMaterialProperty.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 70 74 94.6 %
Date: 2026-05-29 20:35:17 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             : #include "KokkosMesh.h"
      20             : 
      21             : namespace Moose::Kokkos
      22             : {
      23             : 
      24             : inline void
      25        3657 : MaterialPropertyBase::init(const PropRecord & record, const StorageKey &)
      26             : {
      27        3657 :   _record = &record;
      28        3657 :   _id = record.id;
      29        3657 : }
      30             : 
      31             : template <typename T, unsigned int dimension>
      32           0 : MaterialProperty<T, dimension>::MaterialProperty(const T & value)
      33             : {
      34           0 :   _default = true;
      35           0 :   _value = value;
      36           0 : }
      37             : 
      38             : template <typename T, unsigned int dimension>
      39      225675 : MaterialProperty<T, dimension>::MaterialProperty(const MaterialProperty<T, dimension> & property)
      40             : {
      41             :   // If reference exists, copy the reference property
      42             :   // Reference can be nullptr if the property is a default or optional property
      43      225675 :   const auto & prop = property._reference ? *property._reference : property;
      44             : 
      45      225675 :   shallowCopy(prop);
      46             : 
      47      225675 :   _reference = property._reference;
      48      225675 : }
      49             : 
      50             : template <typename T, unsigned int dimension>
      51             : auto &
      52        3292 : MaterialProperty<T, dimension>::operator=(const MaterialProperty<T, dimension> & property)
      53             : {
      54        3292 :   shallowCopy(property);
      55             : 
      56        3292 :   return *this;
      57             : }
      58             : 
      59             : template <typename T, unsigned int dimension>
      60             : void
      61        3657 : MaterialProperty<T, dimension>::init(const PropRecord & record, const StorageKey & key)
      62             : {
      63        3657 :   MaterialPropertyBase::init(record, key);
      64             : 
      65        3657 :   _reference = this;
      66        3657 : }
      67             : 
      68             : #ifdef MOOSE_KOKKOS_SCOPE
      69             : template <typename T, unsigned int dimension>
      70             : void
      71        1419 : MaterialProperty<T, dimension>::copy(const MaterialPropertyBase & prop, StorageKey)
      72             : {
      73        1419 :   auto prop_cast = dynamic_cast<const MaterialProperty<T, dimension> *>(&prop);
      74             : 
      75             :   mooseAssert(prop_cast, "The property to copy should be of the same type and dimension.");
      76             : 
      77        2838 :   for (const auto i : index_range(prop_cast->_data))
      78        1419 :     if (prop_cast->_data[i].isAlloc())
      79        1419 :       _data[i].deepCopy(prop_cast->_data[i]);
      80             : 
      81        1419 :   _data.copyToDevice();
      82        1419 : }
      83             : 
      84             : template <typename T, unsigned int dimension>
      85             : void
      86        2808 : MaterialProperty<T, dimension>::swap(MaterialPropertyBase & prop, StorageKey)
      87             : {
      88        2808 :   auto prop_cast = dynamic_cast<MaterialProperty<T, dimension> *>(&prop);
      89             : 
      90             :   mooseAssert(prop_cast, "The property to swap should be of the same type and dimension.");
      91             : 
      92        2808 :   _data.swap(prop_cast->_data);
      93        2808 : }
      94             : 
      95             : template <typename T, unsigned int dimension>
      96             : void
      97      228967 : MaterialProperty<T, dimension>::shallowCopy(const MaterialProperty<T, dimension> & property)
      98             : {
      99      228967 :   _record = property._record;
     100      228967 :   _id = property._id;
     101      228967 :   _default = property._default;
     102      228967 :   _constant_option = property._constant_option;
     103             : 
     104      228967 :   _reference = property._reference;
     105      228967 :   _data = property._data;
     106      228967 :   _value = property._value;
     107      228967 : }
     108             : 
     109             : template <typename T, unsigned int dimension>
     110             : void
     111        3834 : MaterialProperty<T, dimension>::allocate(const Mesh & mesh,
     112             :                                          const Assembly & assembly,
     113             :                                          const std::set<SubdomainID> & subdomains,
     114             :                                          const bool bnd,
     115             :                                          StorageKey)
     116             : {
     117        3834 :   if (!_data.isAlloc())
     118        3578 :     _data.create(mesh.getNumSubdomains());
     119             : 
     120        3834 :   if (!_constant_option.isAlloc())
     121             :   {
     122        3578 :     _constant_option.create(mesh.getNumSubdomains());
     123        3578 :     _constant_option = PropertyConstantOption::NONE;
     124             :   }
     125             : 
     126        9006 :   for (const auto subdomain : subdomains)
     127             :   {
     128        5172 :     auto sid = mesh.getContiguousSubdomainID(subdomain);
     129        5172 :     auto constant_option = libmesh_map_find(_record->constant_option, subdomain);
     130             : 
     131        5172 :     std::vector<dof_id_type> n;
     132             : 
     133        5376 :     for (unsigned int i = 0; i < dimension; ++i)
     134         204 :       n.push_back(libmesh_map_find(_record->dims, subdomain)[i]);
     135             : 
     136        5172 :     if (constant_option == PropertyConstantOption::NONE)
     137        4611 :       n.push_back(bnd ? assembly.getNumFaceQps(sid) : assembly.getNumQps(sid));
     138         561 :     else if (constant_option == PropertyConstantOption::ELEMENT)
     139         300 :       n.push_back(bnd ? assembly.getElemFacePropertySize(sid)
     140          45 :                       : mesh.getNumSubdomainLocalElements(subdomain));
     141             :     else
     142         306 :       n.push_back(1);
     143             : 
     144        5172 :     if (!_data[sid].isAlloc())
     145        5120 :       _data[sid].createDevice(n);
     146             : 
     147        5172 :     _constant_option[sid] = constant_option;
     148             :   }
     149             : 
     150        3834 :   _data.copyToDevice();
     151        3834 :   _constant_option.copyToDevice();
     152        3834 : }
     153             : 
     154             : template <typename T, unsigned int dimension>
     155             : KOKKOS_FUNCTION MaterialPropertyValue<T, dimension>
     156    40059305 : MaterialProperty<T, dimension>::operator()(const Datum & datum, const unsigned int qp) const
     157             : {
     158    40059305 :   return MaterialPropertyValue<T, dimension>(*this, datum, qp);
     159             : }
     160             : #endif
     161             : 
     162             : template <typename T, unsigned int dimension>
     163             : void
     164         530 : propertyStore(std::ostream & stream, void * prop)
     165             : {
     166         530 :   auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
     167             : 
     168         530 :   dataStore(stream, property->_data, nullptr);
     169         530 : }
     170             : template <typename T, unsigned int dimension>
     171             : void
     172         256 : propertyLoad(std::istream & stream, void * prop)
     173             : {
     174         256 :   auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
     175             : 
     176         256 :   dataLoad(stream, property->_data, nullptr);
     177         256 : }
     178             : 
     179             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14