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

This VectorPostprocessor is intended to be used to calculate accurate volumes from the FeatureFloodCount and/or GrainTracker objects. More...

#include <FeatureVolumeVectorPostprocessor.h>

Inheritance diagram for FeatureVolumeVectorPostprocessor:
[legend]

Public Member Functions

 FeatureVolumeVectorPostprocessor (const InputParameters &parameters)
 
virtual void initialize () override
 
virtual void execute () override
 
virtual void finalize () override
 
Real getFeatureVolume (unsigned int feature_id) const
 Returns the volume for the given grain number. More...
 

Protected Attributes

const bool _single_feature_per_elem
 A Boolean indicating how the volume is calculated. More...
 
const bool _output_centroids
 
const FeatureFloodCount_feature_counter
 A reference to the feature flood count object. More...
 
VectorPostprocessorValue & _var_num
 
VectorPostprocessorValue & _feature_volumes
 
VectorPostprocessorValue & _intersects_bounds
 

Private Member Functions

void accumulateVolumes (const Elem *elem, const std::vector< unsigned int > &var_to_features, std::size_t num_features)
 Add volume contributions to one or entries in the feature volume vector. More...
 
Real computeIntegral (std::size_t var_index) const
 Calculate the integral value of the passed in variable (index) More...
 

Private Attributes

const std::vector< MooseVariableFEBase * > & _vars
 
std::vector< const VariableValue * > _coupled_sln
 
MooseMesh & _mesh
 
Assembly & _assembly
 
const MooseArray< Point > & _q_point
 
QBase *& _qrule
 
const MooseArray< Real > & _JxW
 
const MooseArray< Real > & _coord
 

Detailed Description

This VectorPostprocessor is intended to be used to calculate accurate volumes from the FeatureFloodCount and/or GrainTracker objects.

It is a GeneralVectorPostProcessor instead of the more natural elemental kind so that dependency resolution will work properly when an AuxVariable is not depending on the FeatureFloodCount object. It obtains the coupled variables from the FeatureFloodCount object so that there's one less thing for the user of this class to worry about.

Definition at line 33 of file FeatureVolumeVectorPostprocessor.h.

Constructor & Destructor Documentation

◆ FeatureVolumeVectorPostprocessor()

FeatureVolumeVectorPostprocessor::FeatureVolumeVectorPostprocessor ( const InputParameters &  parameters)

Definition at line 44 of file FeatureVolumeVectorPostprocessor.C.

46  : GeneralVectorPostprocessor(parameters),
47  MooseVariableDependencyInterface(),
48  _single_feature_per_elem(getParam<bool>("single_feature_per_element")),
49  _output_centroids(getParam<bool>("output_centroids")),
50  _feature_counter(getUserObject<FeatureFloodCount>("flood_counter")),
51  _var_num(declareVector("var_num")),
52  _feature_volumes(declareVector("feature_volumes")),
53  _intersects_bounds(declareVector("intersects_bounds")),
55  _mesh(_subproblem.mesh()),
56  _assembly(_subproblem.assembly(_tid)),
57  _q_point(_assembly.qPoints()),
58  _qrule(_assembly.qRule()),
59  _JxW(_assembly.JxW()),
60  _coord(_assembly.coordTransformation())
61 {
62  addMooseVariableDependency(_vars);
63 
64  _coupled_sln.reserve(_vars.size());
65  for (auto & var : _feature_counter.getCoupledVars())
66  _coupled_sln.push_back(&var->sln());
67 }
const std::vector< MooseVariableFEBase * > & _vars
const std::vector< MooseVariable * > & getCoupledVars() const
Returns a const vector to the coupled variable pointers.
const FeatureFloodCount & _feature_counter
A reference to the feature flood count object.
std::vector< const VariableValue * > _coupled_sln
const bool _single_feature_per_elem
A Boolean indicating how the volume is calculated.
const std::vector< MooseVariableFEBase * > & getFECoupledVars() const
Returns a const vector to the coupled MooseVariableFEBase pointers.

Member Function Documentation

◆ accumulateVolumes()

