https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeFullJacobianThread.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 "NonlinearSystem.h"
12#include "FEProblem.h"
13#include "KernelBase.h"
14#include "IntegratedBCBase.h"
15#include "HDGKernel.h"
16#include "DGKernel.h"
17#include "InterfaceKernelBase.h"
18#include "MooseVariableFE.h"
19#include "MooseVariableScalar.h"
20#include "NonlocalKernel.h"
22#include "FVElementalKernel.h"
23#include "libmesh/threads.h"
24
26 const std::set<TagID> & tags)
27 : ComputeJacobianThread(fe_problem, tags)
28{
29}
30
31// Splitting Constructor
37
39
40void
42{
44 for (const auto & it : ce)
45 {
46 MooseVariableFieldBase & ivariable = *(it.first);
47 MooseVariableFieldBase & jvariable = *(it.second);
48
49 if (ivariable.isFV())
50 continue;
51
52 unsigned int ivar = ivariable.number();
53 unsigned int jvar = jvariable.number();
54
55 if (ivariable.activeOnSubdomain(_subdomain) && jvariable.activeOnSubdomain(_subdomain) &&
57 {
58 // only if there are dofs for j-variable (if it is subdomain restricted var, there may not be
59 // any)
60 const auto & kernels = _tag_kernels->getActiveVariableBlockObjects(ivar, _subdomain, _tid);
61 for (const auto & kernel : kernels)
62 if ((kernel->variable().number() == ivar) && kernel->isImplicit())
63 {
64 kernel->prepareShapes(jvar);
65 kernel->computeOffDiagJacobian(jvar);
66 }
67 }
68 }
69
72 {
74 for (const auto & it : cne)
75 {
76 MooseVariableFieldBase & ivariable = *(it.first);
77 MooseVariableFieldBase & jvariable = *(it.second);
78
79 if (ivariable.isFV())
80 continue;
81
82 unsigned int ivar = ivariable.number();
83 unsigned int jvar = jvariable.number();
84
85 if (ivariable.activeOnSubdomain(_subdomain) && jvariable.activeOnSubdomain(_subdomain) &&
87 {
88 const auto & kernels = _tag_kernels->getActiveVariableBlockObjects(ivar, _subdomain, _tid);
89 for (const auto & kernel : kernels)
90 {
91 std::shared_ptr<NonlocalKernel> nonlocal_kernel =
92 std::dynamic_pointer_cast<NonlocalKernel>(kernel);
93 if (nonlocal_kernel)
94 if ((kernel->variable().number() == ivar) && kernel->isImplicit())
95 {
96 kernel->prepareShapes(jvar);
97 kernel->computeNonlocalOffDiagJacobian(jvar);
98 }
99 }
100 }
101 }
102 }
103
104 const std::vector<MooseVariableScalar *> & scalar_vars = _nl.getScalarVariables(_tid);
105 if (scalar_vars.size() > 0)
106 {
107 // go over nl-variables (non-scalar)
108 const std::vector<MooseVariableFieldBase *> & vars = _nl.getVariables(_tid);
109 for (const auto & ivariable : vars)
110 if (ivariable->activeOnSubdomain(_subdomain) > 0 &&
112 {
113 // for each variable get the list of active kernels
114 const auto & kernels =
116 for (const auto & kernel : kernels)
117 if (kernel->isImplicit())
118 {
119 // now, get the list of coupled scalar vars and compute their off-diag jacobians
120 const auto & coupled_scalar_vars = kernel->getCoupledMooseScalarVars();
121
122 // Do: dvar / dscalar_var, only want to process only nl-variables (not aux ones), and
123 // only if this coupling is being used by the preconditioner (otherwise the value is
124 // zero)
125 for (const auto & jvariable : coupled_scalar_vars)
126 if (_nl.hasScalarVariable(jvariable->name()) &&
127 _fe_problem.areCoupled(ivariable->number(), jvariable->number(), _nl.number()))
128 kernel->computeOffDiagJacobianScalar(jvariable->number());
129 }
130 }
131 }
132
133 if (_fe_problem.haveFV())
134 for (auto fv_kernel : _fv_kernels)
135 if (fv_kernel->isImplicit())
136 fv_kernel->computeOffDiagJacobian();
137}
138
139void
141{
142 auto & ce = _fe_problem.couplingEntries(_tid, _nl.number());
143 for (const auto & it : ce)
144 {
145 MooseVariableFieldBase & ivariable = *(it.first);
146 MooseVariableFieldBase & jvariable = *(it.second);
147
148 // We don't currently support coupling with FV variables
149 if (ivariable.isFV() || jvariable.isFV())
150 continue;
151
152 const auto ivar = ivariable.number();
153 const auto jvar = jvariable.number();
154
155 if (!ivariable.activeOnSubdomain(_subdomain))
156 continue;
157
158 // only if there are dofs for j-variable (if it is subdomain restricted var, there may not be
159 // any)
160 if (lower_d_elem)
161 {
162 auto lower_d_subdomain = lower_d_elem->subdomain_id();
163 if (!jvariable.activeOnSubdomain(_subdomain) &&
164 !jvariable.activeOnSubdomain(lower_d_subdomain))
165 continue;
166 }
167 else
168 {
169 if (!jvariable.activeOnSubdomain(_subdomain))
170 continue;
171 }
172
174 continue;
175
176 const auto & bcs = _ibc_warehouse->getActiveBoundaryObjects(bnd_id, _tid);
177 for (const auto & bc : bcs)
178 if (bc->shouldApply() && bc->variable().number() == ivar && bc->isImplicit())
179 {
180 bc->prepareShapes(jvar);
181 bc->computeOffDiagJacobian(jvar);
182 }
183 }
184
187 {
189 for (const auto & it : cne)
190 {
191 MooseVariableFieldBase & ivariable = *(it.first);
192 MooseVariableFieldBase & jvariable = *(it.second);
193
194 if (ivariable.isFV())
195 continue;
196
197 unsigned int ivar = ivariable.number();
198 unsigned int jvar = jvariable.number();
199
200 if (ivariable.activeOnSubdomain(_subdomain) && jvariable.activeOnSubdomain(_subdomain) &&
202 {
203 const std::vector<std::shared_ptr<IntegratedBCBase>> & integrated_bcs =
205 for (const auto & integrated_bc : integrated_bcs)
206 {
207 std::shared_ptr<NonlocalIntegratedBC> nonlocal_integrated_bc =
208 std::dynamic_pointer_cast<NonlocalIntegratedBC>(integrated_bc);
209 if (nonlocal_integrated_bc)
210 if ((integrated_bc->variable().number() == ivar) && integrated_bc->isImplicit())
211 {
212 integrated_bc->prepareShapes(jvar);
213 integrated_bc->computeNonlocalOffDiagJacobian(jvar);
214 }
215 }
216 }
217 }
218 }
219
220 const std::vector<MooseVariableScalar *> & scalar_vars = _nl.getScalarVariables(_tid);
221 if (scalar_vars.size() > 0)
222 {
223 // go over nl-variables (non-scalar)
224 const std::vector<MooseVariableFieldBase *> & vars = _nl.getVariables(_tid);
225 for (const auto & ivar : vars)
226 if (ivar->activeOnSubdomain(_subdomain) > 0 &&
228 {
229 // for each variable get the list of active kernels
230 const auto & bcs = _ibc_warehouse->getActiveBoundaryObjects(bnd_id, _tid);
231 for (const auto & bc : bcs)
232 if (bc->variable().number() == ivar->number() && bc->isImplicit())
233 {
234 // now, get the list of coupled scalar vars and compute their off-diag jacobians
235 const std::vector<MooseVariableScalar *> coupled_scalar_vars =
236 bc->getCoupledMooseScalarVars();
237
238 // Do: dvar / dscalar_var, only want to process only nl-variables (not aux ones), and
239 // only if this coupling is being used by the preconditioner (otherwise the value is
240 // zero)
241 for (const auto & jvar : coupled_scalar_vars)
242 if (_nl.hasScalarVariable(jvar->name()) &&
243 _fe_problem.areCoupled(ivar->number(), jvar->number(), _nl.number()))
244 bc->computeOffDiagJacobianScalar(jvar->number());
245 }
246 }
247 }
248}
249
250void
252{
254 {
255 const auto & ce = _fe_problem.couplingEntries(_tid, _nl.number());
256 for (const auto & it : ce)
257 {
258 MooseVariableFieldBase & ivariable = *(it.first);
259 MooseVariableFieldBase & jvariable = *(it.second);
260
261 if (ivariable.isFV())
262 continue;
263
264 unsigned int ivar = ivariable.number();
265 unsigned int jvar = jvariable.number();
266
267 const auto & int_ks = _ik_warehouse->getActiveBoundaryObjects(bnd_id, _tid);
268 for (const auto & interface_kernel : int_ks)
269 {
270 if (!interface_kernel->isImplicit())
271 continue;
272
273 interface_kernel->prepareShapes(jvar);
274 interface_kernel->prepareNeighborShapes(jvar);
275
276 if (interface_kernel->variable().number() == ivar)
277 interface_kernel->computeElementOffDiagJacobian(jvar);
278
279 if (interface_kernel->neighborVariable().number() == ivar)
280 interface_kernel->computeNeighborOffDiagJacobian(jvar);
281 }
282 }
283 }
284}
285
286void
288{
290 {
291 const auto & ce = _fe_problem.couplingEntries(_tid, _nl.number());
292 for (const auto & it : ce)
293 {
294 MooseVariableFieldBase & ivariable = *(it.first);
295 MooseVariableFieldBase & jvariable = *(it.second);
296
297 if (ivariable.isFV())
298 continue;
299
300 unsigned int ivar = ivariable.number();
301 unsigned int jvar = jvariable.number();
302
303 const auto & dgks = _dg_warehouse->getActiveBlockObjects(_subdomain, _tid);
304 for (const auto & dg : dgks)
305 {
306 // this check may skip some couplings...
307 if (dg->variable().number() == ivar && dg->isImplicit() &&
308 dg->hasBlocks(neighbor->subdomain_id()) &&
309 (jvariable.activeOnSubdomain(_subdomain) ||
311 {
312 dg->prepareShapes(jvar);
313 dg->prepareNeighborShapes(jvar);
314 dg->computeOffDiagJacobian(jvar);
315 }
316 }
317 }
318 }
319}
320
321void
323{
325 "We should not be called if we have no active HDG kernels");
326 for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid))
327 {
328 mooseAssert(
329 hdg_kernel->hasBlocks(_subdomain),
330 "We queried the warehouse for active blocks on this subdomain, so this better be active");
331 mooseAssert(
333 "We should have set a valid neighbor subdomain ID if we made it in side this method");
334 if (hdg_kernel->hasBlocks(_neighbor_subdomain))
335 hdg_kernel->computeJacobianOnSide();
336 }
337}
boundary_id_type BoundaryID
char ** vars
ComputeFullJacobianThread(FEProblemBase &fe_problem, const std::set< TagID > &tags)
virtual void computeOnInternalFace() override
virtual void computeOnElement() override
virtual void computeOnInterface(BoundaryID bnd_id) override
virtual void computeOnBoundary(BoundaryID bnd_id, const Elem *lower_d_elem) override
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual bool haveFV() const override
returns true if this problem includes/needs finite volume functionality.
bool areCoupled(const unsigned int ivar, const unsigned int jvar, const unsigned int nl_sys_num) const
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & nonlocalCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
virtual MooseMesh & mesh() override
virtual bool checkNonlocalCouplingRequirement() const override
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
const std::set< SubdomainID > & interiorLowerDBlocks() const
Definition MooseMesh.h:1550
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
Methods for checking/getting variable kernels for a variable and SubdomainID.
const std::vector< std::shared_ptr< T > > & getActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
bool activeOnSubdomains(const std::set< SubdomainID > &subdomains) const
Is the variable active on the subdomains?
unsigned int number() const
Get variable number coming from libMesh.
bool activeOnSubdomain(SubdomainID subdomain) const
Is the variable active on the subdomain?
This class provides an interface for common operations on field variables of both FE and FV types wit...
MooseObjectWarehouse< InterfaceKernelBase > * _ik_warehouse
std::vector< FVElementalKernel * > _fv_kernels
Current subdomain FVElementalKernels.
NonlinearSystemBase & _nl
Reference to the underlying NonlinearSystemBase.
MooseObjectWarehouse< DGKernelBase > * _dg_warehouse
MooseObjectWarehouse< HDGKernel > * _hdg_warehouse
MooseObjectWarehouse< KernelBase > * _tag_kernels
MooseObjectWarehouse< IntegratedBCBase > * _ibc_warehouse
unsigned int number() const
Gets the number of this system.
const std::vector< MooseVariableFieldBase * > & getVariables(THREAD_ID tid)
Definition SystemBase.h:779
virtual bool hasScalarVariable(const std::string &var_name) const
Definition SystemBase.C:873
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition SystemBase.h:786
SubdomainID _subdomain
The subdomain for the current element.
SubdomainID _neighbor_subdomain
The subdomain for the current neighbor.
const SubdomainID INVALID_BLOCK_ID
Definition MooseTypes.C:20