https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NonlocalIntegratedBC.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#include "Assembly.h"
12#include "MooseVariableFE.h"
13#include "Problem.h"
14#include "SubProblem.h"
15#include "SystemBase.h"
16#include "MooseMesh.h"
17
18#include "libmesh/threads.h"
19#include "libmesh/quadrature.h"
20
27
29 : IntegratedBC(parameters)
30{
31 _mesh.errorIfDistributedMesh("NonlocalIntegratedBC");
32 mooseWarning("NonlocalIntegratedBC is a computationally expensive experimental capability used "
33 "only for integral terms.");
34}
35
36void
38{
40 for (_j = 0; _j < _phi.size();
41 _j++) // looping order for _i & _j are reversed for performance improvement
42 {
44 for (_i = 0; _i < _test.size(); _i++)
45 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
47 }
49
51 {
52 unsigned int rows = _local_ke.m();
53 DenseVector<Number> diag(rows);
54 for (unsigned int i = 0; i < rows; i++)
55 diag(i) = _local_ke(i, i);
56
57 for (const auto & var : _diag_save_in)
58 var->sys().solution().add_vector(diag, var->dofIndices());
59 }
60}
61
62void
64{
65 if (jvar_num == _var.number())
67 else
68 {
69 const auto & jvar = getVariable(jvar_num);
71
72 // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
73 // on the displaced mesh
74 auto phi_size = jvar.dofIndices().size();
75
76 for (_j = 0; _j < phi_size;
77 _j++) // looping order for _i & _j are reversed for performance improvement
78 {
79 getUserObjectJacobian(jvar_num, jvar.dofIndices()[_j]);
80 for (_i = 0; _i < _test.size(); _i++)
81 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
82 _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar.number());
83 }
85 }
86}
87
88void
90{
92 // compiling set of global IDs for the local DOFs on the element
93 std::set<dof_id_type> local_dofindices(_var.dofIndices().begin(), _var.dofIndices().end());
94 // storing the global IDs for all the DOFs of the variable
95 const std::vector<dof_id_type> & var_alldofindices = _var.allDofIndices();
96 unsigned int n_total_dofs = var_alldofindices.size();
97
98 for (_k = 0; _k < n_total_dofs;
99 _k++) // looping order for _i & _k are reversed for performance improvement
100 {
101 // eliminating the local components
102 auto it = local_dofindices.find(var_alldofindices[_k]);
103 if (it == local_dofindices.end())
104 {
105 getUserObjectJacobian(_var.number(), var_alldofindices[_k]);
106 // skip global DOFs that do not contribute to the jacobian
107 if (!globalDoFEnabled(_var, var_alldofindices[_k]))
108 continue;
109
110 for (_i = 0; _i < _test.size(); _i++)
111 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
112 _nonlocal_ke(_i, _k) +=
113 _JxW[_qp] * _coord[_qp] * computeQpNonlocalJacobian(var_alldofindices[_k]);
114 }
115 }
117}
118
119void
121{
122 if (jvar == _var.number())
124 else
125 {
128 // compiling set of global IDs for the local DOFs on the element
129 std::set<dof_id_type> local_dofindices(jv.dofIndices().begin(), jv.dofIndices().end());
130 // storing the global IDs for all the DOFs of the variable
131 const std::vector<dof_id_type> & jv_alldofindices = jv.allDofIndices();
132 unsigned int n_total_dofs = jv_alldofindices.size();
133
134 for (_k = 0; _k < n_total_dofs;
135 _k++) // looping order for _i & _k are reversed for performance improvement
136 {
137 // eliminating the local components
138 auto it = local_dofindices.find(jv_alldofindices[_k]);
139 if (it == local_dofindices.end())
140 {
141 getUserObjectJacobian(jvar, jv_alldofindices[_k]);
142 // skip global DOFs that do not contribute to the jacobian
143 if (!globalDoFEnabled(jv, jv_alldofindices[_k]))
144 continue;
145
146 for (_i = 0; _i < _test.size(); _i++)
147 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
148 _nonlocal_ke(_i, _k) += _JxW[_qp] * _coord[_qp] *
149 computeQpNonlocalOffDiagJacobian(jvar, jv_alldofindices[_k]);
150 }
151 }
153 }
154}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
const QBase *const & _qrule
active quadrature rule
unsigned int _qp
quadrature point index
const MooseArray< Real > & _JxW
transformed Jacobian weights
unsigned int _i
i-th, j-th index for enumerating test and shape functions
std::vector< MooseVariableFEBase * > _diag_save_in
const MooseArray< Real > & _coord
coordinate transformation
Base class for deriving any boundary condition of a integrated type.
MooseVariable & _var
static InputParameters validParams()
virtual Real computeQpJacobian()
Method for computing the diagonal Jacobian at quadrature points.
virtual Real computeQpOffDiagJacobian(unsigned int)
Method for computing an off-diagonal jacobian component at quadrature points.
const VariablePhiValue & _phi
shape function values (in QPs)
const VariableTestValue & _test
test function values (in QPs)
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition MooseMesh.C:3718
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
const std::vector< dof_id_type > & allDofIndices() const
Get all global dofindices for the variable.
unsigned int number() const
Get variable number coming from libMesh.
const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void computeJacobian() override
computeJacobian and computeQpOffDiagJacobian methods are almost same as IntegratedBC except for few a...
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-ivar-residual / d-jvar...
static InputParameters validParams()
virtual void getUserObjectJacobian(unsigned int, dof_id_type)
Optimization option for getting jocobinas from userobject once per dof.
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int, dof_id_type)
NonlocalIntegratedBC(const InputParameters &parameters)
virtual bool globalDoFEnabled(MooseVariableFEBase &, dof_id_type)
optimization option for executing nonlocal jacobian calculation only for nonzero elements
virtual Real computeQpNonlocalJacobian(dof_id_type)
Compute this IntegratedBC's contribution to the Jacobian corresponding to nolocal dof at the current ...
virtual void computeNonlocalOffDiagJacobian(unsigned int jvar) override
Computes Jacobian entries corresponding to nonlocal dofs of the jvar.
virtual void computeNonlocalJacobian() override
computeNonlocalJacobian and computeNonlocalOffDiagJacobian methods are introduced for providing the j...
THREAD_ID _tid
The thread ID for this kernel.
MooseMesh & _mesh
Reference to this Kernel's mesh object.
Assembly & _assembly
Reference to this Kernel's assembly object.
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
SystemBase & _sys
Reference to the EquationSystem object.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:91
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the active tags.
void accumulateTaggedNonlocalMatrix()
Nonlocal Jacobian blocks will be appended by adding the current nonlocal kernel Jacobian.
void prepareMatrixTagNonlocal(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing nonlocal element jacobian according to the active tags.
DenseMatrix< Number > _nonlocal_ke
Holds nonlocal Jacobian entries as they are accumulated by this Kernel.
unsigned int m() const