https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
53void
55{
57 mooseDoOnce(
58 mooseWarning("A variational inequalities solver must be used in conjunction with Bounds"));
59}
60
61Real
63{
64 dof_id_type dof = getDoFIndex();
65
66 if (dof != std::numeric_limits<dof_id_type>::max())
67 {
68 Real bound = getBound();
69 _bounded_vector.set(dof, bound);
70 }
71
72 return 0.0;
73}
74
75dof_id_type
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
98 return std::numeric_limits<dof_id_type>::max();
99}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
void ErrorVector unsigned int
SystemBase & _nl_sys
AuxiliarySystem & _aux_sys
const THREAD_ID _tid
Thread ID.
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition AuxKernel.h:133
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition AuxKernel.h:143
static InputParameters validParams()
Definition AuxKernel.C:27
static InputParameters validParams()
Definition BoundsBase.C:16
BoundsBase(const InputParameters &parameters)
Definition BoundsBase.C:29
virtual Real getBound()=0
Method to get bound value for a variable.
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
NumericVector< Number > & _bounded_vector
Reference to the bounded vector of nonlinear system.
Definition BoundsBase.h:43
virtual Real computeValue() override final
Compute and return the value of the aux variable.
Definition BoundsBase.C:62
MooseVariableFieldBase & _bounded_var
MOOSE variable (base class) we set the bound for.
Definition BoundsBase.h:46
dof_id_type getDoFIndex() const
Return the current DOF index to apply the bound on.
Definition BoundsBase.C:76
FEProblemBase & _c_fe_problem
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
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 InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
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:457
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
const libMesh::FEType & feType() const
Get the type of finite element object.
virtual bool isNodal() const
Is this variable nodal.
unsigned int number() const
Get variable number coming from libMesh.
unsigned int number() const
Gets the number of this system.
MooseVariableField< T > & getActualFieldVariable(THREAD_ID tid, const std::string &var_name)
Returns a field variable pointer - this includes finite volume variables.
Definition SystemBase.C:119
OrderWrapper order
virtual void set(const numeric_index_type i, const T value)=0
bool isSNESVI(FEProblemBase &fe_problem)
check if SNES type is variational inequalities (VI) solver