LCOV - code coverage report
Current view: top level - src/actioncomponents - ComponentBoundaryConditionInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 78 92 84.8 %
Date: 2025-07-17 01:28:37 Functions: 6 8 75.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 "ComponentBoundaryConditionInterface.h"
      11             : 
      12             : InputParameters
      13         550 : ComponentBoundaryConditionInterface::validParams()
      14             : {
      15         550 :   auto params = ActionComponent::validParams();
      16             : 
      17             :   // Support two common types of boundary conditions
      18         550 :   params.addParam<std::vector<VariableName>>(
      19             :       "fixed_value_bc_variables",
      20             :       {},
      21             :       "List of variables that have fixed value boundary condition(s) defined on this component");
      22         550 :   params.addParam<std::vector<std::vector<BoundaryName>>>(
      23             :       "fixed_value_bc_boundaries",
      24             :       {},
      25             :       "Boundaries on which to apply the fixed value boundary condition(s). Outer ordering is "
      26             :       "variables, inner order is surfaces");
      27         550 :   params.addParam<std::vector<std::vector<MooseFunctorName>>>(
      28             :       "fixed_value_bc_values",
      29             :       {},
      30             :       "Functors that provide the fixed value boundary condition(s) values. Outer ordering is "
      31             :       "variables, inner order is surfaces");
      32             : 
      33         550 :   params.addParam<std::vector<VariableName>>(
      34             :       "flux_bc_variables",
      35             :       {},
      36             :       "List of variables that have flux boundary condition(s) defined on this component");
      37         550 :   params.addParam<std::vector<std::vector<BoundaryName>>>(
      38             :       "flux_bc_boundaries",
      39             :       {},
      40             :       "Boundaries on which to apply the flux boundary condition(s). Outer ordering is "
      41             :       "variables, inner order is surfaces");
      42         550 :   params.addParam<std::vector<std::vector<MooseFunctorName>>>(
      43             :       "flux_bc_values",
      44             :       {},
      45             :       "Functors that provide the flux boundary condition(s) values. Outer ordering is "
      46             :       "variables, inner order is surfaces");
      47             : 
      48         550 :   params.addParamNamesToGroup(
      49             :       "fixed_value_bc_variables fixed_value_bc_boundaries fixed_value_bc_values flux_bc_variables "
      50             :       " flux_bc_boundaries flux_bc_values",
      51             :       "Variable boundary conditions");
      52         550 :   return params;
      53           0 : }
      54             : 
      55         168 : ComponentBoundaryConditionInterface::ComponentBoundaryConditionInterface(
      56           0 :     const InputParameters & params)
      57             :   : ActionComponent(params),
      58         168 :     _fixed_value_bc_variables(getParam<std::vector<VariableName>>("fixed_value_bc_variables")),
      59         336 :     _flux_bc_variables(getParam<std::vector<VariableName>>("flux_bc_variables"))
      60             : {
      61         168 :   addRequiredTask("init_component_physics");
      62         168 :   addRequiredTask("check_integrity");
      63             : 
      64             :   // Check for unique elements
      65         336 :   checkVectorParamsNoOverlap<VariableName>({"fixed_value_bc_variables"});
      66         336 :   checkVectorParamsNoOverlap<VariableName>({"flux_bc_variables"});
      67             : 
      68             :   // Check parameter sizes
      69             :   const auto & fixed_value_boundaries =
      70         168 :       getParam<std::vector<std::vector<BoundaryName>>>("fixed_value_bc_boundaries");
      71             :   const auto & fixed_value_values =
      72         168 :       getParam<std::vector<std::vector<MooseFunctorName>>>("fixed_value_bc_values");
      73         168 :   checkVectorParamsSameLength<VariableName, std::vector<BoundaryName>>("fixed_value_bc_variables",
      74             :                                                                        "fixed_value_bc_boundaries");
      75         168 :   checkVectorParamsSameLength<VariableName, std::vector<MooseFunctorName>>(
      76             :       "fixed_value_bc_variables", "fixed_value_bc_values");
      77         168 :   checkTwoDVectorParamsSameLength<BoundaryName, MooseFunctorName>("fixed_value_bc_boundaries",
      78             :                                                                   "fixed_value_bc_values");
      79             :   const auto & flux_boundaries =
      80         168 :       getParam<std::vector<std::vector<BoundaryName>>>("flux_bc_boundaries");
      81         168 :   const auto & flux_values = getParam<std::vector<std::vector<MooseFunctorName>>>("flux_bc_values");
      82         168 :   checkVectorParamsSameLength<VariableName, std::vector<BoundaryName>>("flux_bc_variables",
      83             :                                                                        "flux_bc_boundaries");
      84         168 :   checkVectorParamsSameLength<VariableName, std::vector<MooseFunctorName>>("flux_bc_variables",
      85             :                                                                            "flux_bc_values");
      86         168 :   checkTwoDVectorParamsSameLength<BoundaryName, MooseFunctorName>("flux_bc_boundaries",
      87             :                                                                   "flux_bc_values");
      88             : 
      89             :   // NOTE: We could add a check that for a (variable,boundary) pair, we do not have a fixed value
      90             :   // and a flux BC defined at the same time
      91             :   // TODO: add another check that the boundaries are part of the component
      92             :   // This is not possible yet, components do not keep the list of their boundaries
      93             : 
      94             :   // Form maps for the variable-boundary-value from the input vectors
      95         228 :   for (const auto i : index_range(_fixed_value_bc_variables))
      96             :   {
      97          60 :     const auto & var_name = _fixed_value_bc_variables[i];
      98         120 :     for (const auto j : index_range(fixed_value_boundaries[i]))
      99          60 :       _fixed_value_bcs[var_name][fixed_value_boundaries[i][j]] = fixed_value_values[i][j];
     100             :   }
     101         188 :   for (const auto i : index_range(_flux_bc_variables))
     102             :   {
     103          20 :     const auto & var_name = _flux_bc_variables[i];
     104          40 :     for (const auto j : index_range(flux_boundaries[i]))
     105          20 :       _flux_bcs[var_name][flux_boundaries[i][j]] = flux_values[i][j];
     106             :   }
     107         672 : }
     108             : 
     109             : bool
     110         128 : ComponentBoundaryConditionInterface::hasBoundaryCondition(const VariableName & var_name) const
     111             : {
     112             :   // if there exists at least one BC of that type for that variable
     113         128 :   const bool has_fixed_value = _fixed_value_bcs.count(var_name);
     114         128 :   const bool has_flux = _flux_bcs.count(var_name);
     115             : 
     116         128 :   return has_fixed_value || has_flux;
     117             : }
     118             : 
     119             : bool
     120           0 : ComponentBoundaryConditionInterface::hasBoundaryCondition(const VariableName & var_name,
     121             :                                                           const BoundaryName & boundary) const
     122             : {
     123             :   // if there exists at least one BC of that type for that variable
     124           0 :   const bool has_fixed_value = _fixed_value_bcs.count(var_name);
     125           0 :   const bool has_flux = _flux_bcs.count(var_name);
     126             : 
     127             :   // Now check for that specific boundary
     128           0 :   if (has_fixed_value && libmesh_map_find(_fixed_value_bcs, var_name).count(boundary))
     129           0 :     return true;
     130           0 :   else if (has_flux && libmesh_map_find(_flux_bcs, var_name).count(boundary))
     131           0 :     return true;
     132             :   else
     133           0 :     return false;
     134             : }
     135             : 
     136             : MooseFunctorName
     137          68 : ComponentBoundaryConditionInterface::getBoundaryCondition(const VariableName & var_name,
     138             :                                                           const BoundaryName & boundary,
     139             :                                                           const std::string & requestor_name,
     140             :                                                           BoundaryConditionType & bc_type) const
     141             : {
     142             :   // Ideally all boundary conditions defined by the user in the input will get requested
     143          68 :   _requested_bc_variables.insert(std::make_pair(var_name, boundary));
     144             : 
     145             :   // if there exists at least one BC of that type for that variable
     146          68 :   const bool has_fixed_value = _fixed_value_bcs.count(var_name);
     147          68 :   const bool has_flux = _flux_bcs.count(var_name);
     148             : 
     149             :   // Now check for that specific boundary
     150          68 :   if (has_fixed_value && libmesh_map_find(_fixed_value_bcs, var_name).count(boundary))
     151             :   {
     152          52 :     bc_type = FIXED_VALUE;
     153          52 :     return libmesh_map_find(libmesh_map_find(_fixed_value_bcs, var_name), boundary);
     154             :   }
     155          16 :   else if (has_flux && libmesh_map_find(_flux_bcs, var_name).count(boundary))
     156             :   {
     157          16 :     bc_type = FLUX;
     158          16 :     return libmesh_map_find(libmesh_map_find(_flux_bcs, var_name), boundary);
     159             :   }
     160             :   else
     161           0 :     paramError("fixed_value_bc_variables",
     162           0 :                "Boundary condition for variable '" + var_name + "' on boundary '" + boundary +
     163           0 :                    "' requested by '" + requestor_name +
     164             :                    "' has not been specified on this ActionComponent.");
     165             : }
     166             : 
     167             : std::vector<BoundaryName>
     168          52 : ComponentBoundaryConditionInterface::getBoundaryConditionBoundaries(
     169             :     const VariableName & var_name) const
     170             : {
     171             :   // if there exists at least one BC of that type for that variable
     172          52 :   const bool has_fixed_value = _fixed_value_bcs.count(var_name);
     173          52 :   const bool has_flux = _flux_bcs.count(var_name);
     174             : 
     175          52 :   std::vector<BoundaryName> boundaries;
     176             : 
     177          52 :   if (has_fixed_value)
     178         104 :     for (const auto & boundary_pair : libmesh_map_find(_fixed_value_bcs, var_name))
     179          52 :       boundaries.push_back(boundary_pair.first);
     180             : 
     181          52 :   if (has_flux)
     182          32 :     for (const auto & boundary_pair : libmesh_map_find(_flux_bcs, var_name))
     183          16 :       boundaries.push_back(boundary_pair.first);
     184             : 
     185          52 :   return boundaries;
     186           0 : }
     187             : 
     188             : void
     189         148 : ComponentBoundaryConditionInterface::checkBoundaryConditionsAllRequested() const
     190             : {
     191         148 :   std::string list_missing = "";
     192             : 
     193         196 :   for (const auto & var_pair : _fixed_value_bcs)
     194          96 :     for (const auto & bc_pair : var_pair.second)
     195          48 :       if (std::find(_requested_bc_variables.begin(),
     196             :                     _requested_bc_variables.end(),
     197          96 :                     std::make_pair(VariableName(var_pair.first), BoundaryName(bc_pair.first))) ==
     198          96 :           _requested_bc_variables.end())
     199           8 :         list_missing += "\n- " + var_pair.first + " on " + bc_pair.first;
     200             : 
     201         164 :   for (const auto & var_pair : _flux_bcs)
     202          32 :     for (const auto & bc_pair : var_pair.second)
     203          16 :       if (std::find(_requested_bc_variables.begin(),
     204             :                     _requested_bc_variables.end(),
     205          32 :                     std::make_pair(VariableName(var_pair.first), BoundaryName(bc_pair.first))) ==
     206          32 :           _requested_bc_variables.end())
     207           4 :         list_missing += "\n- " + var_pair.first + " on " + bc_pair.first;
     208             : 
     209         148 :   if (!list_missing.empty())
     210           4 :     mooseError("Boundary conditions for variables and boundaries:" + list_missing +
     211             :                "\n  have been defined on this ActionComponent, but have not been requested by "
     212             :                "any Physics.");
     213         144 : }

Generated by: LCOV version 1.14