https://mooseframework.inl.gov
ComputeGrainCenterUserObject.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 
11 
12 #include "libmesh/quadrature.h"
13 
16 {
18  params.addClassDescription("Userobject for calculating the grain volumes and grain centers");
19  params.addRequiredCoupledVarWithAutoBuild("etas", "var_name_base", "op_num", "order parameters");
20  return params;
21 }
22 
24  : ElementUserObject(parameters),
25  _ncrys(coupledComponents("etas")), // determine number of grains from the number of names passed
26  // in. Note this is the actual number -1
27  _vals(coupledValues("etas")),
28  _ncomp(4 * _ncrys),
29  _grain_data(_ncomp),
30  _grain_volumes(_ncrys),
31  _grain_centers(_ncrys)
32 {
33 }
34 
35 void
37 {
38  for (unsigned int i = 0; i < _ncomp; ++i)
39  _grain_data[i] = 0;
40 }
41 
42 void
44 {
45  for (unsigned int i = 0; i < _ncrys; ++i)
46  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
47  {
48  _grain_data[4 * i + 0] += _JxW[_qp] * _coord[_qp] * (*_vals[i])[_qp];
49  _grain_data[4 * i + 1] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](0) * (*_vals[i])[_qp];
50  _grain_data[4 * i + 2] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](1) * (*_vals[i])[_qp];
51  _grain_data[4 * i + 3] += _JxW[_qp] * _coord[_qp] * _q_point[_qp](2) * (*_vals[i])[_qp];
52  }
53 }
54 
55 void
57 {
59 
60  for (unsigned int i = 0; i < _ncrys; ++i)
61  {
62  _grain_volumes[i] = _grain_data[4 * i + 0];
63  _grain_centers[i](0) = _grain_data[4 * i + 1] / _grain_volumes[i];
64  _grain_centers[i](1) = _grain_data[4 * i + 2] / _grain_volumes[i];
65  _grain_centers[i](2) = _grain_data[4 * i + 3] / _grain_volumes[i];
66  }
67 }
68 
69 void
71 {
72  const auto & pps = static_cast<const ComputeGrainCenterUserObject &>(y);
73  for (unsigned int i = 0; i < _ncomp; ++i)
74  _grain_data[i] += pps._grain_data[i];
75 }
76 
77 const std::vector<Real> &
79 {
80  return _grain_volumes;
81 }
82 
83 const std::vector<Point> &
85 {
86  return _grain_centers;
87 }
std::vector< Real > _grain_data
storing volumes and centers of all the grains
virtual void threadJoin(const UserObject &y)
const MooseArray< Point > & _q_point
const MooseArray< Real > & _coord
static InputParameters validParams()
This UserObject computes a volumes and centers of grains.
const std::vector< double > y
const std::vector< Real > & getGrainVolumes() const
const std::vector< const VariableValue * > _vals
void gatherSum(T &value)
const std::vector< Point > & getGrainCenters() const
const QBase *const & _qrule
void addRequiredCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
const MooseArray< Real > & _JxW
ComputeGrainCenterUserObject(const InputParameters &parameters)
void addClassDescription(const std::string &doc_string)