www.mooseframework.org
CavityPressureUserObject.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 
11 
12 registerMooseObject("SolidMechanicsApp", CavityPressureUserObject);
13 
16 {
18  params.addClassDescription("Uses the ideal gas law to compute internal pressure "
19  "and an initial moles of gas quantity.");
20  params.addRangeCheckedParam<Real>(
21  "initial_pressure",
22  0.0,
23  "initial_pressure >= 0.0",
24  "The initial pressure in the cavity. If not given, a zero initial pressure will be used.");
25  params.addParam<std::vector<PostprocessorName>>("material_input",
26  "The name of the postprocessor(s) that holds the "
27  "amount of material injected into the cavity.");
29  "R", "R > 0.0", "The universal gas constant for the units used.");
30  params.addRequiredParam<PostprocessorName>(
31  "temperature", "The name of the average temperature postprocessor value.");
32  params.addRangeCheckedParam<Real>(
33  "initial_temperature", "initial_temperature > 0.0", "Initial temperature (optional)");
34  params.addRequiredParam<std::vector<PostprocessorName>>(
35  "volume",
36  "The name of the postprocessor(s) that holds the value of the internal volume in the cavity");
37 
38  params.addParam<std::vector<PostprocessorName>>(
39  "additional_volumes",
40  "The name of the postprocessor(s) that hold additional volumes that are connected to the "
41  "cavity but not meshed.");
42  params.addParam<std::vector<PostprocessorName>>(
43  "temperature_of_additional_volumes",
44  "The name of the postprocessor(s) that hold the temperatures of the additional volumes.");
45  params.addParam<Real>(
46  "startup_time",
47  0.0,
48  "The amount of time during which the pressure will ramp from zero to its true value.");
49  params.set<bool>("use_displaced_mesh") = true;
50 
51  return params;
52 }
53 
55  : GeneralUserObject(params),
56  _cavity_pressure(declareRestartableData<Real>("cavity_pressure", 0.0)),
57  _n0(declareRestartableData<Real>("initial_moles", 0.0)),
58  _initial_pressure(getParam<Real>("initial_pressure")),
59  _material_input(params.get<std::vector<PostprocessorName>>("material_input").size()),
60  _volume(params.get<std::vector<PostprocessorName>>("volume").size()),
61  _R(getParam<Real>("R")),
62  _temperature(getPostprocessorValue("temperature")),
63  _init_temp_given(isParamValid("initial_temperature")),
64  _init_temp(_init_temp_given ? getParam<Real>("initial_temperature") : 0.0),
65  _startup_time(getParam<Real>("startup_time")),
66  _initialized(declareRestartableData<bool>("initialized", false)),
67  _additional_volumes(
68  isParamValid("additional_volumes")
69  ? params.get<std::vector<PostprocessorName>>("additional_volumes").size()
70  : zero),
71  _temperature_of_additional_volumes(
72  isParamValid("temperature_of_additional_volumes")
73  ? params.get<std::vector<PostprocessorName>>("temperature_of_additional_volumes").size()
74  : zero),
75  _start_time(0.0)
76 {
77  auto material_names = params.get<std::vector<PostprocessorName>>("material_input");
78  for (unsigned int i = 0; i < _material_input.size(); ++i)
79  _material_input[i] = &getPostprocessorValueByName(material_names[i]);
80 
81  auto volume_names = params.get<std::vector<PostprocessorName>>("volume");
82  for (unsigned int i = 0; i < volume_names.size(); ++i)
83  _volume[i] = &getPostprocessorValueByName(volume_names[i]);
84 
85  if (isParamValid("additional_volumes") != isParamValid("temperature_of_additional_volumes"))
86  mooseError("Both additional volumes and their corresponding temperatures must be specified");
87 
89  mooseError(
90  "The number of additional volumes and temperatures of additional volumes musts be equal.");
91 
92  auto additional_volume_names = params.get<std::vector<PostprocessorName>>("additional_volumes");
93  for (unsigned int i = 0; i < _additional_volumes.size(); ++i)
94  _additional_volumes[i] = &getPostprocessorValueByName(additional_volume_names[i]);
95 
96  auto temperature_of_additional_volume_names =
97  params.get<std::vector<PostprocessorName>>("temperature_of_additional_volumes");
98  for (unsigned int i = 0; i < _temperature_of_additional_volumes.size(); ++i)
100  &getPostprocessorValueByName(temperature_of_additional_volume_names[i]);
101 }
102 
103 Real
105 {
106  Real value = 0;
107  if (quantity == INITIAL_MOLES)
108  {
109  if (_n0 < 0.0)
110  mooseError("In ",
111  _name,
112  ": Negative number of moles calculated as an input for the cavity pressure");
113 
114  value = _n0;
115  }
116  else if (quantity == CAVITY_PRESSURE)
118  else
119  mooseError("In ", _name, ": Unknown quantity.");
120 
121  return value;
122 }
123 
124 void
126 {
127  const Real cavity_volume = computeCavityVolume();
128 
129  if (!_initialized)
130  {
131  Real init_temp = _temperature;
132  if (_init_temp_given)
133  init_temp = _init_temp;
134 
135  if (MooseUtils::absoluteFuzzyLessEqual(init_temp, 0.0))
136  mooseError("Cannot have initial temperature of zero when initializing cavity pressure. "
137  "Does the supplied Postprocessor for temperature execute at initial?");
138 
139  Real volume_temp_ratio = cavity_volume / init_temp;
140 
141  for (unsigned int i = 0; i < _additional_volumes.size(); ++i)
142  volume_temp_ratio += *_additional_volumes[i] / *_temperature_of_additional_volumes[i];
143 
144  _n0 = _initial_pressure * volume_temp_ratio / _R;
145 
146  _start_time = _t - _dt;
147  const Real factor =
150  _initialized = true;
151  }
152 }
153 
154 void
156 {
157  const Real cavity_volume = computeCavityVolume();
158 
159  Real mat = 0;
160 
161  for (unsigned int i = 0; i < _material_input.size(); ++i)
162  mat += *_material_input[i];
163 
164  Real volume_temp_ratio = cavity_volume / _temperature;
165 
166  for (unsigned int i = 0; i < _additional_volumes.size(); ++i)
167  volume_temp_ratio += *_additional_volumes[i] / *_temperature_of_additional_volumes[i];
168 
169  const Real pressure = (_n0 + mat) * _R / volume_temp_ratio;
170  const Real factor = _t >= _start_time + _startup_time ? 1.0 : (_t - _start_time) / _startup_time;
171  _cavity_pressure = factor * pressure;
172 }
173 
174 Real
176 {
177  Real volume = 0;
178  for (unsigned int i = 0; i < _volume.size(); ++i)
179  volume += *_volume[i];
180 
181  return volume;
182 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
Real & _cavity_pressure
The pressure within the cavity.
Real getValue(const MooseEnum &quantity) const
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
CavityPressureUserObject(const InputParameters &parameters)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const Real _init_temp
The initial temperature.
std::vector< const PostprocessorValue * > _volume
Postprocessors whose sum equal the meshed cavity volume.
T & set(const std::string &name, bool quiet_mode=false)
virtual void initialize() override
const Number zero
std::vector< const PostprocessorValue * > _material_input
Postprocessors containing additional material released to the cavity.
virtual void execute() override
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real _R
The ideal gas constant.
bool isParamValid(const std::string &name) const
const bool _init_temp_given
Whether or not an initial temperature is given.
std::vector< const PostprocessorValue * > _temperature_of_additional_volumes
The temperature of the additional volume.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
registerMooseObject("SolidMechanicsApp", CavityPressureUserObject)
const std::string _name
const Real & _temperature
Reference to a postprocessor that contains the cavity temperature.
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
const Real _startup_time
The total time to ramp up the pressure to its initial value.
Real & _n0
Initial number of moles of gas.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _start_time
The time at which the pressure is at its maximum values.
std::vector< const PostprocessorValue * > _additional_volumes
Additional volume that communicates with the cavity volume but is not meshed.
bool absoluteFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
static const std::string pressure
Definition: NS.h:56
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const Elem & get(const ElemType type_in)