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

Generated by: LCOV version 1.14