https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeDiracThread.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 "ComputeDiracThread.h"
11
12// Moose Includes
13#include "ParallelUniqueId.h"
14#include "DiracKernel.h"
15#include "Problem.h"
16#include "NonlinearSystem.h"
17#include "MooseVariableFE.h"
18#include "Assembly.h"
19#include "ThreadedElementLoop.h"
20
21#include "libmesh/threads.h"
22
24 const std::set<TagID> & vector_tags,
25 const std::set<TagID> & matrix_tags,
26 Moose::ComputeType compute_type)
28 _compute_type(compute_type),
29 _nl(feproblem.currentNonlinearSystem()),
30 _vector_tags(vector_tags),
31 _matrix_tags(matrix_tags),
32 _dirac_kernels(_nl.getDiracKernelWarehouse())
33{
34}
35
36// Splitting Constructor
39 _compute_type(x._compute_type),
40 _nl(x._nl),
41 _vector_tags(x._vector_tags),
42 _matrix_tags(x._matrix_tags),
43 _dirac_kernels(x._dirac_kernels)
44{
45}
46
48
49void
51{
52 // Force TID=0 because we run this object _NON THREADED_
53 // Take this out if we ever get Dirac's working with threads!
54 _tid = 0;
55}
56
57void
59{
61
62 std::set<MooseVariableFEBase *> needed_moose_vars;
64
65 // Update material dependencies
66 std::unordered_set<unsigned int> needed_mat_props;
68
71
72 // The combined path always operates on the full suite of residual and Jacobian tags, so there's
73 // no need for (and no single tag set to do) tag-based warehouse selection
75 {
77 return;
78 }
79
80 const bool is_jacobian = _compute_type == Moose::ComputeType::Jacobian;
81 const std::set<TagID> & tags = is_jacobian ? _matrix_tags : _vector_tags;
82
83 // If users pass a empty vector or a full size of vector,
84 // we take all kernels
85 if (!tags.size() || tags.size() == _fe_problem.numMatrixTags())
87 // If we have one tag only, We call tag based storage
88 else if (tags.size() == 1)
89 _dirac_warehouse = is_jacobian
91 : &(_dirac_kernels.getVectorTagObjectWarehouse(*(tags.begin()), _tid));
92 // This one may be expensive, and hopefully we do not use it so often
93 else
96}
97
98void
100{
101 const bool has_dirac_kernels_on_elem = _fe_problem.reinitDirac(elem, _tid);
102 if (!has_dirac_kernels_on_elem)
103 return;
104
105 std::set<MooseVariableFEBase *> needed_moose_vars;
106 const auto & dkernels = _dirac_warehouse->getActiveObjects(_tid);
107
108 // Only call reinitMaterials() if one or more DiracKernels has
109 // actually called getMaterialProperty(). Loop over all the
110 // DiracKernels and check whether this is the case.
111 for (const auto & dirac_kernel : dkernels)
112 {
113 // If any of the DiracKernels have had getMaterialProperty()
114 // called, we need to reinit Materials.
115 if (dirac_kernel->getMaterialPropertyCalled())
116 {
117 _fe_problem.reinitMaterials(_subdomain, _tid, /*swap_stateful=*/false);
118 break;
119 }
120 }
121
122 for (const auto & dirac_kernel : dkernels)
123 {
124 if (!dirac_kernel->hasPointsOnElem(elem))
125 continue;
126
128 {
129 dirac_kernel->computeResidual();
130 continue;
131 }
133 {
134 dirac_kernel->computeResidualAndJacobian();
135 continue;
136 }
137
138 // Get a list of coupled variables from the SubProblem
139 const auto & coupling_entries =
140 dirac_kernel->subProblem().assembly(_tid, _nl.number()).couplingEntries();
141
142 // Loop over the list of coupled variable pairs
143 for (const auto & it : coupling_entries)
144 {
145 const MooseVariableFEBase * const ivariable = it.first;
146 const MooseVariableFEBase * const jvariable = it.second;
147
148 // A variant of the check that is in
149 // ComputeFullJacobianThread::computeJacobian(). We
150 // only want to call computeOffDiagJacobian() if both
151 // variables are active on this subdomain, and the
152 // off-diagonal variable actually has dofs.
153 if (dirac_kernel->variable().number() == ivariable->number() &&
154 ivariable->activeOnSubdomain(_subdomain) && jvariable->activeOnSubdomain(_subdomain) &&
155 (jvariable->numberOfDofs() > 0))
156 {
157 dirac_kernel->prepareShapes(jvariable->number());
158 dirac_kernel->computeOffDiagJacobian(jvariable->number());
159 }
160 }
161 }
162
163 // Note that we do not call swapBackMaterials() here as they were
164 // never swapped in the first place. This avoids messing up
165 // stored values of stateful material properties.
166}
167
168void
176
177void
183
184void
188
189void
191{
193 return;
194 const auto & console = _fe_problem.console();
195 console << "[DBG] Executing Dirac Kernels on " << _fe_problem.getCurrentExecuteOnFlag().name()
196 << std::endl;
197}
198
199void
201{
204 return;
205
206 const auto & dkernels = _dirac_warehouse->getActiveBlockObjects(_subdomain, _tid);
207 const auto & console = _fe_problem.console();
208 console << "[DBG] Ordering of DiracKernels on subdomain " << _subdomain << std::endl;
209 printExecutionOrdering<DiracKernelBase>(dkernels, false);
211}
StoredRange< std::set< const Elem * >::const_iterator, const Elem * > DistElemRange
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
virtual void pre() override
Called before the element range loop.
Moose::ComputeType _compute_type
MooseObjectTagWarehouse< DiracKernelBase > & _dirac_kernels
Storage for DiracKernel objects.
void join(const ComputeDiracThread &)
virtual void post() override
Called after the element range loop.
MooseObjectWarehouse< DiracKernelBase > * _dirac_warehouse
ComputeDiracThread(FEProblemBase &feproblem, const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, Moose::ComputeType compute_type)
const std::set< TagID > & _matrix_tags
NonlinearSystemBase & _nl
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
void printBlockExecutionInformation() const override
Output the order of execution of objects within the current subdomain.
const std::set< TagID > & _vector_tags
void printGeneralExecutionInformation() const override
Output a message indicating execution on this execution flag.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual bool reinitDirac(const Elem *elem, const THREAD_ID tid) override
Returns true if the Problem has Dirac kernels it needs to compute on elem.
virtual void addResidual(const THREAD_ID tid) override
virtual void addJacobian(const THREAD_ID tid) override
void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true)
void clearActiveMaterialProperties(const THREAD_ID tid)
Clear the active material properties.
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
void setActiveMaterialProperties(const std::unordered_set< unsigned int > &mat_prop_ids, const THREAD_ID tid)
Record and set the material properties required by the current computing thread.
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase * > &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
const std::string & name() const
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag.
MooseObjectWarehouse< T > & getMatrixTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has one of the given matrix tags.
MooseObjectWarehouse< T > & getVectorTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object at least has one of the given vector ta...
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag.
void updateVariableDependency(std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
void updateMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
Update material property dependency vector.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread.
virtual unsigned int numberOfDofs() const
Get the number of local DoFs.
unsigned int number() const
Get variable number coming from libMesh.
This class provides an interface for common operations on field variables of both FE and FV types wit...
bool activeOnSubdomain(SubdomainID subdomain) const
Is the variable active on the subdomain?
const ConsoleStream & console() const
Return console handle.
Definition Problem.h:48
virtual unsigned int numMatrixTags() const
The total number of tags.
Definition SubProblem.h:248
unsigned int number() const
Gets the number of this system.
SubdomainID _subdomain
The subdomain for the current element.
std::set< SubdomainID > _blocks_exec_printed
Keep track of which blocks were visited.
Base class for assembly-like calculations.
ComputeType
The type of nonlinear computation being performed.
Definition MooseTypes.h:835