LCOV - code coverage report
Current view: top level - src/actions - CheckFVBCAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 42 47 89.4 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "CheckFVBCAction.h"
      11             : #include "FEProblem.h"
      12             : #include "NonlinearSystem.h"
      13             : #include "FVFluxBC.h"
      14             : #include "FVDirichletBCBase.h"
      15             : 
      16             : registerMooseAction("MooseApp", CheckFVBCAction, "check_integrity");
      17             : 
      18             : InputParameters
      19        3526 : CheckFVBCAction::validParams()
      20             : {
      21        3526 :   InputParameters params = Action::validParams();
      22        3526 :   params.addClassDescription(
      23             :       "Check that boundary conditions are defined correctly for finite volume problems.");
      24        3526 :   return params;
      25           0 : }
      26             : 
      27        3322 : CheckFVBCAction::CheckFVBCAction(const InputParameters & params) : Action(params) {}
      28             : 
      29             : void
      30        3246 : CheckFVBCAction::act()
      31             : {
      32        3246 :   if (_current_task == "check_integrity" && _problem->fvBCsIntegrityCheck())
      33             :   {
      34             :     // check that boundary conditions follow these rules:
      35             :     // 1. One variable cannot define Dirichlet & Flux BCs
      36             :     //    on the same sideset
      37             :     // 2. One variable cannot define more than one Dirichlet BCs
      38             :     //    on the same sideset
      39        3001 :     TheWarehouse & the_warehouse = _problem->theWarehouse();
      40        6026 :     for (const auto i : make_range(_problem->numNonlinearSystems()))
      41             :     {
      42             :       const std::vector<MooseVariableFEBase *> & variables =
      43        3025 :           _problem->getNonlinearSystemBase(i).getVariables(0);
      44             : 
      45        7451 :       for (auto & var : variables)
      46             :       {
      47        4426 :         if (!var->isFV())
      48         394 :           continue;
      49             : 
      50        4032 :         unsigned int var_num = var->number();
      51        4032 :         std::vector<FVFluxBC *> flux_bcs;
      52        4032 :         std::vector<FVDirichletBCBase *> dirichlet_bcs;
      53        4032 :         the_warehouse.query()
      54        4032 :             .template condition<AttribSystem>("FVFluxBC")
      55        4032 :             .template condition<AttribVar>(var_num)
      56        4032 :             .template condition<AttribThread>(0)
      57        8064 :             .template condition<AttribSysNum>(var->sys().number())
      58        4032 :             .queryInto(flux_bcs);
      59             : 
      60        4032 :         the_warehouse.query()
      61        4032 :             .template condition<AttribSystem>("FVDirichletBC")
      62        4032 :             .template condition<AttribVar>(var_num)
      63        4032 :             .template condition<AttribThread>(0)
      64        8064 :             .template condition<AttribSysNum>(var->sys().number())
      65        4032 :             .queryInto(dirichlet_bcs);
      66             : 
      67        4032 :         std::set<BoundaryID> all_flux_side_ids;
      68        5382 :         for (auto & fbc : flux_bcs)
      69             :         {
      70        1350 :           const std::set<BoundaryID> & t = fbc->boundaryIDs();
      71        1350 :           all_flux_side_ids.insert(t.begin(), t.end());
      72             :         }
      73             : 
      74        4032 :         std::set<BoundaryID> all_dirichlet_side_ids;
      75        8996 :         for (auto & dbc : dirichlet_bcs)
      76             :         {
      77        4964 :           const std::set<BoundaryID> & temp = dbc->boundaryIDs();
      78             :           // check rule #2
      79       12122 :           for (auto & t : temp)
      80        7158 :             if (all_dirichlet_side_ids.find(t) != all_dirichlet_side_ids.end())
      81           0 :               mooseError(
      82           0 :                   "Sideset ", t, " defines at least two DirichletBCs for variable ", var->name());
      83        4964 :           all_dirichlet_side_ids.insert(temp.begin(), temp.end());
      84             :         }
      85             : 
      86             :         // check rule #1
      87        5590 :         for (auto & t : all_flux_side_ids)
      88        1558 :           if (all_dirichlet_side_ids.find(t) != all_dirichlet_side_ids.end())
      89           0 :             mooseError(
      90           0 :                 "Sideset ", t, " defines a FluxBC and a DirichletBC for variable ", var->name());
      91        4032 :       }
      92             :     }
      93             :   }
      94        3246 : }

Generated by: LCOV version 1.14