https://mooseframework.inl.gov
InternalSideIndicatorBase.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 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "MooseTypes.h"
15 #include "MooseVariableFE.h"
16 #include "Problem.h"
17 #include "SubProblem.h"
18 #include "SystemBase.h"
19 
20 #include "libmesh/dof_map.h"
21 #include "libmesh/dense_vector.h"
22 #include "libmesh/numeric_vector.h"
23 #include "libmesh/dense_subvector.h"
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/quadrature.h"
26 
28 
31 {
33  params.addRequiredParam<VariableName>(
34  "variable", "The name of the variable that this side indicator applies to");
35  params.addParam<bool>("scale_by_flux_faces",
36  false,
37  "Whether or not to scale the error values by "
38  "the number of flux faces. This attempts to "
39  "not penalize elements on boundaries for "
40  "having less neighbors.");
41 
43  return params;
44 }
45 
47  : Indicator(parameters),
48  NeighborCoupleable(this, false, false),
49  ScalarCoupleable(this),
50  _field_var(_subproblem.getStandardVariable(_tid, name())),
51  _current_elem(_assembly.elem()),
52  _neighbor_elem(_assembly.neighbor()),
53  _current_side(_assembly.side()),
54  _current_side_elem(_assembly.sideElem()),
55  _coord_sys(_assembly.coordSystem()),
56  _qrule(_assembly.qRuleFace()),
57  _q_point(_assembly.qPointsFace()),
58  _JxW(_assembly.JxWFace()),
59  _coord(_assembly.coordTransformation()),
60  _boundary_id(parameters.get<BoundaryID>("_boundary_id")),
61  _scale_by_flux_faces(parameters.get<bool>("scale_by_flux_faces")),
62  _normals(_assembly.normals())
63 {
64  const std::vector<MooseVariableFieldBase *> & coupled_vars = getCoupledMooseVars();
65  for (const auto & var : coupled_vars)
67 
68  // Not supported with the base linear lagrange case
70  paramError("use_displaced_mesh",
71  "Internal side indicators do not support using the displaced mesh at this time. "
72  "They can be used on the undisplaced mesh in a Problem with displaced mesh");
73  // Access into the solution vector assumes constant monomial
75  mooseError("Only constant monomial variables for the internal side indicator are supported");
76 }
77 
78 void
80 {
81  // Derived class decides the contribution at each qp to the indicator value
82  Real sum = 0;
83  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
84  sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();
85 
86  // Contribution is added to the two elements
87  {
88  const auto sys_num = _field_var.sys().number();
89  const auto var_num = _field_var.number();
90  _solution.add(_current_elem->dof_number(sys_num, var_num, 0), sum * _current_elem->hmax());
91  if (_field_var.hasBlocks(_neighbor_elem->subdomain_id()))
92  _solution.add(_neighbor_elem->dof_number(sys_num, var_num, 0), sum * _neighbor_elem->hmax());
93  }
94 }
95 
96 void
98 {
99  unsigned int n_flux_faces = 0;
100 
102  {
103  if (isVarFV())
104  paramError("scale_by_flux_faces", "Unsupported at this time for finite volume variables");
105 
106  // Figure out the total number of sides contributing to the error.
107  // We'll scale by this so boundary elements are less penalized
108  for (unsigned int side = 0; side < _current_elem->n_sides(); side++)
109  if (_current_elem->neighbor_ptr(side) != nullptr)
110  n_flux_faces++;
111  }
112  else
113  n_flux_faces = 1;
114 
115  // The 0 is because CONSTANT MONOMIALS only have one coefficient per element
117 
118  {
119  const auto sys_num = _field_var.sys().number();
120  const auto var_num = _field_var.number();
121 
122  _solution.set(_current_elem->dof_number(sys_num, var_num, 0),
123  std::sqrt(value) / static_cast<Real>(n_flux_faces));
124  }
125 }
std::string name(const ElemQuality q)
const libMesh::FEType & feType() const
Get the type of finite element object.
static InputParameters validParams()
Definition: Indicator.C:21
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
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
unsigned int number() const
Get variable number coming from libMesh.
const MooseArray< Real > & _coord
The coordinate transformation.
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:1155
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const QBase *const & _qrule
The quadrature rule being used.
NumericVector< Number > & _solution
Definition: Indicator.h:71
bool _scale_by_flux_faces
Whether to scale the indicator value by the number of flux faces in an attempt to avoid penalizing in...
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...
virtual void computeIndicator() override
Computes the indicator for the current side.
const bool _use_displaced_mesh
Whether to use the displaced mesh.
Definition: Indicator.h:67
CONSTANT
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
InternalSideIndicatorBase(const InputParameters &parameters)
boundary_id_type BoundaryID
static InputParameters validParams()
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1149
unsigned int _qp
The current quadrature point.
MONOMIAL
static const BoundaryID InternalBndId
const Elem *const & _neighbor_elem
The neighbor element across from the current side.
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition: Coupleable.h:70
virtual void finalize() override
Can be overridden to do a final postprocessing of the indicator field.
const Elem *const & _current_elem
Current element under consideration.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MooseVariableFE< Real > & _field_var
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
virtual Real computeQpIntegral()=0
The virtual function you will want to override to compute error contributions.
bool hasBlocks(const SubdomainID id) const override
Returns whether the functor is defined on this block.
const DoFValue & dofValues() const override
dof values getters
virtual bool isVarFV() const =0
Whether or not the derived classes are acting on a finite volume variable or not. ...
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...
Definition: MooseBase.h:267
Interface for objects that needs scalar coupling capabilities.
const MooseArray< Real > & _JxW
The quadrature weight multiplied by the element Jacobian.
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 void set(const numeric_index_type i, const Number value)=0
virtual void add(const numeric_index_type i, const Number value)=0
SystemBase & sys()
Get the system this variable is part of.
Enhances Coupleable interface to also couple the values from neighbor elements.