https://mooseframework.inl.gov
BoundsBase.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 "BoundsBase.h"
11 #include "SystemBase.h"
12 #include "PetscSupport.h"
13 #include "AuxiliarySystem.h"
14 
17 {
19  MooseEnum type_options("upper=0 lower=1", "upper");
20  params.addParam<MooseEnum>(
21  "bound_type",
22  type_options,
23  "Type of bound. 'upper' refers to the upper bound. 'lower' refers to the lower value.");
24  params.addRequiredParam<NonlinearVariableName>("bounded_variable", "The variable to be bounded");
25  params.registerBase("Bounds");
26  return params;
27 }
28 
30  : AuxKernel(parameters),
31  _type((BoundType)(int)parameters.get<MooseEnum>("bound_type")),
32  _bounded_vector(_type == 0 ? _nl_sys.getVector("upper_bound")
33  : _nl_sys.getVector("lower_bound")),
34  _bounded_var(_nl_sys.getVariable(_tid, getParam<NonlinearVariableName>("bounded_variable"))),
35  _bounded_var_name(parameters.get<NonlinearVariableName>("bounded_variable")),
36  _fe_var(_bounded_var.isFV() ? nullptr
37  : &_subproblem.getStandardVariable(_tid, _bounded_var_name))
38 {
39  // Check that the bounded variable is of a supported type
41  paramError("bounded_variable", "Bounded variable must be nodal or of a CONSTANT order!");
42 
43  const auto & dummy =
44  _aux_sys.getActualFieldVariable<Real>(_tid, parameters.get<AuxVariableName>("variable"));
45 
46  // Check that the dummy variable matches the bounded variable
47  if (dummy.feType() != _bounded_var.feType())
48  paramError("variable",
49  "Dummy bounds aux variable and bounded variable must use the same finite element "
50  "order and family");
51 }
52 
53 void
55 {
56  if (!Moose::PetscSupport::isSNESVI(*dynamic_cast<FEProblemBase *>(&_c_fe_problem)))
57  mooseDoOnce(
58  mooseWarning("A variational inequalities solver must be used in conjunction with Bounds"));
59 }
60 
61 Real
63 {
64  dof_id_type dof = getDoFIndex();
65 
67  {
68  Real bound = getBound();
69  _bounded_vector.set(dof, bound);
70  }
71 
72  return 0.0;
73 }
74 
77 {
78  if (isNodal())
79  {
80  if (_current_node->n_dofs(_nl_sys.number(), _bounded_var.number()) > 0)
81  {
82  mooseAssert(_current_node->n_dofs(_nl_sys.number(), _bounded_var.number()) == 1,
83  "Bounds are only set on one DOF value per node currently");
84  // The zero is for the component, this will only work for Lagrange variables
85  return _current_node->dof_number(_nl_sys.number(), _bounded_var.number(), 0);
86  }
87  }
88  else if (_current_elem->n_dofs(_nl_sys.number(), _bounded_var.number()) > 0)
89  {
90  mooseAssert(_current_elem->n_dofs(_nl_sys.number(), _bounded_var.number()) == 1,
91  "Bounds are only set on one DOF value per element currently");
92  // The zero is for the component, this will only work for CONSTANT variables
93  return _current_elem->dof_number(_nl_sys.number(), _bounded_var.number(), 0);
94  }
95  // No local dof for the bounded variable. This can happen for example if:
96  // - block restriction of dummy is different from bounded variable
97  // - we have a first order variable on a second order mesh
99 }
bool isSNESVI(FEProblemBase &fe_problem)
check if SNES type is variational inequalities (VI) solver
Definition: PetscSupport.C:980
virtual bool isNodal() const
Is this variable nodal.
const libMesh::FEType & feType() const
Get the type of finite element object.
THREAD_ID _tid
Thread ID.
Definition: AuxKernel.h:171
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:435
unsigned int number() const
Get variable number coming from libMesh.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:214
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1133
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
OrderWrapper order
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...
auto max(const L &left, const R &right)
dof_id_type getDoFIndex() const
Return the current DOF index to apply the bound on.
Definition: BoundsBase.C:76
FEProblemBase & _c_fe_problem
Definition: Coupleable.h:1403
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
NumericVector< Number > & _bounded_vector
Reference to the bounded vector of nonlinear system.
Definition: BoundsBase.h:43
MooseVariableFieldBase & _bounded_var
MOOSE variable (base class) we set the bound for.
Definition: BoundsBase.h:46
static InputParameters validParams()
Definition: BoundsBase.C:16
SystemBase & _nl_sys
Definition: AuxKernel.h:167
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
virtual Real computeValue() override final
Compute and return the value of the aux variable.
Definition: BoundsBase.C:62
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1157
AuxiliarySystem & _aux_sys
Definition: AuxKernel.h:168
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
BoundsBase(const InputParameters &parameters)
Definition: BoundsBase.C:29
virtual Real getBound()=0
Method to get bound value for a variable.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
Definition: MooseBase.h:295
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:204
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...
static InputParameters validParams()
Definition: AuxKernel.C:27
virtual void set(const numeric_index_type i, const Number value)=0
virtual void initialSetup() override final
Gets called at the beginning of the simulation before this object is asked to do its job...
Definition: BoundsBase.C:54
void ErrorVector unsigned int
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:86
uint8_t dof_id_type
MooseVariableField< T > & getActualFieldVariable(THREAD_ID tid, const std::string &var_name)
Returns a field variable pointer - this includes finite volume variables.
Definition: SystemBase.C:118