void FeatureVolumeVectorPostprocessor::accumulateVolumes ( const Elem *  elem,
const std::vector< unsigned int > &  var_to_features,
std::size_t  num_features 
)
private

Add volume contributions to one or entries in the feature volume vector.

Definition at line 144 of file FeatureVolumeVectorPostprocessor.C.

Referenced by execute().

148 {
149  unsigned int dominant_feature_id = FeatureFloodCount::invalid_id;
150  Real max_var_value = std::numeric_limits<Real>::lowest();
151 
152  for (auto var_index = beginIndex(var_to_features); var_index < var_to_features.size();
153  ++var_index)
154  {
155  // Only sample "active" variables
156  if (var_to_features[var_index] != FeatureFloodCount::invalid_id)
157  {
158  auto feature_id = var_to_features[var_index];
159  mooseAssert(feature_id < num_features, "Feature ID out of range");
160  auto integral_value = computeIntegral(var_index);
161 
162  // Compute volumes in a simplistic but domain conservative fashion
164  {
165  if (integral_value > max_var_value)
166  {
167  // Update the current dominant feature and associated value
168  max_var_value = integral_value;
169  dominant_feature_id = feature_id;
170  }
171  }
172  // Solution based volume calculation (integral value)
173  else
174  _feature_volumes[feature_id] += integral_value;
175  }
176  }
177 
178  // Accumulate the entire element volume into the dominant feature. Do not use the integral value
179  if (_single_feature_per_elem && dominant_feature_id != FeatureFloodCount::invalid_id)
180  _feature_volumes[dominant_feature_id] += elem->volume();
181 }
static const unsigned int invalid_id
const bool _single_feature_per_elem
A Boolean indicating how the volume is calculated.
Real computeIntegral(std::size_t var_index) const
Calculate the integral value of the passed in variable (index)

◆ computeIntegral()

Real FeatureVolumeVectorPostprocessor::computeIntegral ( std::size_t  var_index) const
private

Calculate the integral value of the passed in variable (index)

Definition at line 184 of file FeatureVolumeVectorPostprocessor.C.

Referenced by accumulateVolumes().

185 {
186  Real sum = 0;
187 
188  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
189  sum += _JxW[qp] * _coord[qp] * (*_coupled_sln[var_index])[qp];
190 
191  return sum;
192 }
std::vector< const VariableValue * > _coupled_sln

◆ execute()

void FeatureVolumeVectorPostprocessor::execute ( )
overridevirtual

Here we retrieve the var to features vector on the current element. We'll use that information to figure out which variables are non-zero (from a threshold perspective) then we can sum those values into appropriate grain index locations.

Definition at line 75 of file FeatureVolumeVectorPostprocessor.C.

76 {
77  const auto num_features = _feature_counter.getTotalFeatureCount();
78 
79  // Reset the variable index and intersect bounds vectors
80  _var_num.assign(num_features, -1); // Invalid
81  _intersects_bounds.assign(num_features, -1); // Invalid
82  for (auto feature_num = beginIndex(_var_num); feature_num < num_features; ++feature_num)
83  {
84  auto var_num = _feature_counter.getFeatureVar(feature_num);
85  if (var_num != FeatureFloodCount::invalid_id)
86  _var_num[feature_num] = var_num;
87 
88  _intersects_bounds[feature_num] =
89  static_cast<unsigned int>(_feature_counter.doesFeatureIntersectBoundary(feature_num));
90  }
91 
93  {
94  VectorPostprocessorValue & center_x = declareVector("centroid_x");
95  center_x.resize(num_features);
96  VectorPostprocessorValue & center_y = declareVector("centroid_y");
97  center_y.resize(num_features);
98  VectorPostprocessorValue & center_z = declareVector("centroid_z");
99  center_z.resize(num_features);
100 
101  for (auto feature_num = beginIndex(_var_num); feature_num < num_features; ++feature_num)
102  {
103  auto p = _feature_counter.featureCentroid(feature_num);
104  center_x[feature_num] = p(0);
105  center_y[feature_num] = p(1);
106  center_z[feature_num] = p(2);
107  }
108  }
109 
110  // Reset the volume vector
111  _feature_volumes.assign(num_features, 0);
112  for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
113  {
114  _fe_problem.prepare(elem, 0);
115  _fe_problem.reinitElem(elem, 0);
116 
123  const auto & var_to_features = _feature_counter.getVarToFeatureVector(elem->id());
124 
125  accumulateVolumes(elem, var_to_features, num_features);
126  }
127 }
void accumulateVolumes(const Elem *elem, const std::vector< unsigned int > &var_to_features, std::size_t num_features)
Add volume contributions to one or entries in the feature volume vector.
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.
virtual std::size_t getTotalFeatureCount() const
Returns the total feature count (active and inactive ids, useful for sizing vectors) ...
virtual unsigned int getFeatureVar(unsigned int feature_id) const
Returns the variable representing the passed in feature.
const FeatureFloodCount & _feature_counter
A reference to the feature flood count object.
static const unsigned int invalid_id
virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const
Returns a Boolean indicating whether this feature intersects any boundary.
virtual Point featureCentroid(unsigned int feature_id) const
Returns the centroid of the designated feature (only suppored without periodic boundaries) ...

