LCOV - code coverage report
Current view: top level - src/loops - ComputeElemAuxVarsThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 77 77 100.0 %
Date: 2025-08-08 20:01:16 Functions: 30 30 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 "ComputeElemAuxVarsThread.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "AuxiliarySystem.h"
      14             : #include "AuxKernel.h"
      15             : #include "SwapBackSentinel.h"
      16             : #include "FEProblem.h"
      17             : #include "MaterialBase.h"
      18             : #include "ThreadedElementLoop.h"
      19             : 
      20             : #include "libmesh/threads.h"
      21             : 
      22             : template <typename AuxKernelType>
      23       80321 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread(
      24             :     FEProblemBase & problem,
      25             :     const MooseObjectWarehouse<AuxKernelType> & storage,
      26             :     bool need_materials)
      27             :   : ThreadedElementLoop<ConstElemRange>(problem),
      28      160642 :     _aux_sys(problem.getAuxiliarySystem()),
      29       80321 :     _aux_kernels(storage),
      30       80321 :     _need_materials(need_materials)
      31             : {
      32       80321 : }
      33             : 
      34             : // Splitting Constructor
      35             : template <typename AuxKernelType>
      36        6828 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread(ComputeElemAuxVarsThread & x,
      37             :                                                                   Threads::split /*split*/)
      38             :   : ThreadedElementLoop<ConstElemRange>(x._fe_problem),
      39        6828 :     _aux_sys(x._aux_sys),
      40        6828 :     _aux_kernels(x._aux_kernels),
      41        6828 :     _need_materials(x._need_materials)
      42             : {
      43        6828 : }
      44             : 
      45             : template <typename AuxKernelType>
      46       93946 : ComputeElemAuxVarsThread<AuxKernelType>::~ComputeElemAuxVarsThread()
      47             : {
      48       93946 : }
      49             : 
      50             : template <typename AuxKernelType>
      51             : void
      52      159855 : ComputeElemAuxVarsThread<AuxKernelType>::subdomainChanged()
      53             : {
      54      159855 :   _fe_problem.subdomainSetup(_subdomain, _tid);
      55             : 
      56      159855 :   std::set<MooseVariableFEBase *> needed_moose_vars;
      57      159855 :   std::unordered_set<unsigned int> needed_mat_props;
      58      159855 :   std::set<TagID> needed_fe_var_matrix_tags;
      59      159855 :   std::set<TagID> needed_fe_var_vector_tags;
      60             : 
      61      159855 :   _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency(
      62      159855 :       _subdomain, needed_fe_var_vector_tags, _tid);
      63      159855 :   if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
      64             :   {
      65             :     const std::vector<std::shared_ptr<AuxKernelType>> & kernels =
      66      157239 :         _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
      67      429640 :     for (const auto & aux : kernels)
      68             :     {
      69      272401 :       aux->subdomainSetup();
      70      272401 :       const auto & mv_deps = aux->getMooseVariableDependencies();
      71      272401 :       const auto & mp_deps = aux->getMatPropDependencies();
      72      272401 :       needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
      73      272401 :       needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
      74             : 
      75      272401 :       auto & fe_var_coup_vtags = aux->getFEVariableCoupleableVectorTags();
      76      272401 :       needed_fe_var_vector_tags.insert(fe_var_coup_vtags.begin(), fe_var_coup_vtags.end());
      77             : 
      78      272401 :       auto & fe_var_coup_mtags = aux->getFEVariableCoupleableMatrixTags();
      79      272401 :       needed_fe_var_matrix_tags.insert(fe_var_coup_mtags.begin(), fe_var_coup_mtags.end());
      80             :     }
      81             :   }
      82             : 
      83      159855 :   _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
      84      159855 :   _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
      85      159855 :   _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_fe_var_matrix_tags, _tid);
      86      159855 :   _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
      87      159855 : }
      88             : 
      89             : template <typename AuxKernelType>
      90             : void
      91    10501176 : ComputeElemAuxVarsThread<AuxKernelType>::onElement(const Elem * elem)
      92             : {
      93    10501176 :   if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
      94             :   {
      95             :     const std::vector<std::shared_ptr<AuxKernelType>> & kernels =
      96    10461298 :         _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
      97    10461298 :     _fe_problem.prepare(elem, _tid);
      98    10461298 :     _fe_problem.reinitElem(elem, _tid);
      99             : 
     100             :     // Set up the sentinel so that, even if reinitMaterials() throws, we
     101             :     // still remember to swap back.
     102    10461298 :     SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid, _need_materials);
     103             : 
     104    10461298 :     if (_need_materials)
     105    10461298 :       _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
     106             : 
     107    27704464 :     for (const auto & aux : kernels)
     108             :     {
     109    17243194 :       aux->compute();
     110    17243179 :       aux->variable().insert(_aux_sys.solution());
     111             : 
     112             :       // update the aux solution vector if writable coupled variables are used
     113    17243179 :       if (aux->hasWritableCoupledVariables())
     114             :       {
     115        1620 :         for (auto * var : aux->getWritableCoupledVariables())
     116        1080 :           var->insert(_aux_sys.solution());
     117             : 
     118         540 :         _fe_problem.reinitElem(elem, _tid);
     119             :       }
     120             :     }
     121    10461270 :   }
     122    10501148 : }
     123             : 
     124             : template <typename AuxKernelType>
     125             : void
     126       87121 : ComputeElemAuxVarsThread<AuxKernelType>::post()
     127             : {
     128       87121 :   _fe_problem.clearActiveElementalMooseVariables(_tid);
     129       87121 :   _fe_problem.clearActiveMaterialProperties(_tid);
     130             : 
     131       87121 :   _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid);
     132       87121 :   _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid);
     133       87121 : }
     134             : 
     135             : template <typename AuxKernelType>
     136             : void
     137        6826 : ComputeElemAuxVarsThread<AuxKernelType>::join(const ComputeElemAuxVarsThread & /*y*/)
     138             : {
     139        6826 : }
     140             : 
     141             : template <typename AuxKernelType>
     142             : void
     143       87149 : ComputeElemAuxVarsThread<AuxKernelType>::printGeneralExecutionInformation() const
     144             : {
     145       87149 :   if (!_fe_problem.shouldPrintExecution(_tid) || !_aux_kernels.hasActiveObjects())
     146       84859 :     return;
     147             : 
     148        2290 :   const auto & console = _fe_problem.console();
     149        2290 :   const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
     150        2290 :   console << "[DBG] Executing auxiliary kernels on elements on " << execute_on << std::endl;
     151             : }
     152             : 
     153             : template <typename AuxKernelType>
     154             : void
     155      159855 : ComputeElemAuxVarsThread<AuxKernelType>::printBlockExecutionInformation() const
     156             : {
     157      163959 :   if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) ||
     158        4104 :       !_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
     159      155751 :     return;
     160             : 
     161        4104 :   const auto & console = _fe_problem.console();
     162        4104 :   const auto & kernels = _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
     163        4104 :   console << "[DBG] Ordering of AuxKernels on block " << _subdomain << std::endl;
     164        4104 :   printExecutionOrdering<AuxKernelType>(kernels, false);
     165        4104 :   _blocks_exec_printed.insert(_subdomain);
     166             : }
     167             : 
     168             : template class ComputeElemAuxVarsThread<AuxKernel>;
     169             : template class ComputeElemAuxVarsThread<VectorAuxKernel>;
     170             : template class ComputeElemAuxVarsThread<ArrayAuxKernel>;

Generated by: LCOV version 1.14