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

Generated by: LCOV version 1.14