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
 
VectorPostprocessorValue & _intersects_specified_bounds
 
VectorPostprocessorValue & _percolated
 
bool _is_boundary_restricted
 Indicates whether the calculation should be run on volumes or area of a boundary. More...
 

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...
 
void accumulateBoundaryFaces (const Elem *elem, const std::vector< unsigned int > &var_to_features, std::size_t num_features, unsigned int side)
 When boundary is supplied as input, compute coverage of that boundary by each feature. More...
 
Real computeIntegral (std::size_t var_index) const
 Calculate the integral value of the passed in variable (index) More...
 
Real computeFaceIntegral (std::size_t var_index) const
 Calculate the integral on the face if boundary is supplied as input. More...
 

Private Attributes

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

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 47 of file FeatureVolumeVectorPostprocessor.C.

49  : GeneralVectorPostprocessor(parameters),
50  MooseVariableDependencyInterface(),
51  BoundaryRestrictable(this, false),
52  _single_feature_per_elem(getParam<bool>("single_feature_per_element")),
53  _output_centroids(getParam<bool>("output_centroids")),
54  _feature_counter(getUserObject<FeatureFloodCount>("flood_counter")),
55  _var_num(declareVector("var_num")),
56  _feature_volumes(declareVector("feature_volumes")),
57  _intersects_bounds(declareVector("intersects_bounds")),
58  _intersects_specified_bounds(declareVector("intersects_specified_bounds")),
59  _percolated(declareVector("percolated")),
61  _mesh(_subproblem.mesh()),
62  _assembly(_subproblem.assembly(_tid)),
63  _q_point(_assembly.qPoints()),
64  _qrule(_assembly.qRule()),
65  _JxW(_assembly.JxW()),
66  _coord(_assembly.coordTransformation()),
67  _qrule_face(_assembly.qRuleFace()),
68  _JxW_face(_assembly.JxWFace())
69 {
70  addMooseVariableDependency(_vars);
71 
72  _is_boundary_restricted = boundaryRestricted();
73 
74  _coupled_sln.reserve(_vars.size());
75  for (auto & var : _feature_counter.getCoupledVars())
76  _coupled_sln.push_back(&var->sln());
77 }

Member Function Documentation

◆ accumulateBoundaryFaces()

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

When boundary is supplied as input, compute coverage of that boundary by each feature.

Definition at line 242 of file FeatureVolumeVectorPostprocessor.C.

247 {
248  unsigned int dominant_feature_id = FeatureFloodCount::invalid_id;
249  Real max_var_value = std::numeric_limits<Real>::lowest();
250 
251  for (MooseIndex(var_to_features) var_index = 0; var_index < var_to_features.size(); ++var_index)
252  {
253  // Only sample "active" variables
254  if (var_to_features[var_index] != FeatureFloodCount::invalid_id)
255  {
256  auto feature_id = var_to_features[var_index];
257  mooseAssert(feature_id < num_features, "Feature ID out of range");
258  auto integral_value = computeFaceIntegral(var_index);
259 
261  {
262  if (integral_value > max_var_value)
263  {
264  // Update the current dominant feature and associated value
265  max_var_value = integral_value;
266  dominant_feature_id = feature_id;
267  }
268  }
269  // Solution based boundary area/length calculation (integral value)
270  else
271  _feature_volumes[feature_id] += integral_value;
272  }
273  }
274 
275  // Accumulate the boundary area/length into the dominant feature. Do not use the integral value
276  if (_single_feature_per_elem && dominant_feature_id != FeatureFloodCount::invalid_id)
277  _feature_volumes[dominant_feature_id] += elem->side_ptr(side)->volume();
278 }

Referenced by execute().

◆ 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 192 of file FeatureVolumeVectorPostprocessor.C.

