14 #include "metaphysicl/raw_type.h" 23 params.
addClassDescription(
"Creates smoother functor(s) using various averaging techniques");
24 params.
addParam<std::vector<MooseFunctorName>>(
"functors_in",
25 "The name(s) of the functors to smooth");
26 params.
addParam<std::vector<MooseFunctorName>>(
"functors_out",
27 "The name(s) of the smooth output functors");
28 MooseEnum smoothing_techniques(
"face_average layered_elem_average remove_checkerboard");
30 "smoothing_technique", smoothing_techniques,
"How to smooth the functor");
38 _functors_in(getParam<
std::vector<MooseFunctorName>>(
"functors_in")),
39 _functors_out(getParam<
std::vector<MooseFunctorName>>(
"functors_out")),
40 _smoothing_technique(getParam<
MooseEnum>(
"smoothing_technique"))
46 auto rm_params = factory.
getValidParams(
"ElementSideNeighborLayers");
47 rm_params.template set<std::string>(
"for_whom") =
name();
48 rm_params.template set<MooseMesh *>(
"mesh") = &const_cast<MooseMesh &>(
_mesh);
49 rm_params.template set<Moose::RelationshipManagerType>(
"rm_type") =
52 rm_params.template set<unsigned short>(
"layers") = 1;
53 rm_params.template set<bool>(
"use_point_neighbors") =
false;
54 rm_params.template set<bool>(
"use_displaced_mesh") =
55 parameters.template get<bool>(
"use_displaced_mesh");
56 mooseAssert(rm_params.areAllRequiredParamsValid(),
57 "All relationship manager parameters should be valid.");
58 auto rm_obj = factory.template create<RelationshipManager>(
59 "ElementSideNeighborLayers",
name() +
"_functor_smoothing", rm_params);
64 factory.releaseSharedObjects(*rm_obj);
72 const auto & functor_in = getFunctor<typename Moose::ADType<T>::type>(
_functors_in[i]);
75 addFunctorProperty<typename Moose::ADType<T>::type>(
83 const Elem * r_elem =
nullptr;
88 if (r_elem && r_elem->n_neighbors() == 0)
97 unsigned int n_faces = 0;
98 for (
const auto side_index : r_elem->side_index_range())
104 r_elem->neighbor_ptr(side_index)->which_neighbor_am_i(r_elem));
109 average += functor_in(face_arg, t);
119 mooseError(
"Face averaging smoothing has only been defined for the ElemArg functor " 120 "argument, not for ",
122 ". Please contact a MOOSE developer or implement it yourself.");
126 if constexpr (std::is_same_v<
const Moose::ElemArg &, decltype(r)>)
128 unsigned int n_neighbors = 0;
129 for (
const auto neighbor : r_elem->neighbor_ptr_range())
135 average /= n_neighbors;
138 mooseError(
"Element layered averaging smoothing has only been defined for the " 139 "ElemArg functor argument, not for ",
141 ". Please contact a MOOSE developer or implement it yourself.");
145 if constexpr (std::is_same_v<
const Moose::ElemArg &, decltype(r)>)
150 average += base_value / 2;
156 unsigned int furthest_one = 0;
157 unsigned int num_neighbors = 0;
158 for (
const auto side_index : r_elem->side_index_range())
160 auto neighbor = r_elem->neighbor_ptr(side_index);
164 auto neighbor_value = functor_in(
Moose::ElemArg{neighbor,
false}, t);
165 if (
abs(neighbor_value - base_value) > delta)
167 furthest_one = side_index;
168 extreme_value = neighbor_value;
169 delta =
abs(neighbor_value - base_value);
175 if (num_neighbors == 1)
177 average += extreme_value / 2;
181 average += extreme_value / 4;
186 auto opposite_side = r_elem->opposite_side(furthest_one);
187 auto neighbor = r_elem->neighbor_ptr(opposite_side);
194 average += extreme_value / 4;
203 for (
const auto side_index : r_elem->side_index_range())
205 auto neighbor = r_elem->neighbor_ptr(side_index);
206 auto neighbor_value =
207 neighbor ? functor_in(
Moose::ElemArg{neighbor,
false}, t) : base_value;
208 if (
abs(neighbor_value - base_value) > delta && side_index != furthest_one)
210 second_extreme_value = neighbor_value;
211 delta =
abs(neighbor_value - base_value);
214 average += second_extreme_value / 4;
218 mooseError(
"Checkerboard removal smoothing has only been defined for the " 219 "ElemArg functor argument, not for ",
221 ". Please contact a MOOSE developer or implement it yourself.");
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
This functor material smooths a functor material property.
const MooseEnum _smoothing_technique
Smoothing technique to use.
static InputParameters validParams()
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
const InputParameters & parameters() const
Get the parameters of the object.
static InputParameters validParams()
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
MooseEnumIterator end() const
const std::vector< MooseFunctorName > _functors_in
Incoming functor(s) names.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
registerMooseObject("MooseApp", FunctorSmoother)
const std::vector< const FaceInfo * > & faceInfo() const
Accessor for local FaceInfo objects.
const std::string & name() const
Get the name of the class.
FunctorMaterials compute functor material properties.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
const std::vector< MooseFunctorName > _functors_out
Smoothed functor(s) names.
A structure defining a "face" evaluation calling argument for Moose functors.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
A structure that is used to evaluate Moose functors logically at an element/cell center.
MooseApp & _app
The MOOSE application this is associated with.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
auto index_range(const T &sizable)
FunctorSmootherTempl(const InputParameters ¶meters)
std::string prettyCppType(const std::string &cpp_type)