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 27 of file AverageGrainVolume.h.

Constructor & Destructor Documentation

◆ AverageGrainVolume()

AverageGrainVolume::AverageGrainVolume ( const InputParameters &  parameters)

Definition at line 45 of file AverageGrainVolume.C.

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

Member Function Documentation

◆ accumulateVolumes()

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

Definition at line 124 of file AverageGrainVolume.C.

Referenced by execute().

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

◆ computeIntegral()

Real AverageGrainVolume::computeIntegral ( std::size_t  var_index) const
protected

Definition at line 143 of file AverageGrainVolume.C.

Referenced by accumulateVolumes().

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

◆ execute()

void AverageGrainVolume::execute ( )
overridevirtual

Definition at line 107 of file AverageGrainVolume.C.

108 {
109  auto num_features = _feature_volumes.size();
110  for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
111  {
112  _fe_problem.prepare(elem, 0);
113  _fe_problem.reinitElem(elem, 0);
114 
115  const std::vector<unsigned int> & var_to_feature_ptr =
118 
119  accumulateVolumes(var_to_feature_ptr, num_features);
120  }
121 }
std::vector< unsigned int > _static_var_to_feature
const FeatureFloodCount * _feature_counter
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.
void accumulateVolumes(const std::vector< unsigned int > &var_to_features, std::size_t libmesh_dbg_var(num_features))
std::vector< Real > _feature_volumes
MooseMesh & _mesh
A reference to the mesh.

◆ getValue()

Real AverageGrainVolume::getValue ( )
overridevirtual

Definition at line 154 of file AverageGrainVolume.C.

155 {
156  _communicator.sum(_feature_volumes);
157 
158  Real total_volume = 0;
159  for (auto & volume : _feature_volumes)
160  total_volume += volume;
161 
162  unsigned int active_features =
164 
165  return total_volume / active_features;
166 }
const FeatureFloodCount * _feature_counter
std::size_t getNumberActiveFeatures() const
Return the number of active features.
std::vector< Real > _feature_volumes

◆ initialize()

void AverageGrainVolume::initialize ( )
overridevirtual

Definition at line 95 of file AverageGrainVolume.C.

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

Member Data Documentation

◆ _assembly

Assembly& AverageGrainVolume::_assembly
private

Definition at line 45 of file AverageGrainVolume.h.

◆ _coord

const MooseArray<Real>& AverageGrainVolume::_coord
private

Definition at line 52 of file AverageGrainVolume.h.

Referenced by computeIntegral().

◆ _feature_counter

const FeatureFloodCount* AverageGrainVolume::_feature_counter
private

Definition at line 53 of file AverageGrainVolume.h.

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

◆ _feature_volumes

std::vector<Real> AverageGrainVolume::_feature_volumes
private

◆ _JxW

const MooseArray<Real>& AverageGrainVolume::_JxW
private

Definition at line 51 of file AverageGrainVolume.h.

Referenced by computeIntegral().

◆ _mesh

MooseMesh& AverageGrainVolume::_mesh
private

A reference to the mesh.

Definition at line 44 of file AverageGrainVolume.h.

Referenced by execute().

◆ _q_point

const MooseArray<Point>& AverageGrainVolume::_q_point
private

Definition at line 49 of file AverageGrainVolume.h.

◆ _qrule

QBase*& AverageGrainVolume::_qrule
private

Definition at line 50 of file AverageGrainVolume.h.

Referenced by computeIntegral().

◆ _static_var_to_feature

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

Definition at line 46 of file AverageGrainVolume.h.

Referenced by AverageGrainVolume(), and execute().

◆ _vals

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

Definition at line 47 of file AverageGrainVolume.h.

Referenced by AverageGrainVolume(), and computeIntegral().


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