196 {
197  unsigned int dominant_feature_id = FeatureFloodCount::invalid_id;
198  Real max_var_value = std::numeric_limits<Real>::lowest();
199 
200  for (MooseIndex(var_to_features) var_index = 0; var_index < var_to_features.size(); ++var_index)
201  {
202  // Only sample "active" variables
203  if (var_to_features[var_index] != FeatureFloodCount::invalid_id)
204  {
205  auto feature_id = var_to_features[var_index];
206  mooseAssert(feature_id < num_features, "Feature ID out of range");
207  auto integral_value = computeIntegral(var_index);
208 
209  // Compute volumes in a simplistic but domain conservative fashion
211  {
212  if (integral_value > max_var_value)
213  {
214  // Update the current dominant feature and associated value
215  max_var_value = integral_value;
216  dominant_feature_id = feature_id;
217  }
218  }
219  // Solution based volume calculation (integral value)
220  else
221  _feature_volumes[feature_id] += integral_value;
222  }
223  }
224 
225  // Accumulate the entire element volume into the dominant feature. Do not use the integral value
226  if (_single_feature_per_elem && dominant_feature_id != FeatureFloodCount::invalid_id)
227  _feature_volumes[dominant_feature_id] += elem->volume();
228 }

Referenced by execute().

◆ computeFaceIntegral()

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

Calculate the integral on the face if boundary is supplied as input.

Definition at line 281 of file FeatureVolumeVectorPostprocessor.C.

282 {
283  Real sum = 0;
284  for (unsigned int qp = 0; qp < _qrule_face->n_points(); ++qp)
285  sum += _JxW_face[qp] * _coord[qp] * (*_coupled_sln[var_index])[qp];
286 
287  return sum;
288 }

Referenced by accumulateBoundaryFaces().

◆ computeIntegral()

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

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

Definition at line 231 of file FeatureVolumeVectorPostprocessor.C.

232 {
233  Real sum = 0;
234 
235  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
236  sum += _JxW[qp] * _coord[qp] * (*_coupled_sln[var_index])[qp];
237 
238  return sum;
239 }

Referenced by accumulateVolumes().

◆ 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 85 of file FeatureVolumeVectorPostprocessor.C.

