www.mooseframework.org
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
AverageGrainVolume Class Reference

Compute the average grain area in a polycrystal. More...

#include <AverageGrainVolume.h>

Inheritance diagram for AverageGrainVolume:
[legend]

Public Member Functions

 AverageGrainVolume (const InputParameters &parameters)
 
virtual void initialize () override
 
virtual void execute () override
 
virtual Real getValue () override
 

Protected Member Functions

void accumulateVolumes (const std::vector< unsigned int > &var_to_features, std::size_t libmesh_dbg_var(num_features))
 
Real computeIntegral (std::size_t var_index) const
 

Private Attributes

MooseMesh & _mesh
 A reference to the mesh. More...
 
Assembly & _assembly
 
std::vector< unsigned int > _static_var_to_feature
 
std::vector< const VariableValue * > _vals
 
std::vector< Real > _feature_volumes
 
const MooseArray< Point > & _q_point
 
QBase *& _qrule
 
const MooseArray< Real > & _JxW
 
const MooseArray< Real > & _coord
 
const FeatureFloodCount_feature_counter
 

Detailed Description

Compute the average grain area in a polycrystal.

Definition at line 25 of file AverageGrainVolume.h.

Constructor & Destructor Documentation

AverageGrainVolume::AverageGrainVolume ( const InputParameters &  parameters)

Definition at line 41 of file AverageGrainVolume.C.

42  : GeneralPostprocessor(parameters),
43  Coupleable(this, false),
44  MooseVariableDependencyInterface(),
45  _mesh(_subproblem.mesh()),
46  _assembly(_subproblem.assembly(0)),
47  _q_point(_assembly.qPoints()),
48  _qrule(_assembly.qRule()),
49  _JxW(_assembly.JxW()),
50  _coord(_assembly.coordTransformation()),
51  _feature_counter(isParamValid("feature_counter")
52  ? &getUserObject<FeatureFloodCount>("feature_counter")
53  : nullptr)
54 {
55  if (!_feature_counter)
56  {
57  if (isParamValid("variable") && isParamValid("grain_num"))
58  {
59  auto num_coupled_vars = coupledComponents("variable");
60  if (num_coupled_vars != getParam<unsigned int>("grain_num"))
61  mooseError("The number of grains must match the number of OPs if a feature_counter is not "
62  "supplied");
63 
64  _vals.resize(num_coupled_vars);
65  for (unsigned int i = 0; i < num_coupled_vars; ++i)
66  _vals[i] = &coupledValue("variable", i);
67 
68  _feature_volumes.resize(num_coupled_vars);
69 
70  // Build a reflexive map (ops map to grains directly)
71  _static_var_to_feature.resize(num_coupled_vars);
72  for (auto i = beginIndex(_static_var_to_feature); i < num_coupled_vars; ++i)
74  }
75  else
76  mooseError("Must supply either a feature_counter object or coupled variables and grain_num");
77  }
78  else
79  {
80  const auto & coupled_vars = _feature_counter->getCoupledVars();
81  _vals.reserve(coupled_vars.size());
82 
83  for (auto & coupled_var : coupled_vars)
84  _vals.emplace_back(&coupled_var->sln());
85 
86  addMooseVariableDependency(coupled_vars);
87  }
88 }
std::vector< unsigned int > _static_var_to_feature
const FeatureFloodCount * _feature_counter
const MooseArray< Point > & _q_point
const MooseArray< Real > & _coord
std::vector< Real > _feature_volumes
const MooseArray< Real > & _JxW
const std::vector< MooseVariable * > & getCoupledVars() const
Returns a const vector to the coupled variable pointers.
MooseMesh & _mesh
A reference to the mesh.
std::vector< const VariableValue * > _vals

Member Function Documentation

void AverageGrainVolume::accumulateVolumes ( const std::vector< unsigned int > &  var_to_features,
std::size_t   libmesh_dbg_varnum_features 
)
protected

Definition at line 123 of file AverageGrainVolume.C.

Referenced by execute().

125 {
126  for (auto var_index = beginIndex(var_to_features); var_index < var_to_features.size();
127  ++var_index)
128  {
129  // Only sample "active" variables
130  if (var_to_features[var_index] != FeatureFloodCount::invalid_id)
131  {
132  auto feature_id = var_to_features[var_index];
133  mooseAssert(feature_id < num_features, "Feature ID out of range");
134  auto integral_value = computeIntegral(var_index);
135 
136  _feature_volumes[feature_id] += integral_value;
137  }
138  }
139 }
std::vector< Real > _feature_volumes
static const unsigned int invalid_id
Real computeIntegral(std::size_t var_index) const
Real AverageGrainVolume::computeIntegral ( std::size_t  var_index) const
protected

