https://mooseframework.inl.gov
DGKernelBase.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 
10 #include "DGKernelBase.h"
11 #include "MooseVariable.h"
12 #include "Problem.h"
13 #include "SubProblem.h"
14 #include "SystemBase.h"
15 #include "MaterialData.h"
16 #include "ParallelUniqueId.h"
17 
18 #include "libmesh/dof_map.h"
19 #include "libmesh/dense_vector.h"
20 #include "libmesh/numeric_vector.h"
21 #include "libmesh/dense_subvector.h"
22 #include "libmesh/libmesh_common.h"
23 #include "libmesh/quadrature.h"
24 
27 {
32  params.addParam<bool>("use_displaced_mesh",
33  false,
34  "Whether or not this object should use the "
35  "displaced mesh for computation. Note that in "
36  "the case this is true but no displacements "
37  "are provided in the Mesh block the "
38  "undisplaced mesh will still be used.");
39  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
40 
41  params.addParam<std::vector<AuxVariableName>>(
42  "save_in",
43  {},
44  "The name of auxiliary variables to save this Kernel's residual contributions to. "
45  " Everything about that variable must match everything about this variable (the "
46  "type, what blocks it's on, etc.)");
47  params.addParam<std::vector<AuxVariableName>>(
48  "diag_save_in",
49  {},
50  "The name of auxiliary variables to save this Kernel's diagonal Jacobian "
51  "contributions to. Everything about that variable must match everything "
52  "about this variable (the type, what blocks it's on, etc.)");
53  params.addParamNamesToGroup("diag_save_in save_in", "Advanced");
54 
55  // DG Kernels always need one layer of ghosting.
56  params.addRelationshipManager("ElementSideNeighborLayers",
60 
61  params.addParam<std::vector<BoundaryName>>(
62  "exclude_boundary", "The internal side sets to be excluded from this kernel.");
63  params.registerBase("DGKernel");
64  params.registerSystemAttributeName("DGKernel");
65 
66  return params;
67 }
68 
69 // Static mutex definitions
72 
74  : NeighborResidualObject(parameters),
75  BlockRestrictable(this),
76  BoundaryRestrictable(this, false), // false for _not_ nodal
78  TwoMaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
79  ElementIDInterface(this),
80  _current_elem(_assembly.elem()),
81  _current_elem_volume(_assembly.elemVolume()),
82 
83  _neighbor_elem(_assembly.neighbor()),
84  _neighbor_elem_volume(_assembly.neighborVolume()),
85 
86  _current_side(_assembly.side()),
87  _current_side_elem(_assembly.sideElem()),
88  _current_side_volume(_assembly.sideElemVolume()),
89 
90  _coord_sys(_assembly.coordSystem()),
91  _q_point(_assembly.qPointsFace()),
92  _qrule(_assembly.qRuleFace()),
93  _JxW(_assembly.JxWFace()),
94  _coord(_assembly.coordTransformation()),
95  _normals(_assembly.normals()),
96 
97  _save_in_strings(parameters.get<std::vector<AuxVariableName>>("save_in")),
98  _diag_save_in_strings(parameters.get<std::vector<AuxVariableName>>("diag_save_in"))
99 {
100  // Gather information on broken boundaries
101  std::vector<BoundaryName> bnd = isParamValid("exclude_boundary")
102  ? getParam<std::vector<BoundaryName>>("exclude_boundary")
103  : std::vector<BoundaryName>(0);
104  auto bnd_ids = _mesh.getBoundaryIDs(bnd);
105 
106  // check if the broken boundary ids are valid
107  auto & valid_ids = _mesh.meshSidesetIds();
108  std::vector<BoundaryName> diff;
109  for (unsigned int i = 0; i < bnd_ids.size(); ++i)
110  if (valid_ids.find(bnd_ids[i]) == valid_ids.end())
111  diff.push_back(bnd[i]);
112  if (!diff.empty())
113  {
114  auto msg = "DGKernel '" + name() +
115  "' contains the following boundary names that do not exist on the mesh: " +
116  Moose::stringify(diff, ", ");
117  paramError("exclude_boundary", msg);
118  }
119 
120  _excluded_boundaries.insert(bnd_ids.begin(), bnd_ids.end());
121 }
122 
123 void
125 {
126  if (!excludeBoundary())
127  {
129 
130  // Compute the residual for this element
132 
133  // Compute the residual for the neighbor
135  }
136 }
137 
138 void
140 {
141  if (!excludeBoundary())
142  {
144 
145  // Compute element-element Jacobian
147 
148  // Compute element-neighbor Jacobian
150 
151  // Compute neighbor-element Jacobian
153 
154  // Compute neighbor-neighbor Jacobian
156  }
157 }
158 
159 void
160 DGKernelBase::computeOffDiagJacobian(const unsigned int jvar_num)
161 {
162  if (!excludeBoundary())
163  {
164  const auto & jvar = getVariable(jvar_num);
165 
166  if (jvar_num == variable().number())
167  computeJacobian();
168  else
169  {
170  precalculateOffDiagJacobian(jvar_num);
171 
172  // Compute element-element Jacobian
174 
175  // Compute element-neighbor Jacobian
177 
178  // Compute neighbor-element Jacobian
180 
181  // Compute neighbor-neighbor Jacobian
183  }
184  }
185 }
186 
187 bool
189 {
190  if (_excluded_boundaries.empty())
191  return false;
192 
193  auto boundary_ids = _mesh.getBoundaryIDs(_current_elem, _current_side);
194  for (auto bid : boundary_ids)
195  if (_excluded_boundaries.find(bid) != _excluded_boundaries.end())
196  return true;
197 
198  // make sure we will also break on the neighboring side
199  unsigned int neighbor_side = _neighbor_elem->which_neighbor_am_i(_current_elem);
200  boundary_ids = _mesh.getBoundaryIDs(_neighbor_elem, neighbor_side);
201  for (auto bid : boundary_ids)
202  if (_excluded_boundaries.find(bid) != _excluded_boundaries.end())
203  return true;
204 
205  return false;
206 }
207 
208 void
209 DGKernelBase::prepareShapes(const unsigned int var_num)
210 {
212 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-residual / d-jvar...
Definition: DGKernelBase.C:160
std::set< BoundaryID > _excluded_boundaries
Broken boundaries.
Definition: DGKernelBase.h:148
static InputParameters validParams()
Factory constructor initializes all internal references needed for residual computation.
Definition: DGKernelBase.C:26
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
static InputParameters validParams()
const std::set< BoundaryID > & meshSidesetIds() const
Returns a read-only reference to the set of sidesets currently present in the Mesh.
Definition: MooseMesh.C:3178
virtual void precalculateOffDiagJacobian(unsigned int)
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
virtual void precalculateResidual()
DGKernelBase(const InputParameters &parameters)
Definition: DGKernelBase.C:73
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
virtual void computeJacobian() override
Computes the jacobian for the current side.
Definition: DGKernelBase.C:139
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
THREAD_ID _tid
The thread ID for this kernel.
virtual void computeElemNeighResidual(Moose::DGResidualType type)=0
Computes the residual for this element or the neighbor.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
static InputParameters validParams()
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual void precalculateJacobian()
void prepareShapes(unsigned int var_num) override final
Prepare shape functions.
Definition: DGKernelBase.C:209
SubProblem & _subproblem
Reference to this kernel&#39;s SubProblem.
bool excludeBoundary() const
Check current element if it contains broken boundary.
Definition: DGKernelBase.C:188
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 ...
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
static Threads::spin_mutex _resid_vars_mutex
Definition: DGKernelBase.h:140
static InputParameters validParams()
This is a base class for objects that can provide residual contributions for both local and neighbor ...
virtual void computeResidual() override
Computes the residual for the current side.
Definition: DGKernelBase.C:124
const Elem *const & _current_elem
Current element.
Definition: DGKernelBase.h:84
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
const unsigned int & _current_side
Current side.
Definition: DGKernelBase.h:96
This interface is designed for DGKernel, InternalSideUserObject, InterfaceUserObject, where material properties on a side of both its primary side (face) and its secondary side (neighbor) all required.
const Elem *const & _neighbor_elem
The neighboring element.
Definition: DGKernelBase.h:90
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 const MooseVariableBase & variable() const =0
Returns the variable that this object operates on.
virtual void computeElemNeighJacobian(Moose::DGJacobianType type)=0
Computes the element/neighbor-element/neighbor Jacobian.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
virtual void prepareFaceShapes(unsigned int var, const THREAD_ID tid)=0
static Threads::spin_mutex _jacoby_vars_mutex
Definition: DGKernelBase.h:141
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
virtual void computeOffDiagElemNeighJacobian(Moose::DGJacobianType type, const MooseVariableFEBase &jvar)=0
Computes the element-element off-diagonal Jacobian.