86 {
87  const auto num_features = _feature_counter.getTotalFeatureCount();
88 
89  // Reset the variable index and intersect bounds vectors
90  _var_num.assign(num_features, -1); // Invalid
91  _intersects_bounds.assign(num_features, -1); // Invalid
92  _intersects_specified_bounds.assign(num_features, -1); // Invalid
93  _percolated.assign(num_features, -1); // Invalid
94  for (MooseIndex(num_features) feature_num = 0; feature_num < num_features; ++feature_num)
95  {
96  auto var_num = _feature_counter.getFeatureVar(feature_num);
97  if (var_num != FeatureFloodCount::invalid_id)
98  _var_num[feature_num] = var_num;
99 
100  _intersects_bounds[feature_num] =
101  static_cast<unsigned int>(_feature_counter.doesFeatureIntersectBoundary(feature_num));
102 
103  _intersects_specified_bounds[feature_num] = static_cast<unsigned int>(
105 
106  _percolated[feature_num] =
107  static_cast<unsigned int>(_feature_counter.isFeaturePercolated(feature_num));
108  }
109 
110  if (_output_centroids)
111  {
112  VectorPostprocessorValue & center_x = declareVector("centroid_x");
113  center_x.resize(num_features);
114  VectorPostprocessorValue & center_y = declareVector("centroid_y");
115  center_y.resize(num_features);
116  VectorPostprocessorValue & center_z = declareVector("centroid_z");
117  center_z.resize(num_features);
118 
119  for (MooseIndex(_var_num) feature_num = 0; feature_num < num_features; ++feature_num)
120  {
121  auto p = _feature_counter.featureCentroid(feature_num);
122  center_x[feature_num] = p(0);
123  center_y[feature_num] = p(1);
124  center_z[feature_num] = p(2);
125  }
126  }
127 
128  // Reset the volume vector
129  _feature_volumes.assign(num_features, 0);
130 
131  // Calculate coverage of a boundary if one has been supplied in the input file
133  {
134  const std::set<BoundaryID> supplied_bnd_ids = BoundaryRestrictable::boundaryIDs();
135  for (auto elem_it = _mesh.bndElemsBegin(), elem_end = _mesh.bndElemsEnd(); elem_it != elem_end;
136  ++elem_it)
137 
138  // loop over only boundaries supplied by user in boundary param
139  for (auto & supplied_bnd_id : supplied_bnd_ids)
140  if (((*elem_it)->_bnd_id) == supplied_bnd_id)
141  {
142  const auto & elem = (*elem_it)->_elem;
143  auto rank = processor_id();
144 
145  if (elem->processor_id() == rank)
146  {
147  _fe_problem.setCurrentSubdomainID(elem, 0);
148  _fe_problem.prepare(elem, 0);
149  _fe_problem.reinitElem(elem, 0);
150  _fe_problem.reinitElemFace(elem, (*elem_it)->_side, (*elem_it)->_bnd_id, 0);
151 
152  const auto & var_to_features = _feature_counter.getVarToFeatureVector(elem->id());
153 
154  accumulateBoundaryFaces(elem, var_to_features, num_features, (*elem_it)->_side);
155  }
156  }
157  }
158  else // If no boundary is supplied, calculate volumes of features as normal
159  for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
160  {
161  _fe_problem.setCurrentSubdomainID(elem, 0);
162  _fe_problem.prepare(elem, 0);
163  _fe_problem.reinitElem(elem, 0);
164 
171  const auto & var_to_features = _feature_counter.getVarToFeatureVector(elem->id());
172 
173  accumulateVolumes(elem, var_to_features, num_features);
174  }
175 }

◆ finalize()

void FeatureVolumeVectorPostprocessor::finalize ( )
overridevirtual

Definition at line 178 of file FeatureVolumeVectorPostprocessor.C.

179 {
180  // Do the parallel sum
181  _communicator.sum(_feature_volumes);
182 }

◆ getFeatureVolume()

Real FeatureVolumeVectorPostprocessor::getFeatureVolume ( unsigned int  feature_id) const

Returns the volume for the given grain number.

Definition at line 185 of file FeatureVolumeVectorPostprocessor.C.

186 {
187  mooseAssert(feature_id < _feature_volumes.size(), "feature_id is out of range");
188  return _feature_volumes[feature_id];
189 }

◆ initialize()

void FeatureVolumeVectorPostprocessor::initialize ( )
overridevirtual

Definition at line 80 of file FeatureVolumeVectorPostprocessor.C.

81 {
82 }

Member Data Documentation

◆ _assembly

Assembly& FeatureVolumeVectorPostprocessor::_assembly
private

Definition at line 88 of file FeatureVolumeVectorPostprocessor.h.

◆ _coord

const MooseArray<Real>& FeatureVolumeVectorPostprocessor::_coord
private

Definition at line 92 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeFaceIntegral(), and 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 55 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 59 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _intersects_specified_bounds

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_intersects_specified_bounds
protected

Definition at line 60 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _is_boundary_restricted

bool FeatureVolumeVectorPostprocessor::_is_boundary_restricted
protected

Indicates whether the calculation should be run on volumes or area of a boundary.

Definition at line 64 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute(), and FeatureVolumeVectorPostprocessor().

◆ _JxW

const MooseArray<Real>& FeatureVolumeVectorPostprocessor::_JxW
private

Definition at line 91 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeIntegral().

◆ _JxW_face

const MooseArray<Real>& FeatureVolumeVectorPostprocessor::_JxW_face
private

Definition at line 94 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeFaceIntegral().

◆ _mesh

MooseMesh& FeatureVolumeVectorPostprocessor::_mesh
private

Definition at line 87 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _output_centroids

const bool FeatureVolumeVectorPostprocessor::_output_centroids
protected

Definition at line 52 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _percolated

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_percolated
protected

Definition at line 61 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _q_point

const MooseArray<Point>& FeatureVolumeVectorPostprocessor::_q_point
private

Definition at line 89 of file FeatureVolumeVectorPostprocessor.h.

◆ _qrule

const QBase* const & FeatureVolumeVectorPostprocessor::_qrule
private

Definition at line 90 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeIntegral().

◆ _qrule_face

const QBase* const & FeatureVolumeVectorPostprocessor::_qrule_face
private

Definition at line 93 of file FeatureVolumeVectorPostprocessor.h.

Referenced by computeFaceIntegral().

◆ _single_feature_per_elem

const bool FeatureVolumeVectorPostprocessor::_single_feature_per_elem
protected

A Boolean indicating how the volume is calculated.

Definition at line 51 of file FeatureVolumeVectorPostprocessor.h.

Referenced by accumulateBoundaryFaces(), and accumulateVolumes().

◆ _var_num

VectorPostprocessorValue& FeatureVolumeVectorPostprocessor::_var_num
protected

Definition at line 57 of file FeatureVolumeVectorPostprocessor.h.

Referenced by execute().

◆ _vars

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

Definition at line 84 of file FeatureVolumeVectorPostprocessor.h.

Referenced by FeatureVolumeVectorPostprocessor().


The documentation for this class was generated from the following files:
FeatureVolumeVectorPostprocessor::_single_feature_per_elem
const bool _single_feature_per_elem
A Boolean indicating how the volume is calculated.
Definition: FeatureVolumeVectorPostprocessor.h:51
FeatureVolumeVectorPostprocessor::accumulateVolumes
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.
Definition: FeatureVolumeVectorPostprocessor.C:192
FeatureFloodCount::doesFeatureIntersectBoundary
virtual bool doesFeatureIntersectBoundary(unsigned int feature_id) const
Returns a Boolean indicating whether this feature intersects any boundary.
Definition: FeatureFloodCount.C:828
FeatureFloodCount::getVarToFeatureVector
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.
Definition: FeatureFloodCount.C:701
FeatureFloodCount::featureCentroid
virtual Point featureCentroid(unsigned int feature_id) const
Returns the centroid of the designated feature (only supported without periodic boundaries)
Definition: FeatureFloodCount.C:900
FeatureVolumeVectorPostprocessor::_qrule
const QBase *const & _qrule
Definition: FeatureVolumeVectorPostprocessor.h:90
FeatureFloodCount::isFeaturePercolated
virtual bool isFeaturePercolated(unsigned int feature_id) const
Returns a Boolean indicating whether this feature is percolated (e.g.
Definition: FeatureFloodCount.C:874
FeatureFloodCount::getTotalFeatureCount
virtual std::size_t getTotalFeatureCount() const
Returns the total feature count (active and inactive ids, useful for sizing vectors)
Definition: FeatureFloodCount.C:798
FeatureVolumeVectorPostprocessor::_qrule_face
const QBase *const & _qrule_face
Definition: FeatureVolumeVectorPostprocessor.h:93
FeatureVolumeVectorPostprocessor::_JxW_face
const MooseArray< Real > & _JxW_face
Definition: FeatureVolumeVectorPostprocessor.h:94
FeatureFloodCount::getCoupledVars
const std::vector< MooseVariable * > & getCoupledVars() const
Returns a const vector to the coupled variable pointers.
Definition: FeatureFloodCount.h:98
FeatureVolumeVectorPostprocessor::_q_point
const MooseArray< Point > & _q_point
Definition: FeatureVolumeVectorPostprocessor.h:89
FeatureVolumeVectorPostprocessor::_feature_volumes
VectorPostprocessorValue & _feature_volumes
Definition: FeatureVolumeVectorPostprocessor.h:58
FeatureVolumeVectorPostprocessor::_intersects_specified_bounds
VectorPostprocessorValue & _intersects_specified_bounds
Definition: FeatureVolumeVectorPostprocessor.h:60
FeatureVolumeVectorPostprocessor::_var_num
VectorPostprocessorValue & _var_num
Definition: FeatureVolumeVectorPostprocessor.h:57
FeatureFloodCount::getFeatureVar
virtual unsigned int getFeatureVar(unsigned int feature_id) const
Returns the variable representing the passed in feature.
Definition: FeatureFloodCount.C:809
FeatureVolumeVectorPostprocessor::_coupled_sln
std::vector< const VariableValue * > _coupled_sln
Definition: FeatureVolumeVectorPostprocessor.h:85
FeatureVolumeVectorPostprocessor::_output_centroids
const bool _output_centroids
Definition: FeatureVolumeVectorPostprocessor.h:52
FeatureFloodCount::doesFeatureIntersectSpecifiedBoundary
virtual bool doesFeatureIntersectSpecifiedBoundary(unsigned int feature_id) const
Returns a Boolean indicating whether this feature intersects boundaries in a user-supplied list.
Definition: FeatureFloodCount.C:850
FeatureVolumeVectorPostprocessor::_feature_counter
const FeatureFloodCount & _feature_counter
A reference to the feature flood count object.
Definition: FeatureVolumeVectorPostprocessor.h:55
FeatureVolumeVectorPostprocessor::computeFaceIntegral
Real computeFaceIntegral(std::size_t var_index) const
Calculate the integral on the face if boundary is supplied as input.
Definition: FeatureVolumeVectorPostprocessor.C:281
FeatureVolumeVectorPostprocessor::_percolated
VectorPostprocessorValue & _percolated
Definition: FeatureVolumeVectorPostprocessor.h:61
FeatureVolumeVectorPostprocessor::_is_boundary_restricted
bool _is_boundary_restricted
Indicates whether the calculation should be run on volumes or area of a boundary.
Definition: FeatureVolumeVectorPostprocessor.h:64
FeatureVolumeVectorPostprocessor::accumulateBoundaryFaces
void accumulateBoundaryFaces(const Elem *elem, const std::vector< unsigned int > &var_to_features, std::size_t num_features, unsigned int side)
When boundary is supplied as input, compute coverage of that boundary by each feature.
Definition: FeatureVolumeVectorPostprocessor.C:242
FeatureFloodCount::invalid_id
static const unsigned int invalid_id
Definition: FeatureFloodCount.h:94
FeatureVolumeVectorPostprocessor::computeIntegral
Real computeIntegral(std::size_t var_index) const
Calculate the integral value of the passed in variable (index)
Definition: FeatureVolumeVectorPostprocessor.C:231
FeatureVolumeVectorPostprocessor::_intersects_bounds
VectorPostprocessorValue & _intersects_bounds
Definition: FeatureVolumeVectorPostprocessor.h:59
FeatureVolumeVectorPostprocessor::_coord
const MooseArray< Real > & _coord
Definition: FeatureVolumeVectorPostprocessor.h:92
FeatureVolumeVectorPostprocessor::_vars
const std::vector< MooseVariableFEBase * > & _vars
Definition: FeatureVolumeVectorPostprocessor.h:84
FeatureVolumeVectorPostprocessor::_assembly
Assembly & _assembly
Definition: FeatureVolumeVectorPostprocessor.h:88
FeatureFloodCount::getFECoupledVars
const std::vector< MooseVariableFEBase * > & getFECoupledVars() const
Returns a const vector to the coupled MooseVariableFEBase pointers.
Definition: FeatureFloodCount.h:101
FeatureVolumeVectorPostprocessor::_mesh
MooseMesh & _mesh
Definition: FeatureVolumeVectorPostprocessor.h:87
FeatureVolumeVectorPostprocessor::_JxW
const MooseArray< Real > & _JxW
Definition: FeatureVolumeVectorPostprocessor.h:91