www.mooseframework.org
InternalSideIndicator.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "InternalSideIndicator.h"
16 
17 // MOOSE includes
18 #include "Assembly.h"
19 #include "MooseTypes.h"
20 #include "MooseVariable.h"
21 #include "Problem.h"
22 #include "SubProblem.h"
23 #include "SystemBase.h"
24 
25 #include "libmesh/dof_map.h"
26 #include "libmesh/dense_vector.h"
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/dense_subvector.h"
29 #include "libmesh/libmesh_common.h"
30 #include "libmesh/quadrature.h"
31 
33 
34 template <>
37 {
39  params.addRequiredParam<VariableName>(
40  "variable", "The name of the variable that this side indicator applies to");
41  params.addParam<bool>("scale_by_flux_faces",
42  false,
43  "Whether or not to scale the error values by "
44  "the number of flux faces. This attempts to "
45  "not penalize elements on boundaries for "
46  "having less neighbors.");
47 
49  return params;
50 }
51 
53  : Indicator(parameters),
54  NeighborCoupleable(this, false, false),
55  ScalarCoupleable(this),
56  NeighborMooseVariableInterface(this, false),
57  _field_var(_sys.getVariable(_tid, name())),
58 
59  _current_elem(_assembly.elem()),
60  _neighbor_elem(_assembly.neighbor()),
61 
62  _current_side(_assembly.side()),
63  _current_side_elem(_assembly.sideElem()),
64 
65  _coord_sys(_assembly.coordSystem()),
66  _q_point(_assembly.qPointsFace()),
67  _qrule(_assembly.qRuleFace()),
68  _JxW(_assembly.JxWFace()),
69  _coord(_assembly.coordTransformation()),
70 
71  _boundary_id(parameters.get<BoundaryID>("_boundary_id")),
72 
73  _var(_subproblem.getVariable(_tid, parameters.get<VariableName>("variable"))),
74  _scale_by_flux_faces(parameters.get<bool>("scale_by_flux_faces")),
75 
76  _u(_var.sln()),
77  _grad_u(_var.gradSln()),
78 
79  _normals(_field_var.normals()),
80 
81  _u_neighbor(_var.slnNeighbor()),
82  _grad_u_neighbor(_var.gradSlnNeighbor())
83 {
84  const std::vector<MooseVariable *> & coupled_vars = getCoupledMooseVars();
85  for (const auto & var : coupled_vars)
87 
89 }
90 
91 void
93 {
94  Real sum = 0;
95 
96  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
97  sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();
98 
99  {
100  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
101 
102  _solution.add(_field_var.nodalDofIndex(), sum * _current_elem->hmax());
104  }
105 }
106 
107 void
109 {
110  unsigned int n_flux_faces = 0;
111 
113  {
114  // Figure out the total number of sides contributing to the error.
115  // We'll scale by this so boundary elements are less penalized
116  for (unsigned int side = 0; side < _current_elem->n_sides(); side++)
117  if (_current_elem->neighbor_ptr(side) != nullptr)
118  n_flux_faces++;
119  }
120  else
121  n_flux_faces = 1;
122 
123  // The 0 is because CONSTANT MONOMIALS only have one coefficient per element...
124  Real value = _field_var.nodalSln()[0];
125 
126  {
127  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
128  _solution.set(_field_var.nodalDofIndex(), std::sqrt(value) / static_cast<Real>(n_flux_faces));
129  }
130 }
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
const std::vector< MooseVariable * > & getCoupledMooseVars() const
Get the list of coupled variables.
Definition: Coupleable.h:63
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addMooseVariableDependency(MooseVariable *var)
Call this function to add the passed in MooseVariable as a variable that this object depends on...
NumericVector< Number > & _solution
Definition: Indicator.h:76
dof_id_type & nodalDofIndexNeighbor()
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...
InputParameters validParams< InternalSideIndicator >()
dof_id_type & nodalDofIndex()
Enhances MooseVariableInterface interface provide values from neighbor elements.
MooseVariable * mooseVariable()
Get the variable that this object is using.
virtual void finalize() override
Can be overridden to do a final postprocessing of the indicator field.
const Elem *& _neighbor_elem
The neighboring element.
InternalSideIndicator(const InputParameters &parameters)
Factory constructor initializes all internal references needed for indicator computation.
InputParameters validParams< Indicator >()
Definition: Indicator.C:27
virtual void computeIndicator() override
Computes the indicator for the current side.
const VariableValue & nodalSln()
virtual const VariableValue & value()
The value of the variable this object is operating on.
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...
const MooseArray< Real > & _JxW
Enhances Coupleable interface to also couple the values from neighbor elements.
boundary_id_type BoundaryID
Definition: MooseTypes.h:75