◆ finalize()

void FeatureVolumeVectorPostprocessor::finalize ( )
overridevirtual

Definition at line 130 of file FeatureVolumeVectorPostprocessor.C.

131 {
132  // Do the parallel sum
133  _communicator.sum(_feature_volumes);
134 }

◆ getFeatureVolume()

Real FeatureVolumeVectorPostprocessor::getFeatureVolume ( unsigned int  feature_id) const

Returns the volume for the given grain number.

Definition at line 137 of file FeatureVolumeVectorPostprocessor.C.

138 {
139  mooseAssert(feature_id < _feature_volumes.size(), "feature_id is out of range");
140  return _feature_volumes[feature_id];
141 }

◆ initialize()

void FeatureVolumeVectorPostprocessor::initialize ( )
overridevirtual

Definition at line 70 of file FeatureVolumeVectorPostprocessor.C.

71 {
72 }

Member Data Documentation

◆ _assembly

Assembly& FeatureVolumeVectorPostprocessor::_assembly
private

Definition at line 73 of file FeatureVolumeVectorPostprocessor.h.

◆ _coord

const MooseArray<Real>& FeatureVolumeVectorPostprocessor::_coord
private

Definition at line 77 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeIntegral().

◆ _coupled_sln

std::vector<const VariableValue *> FeatureVolumeVectorPostprocessor::_coupled_sln
private

◆ _feature_counter

const FeatureFloodCount& FeatureVolumeVectorPostprocessor::_feature_counter
protected

A reference to the feature flood count object.

Definition at line 54 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute(), and FeatureVolumeVectorPostprocessor().

◆ _feature_volumes

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_feature_volumes
protected

◆ _intersects_bounds

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_intersects_bounds
protected

Definition at line 58 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _JxW

const MooseArray<Real>& FeatureVolumeVectorPostprocessor::_JxW
private

Definition at line 76 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeIntegral().

◆ _mesh

MooseMesh& FeatureVolumeVectorPostprocessor::_mesh
private

Definition at line 72 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _output_centroids

const bool FeatureVolumeVectorPostprocessor::_output_centroids
protected

Definition at line 51 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _q_point

const MooseArray<Point>& FeatureVolumeVectorPostprocessor::_q_point
private

Definition at line 74 of file FeatureVolumeVectorPostprocessor.h.

◆ _qrule

QBase*& FeatureVolumeVectorPostprocessor::_qrule
private

Definition at line 75 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeIntegral().

◆ _single_feature_per_elem

const bool FeatureVolumeVectorPostprocessor::_single_feature_per_elem
protected

A Boolean indicating how the volume is calculated.

Definition at line 50 of file FeatureVolumeVectorPostprocessor.h.

Referenced by accumulateVolumes().

◆ _var_num

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_var_num
protected

Definition at line 56 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _vars

const std::vector<MooseVariableFEBase *>& FeatureVolumeVectorPostprocessor::_vars
private

Definition at line 69 of file FeatureVolumeVectorPostprocessor.h.

Referenced by FeatureVolumeVectorPostprocessor().


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