LCOV - code coverage report
Current view: top level - src/ics - InitialConditionWarehouse.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 9a5f1f Lines: 42 43 97.7 %
Date: 2026-06-21 21:23:42 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       62032 : InitialConditionWarehouse::InitialConditionWarehouse()
      17             :   : MooseObjectWarehouseBase<InitialConditionBase>(),
      18       62032 :     _boundary_ics(libMesh::n_threads()),
      19      186096 :     _block_ics(libMesh::n_threads())
      20             : {
      21       62032 : }
      22             : 
      23             : void
      24       61485 : InitialConditionWarehouse::initialSetup(THREAD_ID tid)
      25             : {
      26       61485 :   MooseObjectWarehouseBase<InitialConditionBase>::sort(tid);
      27       91897 :   for (const auto & ic : _active_objects[tid])
      28       30418 :     ic->initialSetup();
      29       61479 : }
      30             : 
      31             : void
      32       33431 : 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       33431 :   const MooseVariableFEBase & var = object->variable();
      38       33431 :   const auto ic_key = std::tuple(var.name(), object->getState());
      39             : 
      40             :   // Boundary Restricted
      41       33431 :   if (object->boundaryRestricted())
      42             :   {
      43          23 :     if (!var.isNodal())
      44           3 :       mooseError("You are trying to set a boundary restricted variable on non-nodal variable. That "
      45             :                  "is not allowed.");
      46             : 
      47          20 :     const auto iter = _boundary_ics[tid].find(ic_key);
      48          20 :     if (iter != _boundary_ics[tid].end() && object->hasBoundary(iter->second))
      49           3 :       mooseError("The initial condition '",
      50           3 :                  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          17 :       _boundary_ics[tid][ic_key].insert(object->boundaryIDs().begin(), object->boundaryIDs().end());
      55             :   }
      56             : 
      57             :   // Block Restricted
      58       33408 :   else if (object->blockRestricted())
      59             :   {
      60        2758 :     auto iter = _block_ics[tid].find(ic_key);
      61        3227 :     if (iter != _block_ics[tid].end() &&
      62         935 :         (object->hasBlocks(iter->second) ||
      63        3224 :          (iter->second.find(Moose::ANY_BLOCK_ID) != iter->second.end())))
      64           3 :       mooseError("The initial condition '",
      65           3 :                  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        2755 :       _block_ics[tid][ic_key].insert(object->blockIDs().begin(), object->blockIDs().end());
      70             :   }
      71             : 
      72             :   // Non-restricted
      73             :   else
      74             :   {
      75       30650 :     auto iter = _block_ics[tid].find(ic_key);
      76       30650 :     if (iter != _block_ics[tid].end())
      77           6 :       mooseError("The initial condition '",
      78           6 :                  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       30644 :       _block_ics[tid][ic_key].insert(Moose::ANY_BLOCK_ID);
      83             :   }
      84             : 
      85             :   // Add the IC to the storage
      86       33416 :   MooseObjectWarehouseBase<InitialConditionBase>::addObject(object, tid, recurse);
      87       33416 : }
      88             : 
      89             : std::set<std::string>
      90       59696 : InitialConditionWarehouse::getDependObjects() const
      91             : {
      92       59696 :   std::set<std::string> depend_objects;
      93             : 
      94       59696 :   const auto & ics = getActiveObjects();
      95       89020 :   for (const auto & ic : ics)
      96             :   {
      97       29324 :     const auto & uo = ic->getDependObjects();
      98       29324 :     depend_objects.insert(uo.begin(), uo.end());
      99             :   }
     100             : 
     101       59696 :   return depend_objects;
     102           0 : }

Generated by: LCOV version 1.14