www.mooseframework.org
LevelSetVolume.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "LevelSetVolume.h"
11 
12 registerMooseObject("LevelSetApp", LevelSetVolume);
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<ElementVariablePostprocessor>();
19  params.addClassDescription(
20  "Compute the area or volume of the region inside or outside of a level set contour.");
21  params.addParam<Real>(
22  "threshold", 0.0, "The level set threshold to consider for computing area/volume.");
23 
24  MooseEnum loc("inside=0 outside=1", "inside");
25  params.addParam<MooseEnum>("location", loc, "The location of the area/volume to be computed.");
26  return params;
27 }
28 
29 LevelSetVolume::LevelSetVolume(const InputParameters & parameters)
30  : ElementVariablePostprocessor(parameters),
31  _threshold(getParam<Real>("threshold")),
32  _inside(getParam<MooseEnum>("location") == "inside")
33 {
34 }
35 
36 void
38 {
39  _volume = 0;
40 }
41 
42 void
44 {
45  Real cnt = 0;
46  Real n = _u.size();
47 
48  // Perform the check for inside/outside outside the qp loop for speed
49  if (_inside)
50  {
51  for (_qp = 0; _qp < n; ++_qp)
52  if (_u[_qp] <= _threshold)
53  cnt++;
54  }
55  else
56  {
57  for (_qp = 0; _qp < n; ++_qp)
58  if (_u[_qp] > _threshold)
59  cnt++;
60  }
61  _volume += cnt / n * _current_elem_volume;
62 }
63 
64 void
66 {
67  gatherSum(_volume);
68 }
69 
70 Real
72 {
73  return _volume;
74 }
75 
76 void
77 LevelSetVolume::threadJoin(const UserObject & y)
78 {
79  const LevelSetVolume & pps = static_cast<const LevelSetVolume &>(y);
80  _volume += pps._volume;
81 }
registerMooseObject
registerMooseObject("LevelSetApp", LevelSetVolume)
LevelSetVolume::execute
virtual void execute() override
Definition: LevelSetVolume.C:43
LevelSetVolume::getValue
virtual Real getValue() override
Definition: LevelSetVolume.C:71
LevelSetVolume::_threshold
const Real & _threshold
The level set contour to consider for computing inside vs. outside of the volume.
Definition: LevelSetVolume.h:41
validParams< LevelSetVolume >
InputParameters validParams< LevelSetVolume >()
Definition: LevelSetVolume.C:16
LevelSetVolume::_volume
Real _volume
The accumulated volume to return as a PostprocessorValue.
Definition: LevelSetVolume.h:34
LevelSetVolume.h
LevelSetVolume::finalize
virtual void finalize() override
Definition: LevelSetVolume.C:65
LevelSetVolume::initialize
virtual void initialize() override
Definition: LevelSetVolume.C:37
LevelSetVolume::LevelSetVolume
LevelSetVolume(const InputParameters &parameters)
Definition: LevelSetVolume.C:29
LevelSetVolume
Postprocessor to compute the area/volume inside and outside of a level set contour.
Definition: LevelSetVolume.h:24
LevelSetVolume::_inside
const bool _inside
Flag for triggering the internal volume calculation.
Definition: LevelSetVolume.h:44
LevelSetVolume::threadJoin
virtual void threadJoin(const UserObject &y) override
Definition: LevelSetVolume.C:77