LCOV - code coverage report
Current view: top level - src/loops - ComputeIndicatorThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 110 110 100.0 %
Date: 2026-05-29 20:35:17 Functions: 13 13 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             : #include "ComputeIndicatorThread.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "AuxiliarySystem.h"
      14             : #include "FEProblem.h"
      15             : #include "Indicator.h"
      16             : #include "InternalSideIndicatorBase.h"
      17             : #include "MooseVariableFE.h"
      18             : #include "Problem.h"
      19             : #include "SwapBackSentinel.h"
      20             : // For dynamic casting to Coupleable
      21             : #include "Material.h"
      22             : #include "InterfaceMaterial.h"
      23             : 
      24             : #include "libmesh/threads.h"
      25             : 
      26        4750 : ComputeIndicatorThread::ComputeIndicatorThread(FEProblemBase & fe_problem, bool finalize)
      27             :   : ThreadedElementLoop<ConstElemRange>(fe_problem),
      28        4750 :     _fe_problem(fe_problem),
      29        9500 :     _aux_sys(fe_problem.getAuxiliarySystem()),
      30        4750 :     _indicator_whs(_fe_problem.getIndicatorWarehouse()),
      31        4750 :     _internal_side_indicators(_fe_problem.getInternalSideIndicatorWarehouse()),
      32        4750 :     _finalize(finalize)
      33             : {
      34        4750 : }
      35             : 
      36             : // Splitting Constructor
      37         490 : ComputeIndicatorThread::ComputeIndicatorThread(ComputeIndicatorThread & x, Threads::split split)
      38             :   : ThreadedElementLoop<ConstElemRange>(x, split),
      39         490 :     _fe_problem(x._fe_problem),
      40         490 :     _aux_sys(x._aux_sys),
      41         490 :     _indicator_whs(x._indicator_whs),
      42         490 :     _internal_side_indicators(x._internal_side_indicators),
      43         490 :     _finalize(x._finalize)
      44             : {
      45         490 : }
      46             : 
      47        5730 : ComputeIndicatorThread::~ComputeIndicatorThread() {}
      48             : 
      49             : void
      50       25528 : ComputeIndicatorThread::subdomainChanged()
      51             : {
      52       25528 :   _fe_problem.subdomainSetup(_subdomain, _tid);
      53             : 
      54       25528 :   _indicator_whs.subdomainSetup(_tid);
      55       25528 :   _internal_side_indicators.subdomainSetup(_tid);
      56             : 
      57       25528 :   std::set<MooseVariableFEBase *> needed_moose_vars;
      58       25528 :   _indicator_whs.updateVariableDependency(needed_moose_vars, _tid);
      59       25528 :   _internal_side_indicators.updateVariableDependency(needed_moose_vars, _tid);
      60       25528 :   _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
      61             : 
      62             :   // Update variable coupleable vector tags
      63       25528 :   std::set<TagID> needed_var_vector_tags;
      64       25528 :   _indicator_whs.updateBlockFEVariableCoupledVectorTagDependency(
      65       25528 :       _subdomain, needed_var_vector_tags, _tid);
      66       25528 :   _internal_side_indicators.updateBlockFEVariableCoupledVectorTagDependency(
      67       25528 :       _subdomain, needed_var_vector_tags, _tid);
      68       25528 :   _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency(
      69       25528 :       _subdomain, needed_var_vector_tags, _tid);
      70       25528 :   _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_var_vector_tags, _tid);
      71             : 
      72       25528 :   std::unordered_set<unsigned int> needed_mat_props;
      73       25528 :   _indicator_whs.updateMatPropDependency(needed_mat_props, _tid);
      74       25528 :   _internal_side_indicators.updateMatPropDependency(needed_mat_props, _tid);
      75             : 
      76       25528 :   _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
      77       25528 : }
      78             : 
      79             : void
      80     1523446 : ComputeIndicatorThread::onElement(const Elem * elem)
      81             : {
      82     5442852 :   for (auto * var : _aux_sys._elem_vars[_tid])
      83     3919406 :     var->prepareAux();
      84             : 
      85     1523446 :   _fe_problem.prepare(elem, _tid);
      86     1523446 :   _fe_problem.reinitElem(elem, _tid);
      87             : 
      88             :   // Set up Sentinel class so that, even if reinitMaterials() throws, we
      89             :   // still remember to swap back during stack unwinding.
      90     1523446 :   SwapBackSentinel sentinel(_fe_problem, &FEProblemBase::swapBackMaterials, _tid);
      91             : 
      92     1523446 :   _fe_problem.reinitMaterials(_subdomain, _tid);
      93             : 
      94             :   // Compute
      95     1523446 :   if (!_finalize)
      96             :   {
      97      761723 :     if (_indicator_whs.hasActiveBlockObjects(_subdomain, _tid))
      98             :     {
      99             :       const std::vector<std::shared_ptr<Indicator>> & indicators =
     100       33256 :           _indicator_whs.getActiveBlockObjects(_subdomain, _tid);
     101       66512 :       for (const auto & indicator : indicators)
     102       33256 :         indicator->computeIndicator();
     103             :     }
     104             :   }
     105             : 
     106             :   // Finalize
     107             :   else
     108             :   {
     109      761723 :     if (_indicator_whs.hasActiveBlockObjects(_subdomain, _tid))
     110             :     {
     111             :       const std::vector<std::shared_ptr<Indicator>> & indicators =
     112       33256 :           _indicator_whs.getActiveBlockObjects(_subdomain, _tid);
     113       66512 :       for (const auto & indicator : indicators)
     114       33256 :         indicator->finalize();
     115             :     }
     116             : 
     117      761723 :     if (_internal_side_indicators.hasActiveBlockObjects(_subdomain, _tid))
     118             :     {
     119             :       const std::vector<std::shared_ptr<InternalSideIndicatorBase>> & internal_indicators =
     120      749115 :           _internal_side_indicators.getActiveBlockObjects(_subdomain, _tid);
     121     1503222 :       for (const auto & internal_indicator : internal_indicators)
     122      754107 :         internal_indicator->finalize();
     123             :     }
     124             :   }
     125             : 
     126     1523446 :   if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
     127     2721426 :     for (auto * var : _aux_sys._elem_vars[_tid])
     128     1959703 :       var->add(_aux_sys.solution());
     129     1523446 : }
     130             : 
     131             : void
     132      248646 : ComputeIndicatorThread::onBoundary(const Elem * /*elem*/,
     133             :                                    unsigned int /*side*/,
     134             :                                    BoundaryID /*bnd_id*/,
     135             :                                    const Elem * /*lower_d_elem = nullptr*/)
     136             : {
     137      248646 : }
     138             : 
     139             : void
     140     3051382 : ComputeIndicatorThread::onInternalSide(const Elem * elem, unsigned int side)
     141             : {
     142     3051382 :   if (_finalize) // If finalizing we only do something on the elements
     143     1525691 :     return;
     144             : 
     145             :   // Pointer to the neighbor we are currently working on.
     146     1525691 :   const Elem * neighbor = elem->neighbor_ptr(side);
     147             : 
     148     5467115 :   for (auto * var : _aux_sys._elem_vars[_tid])
     149     3941424 :     var->prepareAux();
     150             : 
     151     1525691 :   SubdomainID block_id = elem->subdomain_id();
     152     1525691 :   if (_internal_side_indicators.hasActiveBlockObjects(block_id, _tid))
     153             :   {
     154     1502606 :     _fe_problem.reinitNeighbor(elem, side, _tid);
     155             : 
     156             :     // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
     157             :     // still remember to swap back during stack unwinding.
     158     1502606 :     SwapBackSentinel face_sentinel(_fe_problem, &FEProblemBase::swapBackMaterialsFace, _tid);
     159     1502606 :     _fe_problem.reinitMaterialsFace(block_id, _tid);
     160             : 
     161             :     SwapBackSentinel neighbor_sentinel(
     162     1502606 :         _fe_problem, &FEProblemBase::swapBackMaterialsNeighbor, _tid);
     163     1502606 :     _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
     164             : 
     165             :     const std::vector<std::shared_ptr<InternalSideIndicatorBase>> & indicators =
     166     1502606 :         _internal_side_indicators.getActiveBlockObjects(block_id, _tid);
     167     3014492 :     for (const auto & indicator : indicators)
     168     1511886 :       indicator->computeIndicator();
     169     1502606 :   }
     170             : }
     171             : 
     172             : void
     173     1523446 : ComputeIndicatorThread::postElement(const Elem * /*elem*/)
     174             : {
     175     1523446 : }
     176             : 
     177             : void
     178        5240 : ComputeIndicatorThread::post()
     179             : {
     180        5240 :   _fe_problem.clearActiveElementalMooseVariables(_tid);
     181        5240 :   _fe_problem.clearActiveMaterialProperties(_tid);
     182        5240 : }
     183             : 
     184             : void
     185         490 : ComputeIndicatorThread::join(const ComputeIndicatorThread & /*y*/)
     186             : {
     187         490 : }
     188             : 
     189             : void
     190        5240 : ComputeIndicatorThread::printGeneralExecutionInformation() const
     191             : {
     192        5240 :   if (!_fe_problem.shouldPrintExecution(_tid))
     193        5114 :     return;
     194             : 
     195         126 :   const auto & console = _fe_problem.console();
     196         126 :   const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
     197         126 :   if (!_finalize)
     198          63 :     console << "[DBG] Executing indicators on elements then on internal sides on " << execute_on
     199          63 :             << std::endl;
     200             :   else
     201          63 :     console << "[DBG] Finalizing indicator loop" << std::endl;
     202             : }
     203             : 
     204             : void
     205       25528 : ComputeIndicatorThread::printBlockExecutionInformation() const
     206             : {
     207       25528 :   if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain))
     208       25402 :     return;
     209             : 
     210         126 :   const auto & console = _fe_problem.console();
     211         126 :   if (_indicator_whs.hasActiveBlockObjects(_subdomain, _tid))
     212             :   {
     213          72 :     const auto & indicators = _indicator_whs.getActiveBlockObjects(_subdomain, _tid);
     214          72 :     console << "[DBG] Ordering of element indicators on block " << _subdomain << std::endl;
     215         216 :     printExecutionOrdering<Indicator>(indicators, false);
     216             :   }
     217         126 :   if (_internal_side_indicators.hasActiveBlockObjects(_subdomain, _tid))
     218             :   {
     219         126 :     const auto & indicators = _internal_side_indicators.getActiveBlockObjects(_subdomain, _tid);
     220         126 :     console << "[DBG] Ordering of element internal sides indicators on block " << _subdomain
     221         126 :             << std::endl;
     222         378 :     printExecutionOrdering<InternalSideIndicatorBase>(indicators, false);
     223             :   }
     224         126 :   _blocks_exec_printed.insert(_subdomain);
     225             : }

Generated by: LCOV version 1.14