www.mooseframework.org
CavityPressureUserObject.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 /****************************************************************/
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<GeneralUserObject>();
14  params.addParam<Real>(
15  "initial_pressure",
16  0,
17  "The initial pressure in the cavity. If not given, a zero initial pressure will be used.");
18  params.addParam<std::vector<PostprocessorName>>("material_input",
19  "The name of the postprocessor(s) that holds the "
20  "amount of material injected into the cavity.");
21  params.addRequiredParam<Real>("R", "The universal gas constant for the units used.");
22  params.addRequiredParam<PostprocessorName>(
23  "temperature", "The name of the average temperature postprocessor value.");
24  params.addParam<Real>("initial_temperature", "Initial temperature (optional)");
25  params.addRequiredParam<PostprocessorName>(
26  "volume", "The name of the internal volume postprocessor value.");
27  params.addParam<Real>(
28  "startup_time",
29  0,
30  "The amount of time during which the pressure will ramp from zero to its true value.");
31  params.set<bool>("use_displaced_mesh") = true;
32 
33  params.addPrivateParam<std::string>("built_by_action", ""); // Hide from input file dump
34  return params;
35 }
36 
38  : GeneralUserObject(params),
39  _cavity_pressure(declareRestartableData<Real>("cavity_pressure", 0)),
40  _n0(declareRestartableData<Real>("initial_moles", 0)),
41  _initial_pressure(getParam<Real>("initial_pressure")),
42  _material_input(),
43  _R(getParam<Real>("R")),
44  _temperature(getPostprocessorValue("temperature")),
45  _init_temp_given(isParamValid("initial_temperature")),
46  _init_temp(_init_temp_given ? getParam<Real>("initial_temperature") : 0),
47  _volume(getPostprocessorValue("volume")),
48  _start_time(0),
49  _startup_time(getParam<Real>("startup_time")),
50  _initialized(declareRestartableData<bool>("initialized", false))
51 {
52  if (isParamValid("material_input"))
53  {
54  std::vector<PostprocessorName> ppn =
55  params.get<std::vector<PostprocessorName>>("material_input");
56  const unsigned int len = ppn.size();
57  for (unsigned int i = 0; i < len; ++i)
58  _material_input.push_back(&getPostprocessorValueByName(ppn[i]));
59  }
60 }
61 
62 Real
63 CavityPressureUserObject::getValue(const std::string & quantity) const
64 {
65  Real value = 0;
66  if ("initial_moles" == quantity)
67  {
68  if (_n0 < 0.0)
69  mooseError("Negative number of moles calculated as an input for the cavity pressure");
70 
71  value = _n0;
72  }
73  else if ("cavity_pressure" == quantity)
74  value = _cavity_pressure;
75  else
76  mooseError("Unknown quantity in " + name());
77 
78  return value;
79 }
80 
81 void
83 {
84  if (!_initialized)
85  {
86  Real init_temp = _temperature;
87  if (_init_temp_given)
88  init_temp = _init_temp;
89 
90  if (MooseUtils::absoluteFuzzyLessEqual(init_temp, 0.0))
91  mooseError("Cannot have initial temperature of zero when initializing cavity pressure. "
92  "Does the supplied Postprocessor for temperature execute at initial?");
93 
94  _n0 = _initial_pressure * _volume / (_R * init_temp);
95  _start_time = _t - _dt;
96  const Real factor =
97  _t >= _start_time + _startup_time ? 1.0 : (_t - _start_time) / _startup_time;
99  _initialized = true;
100  }
101 }
102 
103 void
105 {
106  Real mat = 0;
107  for (unsigned int i = 0; i < _material_input.size(); ++i)
108  mat += *_material_input[i];
109 
110  const Real pressure = (_n0 + mat) * _R * _temperature / _volume;
111  const Real factor = _t >= _start_time + _startup_time ? 1.0 : (_t - _start_time) / _startup_time;
112  _cavity_pressure = factor * pressure;
113 }
CavityPressureUserObject(const InputParameters &parameters)
std::vector< const PostprocessorValue * > _material_input
const std::string pressure
Definition: NS.h:24
Real getValue(const std::string &quantity) const
InputParameters validParams< CavityPressureUserObject >()