www.mooseframework.org
ComputeGrainCenterUserObject.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 
10 #include "libmesh/quadrature.h"
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<ElementUserObject>();
17  params.addClassDescription("Userobject for calculating the grain volume and grain center");
18  params.addRequiredCoupledVarWithAutoBuild("etas", "var_name_base", "op_num", "order parameters");
19  return params;
20 }
21 
23  : ElementUserObject(parameters),
24  _ncrys(coupledComponents("etas")), // determine number of grains from the number of names passed
25  // in. Note this is the actual number -1
26  _vals(_ncrys), // Size variable arrays
27  _ncomp(4 * _ncrys),
28  _grain_data(_ncomp),
29  _grain_volumes(_ncrys),
30  _grain_centers(_ncrys)
31 {
32  for (unsigned int i = 0; i < _ncrys; ++i)
33  _vals[i] = &coupledValue("etas", i);
34 }
35 
36 void
38 {
39  for (unsigned int i = 0; i < _ncomp; ++i)
40  _grain_data[i] = 0;
41 }
42 
43 void
45 {
46  for (unsigned int i = 0; i < _ncrys; ++i)
47  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
48  {
49  _grain_data[4 * i + 0] += _JxW[_qp] * _coord[_qp] * (*_vals[i])[_qp];
50  _grain_data[4 * i + 1] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](0) * (*_vals[i])[_qp];
51  _grain_data[4 * i + 2] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](1) * (*_vals[i])[_qp];
52  _grain_data[4 * i + 3] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](2) * (*_vals[i])[_qp];
53  }
54 }
55 
56 void
58 {
59  gatherSum(_grain_data);
60 
61  for (unsigned int i = 0; i < _ncrys; ++i)
62  {
63  _grain_volumes[i] = _grain_data[4 * i + 0];
64  _grain_centers[i](0) = _grain_data[4 * i + 1] / _grain_volumes[i];
65  _grain_centers[i](1) = _grain_data[4 * i + 2] / _grain_volumes[i];
66  _grain_centers[i](2) = _grain_data[4 * i + 3] / _grain_volumes[i];
67  }
68 }
69 
70 void
72 {
73  const ComputeGrainCenterUserObject & pps = static_cast<const ComputeGrainCenterUserObject &>(y);
74  for (unsigned int i = 0; i < _ncomp; ++i)
75  _grain_data[i] += pps._grain_data[i];
76 }
77 
78 const std::vector<Real> &
80 {
81  return _grain_volumes;
82 }
83 
84 const std::vector<Point> &
86 {
87  return _grain_centers;
88 }
std::vector< Real > _grain_data
storing volumes and centers of all the grains
virtual void threadJoin(const UserObject &y)
This UserObject computes a volumes and centers of grains.
const std::vector< Real > & getGrainVolumes() const
const std::vector< Point > & getGrainCenters() const
InputParameters validParams< ComputeGrainCenterUserObject >()
ComputeGrainCenterUserObject(const InputParameters &parameters)
std::vector< const VariableValue * > _vals