LCOV - code coverage report
Current view: top level - src/physics - PhysicsComponentInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 52 61 85.2 %
Date: 2025-08-08 20:01:16 Functions: 8 9 88.9 %
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 "PhysicsComponentInterface.h"
      11             : #include "ComponentInitialConditionInterface.h"
      12             : 
      13             : InputParameters
      14         692 : PhysicsComponentInterface::validParams()
      15             : {
      16         692 :   InputParameters params = PhysicsBase::validParams();
      17             :   // we likely do not need all these parameters. But developers could expect them
      18         692 :   return params;
      19             : }
      20             : 
      21         294 : PhysicsComponentInterface::PhysicsComponentInterface(const InputParameters & parameters)
      22         294 :   : PhysicsBase(parameters)
      23             : {
      24         294 :   addRequiredPhysicsTask("add_ic");
      25         294 : }
      26             : 
      27             : void
      28        2242 : PhysicsComponentInterface::actOnAdditionalTasks()
      29             : {
      30             :   // TODO: find a way to force this routine to be called by derived classes
      31        2242 :   if (_current_task == "add_ic")
      32         250 :     addInitialConditionsFromComponents();
      33        1992 :   else if (_current_task == "add_bc" || _current_task == "add_fv_bc")
      34         242 :     addBoundaryConditionsFromComponents();
      35        2234 : }
      36             : 
      37             : void
      38         136 : PhysicsComponentInterface::addComponent(const ActionComponent & comp)
      39             : {
      40             :   // Adds the component's blocks to the block restriction at least
      41         136 :   PhysicsBase::addComponent(comp);
      42             : 
      43             :   // Move initial conditions from components to the Physics
      44         136 :   if (const auto comp_ic = dynamic_cast<const ComponentInitialConditionInterface *>(&comp))
      45             :   {
      46         272 :     for (const auto & var_name : solverVariableNames())
      47         136 :       if (comp_ic->hasInitialCondition(var_name))
      48         102 :         addInitialCondition(comp.name(), var_name, comp_ic->getInitialCondition(var_name, name()));
      49         136 :     for (const auto & var_name : auxVariableNames())
      50           0 :       if (comp_ic->hasInitialCondition(var_name))
      51           0 :         addInitialCondition(comp.name(), var_name, comp_ic->getInitialCondition(var_name, name()));
      52             :   }
      53             : 
      54             :   // Move boundary conditions from components to the Physics
      55         136 :   if (const auto comp_bc = dynamic_cast<const ComponentBoundaryConditionInterface *>(&comp))
      56             :   {
      57         272 :     for (const auto & var_name : solverVariableNames())
      58         136 :       if (comp_bc->hasBoundaryCondition(var_name))
      59         127 :         for (const auto & boundary : comp_bc->getBoundaryConditionBoundaries(var_name))
      60             :         {
      61             :           ComponentBoundaryConditionInterface::BoundaryConditionType bc_type;
      62             :           const auto boundary_functor =
      63          72 :               comp_bc->getBoundaryCondition(var_name, boundary, name(), bc_type);
      64          72 :           addBoundaryCondition(comp.name(), var_name, boundary, boundary_functor, bc_type);
      65         127 :         }
      66         136 :     for (const auto & var_name : auxVariableNames())
      67           0 :       if (comp_bc->hasBoundaryCondition(var_name))
      68           0 :         for (const auto & boundary : comp_bc->getBoundaryConditionBoundaries(var_name))
      69             :         {
      70             :           ComponentBoundaryConditionInterface::BoundaryConditionType bc_type;
      71             :           const auto boundary_functor =
      72           0 :               comp_bc->getBoundaryCondition(var_name, boundary, name(), bc_type);
      73           0 :           addBoundaryCondition(comp.name(), var_name, boundary, boundary_functor, bc_type);
      74           0 :         }
      75             :   }
      76         136 : }
      77             : 
      78             : void
      79         102 : PhysicsComponentInterface::addInitialCondition(const ComponentName & component_name,
      80             :                                                const VariableName & var_name,
      81             :                                                const MooseFunctorName & ic_value)
      82             : {
      83         102 :   _components_initial_conditions[component_name][var_name] = ic_value;
      84         102 : }
      85             : 
      86             : void
      87          72 : PhysicsComponentInterface::addBoundaryCondition(
      88             :     const ComponentName & component_name,
      89             :     const VariableName & var_name,
      90             :     const BoundaryName & boundary_name,
      91             :     const MooseFunctorName & bc_value,
      92             :     const ComponentBoundaryConditionInterface::BoundaryConditionType & bc_type)
      93             : {
      94         144 :   _components_boundary_conditions[component_name][std::make_pair(var_name, boundary_name)] =
      95         216 :       std::make_pair(bc_value, bc_type);
      96          72 : }
      97             : 
      98             : void
      99           8 : PhysicsComponentInterface::addInitialConditionsFromComponents()
     100             : {
     101           8 :   if (_components_initial_conditions.size())
     102             :   {
     103           4 :     std::vector<ComponentName> all_components(_components_initial_conditions.size());
     104           8 :     for (const auto & comp : _components_initial_conditions)
     105           4 :       all_components.push_back(comp.first);
     106           4 :     mooseError("Component(s) '",
     107           4 :                Moose::stringify(all_components),
     108             :                "' requested to add the following initial conditions for this Physics. This Physics "
     109             :                "however does not implement the 'addInitialConditionsFromComponents' "
     110             :                "routine, so it cannot create these initial conditions");
     111           0 :   }
     112           4 : }
     113             : 
     114             : void
     115         103 : PhysicsComponentInterface::addBoundaryConditionsFromComponents()
     116             : {
     117         103 :   if (_components_boundary_conditions.size())
     118             :   {
     119           4 :     std::vector<ComponentName> all_components(_components_boundary_conditions.size());
     120           8 :     for (const auto & comp : _components_boundary_conditions)
     121           4 :       all_components.push_back(comp.first);
     122           4 :     mooseError("Component(s) '",
     123           4 :                Moose::stringify(all_components),
     124             :                "' requested to add boundary conditions for the variable of this Physics. This "
     125             :                "Physics however does not implement the 'addBoundaryConditionsFromComponents' "
     126             :                "routine, so it cannot create these boundary conditions");
     127           0 :   }
     128          99 : }

Generated by: LCOV version 1.14