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 28588 : VectorMagnitudeFunctorMaterialTempl<is_ad>::validParams() 19 : { 20 28588 : InputParameters params = FunctorMaterial::validParams(); 21 57176 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 22 28588 : 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 28588 : params.addParam<MooseFunctorName>("x_functor", "The functor corresponding to the x component."); 26 85764 : params.addParam<MooseFunctorName>( 27 57176 : "y_functor", 0, "The functor corresponding to the y component."); 28 85764 : params.addParam<MooseFunctorName>( 29 57176 : "z_functor", 0, "The functor corresponding to the z component."); 30 28588 : params.addRequiredParam<MooseFunctorName>( 31 : "vector_magnitude_name", "The name of the vector magnitude functor that we are creating."); 32 28588 : params.addParam<MooseFunctorName>( 33 : "vector_functor", "The name of a vector functor that we will take the magnitude of."); 34 28588 : return params; 35 28588 : } 36 : 37 : template <bool is_ad> 38 34 : VectorMagnitudeFunctorMaterialTempl<is_ad>::VectorMagnitudeFunctorMaterialTempl( 39 : const InputParameters & parameters) 40 : : FunctorMaterial(parameters), 41 34 : _x(isParamValid("x_functor") ? &getFunctor<GenericReal<is_ad>>("x_functor") : nullptr), 42 34 : _y(getFunctor<GenericReal<is_ad>>("y_functor")), 43 34 : _z(getFunctor<GenericReal<is_ad>>("z_functor")), 44 68 : _vector_functor(isParamValid("vector_functor") 45 34 : ? &getFunctor<VectorValue<GenericReal<is_ad>>>("vector_functor") 46 34 : : nullptr) 47 : { 48 34 : auto check_error = 49 82 : [this, ¶meters](const std::string & scalar_functor, const bool must_equal_one) 50 : { 51 106 : auto error_message = [&scalar_functor, this]() 52 : { 53 16 : mooseError("Either a '", 54 : scalar_functor, 55 : "' or 'vector_functor' parameter " 56 : "must be provided to '", 57 8 : name(), 58 : "'"); 59 : }; 60 90 : const unsigned short sum = 61 90 : parameters.isParamSetByUser(scalar_functor) + parameters.isParamSetByUser("vector_functor"); 62 90 : if (must_equal_one) 63 : { 64 34 : if (sum != 1) 65 4 : error_message(); 66 : } 67 : else 68 : { 69 56 : if (sum > 1) 70 4 : error_message(); 71 : } 72 : }; 73 : 74 34 : check_error("x_functor", true); 75 30 : 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 26 : if (isParamValid("x_functor")) 81 13 : addFunctorProperty<GenericReal<is_ad>>( 82 : "vector_magnitude_name", 83 9600 : [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 6400 : return std::sqrt((x * x) + (y * y) + (z * z)); 89 3200 : }, 90 : clearance_schedule); 91 : else 92 13 : addFunctorProperty<GenericReal<is_ad>>( 93 : "vector_magnitude_name", 94 86400 : [this](const auto & r, const auto & t) -> GenericReal<is_ad> 95 : { 96 86400 : const auto vec = (*_vector_functor)(r, t); 97 172800 : return vec.norm(); 98 86400 : }, 99 : clearance_schedule); 100 26 : } 101 : 102 : template class VectorMagnitudeFunctorMaterialTempl<false>; 103 : template class VectorMagnitudeFunctorMaterialTempl<true>;