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 
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),
52  _field_var(_subproblem.getStandardVariable(_tid, name())),
53 
54  _current_elem(_assembly.elem()),
55  _neighbor_elem(_assembly.neighbor()),
56 
57  _current_side(_assembly.side()),
58  _current_side_elem(_assembly.sideElem()),
59 
60  _coord_sys(_assembly.coordSystem()),
61  _q_point(_assembly.qPointsFace()),
62  _qrule(_assembly.qRuleFace()),
63  _JxW(_assembly.JxWFace()),
64  _coord(_assembly.coordTransformation()),
65 
66  _boundary_id(parameters.get<BoundaryID>("_boundary_id")),
67 
68  _var(mooseVariableField()),
69  _scale_by_flux_faces(parameters.get<bool>("scale_by_flux_faces")),
70 
71  _u(_var.sln()),
72  _grad_u(_var.gradSln()),
73 
74  _normals(_assembly.normals()),
75 
76  _u_neighbor(_var.slnNeighbor()),
77  _grad_u_neighbor(_var.gradSlnNeighbor())
78 {
79  const std::vector<MooseVariableFieldBase *> & coupled_vars = getCoupledMooseVars();
80  for (const auto & var : coupled_vars)
82 
84 }
85 
86 void
88 {
89  Real sum = 0;
90 
91  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
92  sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();
93 
94  {
95  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
96 
99  }
100 }
101 
102 void
104 {
105  unsigned int n_flux_faces = 0;
106 
108  {
109  if (_var.isFV())
110  paramError("scale_by_flux_faces", "Unsupported at this time for finite volume variables");
111 
112  // Figure out the total number of sides contributing to the error.
113  // We'll scale by this so boundary elements are less penalized
114  for (unsigned int side = 0; side < _current_elem->n_sides(); side++)
115  if (_current_elem->neighbor_ptr(side) != nullptr)
116  n_flux_faces++;
117  }
118  else
119  n_flux_faces = 1;
120 
121  // The 0 is because CONSTANT MONOMIALS only have one coefficient per element...
123 
124  {
125  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
126  _solution.set(_field_var.nodalDofIndex(), std::sqrt(value) / static_cast<Real>(n_flux_faces));
127  }
128 }
std::string name(const ElemQuality q)
VarFieldType
Definition: MooseTypes.h:634
static InputParameters validParams()
Factory constructor initializes all internal references needed for indicator computation.
static InputParameters validParams()
Definition: Indicator.C:21
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
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:1147
virtual bool isFV() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
NumericVector< Number > & _solution
Definition: Indicator.h:68
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
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...
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)
MooseVariableField< Real > & _var
boundary_id_type BoundaryID
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
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.
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 ...
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition: Coupleable.h:69
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
const dof_id_type & nodalDofIndexNeighbor() const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const dof_id_type & nodalDofIndex() const override
const MooseArray< Real > & _coord
const DoFValue & dofValues() const override
dof values getters
MooseVariableField< Real > & mooseVariableField()
Return the MooseVariableField<T> object that this interface acts on.
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...
virtual void set(const numeric_index_type i, const Number value)=0
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void add(const numeric_index_type i, const Number value)=0
const MooseArray< Real > & _JxW
Enhances Coupleable interface to also couple the values from neighbor elements.
const Elem *const & _current_elem
const QBase *const & _qrule