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