https://mooseframework.inl.gov
ThresholdElementSubdomainModifier.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 
11 
14 {
16 
17  params.addRequiredParam<Real>("threshold",
18  "The value above (or below) which to change the element subdomain");
19  params.addParam<MooseEnum>("criterion_type",
20  MooseEnum("BELOW EQUAL ABOVE", "ABOVE"),
21  "Criterion to use for the threshold");
22  params.addRequiredParam<SubdomainID>("subdomain_id",
23  "The subdomain ID of the element when the criterion is met");
24  params.addParam<SubdomainID>(
25  "complement_subdomain_id",
26  "The subdomain ID of the element when the criterion is not met. If not provided, the element "
27  "subdomain ID will not be modified if the criterion is not met.");
28  return params;
29 }
30 
32  const InputParameters & parameters)
33  : ElementSubdomainModifier(parameters),
34  _threshold(getParam<Real>("threshold")),
35  _criterion_type(getParam<MooseEnum>("criterion_type").getEnum<CriterionType>()),
36  _subdomain_id(getParam<SubdomainID>("subdomain_id")),
37  _complement_subdomain_id(isParamValid("complement_subdomain_id")
38  ? getParam<SubdomainID>("complement_subdomain_id")
40 {
41 }
42 
45 {
46  Real criterion = computeValue();
47 
48  bool criterion_met = false;
49  switch (_criterion_type)
50  {
52  criterion_met = MooseUtils::absoluteFuzzyEqual(criterion - _threshold, 0);
53  break;
54 
56  criterion_met = criterion < _threshold;
57  break;
58 
60  criterion_met = criterion > _threshold;
61  break;
62  }
63 
64  return criterion_met ? _subdomain_id : _complement_subdomain_id;
65 }
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:371
const SubdomainID _subdomain_id
Target subdomain ID.
virtual SubdomainID computeSubdomainID() override
Compute the subdomain ID of the current element.
enum ThresholdElementSubdomainModifier::CriterionType _criterion_type
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
ThresholdElementSubdomainModifier(const InputParameters &parameters)
virtual Real computeValue()=0
Compute the value used in the criterion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real _threshold
Threshold to modify the element subdomain ID.
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...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...