https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FunctorADConverter.C
Go to the documentation of this file.
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
16
17template <typename T>
20{
22 params.addClassDescription("Converts regular functors to AD functors and "
23 "AD functors to regular functors");
24 params.addParam<std::vector<MooseFunctorName>>(
25 "reg_props_in", {}, "The names of the regular functors to convert to AD functors");
26 params.addParam<std::vector<MooseFunctorName>>(
27 "ad_props_out", {}, "The names of the output AD functors");
28 params.addParam<std::vector<MooseFunctorName>>(
29 "ad_props_in", {}, "The names of the AD functors to convert to regular functors");
30 params.addParam<std::vector<MooseFunctorName>>(
31 "reg_props_out", {}, "The names of the output regular functors");
32 return params;
33}
34
35template <typename T>
37 : FunctorMaterial(parameters)
38{
39 const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
40 auto reg_props_in = getParam<std::vector<MooseFunctorName>>("reg_props_in");
41 auto ad_props_out = getParam<std::vector<MooseFunctorName>>("ad_props_out");
42 auto ad_props_in = getParam<std::vector<MooseFunctorName>>("ad_props_in");
43 auto reg_props_out = getParam<std::vector<MooseFunctorName>>("reg_props_out");
44
45 // Check input sizes
46 if (reg_props_in.size() != ad_props_out.size())
47 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 if (ad_props_in.size() != reg_props_out.size())
53 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 for (const auto i : index_range(reg_props_in))
61 for (const auto j : index_range(reg_props_in))
62 if (reg_props_in[i] == ad_props_out[j])
63 paramError("reg_props_in",
64 "Functor names may not overlap between reg_props_in and ad_props_out");
65
66 for (const auto i : index_range(reg_props_in))
67 for (const auto j : index_range(ad_props_in))
68 if (reg_props_in[i] == reg_props_out[j])
69 paramError("reg_props_in",
70 "Functor names may not overlap between reg_props_in and reg_props_out");
71
72 for (const auto i : index_range(ad_props_in))
73 for (const auto j : index_range(ad_props_in))
74 if (ad_props_in[i] == reg_props_out[j])
75 paramError("ad_props_in",
76 "Functor names may not overlap between ad_props_in and reg_props_out");
77
78 for (const auto i : index_range(ad_props_in))
79 for (const auto j : index_range(reg_props_in))
80 if (ad_props_in[i] == ad_props_out[j])
81 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 for (const auto i : index_range(reg_props_in))
86 {
87 const auto & reg_functor = getFunctor<T>(reg_props_in[i]);
88 addFunctorProperty<typename Moose::ADType<T>::type>(
89 ad_props_out[i],
90 [&reg_functor](const auto & r, const auto & t) -> typename Moose::ADType<T>::type
91 { return reg_functor(r, t); },
92 clearance_schedule);
93 }
94
95 // Define the regular functors
96 for (const auto i : index_range(ad_props_in))
97 {
98 const auto & ad_functor = getFunctor<typename Moose::ADType<T>::type>(ad_props_in[i]);
99 addFunctorProperty<T>(
100 reg_props_out[i],
101 [&ad_functor](const auto & r, const auto & t) -> T
102 { return MetaPhysicL::raw_value(ad_functor(r, t)); },
103 clearance_schedule);
104 }
105}
106
107template class FunctorADConverterTempl<Real>;
registerMooseObject("MooseApp", FunctorADConverter)
This material converts regular functors to AD functors and AD functors to regular functors.
static InputParameters validParams()
FunctorADConverterTempl(const InputParameters &parameters)
FunctorMaterials compute functor material properties.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
MooseEnumIterator end() const
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
auto raw_value(const Eigen::Map< T > &in)