https://mooseframework.inl.gov
ActivateElementsCoupled.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 
13 
16 {
18 
19  params.addRequiredParam<Real>("activate_value", "The value above which to activate the element");
20  params.addRequiredCoupledVar(
21  "coupled_var",
22  "The variable value will be used to decide wether an element whould be activated.");
23  params.addParam<MooseEnum>("activate_type",
24  MooseEnum("below equal above", "above"),
25  "Activate element when below or above the activate_value");
26  return params;
27 }
28 
30  : ActivateElementsUserObjectBase(parameters),
31  _coupled_var(coupledValue("coupled_var")),
32  _activate_value(
33  declareRestartableData<Real>("activate_value", getParam<Real>("activate_value"))),
34  _activate_type(getParam<MooseEnum>("activate_type").getEnum<ActivateType>())
35 {
36 }
37 
38 bool
40 {
41  bool is_activated = false;
42  Real avg_val = 0.0;
43 
44  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
45  avg_val += _coupled_var[qp];
46  avg_val /= _qrule->n_points();
47 
48  switch (_activate_type)
49  {
51  is_activated = (avg_val < _activate_value);
52  break;
53 
55  is_activated = MooseUtils::absoluteFuzzyEqual(avg_val - _activate_value, 0.0);
56  break;
57 
59  is_activated = (avg_val > _activate_value);
60  break;
61  }
62 
63  return is_activated;
64 }
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:380
static InputParameters validParams()
const VariableValue & _coupled_var
variable value to decide wether an element whould be activated
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
ActivateType
type of activation - blow or above
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...
ActivateElementsCoupled(const InputParameters &parameters)
registerMooseObject("MooseApp", ActivateElementsCoupled)
enum ActivateElementsCoupled::ActivateType _activate_type
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
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...
virtual bool isElementActivated() override
const Real _activate_value
variable value to decide wether an element whould be activated