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>(
82 const Elem * r_elem =
nullptr;
87 if (r_elem && r_elem->n_neighbors() == 0)
96 unsigned int n_faces = 0;
97 for (
const auto side_index : r_elem->side_index_range())
103 r_elem->neighbor_ptr(side_index)->which_neighbor_am_i(r_elem));
108 average += functor_in(face_arg, t);
118 mooseError(
"Face averaging smoothing has only been defined for the ElemArg functor " 119 "argument, not for ",
121 ". Please contact a MOOSE developer or implement it yourself.");
125 if constexpr (std::is_same_v<
const Moose::ElemArg &, decltype(r)>)
127 unsigned int n_neighbors = 0;
128 for (
const auto neighbor : r_elem->neighbor_ptr_range())
134 average /= n_neighbors;
137 mooseError(
"Element layered averaging smoothing has only been defined for the " 138 "ElemArg functor argument, not for ",
140 ". Please contact a MOOSE developer or implement it yourself.");
144 if constexpr (std::is_same_v<
const Moose::ElemArg &, decltype(r)>)
149 average += base_value / 2;
155 unsigned int furthest_one = 0;
156 unsigned int num_neighbors = 0;
157 for (
const auto side_index : r_elem->side_index_range())
159 auto neighbor = r_elem->neighbor_ptr(side_index);
163 auto neighbor_value = functor_in(
Moose::ElemArg{neighbor,
false}, t);
164 if (
std::abs(neighbor_value - base_value) > delta)
166 furthest_one = side_index;
167 extreme_value = neighbor_value;
168 delta =
std::abs(neighbor_value - base_value);
174 if (num_neighbors == 1)
176 average += extreme_value / 2;
180 average += extreme_value / 4;
185 auto opposite_side = r_elem->opposite_side(furthest_one);
186 auto neighbor = r_elem->neighbor_ptr(opposite_side);
193 average += extreme_value / 4;
202 for (
const auto side_index : r_elem->side_index_range())
204 auto neighbor = r_elem->neighbor_ptr(side_index);
205 auto neighbor_value =
206 neighbor ? functor_in(
Moose::ElemArg{neighbor,
false}, t) : base_value;
207 if (
std::abs(neighbor_value - base_value) > delta && side_index != furthest_one)
209 second_extreme_value = neighbor_value;
210 delta =
std::abs(neighbor_value - base_value);
213 average += second_extreme_value / 4;
217 mooseError(
"Checkerboard removal smoothing has only been defined for the " 218 "ElemArg functor argument, not for ",
220 ". 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)