LCOV - code coverage report
Current view: top level - src/loops - ComputeInitialConditionThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 58 61 95.1 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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 "ComputeInitialConditionThread.h"
      11             : #include "FEProblem.h"
      12             : #include "DisplacedProblem.h"
      13             : #include "Assembly.h"
      14             : #include "InitialCondition.h"
      15             : 
      16       53698 : ComputeInitialConditionThread::ComputeInitialConditionThread(FEProblemBase & fe_problem)
      17       53698 :   : _fe_problem(fe_problem)
      18             : {
      19       53698 : }
      20             : 
      21        4732 : ComputeInitialConditionThread::ComputeInitialConditionThread(ComputeInitialConditionThread & x,
      22        4732 :                                                              Threads::split /*split*/)
      23        4732 :   : _fe_problem(x._fe_problem)
      24             : {
      25        4732 : }
      26             : 
      27             : void
      28       58430 : ComputeInitialConditionThread::operator()(const ConstElemRange & range)
      29             : {
      30       58430 :   ParallelUniqueId puid;
      31       58430 :   _tid = puid.id;
      32       58430 :   const auto current_ic_state = _fe_problem.getCurrentICState();
      33             : 
      34       58430 :   const InitialConditionWarehouse & warehouse = _fe_problem.getInitialConditionWarehouse();
      35       58430 :   printGeneralExecutionInformation();
      36             : 
      37             :   // Iterate over all the elements in the range
      38     9448354 :   for (const auto & elem : range)
      39             :   {
      40     9389931 :     const unsigned int n_nodes = elem->n_nodes();
      41             : 
      42             :     // we need to execute objects that are for all subdomains covered by this
      43             :     // elements' nodes.
      44     9389931 :     std::set<SubdomainID> block_ids;
      45    61429518 :     for (unsigned int n = 0; n < n_nodes; n++)
      46             :     {
      47    52039587 :       auto node = elem->node_ptr(n);
      48    52039587 :       const auto & ids = _fe_problem.mesh().getNodeBlockIds(*node);
      49    52039587 :       block_ids.insert(ids.begin(), ids.end());
      50             :     }
      51             : 
      52             :     // we need to remember the order the variables originally are provided in
      53             :     // since the ics dependencies are resolved to handle the inter-variable
      54             :     // dependencies correctly.
      55     9389931 :     std::vector<MooseVariableFEBase *> order;
      56             : 
      57             :     // group all initial condition objects by variable. so we can compute all
      58             :     // its dof values at once and copy into solution vector once.  This is
      59             :     // necessary because we have to collect extra off-block ic objects from
      60             :     // nodes shared between subdomains for cases where the off-block ic "wins"
      61             :     // on the interface.  The grouping is required because we need to have all
      62             :     // the dof values for the element determined together so we can compute
      63             :     // the correct qp values, etc. for the variable.
      64     9389931 :     std::map<MooseVariableFEBase *, std::vector<std::shared_ptr<InitialConditionBase>>> groups;
      65    19330722 :     for (auto id : block_ids)
      66     9940791 :       if (warehouse.hasActiveBlockObjects(id, _tid))
      67     3703402 :         for (auto ic : warehouse.getActiveBlockObjects(id, _tid))
      68             :         {
      69     4674940 :           if ((id != elem->subdomain_id() && !ic->variable().isNodal()) ||
      70     2295274 :               ic->getState() != current_ic_state)
      71       84392 :             continue;
      72     2295274 :           order.push_back(&(ic->variable()));
      73     2295274 :           groups[&(ic->variable())].push_back(ic);
      74     2379666 :         }
      75             : 
      76     9389931 :     _fe_problem.setCurrentSubdomainID(elem, _tid);
      77     9389931 :     _fe_problem.prepare(elem, _tid);
      78     9389931 :     _fe_problem.reinitElem(elem, _tid);
      79             : 
      80    11685198 :     for (auto var : order)
      81             :     {
      82     2295274 :       DenseVector<Real> Ue;
      83     2295274 :       auto & vec = groups[var];
      84             : 
      85             :       // because of all the off-node shenanigans/grouping above, per-variable
      86             :       // objects could possible have their order jumbled - so re-sort just in
      87             :       // case.
      88             :       try
      89             :       {
      90     2295274 :         DependencyResolverInterface::sort<std::shared_ptr<InitialConditionBase>>(vec);
      91             :       }
      92           0 :       catch (CyclicDependencyException<std::shared_ptr<InitialConditionBase>> & e)
      93             :       {
      94           0 :         DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<InitialConditionBase>>(
      95             :             e, "Cyclic dependency detected in object ordering");
      96           0 :       }
      97             : 
      98     4512087 :       for (auto ic : vec)
      99     2216820 :         ic->compute();
     100     2295267 :       vec.clear();
     101             : 
     102             :       // Now that all dofs are set for this variable, solemnize the solution.
     103     2295267 :       var->insert(var->sys().solution());
     104     2295267 :     }
     105     9389924 :   }
     106       58423 : }
     107             : 
     108             : void
     109        4732 : ComputeInitialConditionThread::join(const ComputeInitialConditionThread & /*y*/)
     110             : {
     111        4732 : }
     112             : 
     113             : void
     114       58430 : ComputeInitialConditionThread::printGeneralExecutionInformation() const
     115             : {
     116       58430 :   const auto & ic_wh = _fe_problem.getInitialConditionWarehouse();
     117       58430 :   if (_fe_problem.shouldPrintExecution(_tid) && ic_wh.hasActiveObjects())
     118             :   {
     119          80 :     const auto & console = _fe_problem.console();
     120          80 :     const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
     121          80 :     console << "[DBG] Executing initial conditions on elements on " << execute_on << std::endl;
     122          80 :     console << "[DBG] Unordered list:" << std::endl;
     123          80 :     console << ic_wh.activeObjectsToFormattedString() << std::endl;
     124          80 :     console << "[DBG] The order of execution is defined by dependency resolution on every element"
     125          80 :             << std::endl;
     126             :   }
     127       58430 : }

Generated by: LCOV version 1.14