LCOV - code coverage report
Current view: top level - src/functormaterials - VectorMagnitudeFunctorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 50 50 100.0 %
Date: 2026-05-29 20:35:17 Functions: 9 44 20.5 %
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 "VectorMagnitudeFunctorMaterial.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", VectorMagnitudeFunctorMaterial);
      14             : registerMooseObject("MooseApp", ADVectorMagnitudeFunctorMaterial);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18        6178 : VectorMagnitudeFunctorMaterialTempl<is_ad>::validParams()
      19             : {
      20        6178 :   InputParameters params = FunctorMaterial::validParams();
      21       18534 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
      22       12356 :   params.addClassDescription(
      23             :       "This class takes up to three scalar-valued functors corresponding to vector "
      24             :       "components *or* a single vector functor and computes the Euclidean norm.");
      25       24712 :   params.addParam<MooseFunctorName>("x_functor", "The functor corresponding to the x component.");
      26       18534 :   params.addParam<MooseFunctorName>(
      27       12356 :       "y_functor", 0, "The functor corresponding to the y component.");
      28       18534 :   params.addParam<MooseFunctorName>(
      29       12356 :       "z_functor", 0, "The functor corresponding to the z component.");
      30       24712 :   params.addRequiredParam<MooseFunctorName>(
      31             :       "vector_magnitude_name", "The name of the vector magnitude functor that we are creating.");
      32       18534 :   params.addParam<MooseFunctorName>(
      33             :       "vector_functor", "The name of a vector functor that we will take the magnitude of.");
      34        6178 :   return params;
      35        6178 : }
      36             : 
      37             : template <bool is_ad>
      38          32 : VectorMagnitudeFunctorMaterialTempl<is_ad>::VectorMagnitudeFunctorMaterialTempl(
      39             :     const InputParameters & parameters)
      40             :   : FunctorMaterial(parameters),
      41          64 :     _x(isParamValid("x_functor") ? &getFunctor<GenericReal<is_ad>>("x_functor") : nullptr),
      42          64 :     _y(getFunctor<GenericReal<is_ad>>("y_functor")),
      43          64 :     _z(getFunctor<GenericReal<is_ad>>("z_functor")),
      44          64 :     _vector_functor(isParamValid("vector_functor")
      45          70 :                         ? &getFunctor<VectorValue<GenericReal<is_ad>>>("vector_functor")
      46          32 :                         : nullptr)
      47             : {
      48          32 :   auto check_error =
      49          81 :       [this, &parameters](const std::string & scalar_functor, const bool must_equal_one)
      50             :   {
      51          93 :     auto error_message = [&scalar_functor, this]()
      52             :     {
      53          12 :       mooseError("Either a '",
      54             :                  scalar_functor,
      55             :                  "' or 'vector_functor' parameter "
      56             :                  "must be provided to '",
      57           6 :                  name(),
      58             :                  "'");
      59             :     };
      60          87 :     const unsigned short sum =
      61         174 :         parameters.isParamSetByUser(scalar_functor) + parameters.isParamSetByUser("vector_functor");
      62          87 :     if (must_equal_one)
      63             :     {
      64          32 :       if (sum != 1)
      65           3 :         error_message();
      66             :     }
      67             :     else
      68             :     {
      69          55 :       if (sum > 1)
      70           3 :         error_message();
      71             :     }
      72             :   };
      73             : 
      74          61 :   check_error("x_functor", true);
      75          55 :   check_error("y_functor", false);
      76          26 :   check_error("z_functor", false);
      77             : 
      78          26 :   const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
      79             : 
      80          78 :   if (isParamValid("x_functor"))
      81          39 :     addFunctorProperty<GenericReal<is_ad>>(
      82             :         "vector_magnitude_name",
      83        3200 :         [this](const auto & r, const auto & t) -> GenericReal<is_ad>
      84             :         {
      85        3200 :           const auto x = (*_x)(r, t);
      86        3200 :           const auto y = _y(r, t);
      87        3200 :           const auto z = _z(r, t);
      88             :           using std::sqrt;
      89        6400 :           return sqrt((x * x) + (y * y) + (z * z));
      90        3200 :         },
      91             :         clearance_schedule);
      92             :   else
      93          39 :     addFunctorProperty<GenericReal<is_ad>>(
      94             :         "vector_magnitude_name",
      95       86400 :         [this](const auto & r, const auto & t) -> GenericReal<is_ad>
      96             :         {
      97       86400 :           const auto vec = (*_vector_functor)(r, t);
      98      172800 :           return vec.norm();
      99       86400 :         },
     100             :         clearance_schedule);
     101          26 : }
     102             : 
     103             : template class VectorMagnitudeFunctorMaterialTempl<false>;
     104             : template class VectorMagnitudeFunctorMaterialTempl<true>;

Generated by: LCOV version 1.14