LCOV - code coverage report
Current view: top level - src/ics - InitialConditionWarehouse.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 42 43 97.7 %
Date: 2025-08-08 20:01:16 Functions: 4 4 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 "InitialConditionWarehouse.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "InitialConditionBase.h"
      14             : #include "MooseVariableFE.h"
      15             : 
      16       62498 : InitialConditionWarehouse::InitialConditionWarehouse()
      17             :   : MooseObjectWarehouseBase<InitialConditionBase>(),
      18       62498 :     _boundary_ics(libMesh::n_threads()),
      19      124996 :     _block_ics(libMesh::n_threads())
      20             : {
      21       62498 : }
      22             : 
      23             : void
      24       61388 : InitialConditionWarehouse::initialSetup(THREAD_ID tid)
      25             : {
      26       61388 :   MooseObjectWarehouseBase<InitialConditionBase>::sort(tid);
      27       89489 :   for (const auto & ic : _active_objects[tid])
      28       28109 :     ic->initialSetup();
      29       61380 : }
      30             : 
      31             : void
      32       31286 : InitialConditionWarehouse::addObject(std::shared_ptr<InitialConditionBase> object,
      33             :                                      THREAD_ID tid,
      34             :                                      bool recurse)
      35             : {
      36             :   // Check that when object is boundary restricted that the variable is nodal
      37       31286 :   const MooseVariableFEBase & var = object->variable();
      38       31286 :   const auto ic_key = std::tuple(var.name(), object->getState());
      39             : 
      40             :   // Boundary Restricted
      41       31286 :   if (object->boundaryRestricted())
      42             :   {
      43          27 :     if (!var.isNodal())
      44           4 :       mooseError("You are trying to set a boundary restricted variable on non-nodal variable. That "
      45             :                  "is not allowed.");
      46             : 
      47          23 :     const auto iter = _boundary_ics[tid].find(ic_key);
      48          23 :     if (iter != _boundary_ics[tid].end() && object->hasBoundary(iter->second))
      49           8 :       mooseError("The initial condition '",
      50           4 :                  object->name(),
      51             :                  "' is being defined on a boundary that already has an initial condition defined "
      52             :                  "with the same variable and state.");
      53             :     else
      54          19 :       _boundary_ics[tid][ic_key].insert(object->boundaryIDs().begin(), object->boundaryIDs().end());
      55             :   }
      56             : 
      57             :   // Block Restricted
      58       31259 :   else if (object->blockRestricted())
      59             :   {
      60        2549 :     auto iter = _block_ics[tid].find(ic_key);
      61        3064 :     if (iter != _block_ics[tid].end() &&
      62        1026 :         (object->hasBlocks(iter->second) ||
      63        3060 :          (iter->second.find(Moose::ANY_BLOCK_ID) != iter->second.end())))
      64           8 :       mooseError("The initial condition '",
      65           4 :                  object->name(),
      66             :                  "' is being defined on a block that already has an initial condition defined "
      67             :                  "with the same variable and state.");
      68             :     else
      69        2545 :       _block_ics[tid][ic_key].insert(object->blockIDs().begin(), object->blockIDs().end());
      70             :   }
      71             : 
      72             :   // Non-restricted
      73             :   else
      74             :   {
      75       28710 :     auto iter = _block_ics[tid].find(ic_key);
      76       28710 :     if (iter != _block_ics[tid].end())
      77          16 :       mooseError("The initial condition '",
      78           8 :                  object->name(),
      79             :                  "' is being defined on a block that already has an initial condition defined "
      80             :                  "with the same variable and state.");
      81             :     else
      82       28702 :       _block_ics[tid][ic_key].insert(Moose::ANY_BLOCK_ID);
      83             :   }
      84             : 
      85             :   // Add the IC to the storage
      86       31266 :   MooseObjectWarehouseBase<InitialConditionBase>::addObject(object, tid, recurse);
      87       31266 : }
      88             : 
      89             : std::set<std::string>
      90       59892 : InitialConditionWarehouse::getDependObjects() const
      91             : {
      92       59892 :   std::set<std::string> depend_objects;
      93             : 
      94       59892 :   const auto & ics = getActiveObjects();
      95       87451 :   for (const auto & ic : ics)
      96             :   {
      97       27559 :     const auto & uo = ic->getDependObjects();
      98       27559 :     depend_objects.insert(uo.begin(), uo.end());
      99             :   }
     100             : 
     101       59892 :   return depend_objects;
     102           0 : }

Generated by: LCOV version 1.14