www.mooseframework.org
DiscreteNucleationMap.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 #include "MooseMesh.h"
10 
11 #include "libmesh/quadrature.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<ElementUserObject>();
18  params.addClassDescription("Generates a spatial smoothed map of all nucleation sites with the "
19  "data of the DiscreteNucleationInserter for use by the "
20  "DiscreteNucleation material.");
21  params.addParam<Real>("radius", 0.0, "Radius for the inserted nuclei");
22  params.addParam<Real>("int_width", 0.0, "Nucleus interface width for smooth nuclei");
23  params.addRequiredParam<UserObjectName>("inserter", "DiscreteNucleationInserter user object");
24  params.addCoupledVar("periodic",
25  "Use the periodicity settings of this variable to populate the grain map");
26  MultiMooseEnum setup_options(SetupInterface::getExecuteOptions());
27  // the mapping needs to run at timestep begin, which is after the adaptivity
28  // run of the previous timestep.
29  setup_options = "timestep_begin";
30  params.set<MultiMooseEnum>("execute_on") = setup_options;
31  return params;
32 }
33 
34 DiscreteNucleationMap::DiscreteNucleationMap(const InputParameters & parameters)
35  : ElementUserObject(parameters),
36  _mesh_changed(false),
37  _inserter(getUserObject<DiscreteNucleationInserter>("inserter")),
38  _periodic(isCoupled("periodic") ? coupled("periodic") : -1),
39  _radius(getParam<Real>("radius")),
40  _int_width(getParam<Real>("int_width")),
41  _nucleus_list(_inserter.getNucleusList())
42 {
43  _zero_map.assign(_fe_problem.getMaxQps(), 0.0);
44 }
45 
46 void
48 {
50  {
51  _rebuild_map = true;
52  _nucleus_map.clear();
53  }
54  else
55  _rebuild_map = false;
56 
57  _mesh_changed = false;
58 }
59 
60 void
62 {
63  if (_rebuild_map)
64  {
65  // reserve space for each quadrature point in the element
66  _elem_map.assign(_qrule->n_points(), 0);
67 
68  // store a random number for each quadrature point
69  unsigned int active_nuclei = 0;
70  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
71  {
72  Real r, rmin = std::numeric_limits<Real>::max();
73 
74  // find the distance to the closest nucleus
75  for (unsigned i = 0; i < _nucleus_list.size(); ++i)
76  {
77  // use a non-periodic or periodic distance
78  r = _periodic < 0
79  ? (_q_point[qp] - _nucleus_list[i].second).norm()
80  : _mesh.minPeriodicDistance(_periodic, _q_point[qp], _nucleus_list[i].second);
81  if (r < rmin)
82  rmin = r;
83  }
84 
85  // compute intensity value with smooth interface
86  Real value = 0.0;
87  if (rmin <= _radius - _int_width / 2.0) // Inside circle
88  {
89  active_nuclei++;
90  value = 1.0;
91  }
92  else if (rmin < _radius + _int_width / 2.0) // Smooth interface
93  {
94  Real int_pos = (rmin - _radius + _int_width / 2.0) / _int_width;
95  active_nuclei++;
96  value = (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
97  }
98  _elem_map[qp] = value;
99  }
100 
101  // if the map is not empty insert it
102  if (active_nuclei > 0)
103  _nucleus_map.insert(
104  std::pair<dof_id_type, std::vector<Real>>(_current_elem->id(), _elem_map));
105  }
106 }
107 
108 void
110 {
111  // if the map needs to be updated we merge the maps from all threads
112  if (_rebuild_map)
113  {
114  const DiscreteNucleationMap & uo = static_cast<const DiscreteNucleationMap &>(y);
115  _nucleus_map.insert(uo._nucleus_map.begin(), uo._nucleus_map.end());
116  }
117 }
118 
119 void
121 {
122  _mesh_changed = true;
123 }
124 
125 const std::vector<Real> &
126 DiscreteNucleationMap::nuclei(const Elem * elem) const
127 {
128  NucleusMap::const_iterator i = _nucleus_map.find(elem->id());
129 
130  // if no entry in the map was found the element contains no nucleus
131  if (i == _nucleus_map.end())
132  return _zero_map;
133 
134  return i->second;
135 }
This UserObject maintains a per QP map that indicates if a nucleus is present or not.
bool _mesh_changed
Did the mesh change since the last execution of this PP?
virtual void threadJoin(const UserObject &y)
int _periodic
variable number to use for minPeriodicDistance calls (i.e. use the periodicity of this variable) ...
const Real _int_width
Nucleus interface width.
const DiscreteNucleationInserter & _inserter
UserObject that manages nucleus insertin and deletion.
DiscreteNucleationMap(const InputParameters &parameters)
This UserObject manages the insertion and expiration of nuclei in the simulation domain it manages a ...
std::vector< Real > _zero_map
Dummy map for elements without nuclei.
const Real _radius
Nucleus radius.
std::vector< Real > _elem_map
Buffer for building the per QP map.
bool _rebuild_map
Do we need to rebuild the map during this timestep?
const DiscreteNucleationInserter::NucleusList & _nucleus_list
list of nuclei maintained bu the inserter object
InputParameters validParams< DiscreteNucleationMap >()
const std::vector< Real > & nuclei(const Elem *) const