www.mooseframework.org
FeatureVolumeVectorPostprocessor.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 // MOOSE includes
11 #include "Assembly.h"
12 #include "FeatureFloodCount.h"
13 #include "GrainTrackerInterface.h"
14 #include "MooseMesh.h"
15 #include "MooseVariable.h"
16 
17 #include "libmesh/quadrature.h"
18 
19 template <>
20 InputParameters
22 {
23  InputParameters params = validParams<GeneralVectorPostprocessor>();
24 
25  params.addRequiredParam<UserObjectName>("flood_counter",
26  "The FeatureFloodCount UserObject to get values from.");
27  params.addParam<bool>("single_feature_per_element",
28  false,
29  "Set this Boolean if you wish to use an element based volume where"
30  " the dominant order parameter determines the feature that accumulates the "
31  "entire element volume");
32  return params;
33 }
34 
36  const InputParameters & parameters)
37  : GeneralVectorPostprocessor(parameters),
38  MooseVariableDependencyInterface(),
39  _single_feature_per_elem(getParam<bool>("single_feature_per_element")),
40  _feature_counter(getUserObject<FeatureFloodCount>("flood_counter")),
41  _var_num(declareVector("var_num")),
42  _feature_volumes(declareVector("feature_volumes")),
43  _intersects_bounds(declareVector("intersects_bounds")),
44  _vars(_feature_counter.getCoupledVars()),
45  _mesh(_subproblem.mesh()),
46  _assembly(_subproblem.assembly(_tid)),
47  _q_point(_assembly.qPoints()),
48  _qrule(_assembly.qRule()),
49  _JxW(_assembly.JxW()),
50  _coord(_assembly.coordTransformation())
51 {
52  addMooseVariableDependency(_vars);
53 
54  _coupled_sln.reserve(_vars.size());
55  for (auto & var : _vars)
56  _coupled_sln.push_back(&var->sln());
57 }
58 
59 void
61 {
62 }
63 
64 void
66 {
67  const auto num_features = _feature_counter.getTotalFeatureCount();
68 
69  // Reset the variable index and intersect bounds vectors
70  _var_num.assign(num_features, -1); // Invalid
71  _intersects_bounds.assign(num_features, -1); // Invalid
72  for (auto feature_num = beginIndex(_var_num); feature_num < num_features; ++feature_num)
73  {
74  auto var_num = _feature_counter.getFeatureVar(feature_num);
75  if (var_num != FeatureFloodCount::invalid_id)
76  _var_num[feature_num] = var_num;
77 
78  _intersects_bounds[feature_num] =
79  static_cast<unsigned int>(_feature_counter.doesFeatureIntersectBoundary(feature_num));
80  }
81 
82  // Reset the volume vector
83  _feature_volumes.assign(num_features, 0);
84  const auto end = _mesh.getMesh().active_local_elements_end();
85  for (auto el = _mesh.getMesh().active_local_elements_begin(); el != end; ++el)
86  {
87  const Elem * elem = *el;
88  _fe_problem.prepare(elem, 0);
89  _fe_problem.reinitElem(elem, 0);
90 
97  const auto & var_to_features = _feature_counter.getVarToFeatureVector(elem->id());
98 
99  accumulateVolumes(elem, var_to_features, num_features);
100  }
101 }
102 
103 void
105 {
106  // Do the parallel sum
107  _communicator.sum(_feature_volumes);
108 }
109 
110 Real
112 {
113  mooseAssert(feature_id < _feature_volumes.size(), "feature_id is out of range");
114  return _feature_volumes[feature_id];
115 }
116 
117 void
119  const Elem * elem,
120  const std::vector<unsigned int> & var_to_features,
121  std::size_t libmesh_dbg_var(num_features))
122 {
123  unsigned int dominant_feature_id = FeatureFloodCount::invalid_id;
124  Real max_var_value = std::numeric_limits<Real>::lowest();
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  // Compute volumes in a simplistic but domain conservative fashion
138  {
139  if (integral_value > max_var_value)
140  {
141  // Update the current dominant feature and associated value
142  max_var_value = integral_value;
143  dominant_feature_id = feature_id;
144  }
145  }
146  // Solution based volume calculation (integral value)
147  else
148  _feature_volumes[feature_id] += integral_value;
149  }
150  }
151 
152  // Accumulate the entire element volume into the dominant feature. Do not use the integral value
153  if (_single_feature_per_elem && dominant_feature_id != FeatureFloodCount::invalid_id)
154  _feature_volumes[dominant_feature_id] += elem->volume();
155 }
156 
157 Real
159 {
160  Real sum = 0;
161 
162  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
163  sum += _JxW[qp] * _coord[qp] * (*_coupled_sln[var_index])[qp];
164 
165  return sum;
166 }
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.
const std::vector< MooseVariable * > & _vars
virtual unsigned int getFeatureVar(unsigned int feature_id) const
Returns the variable representing the passed in feature.
virtual std::size_t getTotalFeatureCount() const
Returns the total feature count (active and inactive ids, useful for sizing vectors) ...
Real computeIntegral(std::size_t var_index) const
Calculate the integral value of the passed in variable (index)
This object will mark nodes or elements of continuous regions all with a unique number for the purpos...
InputParameters validParams< FeatureVolumeVectorPostprocessor >()
const FeatureFloodCount & _feature_counter
A reference to the feature flood count object.
static const unsigned int invalid_id
std::vector< const VariableValue * > _coupled_sln
Real getFeatureVolume(unsigned int feature_id) const
Returns the volume for the given grain number.
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 bool doesFeatureIntersectBoundary(unsigned int feature_id) const
Returns a Boolean indicating whether this feature intersects any boundary.
const bool _single_feature_per_elem
A Boolean indicating how the volume is calculated.
FeatureVolumeVectorPostprocessor(const InputParameters &parameters)