www.mooseframework.org
ProjectMaterialProperties.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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
12 #include "Problem.h"
13 #include "FEProblem.h"
15 #include "MaterialData.h"
16 #include "Assembly.h"
17 #include "AuxKernel.h"
18 
19 #include "libmesh/threads.h"
20 #include "libmesh/elem.h"
21 
23  bool refine,
24  FEProblemBase & fe_problem,
25  MaterialPropertyStorage & material_props,
26  MaterialPropertyStorage & bnd_material_props,
27  std::vector<std::vector<std::unique_ptr<Assembly>>> & assembly)
29  _refine(refine),
30  _fe_problem(fe_problem),
31  _material_props(material_props),
32  _bnd_material_props(bnd_material_props),
33  _assembly(assembly),
34  _need_internal_side_material(false),
35  _materials(_fe_problem.getRegularMaterialsWarehouse()),
36  _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse())
37 {
38 }
39 
40 // Splitting Constructor
42  Threads::split split)
44  _refine(x._refine),
45  _fe_problem(x._fe_problem),
46  _material_props(x._material_props),
47  _bnd_material_props(x._bnd_material_props),
48  _assembly(x._assembly),
49  _need_internal_side_material(x._need_internal_side_material),
50  _materials(x._materials),
51  _discrete_materials(x._discrete_materials)
52 {
53 }
54 
56 
57 void
59 {
61 }
62 
63 void
65 {
66  // This check mirrors the check in ComputeMaterialsObjectThread::onElement as it must because it
67  // is possible that there are no materials on this element's subdomain, e.g. if we are doing
68  // mortar, in which case the properties will not have been resized in
69  // ComputeMaterialsObjectThread::onElement, and consequently if we were to proceed we would get
70  // bad access errors
71  if (!_materials.hasActiveBlockObjects(elem->subdomain_id(), _tid) &&
72  !_discrete_materials.hasActiveBlockObjects(elem->subdomain_id(), _tid))
73  return;
74 
75  _assembly[_tid][0]->reinit(elem);
76 
77  if (_refine)
78  {
79  if (_mesh.doingPRefinement())
80  {
81  const auto & p_refinement_map = _mesh.getPRefinementMap(*elem);
83  p_refinement_map,
84  *_assembly[_tid][0]->qRule(),
85  *_assembly[_tid][0]->qRuleFace(),
86  _tid,
87  *elem,
88  -1);
89  }
90  else
91  {
92  const std::vector<std::vector<QpMap>> & refinement_map =
93  _mesh.getRefinementMap(*elem, -1, -1, -1);
94 
97  refinement_map,
98  *_assembly[_tid][0]->qRule(),
99  *_assembly[_tid][0]->qRuleFace(),
100  _material_props, // Passing in the same properties to do volume to volume projection
101  _tid,
102  *elem,
103  -1,
104  -1,
105  -1); // Gets us volume projection
106  }
107  }
108  else
109  {
110  if (_mesh.doingPRefinement())
111  {
112  const auto & p_coarsening_map = _mesh.getPCoarseningMap(*elem);
114  p_coarsening_map,
115  *_assembly[_tid][0]->qRule(),
116  *_assembly[_tid][0]->qRuleFace(),
117  _tid,
118  *elem,
119  -1);
120  }
121  else
122  {
123  const std::vector<std::pair<unsigned int, QpMap>> & coarsening_map =
124  _mesh.getCoarseningMap(*elem, -1);
125 
126  _material_props.restrictStatefulProps(coarsening_map,
128  *_assembly[_tid][0]->qRule(),
129  *_assembly[_tid][0]->qRuleFace(),
130  _tid,
131  *elem,
132  -1);
133  }
134  }
135 }
136 
137 void
139  unsigned int side,
140  BoundaryID bnd_id,
141  const Elem * /*lower_d_elem = nullptr*/)
142 {
145  {
146  _assembly[_tid][0]->reinit(elem, side);
147 
148  if (_refine)
149  {
150  if (_mesh.doingPRefinement())
151  {
152  const auto & p_refinement_map = _mesh.getPRefinementSideMap(*elem);
154  p_refinement_map,
155  *_assembly[_tid][0]->qRule(),
156  *_assembly[_tid][0]->qRuleFace(),
157  _tid,
158  *elem,
159  side);
160  }
161  else
162  {
163  const std::vector<std::vector<QpMap>> & refinement_map =
164  _mesh.getRefinementMap(*elem, side, -1, side);
165 
168  refinement_map,
169  *_assembly[_tid][0]->qRule(),
170  *_assembly[_tid][0]->qRuleFace(),
171  _bnd_material_props, // Passing in the same properties to do side_to_side projection
172  _tid,
173  *elem,
174  side,
175  -1,
176  side); // Gets us side to side projection
177  }
178  }
179  else
180  {
181  if (_mesh.doingPRefinement())
182  {
183  const auto & p_coarsening_map = _mesh.getPCoarseningSideMap(*elem);
185  p_coarsening_map,
186  *_assembly[_tid][0]->qRule(),
187  *_assembly[_tid][0]->qRuleFace(),
188  _tid,
189  *elem,
190  side);
191  }
192  else
193  {
194  const std::vector<std::pair<unsigned int, QpMap>> & coarsening_map =
195  _mesh.getCoarseningMap(*elem, side);
196 
199  *_assembly[_tid][0]->qRule(),
200  *_assembly[_tid][0]->qRuleFace(),
201  _tid,
202  *elem,
203  side);
204  }
205  }
206  }
207 }
208 
209 void
210 ProjectMaterialProperties::onInternalSide(const Elem * elem, unsigned int /*side*/)
211 {
213  _refine) // If we're refining then we need to also project "internal" child sides.
214  {
215  mooseError("I'm pretty sure we're not handling stateful material property prolongation or "
216  "restriction correctly on internal sides");
217  for (unsigned int child = 0; child < elem->n_children(); child++)
218  {
219  const Elem * child_elem = elem->child_ptr(child);
220 
221  for (unsigned int side = 0; side < child_elem->n_sides(); side++)
222  {
223  if (!elem->is_child_on_side(child, side)) // Otherwise we already projected it
224  {
225  const std::vector<std::vector<QpMap>> & refinement_map =
226  _mesh.getRefinementMap(*elem, -1, child, side);
227 
230  refinement_map,
231  *_assembly[_tid][0]->qRule(),
232  *_assembly[_tid][0]->qRuleFace(),
233  _material_props, // Passing in the same properties to do side_to_side projection
234  _tid,
235  *elem,
236  -1,
237  child,
238  side); // Gets us volume to side projection
239  }
240  }
241  }
242  }
243 }
244 
245 void
247 {
248 }
const std::vector< QpMap > & getPCoarseningSideMap(const Elem &elem) const
Get the map describing for each side quadrature point (qp) on the coarse level which qp on the previo...
Definition: MooseMesh.C:4114
Base class for assembly-like calculations.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
ProjectMaterialProperties(bool refine, FEProblemBase &fe_problem, MaterialPropertyStorage &material_props, MaterialPropertyStorage &bnd_material_props, std::vector< std::vector< std::unique_ptr< Assembly >>> &assembly)
void prolongStatefulProps(processor_id_type pid, const std::vector< std::vector< QpMap >> &refinement_map, const QBase &qrule, const QBase &qrule_face, MaterialPropertyStorage &parent_material_props, const THREAD_ID tid, const Elem &elem, const int input_parent_side, const int input_child, const int input_child_side)
Creates storage for newly created elements from mesh Adaptivity.
void restrictStatefulProps(const std::vector< std::pair< unsigned int, QpMap >> &coarsening_map, const std::vector< const Elem *> &coarsened_element_children, const QBase &qrule, const QBase &qrule_face, const THREAD_ID tid, const Elem &elem, int input_side=-1)
Creates storage for newly created elements from mesh Adaptivity.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
const std::vector< std::pair< unsigned int, QpMap > > & getCoarseningMap(const Elem &elem, int input_side)
Get the coarsening map for a given element type.
Definition: MooseMesh.C:2326
const std::vector< std::vector< QpMap > > & getRefinementMap(const Elem &elem, int parent_side, int child, int child_side)
Get the refinement map for a given element type.
Definition: MooseMesh.C:2262
Stores the stateful material properties computed by materials.
MaterialPropertyStorage & _bnd_material_props
const MaterialWarehouse & _discrete_materials
Discrete materials warehouse.
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
These methods are used to determine whether stateful material properties need to be stored on interna...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
StoredRange< std::vector< const Elem * >::iterator, const Elem * > ConstElemPointerRange
Definition: MooseTypes.h:206
bool _refine
Whether or not you are projecting refinements. Set to false for coarsening.
const MaterialWarehouse & _materials
Materials warehouse.
MaterialPropertyStorage & _material_props
bool needSubdomainMaterialOnSide(SubdomainID subdomain_id, const THREAD_ID tid)
boundary_id_type BoundaryID
void updateStatefulPropsForPRefinement(const processor_id_type pid, const std::vector< QpMap > &p_refinement_map, const QBase &qrule, const QBase &qrule_face, const THREAD_ID tid, const Elem &elem, const int input_side)
Based on the p-refinement flag of elem, either prolong (for refinement) or restrict (for coarsening) ...
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
const std::vector< QpMap > & getPRefinementMap(const Elem &elem) const
Get the map describing for each volumetric quadrature point (qp) on the refined level which qp on the...
Definition: MooseMesh.C:4096
const std::vector< QpMap > & getPRefinementSideMap(const Elem &elem) const
Get the map describing for each side quadrature point (qp) on the refined level which qp on the previ...
Definition: MooseMesh.C:4102
tbb::split split
const std::vector< const Elem * > & coarsenedElementChildren(const Elem *elem) const
Get the newly removed children element ids for an element that was just coarsened.
Definition: MooseMesh.C:745
SubdomainID _subdomain
The subdomain for the current element.
void join(const ProjectMaterialProperties &)
void doingPRefinement(bool doing_p_refinement)
Indicate whether the kind of adaptivity we&#39;re doing is p-refinement.
Definition: MooseMesh.h:1325
processor_id_type processor_id() const
const std::vector< QpMap > & getPCoarseningMap(const Elem &elem) const
Get the map describing for each volumetric quadrature point (qp) on the coarse level which qp on the ...
Definition: MooseMesh.C:4108
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
std::vector< std::vector< std::unique_ptr< Assembly > > > & _assembly