Definition at line 142 of file AverageGrainVolume.C.

Referenced by accumulateVolumes().

143 {
144  Real sum = 0;
145 
146  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
147  sum += _JxW[qp] * _coord[qp] * (*_vals[var_index])[qp];
148 
149  return sum;
150 }
const MooseArray< Real > & _coord
const MooseArray< Real > & _JxW
std::vector< const VariableValue * > _vals
void AverageGrainVolume::execute ( )
overridevirtual

Definition at line 103 of file AverageGrainVolume.C.

104 {
105  auto num_features = _feature_volumes.size();
106 
107  const auto end = _mesh.getMesh().active_local_elements_end();
108  for (auto el = _mesh.getMesh().active_local_elements_begin(); el != end; ++el)
109  {
110  const Elem * elem = *el;
111  _fe_problem.prepare(elem, 0);
112  _fe_problem.reinitElem(elem, 0);
113 
114  const std::vector<unsigned int> & var_to_feature_ptr =
117 
118  accumulateVolumes(var_to_feature_ptr, num_features);
119  }
120 }
std::vector< unsigned int > _static_var_to_feature
const FeatureFloodCount * _feature_counter
void accumulateVolumes(const std::vector< unsigned int > &var_to_features, std::size_t libmesh_dbg_var(num_features))
std::vector< Real > _feature_volumes
virtual const std::vector< unsigned int > & getVarToFeatureVector(dof_id_type elem_id) const
Returns a list of active unique feature ids for a particular element.
MooseMesh & _mesh
A reference to the mesh.
Real AverageGrainVolume::getValue ( )
overridevirtual

Definition at line 153 of file AverageGrainVolume.C.

154 {
155  _communicator.sum(_feature_volumes);
156 
157  Real total_volume = 0;
158  for (auto & volume : _feature_volumes)
159  total_volume += volume;
160 
161  return total_volume / _feature_volumes.size();
162 }
std::vector< Real > _feature_volumes
void AverageGrainVolume::initialize ( )
overridevirtual

Definition at line 91 of file AverageGrainVolume.C.

92 {
93  auto num_features = _feature_volumes.size();
94 
95  // When using FeatureFloodCount, the number of grains may not be fixed. Resize as appropriate
96  if (_feature_counter)
97  num_features = _feature_counter->getTotalFeatureCount();
98 
99  _feature_volumes.assign(num_features, 0);
100 }
const FeatureFloodCount * _feature_counter
std::vector< Real > _feature_volumes
virtual std::size_t getTotalFeatureCount() const
Returns the total feature count (active and inactive ids, useful for sizing vectors) ...

Member Data Documentation

Assembly& AverageGrainVolume::_assembly
private

Definition at line 43 of file AverageGrainVolume.h.

const MooseArray<Real>& AverageGrainVolume::_coord
private

Definition at line 50 of file AverageGrainVolume.h.

Referenced by computeIntegral().

const FeatureFloodCount* AverageGrainVolume::_feature_counter
private

Definition at line 51 of file AverageGrainVolume.h.

Referenced by AverageGrainVolume(), execute(), and initialize().

std::vector<Real> AverageGrainVolume::_feature_volumes
private
const MooseArray<Real>& AverageGrainVolume::_JxW
private

Definition at line 49 of file AverageGrainVolume.h.

Referenced by computeIntegral().

MooseMesh& AverageGrainVolume::_mesh
private

A reference to the mesh.

Definition at line 42 of file AverageGrainVolume.h.

Referenced by execute().

const MooseArray<Point>& AverageGrainVolume::_q_point
private

Definition at line 47 of file AverageGrainVolume.h.

QBase*& AverageGrainVolume::_qrule
private

Definition at line 48 of file AverageGrainVolume.h.

Referenced by computeIntegral().

std::vector<unsigned int> AverageGrainVolume::_static_var_to_feature
private

Definition at line 44 of file AverageGrainVolume.h.

Referenced by AverageGrainVolume(), and execute().

std::vector<const VariableValue *> AverageGrainVolume::_vals
private

Definition at line 45 of file AverageGrainVolume.h.

Referenced by AverageGrainVolume(), and computeIntegral().


The documentation for this class was generated from the following files: