LCOV - code coverage report
Current view: top level - src/loops - ComputeMaterialsObjectThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 130 148 87.8 %
Date: 2026-05-29 20:35:17 Functions: 9 9 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             : // MOOSE includes
      11             : #include "ComputeMaterialsObjectThread.h"
      12             : #include "NonlinearSystem.h"
      13             : #include "Problem.h"
      14             : #include "FEProblem.h"
      15             : #include "MaterialPropertyStorage.h"
      16             : #include "MaterialData.h"
      17             : #include "Assembly.h"
      18             : #include "AuxKernel.h"
      19             : #include "Material.h"
      20             : 
      21             : #include "libmesh/threads.h"
      22             : #include "libmesh/quadrature.h"
      23             : 
      24        9663 : ComputeMaterialsObjectThread::ComputeMaterialsObjectThread(
      25             :     FEProblemBase & fe_problem,
      26             :     MaterialPropertyStorage & material_props,
      27             :     MaterialPropertyStorage & bnd_material_props,
      28             :     MaterialPropertyStorage & neighbor_material_props,
      29        9663 :     std::vector<std::vector<std::unique_ptr<Assembly>>> & assembly)
      30             :   : ThreadedElementLoop<ConstElemRange>(fe_problem),
      31        9663 :     _fe_problem(fe_problem),
      32        9663 :     _material_props(material_props),
      33        9663 :     _bnd_material_props(bnd_material_props),
      34        9663 :     _neighbor_material_props(neighbor_material_props),
      35       19326 :     _materials(_fe_problem.getRegularMaterialsWarehouse()),
      36        9663 :     _interface_materials(_fe_problem.getInterfaceMaterialsWarehouse()),
      37        9663 :     _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse()),
      38        9663 :     _assembly(assembly),
      39        9663 :     _need_internal_side_material(false),
      40        9663 :     _has_stateful_props(_material_props.hasStatefulProperties()),
      41        9663 :     _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
      42       19326 :     _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
      43             : {
      44        9663 : }
      45             : 
      46             : // Splitting Constructor
      47         804 : ComputeMaterialsObjectThread::ComputeMaterialsObjectThread(ComputeMaterialsObjectThread & x,
      48         804 :                                                            Threads::split split)
      49             :   : ThreadedElementLoop<ConstElemRange>(x, split),
      50         804 :     _fe_problem(x._fe_problem),
      51         804 :     _material_props(x._material_props),
      52         804 :     _bnd_material_props(x._bnd_material_props),
      53         804 :     _neighbor_material_props(x._neighbor_material_props),
      54         804 :     _materials(x._materials),
      55         804 :     _interface_materials(x._interface_materials),
      56         804 :     _discrete_materials(x._discrete_materials),
      57         804 :     _assembly(x._assembly),
      58         804 :     _need_internal_side_material(x._need_internal_side_material),
      59        1608 :     _has_stateful_props(_material_props.hasStatefulProperties()),
      60         804 :     _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
      61        1608 :     _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
      62             : {
      63         804 : }
      64             : 
      65             : void
      66       87765 : ComputeMaterialsObjectThread::subdomainChanged()
      67             : {
      68       87765 :   _need_internal_side_material = _fe_problem.needInternalNeighborSideMaterial(_subdomain, _tid);
      69       87765 :   _fe_problem.subdomainSetup(_subdomain, _tid);
      70             : 
      71       87765 :   std::set<MooseVariableFEBase *> needed_moose_vars;
      72       87765 :   _materials.updateVariableDependency(needed_moose_vars, _tid);
      73       87765 :   _discrete_materials.updateVariableDependency(needed_moose_vars, _tid);
      74       87765 :   _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
      75             : 
      76       87765 :   std::set<TagID> needed_fe_var_vector_tags;
      77       87765 :   _materials.updateBlockFEVariableCoupledVectorTagDependency(
      78       87765 :       _subdomain, needed_fe_var_vector_tags, _tid);
      79       87765 :   _discrete_materials.updateBlockFEVariableCoupledVectorTagDependency(
      80       87765 :       _subdomain, needed_fe_var_vector_tags, _tid);
      81       87765 :   _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
      82             : 
      83             :   // Note that we do not know here which materials will be active on this subdomain because we don't
      84             :   // have the various warehouses (kernels, ...) to gather the needed material properties like in
      85             :   // NonlinearThread
      86       87765 : }
      87             : 
      88             : void
      89     1744584 : ComputeMaterialsObjectThread::onElement(const Elem * elem)
      90             : {
      91     2307511 :   if (_materials.hasActiveBlockObjects(_subdomain, _tid) ||
      92      562927 :       _discrete_materials.hasActiveBlockObjects(_subdomain, _tid))
      93             :   {
      94     1181957 :     _fe_problem.prepare(elem, _tid);
      95     1181957 :     _fe_problem.reinitElem(elem, _tid);
      96             : 
      97     1181957 :     auto & material_data = _material_props.getMaterialData(_tid);
      98             : 
      99     1181957 :     unsigned int n_points = _assembly[_tid][0]->qRule()->n_points();
     100     1181957 :     material_data.resize(n_points);
     101             : 
     102     1181957 :     if (_has_stateful_props)
     103             :     {
     104       68620 :       if (_discrete_materials.hasActiveBlockObjects(_subdomain, _tid))
     105           0 :         _material_props.initStatefulProps(
     106           0 :             _tid, _discrete_materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
     107       68620 :       if (_materials.hasActiveBlockObjects(_subdomain, _tid))
     108       68620 :         _material_props.initStatefulProps(
     109       68620 :             _tid, _materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
     110             :     }
     111             :   }
     112     1744584 : }
     113             : 
     114             : void
     115      346346 : ComputeMaterialsObjectThread::onBoundary(const Elem * elem,
     116             :                                          unsigned int side,
     117             :                                          BoundaryID bnd_id,
     118             :                                          const Elem * /*lower_d_elem = nullptr*/)
     119             : {
     120      346346 :   if (_fe_problem.needBoundaryMaterialOnSide(bnd_id, _tid))
     121             :   {
     122       85536 :     _fe_problem.reinitElemFace(elem, side, _tid);
     123       85536 :     const auto face_n_points = _assembly[_tid][/*system_index*/ 0]->qRuleFace()->n_points();
     124             : 
     125       85536 :     _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
     126             : 
     127       85536 :     if (_has_bnd_stateful_props)
     128             :     {
     129             :       // Face Materials
     130        3685 :       if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     131           0 :         _bnd_material_props.initStatefulProps(
     132             :             _tid,
     133           0 :             _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     134             :             face_n_points,
     135             :             *elem,
     136             :             side);
     137        3685 :       if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     138        3685 :         _bnd_material_props.initStatefulProps(
     139             :             _tid,
     140        3685 :             _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     141             :             face_n_points,
     142             :             *elem,
     143             :             side);
     144             : 
     145             :       // Boundary Materials
     146        3685 :       if (_discrete_materials.hasActiveBoundaryObjects(bnd_id, _tid))
     147           0 :         _bnd_material_props.initStatefulProps(
     148           0 :             _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
     149        3685 :       if (_materials.hasActiveBoundaryObjects(bnd_id, _tid))
     150         271 :         _bnd_material_props.initStatefulProps(
     151         271 :             _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
     152             :     }
     153             :   }
     154      346346 : }
     155             : 
     156             : void
     157     3552717 : ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
     158             : {
     159     3552717 :   if (_need_internal_side_material)
     160             :   {
     161       11705 :     const Elem * neighbor = elem->neighbor_ptr(side);
     162             : 
     163       11705 :     _fe_problem.reinitElemNeighborAndLowerD(elem, side, _tid);
     164       11705 :     unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
     165       11705 :     _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
     166       11705 :     _neighbor_material_props.getMaterialData(_tid).resize(face_n_points);
     167             : 
     168       11705 :     if (_has_bnd_stateful_props)
     169             :     {
     170         425 :       if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     171           0 :         _bnd_material_props.initStatefulProps(
     172             :             _tid,
     173           0 :             _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     174             :             face_n_points,
     175             :             *elem,
     176             :             side);
     177         425 :       if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     178         425 :         _bnd_material_props.initStatefulProps(
     179             :             _tid,
     180         425 :             _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     181             :             face_n_points,
     182             :             *elem,
     183             :             side);
     184             :     }
     185             : 
     186       11705 :     unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
     187             : 
     188       11705 :     if (_has_neighbor_stateful_props)
     189             :     {
     190             :       // Neighbor Materials
     191         408 :       if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
     192         204 :               neighbor->subdomain_id(), _tid))
     193           0 :         _neighbor_material_props.initStatefulProps(
     194             :             _tid,
     195           0 :             _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
     196           0 :                 neighbor->subdomain_id(), _tid),
     197             :             face_n_points,
     198             :             *elem,
     199             :             side);
     200         204 :       if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
     201             :                                                                           _tid))
     202         204 :         _neighbor_material_props.initStatefulProps(
     203             :             _tid,
     204         204 :             _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
     205         204 :                 neighbor->subdomain_id(), _tid),
     206             :             face_n_points,
     207             :             *neighbor,
     208             :             neighbor_side);
     209             :     }
     210             :   }
     211     3552717 : }
     212             : 
     213             : void
     214       10322 : ComputeMaterialsObjectThread::onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id)
     215             : {
     216       10322 :   if (!_fe_problem.needInterfaceMaterialOnSide(bnd_id, _tid))
     217        7108 :     return;
     218             : 
     219        3214 :   _fe_problem.reinitElemFace(elem, side, _tid);
     220        3214 :   unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
     221             : 
     222        3214 :   _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
     223        3214 :   _neighbor_material_props.getMaterialData(_tid).resize(face_n_points);
     224             : 
     225        3214 :   if (_has_bnd_stateful_props)
     226             :   {
     227             :     // Face Materials
     228         489 :     if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     229           0 :       _bnd_material_props.initStatefulProps(
     230             :           _tid,
     231           0 :           _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     232             :           face_n_points,
     233             :           *elem,
     234             :           side);
     235             : 
     236         489 :     if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
     237         489 :       _bnd_material_props.initStatefulProps(
     238             :           _tid,
     239         489 :           _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
     240             :           face_n_points,
     241             :           *elem,
     242             :           side);
     243             : 
     244             :     // Boundary Materials
     245         489 :     if (_discrete_materials.hasActiveBoundaryObjects(bnd_id, _tid))
     246           0 :       _bnd_material_props.initStatefulProps(
     247           0 :           _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
     248             : 
     249         489 :     if (_materials.hasActiveBoundaryObjects(bnd_id, _tid))
     250          67 :       _bnd_material_props.initStatefulProps(
     251          67 :           _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
     252             :   }
     253             : 
     254        3214 :   const Elem * neighbor = elem->neighbor_ptr(side);
     255        3214 :   unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
     256             : 
     257             :   // Do we have neighbor stateful properties or do we have stateful interface material properties?
     258             :   // If either then we need to reinit the neighbor, so at least at a minimum _neighbor_elem isn't
     259             :   // NULL!
     260        6428 :   if (neighbor->active() &&
     261        3214 :       (_has_neighbor_stateful_props ||
     262        2792 :        (_has_bnd_stateful_props && _interface_materials.hasActiveBoundaryObjects(bnd_id, _tid))))
     263         439 :     _fe_problem.reinitNeighbor(elem, side, _tid);
     264             : 
     265        3214 :   if (_has_neighbor_stateful_props && neighbor->active())
     266             :   {
     267             :     // Neighbor Materials
     268         844 :     if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
     269         422 :             neighbor->subdomain_id(), _tid))
     270           0 :       _neighbor_material_props.initStatefulProps(
     271             :           _tid,
     272           0 :           _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
     273           0 :               neighbor->subdomain_id(), _tid),
     274             :           face_n_points,
     275             :           *elem,
     276             :           side);
     277             : 
     278         422 :     if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
     279             :                                                                         _tid))
     280         422 :       _neighbor_material_props.initStatefulProps(
     281             :           _tid,
     282         422 :           _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(neighbor->subdomain_id(),
     283             :                                                                           _tid),
     284             :           face_n_points,
     285             :           *neighbor,
     286             :           neighbor_side);
     287             :   }
     288             : 
     289             :   // Interface Materials. Make sure we do these after neighbors
     290        3214 :   if (_has_bnd_stateful_props && _interface_materials.hasActiveBoundaryObjects(bnd_id, _tid))
     291         141 :     _bnd_material_props.initStatefulProps(
     292             :         _tid,
     293         141 :         _interface_materials.getActiveBoundaryObjects(bnd_id, _tid),
     294             :         face_n_points,
     295             :         *elem,
     296             :         side);
     297             : }
     298             : 
     299             : void
     300         804 : ComputeMaterialsObjectThread::join(const ComputeMaterialsObjectThread & /*y*/)
     301             : {
     302         804 : }
     303             : 
     304             : void
     305       10467 : ComputeMaterialsObjectThread::post()
     306             : {
     307       10467 :   _fe_problem.clearActiveElementalMooseVariables(_tid);
     308       10467 : }

Generated by: LCOV version 1.14