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 "FunctorADConverter.h" 11 : 12 : #include "metaphysicl/raw_type.h" 13 : 14 : registerMooseObject("MooseApp", FunctorADConverter); 15 : registerMooseObject("MooseApp", VectorFunctorADConverter); 16 : 17 : template <typename T> 18 : InputParameters 19 28648 : FunctorADConverterTempl<T>::validParams() 20 : { 21 28648 : InputParameters params = FunctorMaterial::validParams(); 22 28648 : params.addClassDescription("Converts regular functors to AD functors and " 23 : "AD functors to regular functors"); 24 28648 : params.addParam<std::vector<MooseFunctorName>>( 25 : "reg_props_in", {}, "The names of the regular functors to convert to AD functors"); 26 28648 : params.addParam<std::vector<MooseFunctorName>>( 27 : "ad_props_out", {}, "The names of the output AD functors"); 28 28648 : params.addParam<std::vector<MooseFunctorName>>( 29 : "ad_props_in", {}, "The names of the AD functors to convert to regular functors"); 30 28648 : params.addParam<std::vector<MooseFunctorName>>( 31 : "reg_props_out", {}, "The names of the output regular functors"); 32 28648 : return params; 33 0 : } 34 : 35 : template <typename T> 36 70 : FunctorADConverterTempl<T>::FunctorADConverterTempl(const InputParameters & parameters) 37 70 : : FunctorMaterial(parameters) 38 : { 39 70 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 40 70 : auto reg_props_in = getParam<std::vector<MooseFunctorName>>("reg_props_in"); 41 70 : auto ad_props_out = getParam<std::vector<MooseFunctorName>>("ad_props_out"); 42 70 : auto ad_props_in = getParam<std::vector<MooseFunctorName>>("ad_props_in"); 43 70 : auto reg_props_out = getParam<std::vector<MooseFunctorName>>("reg_props_out"); 44 : 45 : // Check input sizes 46 70 : if (reg_props_in.size() != ad_props_out.size()) 47 4 : paramError("ad_props_out", 48 : "The number of output AD functors must match the number of input regular " 49 : "functors, which is " + 50 : std::to_string(reg_props_in.size())); 51 : 52 66 : if (ad_props_in.size() != reg_props_out.size()) 53 4 : paramError("reg_props_out", 54 : "The number of output regular functors must match the number of input AD " 55 : "functors, which is " + 56 : std::to_string(ad_props_in.size())); 57 : 58 : // Check input names for overlaps, before possibly hitting a harder to 59 : // interpret error at functor definition 60 83 : for (const auto i : index_range(reg_props_in)) 61 46 : for (const auto j : index_range(reg_props_in)) 62 25 : if (reg_props_in[i] == ad_props_out[j]) 63 4 : paramError("reg_props_in", 64 : "Functor names may not overlap between reg_props_in and ad_props_out"); 65 : 66 75 : for (const auto i : index_range(reg_props_in)) 67 25 : for (const auto j : index_range(ad_props_in)) 68 8 : if (reg_props_in[i] == reg_props_out[j]) 69 4 : paramError("reg_props_in", 70 : "Functor names may not overlap between reg_props_in and reg_props_out"); 71 : 72 91 : for (const auto i : index_range(ad_props_in)) 73 78 : for (const auto j : index_range(ad_props_in)) 74 41 : if (ad_props_in[i] == reg_props_out[j]) 75 4 : paramError("ad_props_in", 76 : "Functor names may not overlap between ad_props_in and reg_props_out"); 77 : 78 83 : for (const auto i : index_range(ad_props_in)) 79 37 : for (const auto j : index_range(reg_props_in)) 80 4 : if (ad_props_in[i] == ad_props_out[j]) 81 4 : paramError("ad_props_in", 82 : "Functor names may not overlap between ad_props_in and ad_props_out"); 83 : 84 : // Define the AD functors 85 59 : for (const auto i : index_range(reg_props_in)) 86 : { 87 13 : const auto & reg_functor = getFunctor<T>(reg_props_in[i]); 88 13 : addFunctorProperty<typename Moose::ADType<T>::type>( 89 : ad_props_out[i], 90 240 : [®_functor](const auto & r, const auto & t) -> typename Moose::ADType<T>::type 91 480 : { return reg_functor(r, t); }, 92 : clearance_schedule); 93 : } 94 : 95 : // Define the regular functors 96 79 : for (const auto i : index_range(ad_props_in)) 97 : { 98 33 : const auto & ad_functor = getFunctor<typename Moose::ADType<T>::type>(ad_props_in[i]); 99 33 : addFunctorProperty<T>( 100 : reg_props_out[i], 101 240 : [&ad_functor](const auto & r, const auto & t) -> T 102 240 : { return MetaPhysicL::raw_value(ad_functor(r, t)); }, 103 : clearance_schedule); 104 : } 105 46 : } 106 : 107 : template class FunctorADConverterTempl<Real>; 108 : template class FunctorADConverterTempl<RealVectorValue>;