Line data Source code
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 "CavityPressureUserObject.h" 11 : 12 : registerMooseObject("TensorMechanicsApp", CavityPressureUserObject); 13 : 14 : InputParameters 15 0 : CavityPressureUserObject::validParams() 16 : { 17 0 : InputParameters params = GeneralUserObject::validParams(); 18 0 : params.addClassDescription("Uses the ideal gas law to compute internal pressure " 19 : "and an initial moles of gas quantity."); 20 0 : params.addRangeCheckedParam<Real>( 21 : "initial_pressure", 22 0 : 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 0 : 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."); 28 0 : params.addRequiredRangeCheckedParam<Real>( 29 : "R", "R > 0.0", "The universal gas constant for the units used."); 30 0 : params.addRequiredParam<PostprocessorName>( 31 : "temperature", "The name of the average temperature postprocessor value."); 32 0 : params.addRangeCheckedParam<Real>( 33 : "initial_temperature", "initial_temperature > 0.0", "Initial temperature (optional)"); 34 0 : 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 0 : 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 0 : 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 0 : params.addParam<Real>( 46 : "startup_time", 47 0 : 0.0, 48 : "The amount of time during which the pressure will ramp from zero to its true value."); 49 0 : params.set<bool>("use_displaced_mesh") = true; 50 : 51 0 : return params; 52 0 : } 53 : 54 0 : CavityPressureUserObject::CavityPressureUserObject(const InputParameters & params) 55 : : GeneralUserObject(params), 56 0 : _cavity_pressure(declareRestartableData<Real>("cavity_pressure", 0.0)), 57 0 : _n0(declareRestartableData<Real>("initial_moles", 0.0)), 58 0 : _initial_pressure(getParam<Real>("initial_pressure")), 59 0 : _material_input(params.get<std::vector<PostprocessorName>>("material_input").size()), 60 0 : _volume(params.get<std::vector<PostprocessorName>>("volume").size()), 61 0 : _R(getParam<Real>("R")), 62 0 : _temperature(getPostprocessorValue("temperature")), 63 0 : _init_temp_given(isParamValid("initial_temperature")), 64 0 : _init_temp(_init_temp_given ? getParam<Real>("initial_temperature") : 0.0), 65 0 : _startup_time(getParam<Real>("startup_time")), 66 0 : _initialized(declareRestartableData<bool>("initialized", false)), 67 0 : _additional_volumes( 68 0 : isParamValid("additional_volumes") 69 0 : ? params.get<std::vector<PostprocessorName>>("additional_volumes").size() 70 : : zero), 71 0 : _temperature_of_additional_volumes( 72 0 : isParamValid("temperature_of_additional_volumes") 73 0 : ? params.get<std::vector<PostprocessorName>>("temperature_of_additional_volumes").size() 74 : : zero), 75 0 : _start_time(0.0) 76 : { 77 0 : auto material_names = params.get<std::vector<PostprocessorName>>("material_input"); 78 0 : for (unsigned int i = 0; i < _material_input.size(); ++i) 79 0 : _material_input[i] = &getPostprocessorValueByName(material_names[i]); 80 : 81 0 : auto volume_names = params.get<std::vector<PostprocessorName>>("volume"); 82 0 : for (unsigned int i = 0; i < volume_names.size(); ++i) 83 0 : _volume[i] = &getPostprocessorValueByName(volume_names[i]); 84 : 85 0 : if (isParamValid("additional_volumes") != isParamValid("temperature_of_additional_volumes")) 86 0 : mooseError("Both additional volumes and their corresponding temperatures must be specified"); 87 : 88 0 : if (_additional_volumes.size() != _temperature_of_additional_volumes.size()) 89 0 : mooseError( 90 : "The number of additional volumes and temperatures of additional volumes musts be equal."); 91 : 92 0 : auto additional_volume_names = params.get<std::vector<PostprocessorName>>("additional_volumes"); 93 0 : for (unsigned int i = 0; i < _additional_volumes.size(); ++i) 94 0 : _additional_volumes[i] = &getPostprocessorValueByName(additional_volume_names[i]); 95 : 96 : auto temperature_of_additional_volume_names = 97 0 : params.get<std::vector<PostprocessorName>>("temperature_of_additional_volumes"); 98 0 : for (unsigned int i = 0; i < _temperature_of_additional_volumes.size(); ++i) 99 0 : _temperature_of_additional_volumes[i] = 100 0 : &getPostprocessorValueByName(temperature_of_additional_volume_names[i]); 101 0 : } 102 : 103 : Real 104 0 : CavityPressureUserObject::getValue(const MooseEnum & quantity) const 105 : { 106 : Real value = 0; 107 0 : if (quantity == INITIAL_MOLES) 108 : { 109 0 : if (_n0 < 0.0) 110 0 : mooseError("In ", 111 0 : _name, 112 : ": Negative number of moles calculated as an input for the cavity pressure"); 113 : 114 : value = _n0; 115 : } 116 0 : else if (quantity == CAVITY_PRESSURE) 117 0 : value = _cavity_pressure; 118 : else 119 0 : mooseError("In ", _name, ": Unknown quantity."); 120 : 121 0 : return value; 122 : } 123 : 124 : void 125 0 : CavityPressureUserObject::initialize() 126 : { 127 0 : const Real cavity_volume = computeCavityVolume(); 128 : 129 0 : if (!_initialized) 130 : { 131 0 : Real init_temp = _temperature; 132 0 : if (_init_temp_given) 133 0 : init_temp = _init_temp; 134 : 135 0 : if (MooseUtils::absoluteFuzzyLessEqual(init_temp, 0.0)) 136 0 : mooseError("Cannot have initial temperature of zero when initializing cavity pressure. " 137 : "Does the supplied Postprocessor for temperature execute at initial?"); 138 : 139 0 : Real volume_temp_ratio = cavity_volume / init_temp; 140 : 141 0 : for (unsigned int i = 0; i < _additional_volumes.size(); ++i) 142 0 : volume_temp_ratio += *_additional_volumes[i] / *_temperature_of_additional_volumes[i]; 143 : 144 0 : _n0 = _initial_pressure * volume_temp_ratio / _R; 145 : 146 0 : _start_time = _t - _dt; 147 : const Real factor = 148 0 : _t >= _start_time + _startup_time ? 1.0 : (_t - _start_time) / _startup_time; 149 0 : _cavity_pressure = factor * _initial_pressure; 150 0 : _initialized = true; 151 : } 152 0 : } 153 : 154 : void 155 0 : CavityPressureUserObject::execute() 156 : { 157 0 : const Real cavity_volume = computeCavityVolume(); 158 : 159 : Real mat = 0; 160 : 161 0 : for (unsigned int i = 0; i < _material_input.size(); ++i) 162 0 : mat += *_material_input[i]; 163 : 164 0 : Real volume_temp_ratio = cavity_volume / _temperature; 165 : 166 0 : for (unsigned int i = 0; i < _additional_volumes.size(); ++i) 167 0 : volume_temp_ratio += *_additional_volumes[i] / *_temperature_of_additional_volumes[i]; 168 : 169 0 : const Real pressure = (_n0 + mat) * _R / volume_temp_ratio; 170 0 : const Real factor = _t >= _start_time + _startup_time ? 1.0 : (_t - _start_time) / _startup_time; 171 0 : _cavity_pressure = factor * pressure; 172 0 : } 173 : 174 : Real 175 0 : CavityPressureUserObject::computeCavityVolume() 176 : { 177 : Real volume = 0; 178 0 : for (unsigned int i = 0; i < _volume.size(); ++i) 179 0 : volume += *_volume[i]; 180 : 181 0 : return volume; 182 : }