www.mooseframework.org
InternalVolume.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 "InternalVolume.h"
11 
12 #include "MooseMesh.h"
13 #include "Function.h"
14 
16 
17 template <>
18 InputParameters
20 {
21  InputParameters params = validParams<SideIntegralPostprocessor>();
22  params.addClassDescription("Computes the volume of an enclosed area by "
23  "performing an integral over a user-supplied boundary.");
24  params.addRangeCheckedParam<unsigned int>(
25  "component", 0, "component<3", "The component to use in the integration");
26  params.addParam<Real>(
27  "scale_factor", 1, "A scale factor to be applied to the internal volume calculation");
28  params.addParam<FunctionName>("addition",
29  0,
30  "An additional volume to be included in the "
31  "internal volume calculation. A time-dependent "
32  "function is expected.");
33  params.set<bool>("use_displaced_mesh") = true;
34  return params;
35 }
36 
37 InternalVolume::InternalVolume(const InputParameters & parameters)
38  : SideIntegralPostprocessor(parameters),
39  _component(getParam<unsigned int>("component")),
40  _scale(getParam<Real>("scale_factor")),
41  _addition(getFunction("addition"))
42 {
43 }
44 
45 // / /
46 // | |
47 // | div(F) dV = | F dot n dS
48 // | |
49 // / V / dS
50 //
51 // with
52 // F = a field
53 // n = the normal at the surface
54 // V = the volume of the domain
55 // S = the surface of the domain
56 //
57 // If we choose F as [x 0 0]^T, then
58 // div(F) = 1.
59 // So,
60 //
61 // / /
62 // | |
63 // | dV = | x * n[0] dS
64 // | |
65 // / V / dS
66 //
67 // That is, the volume of the domain is the integral over the surface of the domain
68 // of the x position of the surface times the x-component of the normal of the
69 // surface.
70 
71 void
73 {
74  SideIntegralPostprocessor::initialSetup();
75 
76  const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
77  std::set<SubdomainID>::const_iterator iter = subdomains.begin();
78  const std::set<SubdomainID>::const_iterator iter_end = subdomains.end();
79  for (; iter != iter_end; ++iter)
80  {
81  const std::set<BoundaryID> & boundaries = _mesh.getSubdomainBoundaryIds(*iter);
82  std::set<BoundaryID>::const_iterator bnd = boundaries.begin();
83  const std::set<BoundaryID>::const_iterator bnd_end = boundaries.end();
84  for (; bnd != bnd_end; ++bnd)
85  {
86  const std::set<BoundaryID> & b = boundaryIDs();
87  std::set<BoundaryID>::const_iterator bit = b.begin();
88  const std::set<BoundaryID>::const_iterator bit_end = b.end();
89  for (; bit != bit_end; ++bit)
90  if (*bit == *bnd)
91  {
92  Moose::CoordinateSystemType coord_sys = _fe_problem.getCoordSystem(*iter);
93  if (_component != 0 && coord_sys == Moose::COORD_RSPHERICAL)
94  mooseError("With spherical coordinates, the component must be 0 in InternalVolume.");
95 
96  if (_component > 1 && coord_sys == Moose::COORD_RZ)
97  mooseError(
98  "With cylindrical coordinates, the component must be 0 or 1 in InternalVolume.");
99  }
100  }
101  }
102 }
103 
104 Real
106 {
107  // Default scale factor is 1
108  Real scale = 1.0;
109  if (_coord_sys == Moose::COORD_RSPHERICAL)
110  {
111  // MOOSE will multiply by 4*pi*r*r
112  scale = 1.0 / 3.0;
113  }
114  else if (_coord_sys == Moose::COORD_RZ && _component == 0)
115  {
116  // MOOSE will multiply by 2*pi*r
117  // Will integrate over z giving 0.5*2*pi*r*r*height
118  scale = 0.5;
119  }
120  else if (_coord_sys == Moose::COORD_RZ && _component == 1)
121  {
122  // MOOSE will multiply by 2*pi*r
123  // Will integrate over r:
124  // integral(2*pi*r*height) over r:
125  // pi*r*r*height
126  scale = 1.0;
127  }
128  return -scale * _q_point[_qp](_component) * _normals[_qp](_component);
129 }
130 
131 Real
133 {
134  Point p;
135  return _scale * SideIntegralPostprocessor::getValue() + _addition.value(_t, p);
136 }
InternalVolume::_component
const unsigned int _component
Definition: InternalVolume.h:41
InternalVolume::initialSetup
void initialSetup()
Definition: InternalVolume.C:72
InternalVolume
This class computes the volume of an interior space.
Definition: InternalVolume.h:30
InternalVolume::_scale
const Real _scale
Definition: InternalVolume.h:42
InternalVolume::getValue
virtual Real getValue()
Definition: InternalVolume.C:132
registerMooseObject
registerMooseObject("MiscApp", InternalVolume)
InternalVolume::InternalVolume
InternalVolume(const InputParameters &parameters)
Definition: InternalVolume.C:37
validParams< InternalVolume >
InputParameters validParams< InternalVolume >()
Definition: InternalVolume.C:19
InternalVolume.h
InternalVolume::computeQpIntegral
virtual Real computeQpIntegral()
Definition: InternalVolume.C:105
InternalVolume::_addition
const Function & _addition
Definition: InternalVolume.h:43