Line data Source code
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 : // MOOSE includes
11 : #include "ComputeMaterialsObjectThread.h"
12 : #include "NonlinearSystem.h"
13 : #include "Problem.h"
14 : #include "FEProblem.h"
15 : #include "MaterialPropertyStorage.h"
16 : #include "MaterialData.h"
17 : #include "Assembly.h"
18 : #include "AuxKernel.h"
19 : #include "Material.h"
20 :
21 : #include "libmesh/threads.h"
22 : #include "libmesh/quadrature.h"
23 :
24 8805 : ComputeMaterialsObjectThread::ComputeMaterialsObjectThread(
25 : FEProblemBase & fe_problem,
26 : MaterialPropertyStorage & material_props,
27 : MaterialPropertyStorage & bnd_material_props,
28 : MaterialPropertyStorage & neighbor_material_props,
29 8805 : std::vector<std::vector<std::unique_ptr<Assembly>>> & assembly)
30 : : ThreadedElementLoop<ConstElemRange>(fe_problem),
31 8805 : _fe_problem(fe_problem),
32 8805 : _material_props(material_props),
33 8805 : _bnd_material_props(bnd_material_props),
34 8805 : _neighbor_material_props(neighbor_material_props),
35 17610 : _materials(_fe_problem.getRegularMaterialsWarehouse()),
36 8805 : _interface_materials(_fe_problem.getInterfaceMaterialsWarehouse()),
37 8805 : _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse()),
38 8805 : _assembly(assembly),
39 8805 : _need_internal_side_material(false),
40 8805 : _has_stateful_props(_material_props.hasStatefulProperties()),
41 8805 : _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
42 17610 : _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
43 : {
44 8805 : }
45 :
46 : // Splitting Constructor
47 596 : ComputeMaterialsObjectThread::ComputeMaterialsObjectThread(ComputeMaterialsObjectThread & x,
48 596 : Threads::split split)
49 : : ThreadedElementLoop<ConstElemRange>(x, split),
50 596 : _fe_problem(x._fe_problem),
51 596 : _material_props(x._material_props),
52 596 : _bnd_material_props(x._bnd_material_props),
53 596 : _neighbor_material_props(x._neighbor_material_props),
54 596 : _materials(x._materials),
55 596 : _interface_materials(x._interface_materials),
56 596 : _discrete_materials(x._discrete_materials),
57 596 : _assembly(x._assembly),
58 596 : _need_internal_side_material(x._need_internal_side_material),
59 1192 : _has_stateful_props(_material_props.hasStatefulProperties()),
60 596 : _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
61 1192 : _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
62 : {
63 596 : }
64 :
65 : void
66 44253 : ComputeMaterialsObjectThread::subdomainChanged()
67 : {
68 44253 : _need_internal_side_material = _fe_problem.needSubdomainMaterialOnSide(_subdomain, _tid);
69 44253 : _fe_problem.subdomainSetup(_subdomain, _tid);
70 :
71 44253 : std::set<MooseVariableFEBase *> needed_moose_vars;
72 44253 : _materials.updateVariableDependency(needed_moose_vars, _tid);
73 44253 : _discrete_materials.updateVariableDependency(needed_moose_vars, _tid);
74 44253 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
75 :
76 44253 : std::set<TagID> needed_fe_var_vector_tags;
77 44253 : _materials.updateBlockFEVariableCoupledVectorTagDependency(
78 44253 : _subdomain, needed_fe_var_vector_tags, _tid);
79 44253 : _discrete_materials.updateBlockFEVariableCoupledVectorTagDependency(
80 44253 : _subdomain, needed_fe_var_vector_tags, _tid);
81 44253 : _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
82 44253 : }
83 :
84 : void
85 1709640 : ComputeMaterialsObjectThread::onElement(const Elem * elem)
86 : {
87 1717122 : if (_materials.hasActiveBlockObjects(_subdomain, _tid) ||
88 7482 : _discrete_materials.hasActiveBlockObjects(_subdomain, _tid))
89 : {
90 1702458 : _fe_problem.prepare(elem, _tid);
91 1702458 : _fe_problem.reinitElem(elem, _tid);
92 :
93 1702458 : auto & material_data = _material_props.getMaterialData(_tid);
94 :
95 1702458 : unsigned int n_points = _assembly[_tid][0]->qRule()->n_points();
96 1702458 : material_data.resize(n_points);
97 :
98 1702458 : if (_has_stateful_props)
99 : {
100 265742 : if (_discrete_materials.hasActiveBlockObjects(_subdomain, _tid))
101 0 : _material_props.initStatefulProps(
102 0 : _tid, _discrete_materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
103 265742 : if (_materials.hasActiveBlockObjects(_subdomain, _tid))
104 265742 : _material_props.initStatefulProps(
105 265742 : _tid, _materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
106 : }
107 : }
108 1709640 : }
109 :
110 : void
111 347810 : ComputeMaterialsObjectThread::onBoundary(const Elem * elem,
112 : unsigned int side,
113 : BoundaryID bnd_id,
114 : const Elem * /*lower_d_elem = nullptr*/)
115 : {
116 347810 : if (_fe_problem.needBoundaryMaterialOnSide(bnd_id, _tid))
117 : {
118 111944 : _fe_problem.reinitElemFace(elem, side, _tid);
119 111944 : unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
120 :
121 111944 : _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
122 :
123 111944 : if (_has_bnd_stateful_props)
124 : {
125 : // Face Materials
126 3102 : if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
127 0 : _bnd_material_props.initStatefulProps(
128 : _tid,
129 0 : _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
130 : face_n_points,
131 : *elem,
132 : side);
133 3102 : if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
134 3102 : _bnd_material_props.initStatefulProps(
135 : _tid,
136 3102 : _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
137 : face_n_points,
138 : *elem,
139 : side);
140 :
141 : // Boundary Materials
142 3102 : if (_discrete_materials.hasActiveBoundaryObjects(bnd_id, _tid))
143 0 : _bnd_material_props.initStatefulProps(
144 0 : _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
145 3102 : if (_materials.hasActiveBoundaryObjects(bnd_id, _tid))
146 228 : _bnd_material_props.initStatefulProps(
147 228 : _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
148 : }
149 : }
150 347810 : }
151 :
152 : void
153 3447450 : ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
154 : {
155 3447450 : if (_need_internal_side_material)
156 : {
157 13159 : const Elem * neighbor = elem->neighbor_ptr(side);
158 :
159 13159 : _fe_problem.reinitElemNeighborAndLowerD(elem, side, _tid);
160 13159 : unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
161 13159 : _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
162 13159 : _neighbor_material_props.getMaterialData(_tid).resize(face_n_points);
163 :
164 13159 : if (_has_bnd_stateful_props)
165 : {
166 475 : if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
167 0 : _bnd_material_props.initStatefulProps(
168 : _tid,
169 0 : _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
170 : face_n_points,
171 : *elem,
172 : side);
173 475 : if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
174 475 : _bnd_material_props.initStatefulProps(
175 : _tid,
176 475 : _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
177 : face_n_points,
178 : *elem,
179 : side);
180 : }
181 :
182 13159 : unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
183 :
184 13159 : if (_has_neighbor_stateful_props)
185 : {
186 : // Neighbor Materials
187 456 : if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
188 228 : neighbor->subdomain_id(), _tid))
189 0 : _neighbor_material_props.initStatefulProps(
190 : _tid,
191 0 : _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
192 0 : neighbor->subdomain_id(), _tid),
193 : face_n_points,
194 : *elem,
195 : side);
196 228 : if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
197 : _tid))
198 228 : _neighbor_material_props.initStatefulProps(
199 : _tid,
200 228 : _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
201 228 : neighbor->subdomain_id(), _tid),
202 : face_n_points,
203 : *neighbor,
204 : neighbor_side);
205 : }
206 : }
207 3447450 : }
208 :
209 : void
210 9805 : ComputeMaterialsObjectThread::onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id)
211 : {
212 9805 : if (!_fe_problem.needInterfaceMaterialOnSide(bnd_id, _tid))
213 5274 : return;
214 :
215 4531 : _fe_problem.reinitElemFace(elem, side, _tid);
216 4531 : unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
217 :
218 4531 : _bnd_material_props.getMaterialData(_tid).resize(face_n_points);
219 4531 : _neighbor_material_props.getMaterialData(_tid).resize(face_n_points);
220 :
221 4531 : if (_has_bnd_stateful_props)
222 : {
223 : // Face Materials
224 587 : if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
225 0 : _bnd_material_props.initStatefulProps(
226 : _tid,
227 0 : _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
228 : face_n_points,
229 : *elem,
230 : side);
231 :
232 587 : if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
233 587 : _bnd_material_props.initStatefulProps(
234 : _tid,
235 587 : _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
236 : face_n_points,
237 : *elem,
238 : side);
239 :
240 : // Boundary Materials
241 587 : if (_discrete_materials.hasActiveBoundaryObjects(bnd_id, _tid))
242 0 : _bnd_material_props.initStatefulProps(
243 0 : _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
244 :
245 587 : if (_materials.hasActiveBoundaryObjects(bnd_id, _tid))
246 113 : _bnd_material_props.initStatefulProps(
247 113 : _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
248 : }
249 :
250 4531 : const Elem * neighbor = elem->neighbor_ptr(side);
251 4531 : unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
252 :
253 : // Do we have neighbor stateful properties or do we have stateful interface material properties?
254 : // If either then we need to reinit the neighbor, so at least at a minimum _neighbor_elem isn't
255 : // NULL!
256 9062 : if (neighbor->active() &&
257 4531 : (_has_neighbor_stateful_props ||
258 4057 : (_has_bnd_stateful_props && _interface_materials.hasActiveBoundaryObjects(bnd_id, _tid))))
259 493 : _fe_problem.reinitNeighbor(elem, side, _tid);
260 :
261 4531 : if (_has_neighbor_stateful_props && neighbor->active())
262 : {
263 : // Neighbor Materials
264 948 : if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
265 474 : neighbor->subdomain_id(), _tid))
266 0 : _neighbor_material_props.initStatefulProps(
267 : _tid,
268 0 : _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
269 0 : neighbor->subdomain_id(), _tid),
270 : face_n_points,
271 : *elem,
272 : side);
273 :
274 474 : if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
275 : _tid))
276 474 : _neighbor_material_props.initStatefulProps(
277 : _tid,
278 474 : _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(neighbor->subdomain_id(),
279 : _tid),
280 : face_n_points,
281 : *neighbor,
282 : neighbor_side);
283 : }
284 :
285 : // Interface Materials. Make sure we do these after neighbors
286 4531 : if (_has_bnd_stateful_props && _interface_materials.hasActiveBoundaryObjects(bnd_id, _tid))
287 151 : _bnd_material_props.initStatefulProps(
288 : _tid,
289 151 : _interface_materials.getActiveBoundaryObjects(bnd_id, _tid),
290 : face_n_points,
291 : *elem,
292 : side);
293 : }
294 :
295 : void
296 596 : ComputeMaterialsObjectThread::join(const ComputeMaterialsObjectThread & /*y*/)
297 : {
298 596 : }
299 :
300 : void
301 9401 : ComputeMaterialsObjectThread::post()
302 : {
303 9401 : _fe_problem.clearActiveElementalMooseVariables(_tid);
304 9401 : }
|