www.mooseframework.org
InternalSideIndicator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "InternalSideIndicator.h"
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 
29 template <>
32 {
34  params.addRequiredParam<VariableName>(
35  "variable", "The name of the variable that this side indicator applies to");
36  params.addParam<bool>("scale_by_flux_faces",
37  false,
38  "Whether or not to scale the error values by "
39  "the number of flux faces. This attempts to "
40  "not penalize elements on boundaries for "
41  "having less neighbors.");
42 
44  return params;
45 }
46 
48  : Indicator(parameters),
49  NeighborCoupleable(this, false, false),
50  ScalarCoupleable(this),
53  _field_var(_subproblem.getStandardVariable(_tid, name())),
54 
55  _current_elem(_assembly.elem()),
56  _neighbor_elem(_assembly.neighbor()),
57 
58  _current_side(_assembly.side()),
59  _current_side_elem(_assembly.sideElem()),
60 
61  _coord_sys(_assembly.coordSystem()),
62  _q_point(_assembly.qPointsFace()),
63  _qrule(_assembly.qRuleFace()),
64  _JxW(_assembly.JxWFace()),
65  _coord(_assembly.coordTransformation()),
66 
67  _boundary_id(parameters.get<BoundaryID>("_boundary_id")),
68 
69  _var(_subproblem.getStandardVariable(_tid, parameters.get<VariableName>("variable"))),
70  _scale_by_flux_faces(parameters.get<bool>("scale_by_flux_faces")),
71 
72  _u(_var.sln()),
73  _grad_u(_var.gradSln()),
74 
75  _normals(_assembly.normals()),
76 
77  _u_neighbor(_var.slnNeighbor()),
78  _grad_u_neighbor(_var.gradSlnNeighbor())
79 {
80  const std::vector<MooseVariableFEBase *> & coupled_vars = getCoupledMooseVars();
81  for (const auto & var : coupled_vars)
83 
85 }
86 
87 void
89 {
90  Real sum = 0;
91 
92  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
93  sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();
94 
95  {
96  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
97 
98  _solution.add(_field_var.nodalDofIndex(), sum * _current_elem->hmax());
100  }
101 }
102 
103 void
105 {
106  unsigned int n_flux_faces = 0;
107 
109  {
110  // Figure out the total number of sides contributing to the error.
111  // We'll scale by this so boundary elements are less penalized
112  for (unsigned int side = 0; side < _current_elem->n_sides(); side++)
113  if (_current_elem->neighbor_ptr(side) != nullptr)
114  n_flux_faces++;
115  }
116  else
117  n_flux_faces = 1;
118 
119  // The 0 is because CONSTANT MONOMIALS only have one coefficient per element...
120  Real value = _field_var.dofValues()[0];
121 
122  {
123  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
124  _solution.set(_field_var.nodalDofIndex(), std::sqrt(value) / static_cast<Real>(n_flux_faces));
125  }
126 }
VarFieldType
Definition: MooseTypes.h:488
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...
virtual Real computeQpIntegral()=0
The virtual function you will want to override to compute error contributions.
static const BoundaryID InternalBndId
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
NumericVector< Number > & _solution
Definition: Indicator.h:70
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 addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
InputParameters validParams< InternalSideIndicator >()
MooseVariableFE< Real > * mooseVariable() const
Get the variable that this object is using.
Enhances MooseVariableInterface interface provide values from neighbor elements.
virtual void finalize() override
Can be overridden to do a final postprocessing of the indicator field.
InternalSideIndicator(const InputParameters &parameters)
Factory constructor initializes all internal references needed for indicator computation.
boundary_id_type BoundaryID
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
InputParameters validParams< Indicator >()
Definition: Indicator.C:22
virtual void computeIndicator() override
Computes the indicator for the current side.
virtual const OutputTools< Real >::VariableValue & value()
The value of the variable this object is operating on.
const Elem *const & _neighbor_elem
The neighboring element.
const dof_id_type & nodalDofIndexNeighbor() const override
const dof_id_type & nodalDofIndex() const override
const std::vector< MooseVariableFEBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition: Coupleable.h:90
const MooseArray< Real > & _coord
Interface for objects that needs scalar coupling capabilities.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
Definition: Moose.h:112
const MooseArray< Real > & _JxW
Enhances Coupleable interface to also couple the values from neighbor elements.
const MooseArray< Number > & dofValues() override
Returns dof solution on element.
const Elem *const & _current_elem
const QBase *const & _qrule