https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
74 if (_field_var.feType() != libMesh::FEType(CONSTANT, MONOMIAL))
75 mooseError("Only constant monomial variables for the internal side indicator are supported");
76}
77
78void
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
96void
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
116 Real value = _field_var.dofValues()[0];
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}
boundary_id_type BoundaryID
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition Coupleable.h:84
static InputParameters validParams()
Definition Indicator.C:21
const bool _use_displaced_mesh
Whether to use the displaced mesh.
Definition Indicator.h:67
NumericVector< Number > & _solution
Definition Indicator.h:71
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 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...
const Elem *const & _current_elem
Current element under consideration.
bool _scale_by_flux_faces
Whether to scale the indicator value by the number of flux faces in an attempt to avoid penalizing in...
unsigned int _qp
The current quadrature point.
const MooseArray< Real > & _JxW
The quadrature weight multiplied by the element Jacobian.
virtual bool isVarFV() const =0
Whether or not the derived classes are acting on a finite volume variable or not.
const MooseArray< Real > & _coord
The coordinate transformation.
const Elem *const & _neighbor_elem
The neighbor element across from the current side.
static InputParameters validParams()
virtual Real computeQpIntegral()=0
The virtual function you will want to override to compute error contributions.
MooseVariableFE< Real > & _field_var
virtual void finalize() override
Can be overridden to do a final postprocessing of the indicator field.
static const BoundaryID InternalBndId
const QBase *const & _qrule
The quadrature rule being used.
virtual void computeIndicator() override
Computes the indicator for the current side.
InternalSideIndicatorBase(const InputParameters &parameters)
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
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:271
const libMesh::FEType & feType() const
Get the type of finite element object.
SystemBase & sys()
Get the system this variable is part of.
unsigned int number() const
Get variable number coming from libMesh.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
const DofValues & dofValues() const override
dof values getters
bool hasBlocks(const SubdomainID id) const override
Returns whether the functor is defined on this block.
Enhances Coupleable interface to also couple the values from neighbor elements.
Interface for objects that needs scalar coupling capabilities.
unsigned int number() const
Gets the number of this system.
virtual void set(const numeric_index_type i, const T value)=0
virtual void add(const numeric_index_type i, const T value)=0