Line data Source code
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 : 10 : #include "NodalGravity.h" 11 : #include "MooseUtils.h" 12 : #include "DelimitedFileReader.h" 13 : #include "Function.h" 14 : 15 : registerMooseObject("SolidMechanicsApp", NodalGravity); 16 : 17 : InputParameters 18 32 : NodalGravity::validParams() 19 : { 20 32 : InputParameters params = NodalKernel::validParams(); 21 32 : params.addClassDescription("Computes the gravitational force for a given nodal mass."); 22 96 : params.addRangeCheckedParam<Real>("alpha", 23 64 : 0.0, 24 : "alpha >= -0.3333 & alpha <= 0.0", 25 : "Alpha parameter for mass dependent numerical damping induced " 26 : "by HHT time integration scheme"); 27 64 : params.addParam<Real>("mass", "Mass associated with the node"); 28 64 : params.addParam<FileName>( 29 : "nodal_mass_file", 30 : "The file containing the nodal positions and the corresponding nodal masses."); 31 64 : params.addParam<Real>("gravity_value", 0.0, "Acceleration due to gravity."); 32 : // A ConstantFunction of "1" is supplied as the default 33 64 : params.addParam<FunctionName>( 34 : "function", "1", "A function that describes the gravitational force"); 35 32 : return params; 36 0 : } 37 : 38 20 : NodalGravity::NodalGravity(const InputParameters & parameters) 39 : : NodalKernel(parameters), 40 20 : _has_mass(isParamValid("mass")), 41 40 : _has_nodal_mass_file(isParamValid("nodal_mass_file")), 42 28 : _mass(_has_mass ? getParam<Real>("mass") : 0.0), 43 40 : _alpha(getParam<Real>("alpha")), 44 40 : _gravity_value(getParam<Real>("gravity_value")), 45 40 : _function(getFunction("function")) 46 : { 47 20 : if (!_has_nodal_mass_file && !_has_mass) 48 2 : mooseError("NodalGravity: Please provide either mass or nodal_mass_file as input."); 49 18 : else if (_has_nodal_mass_file && _has_mass) 50 2 : mooseError("NodalGravity: Please provide either mass or nodal_mass_file as input, not both."); 51 : 52 16 : if (_has_nodal_mass_file) 53 : { 54 30 : MooseUtils::DelimitedFileReader nodal_mass_file(getParam<FileName>("nodal_mass_file")); 55 : nodal_mass_file.setHeaderFlag(MooseUtils::DelimitedFileReader::HeaderFlag::OFF); 56 10 : nodal_mass_file.read(); 57 10 : std::vector<std::vector<Real>> data = nodal_mass_file.getData(); 58 10 : if (data.size() != 4) 59 4 : mooseError("NodalGravity: The number of columns in ", 60 : getParam<FileName>("nodal_mass_file"), 61 : " should be 4."); 62 : 63 8 : unsigned int node_found = 0; 64 8 : const std::set<BoundaryID> bnd_ids = BoundaryRestrictable::boundaryIDs(); 65 22 : for (auto & bnd_id : bnd_ids) 66 : { 67 14 : const std::vector<dof_id_type> & bnd_node_set = _mesh.getNodeList(bnd_id); 68 28 : for (auto & bnd_node : bnd_node_set) 69 : { 70 14 : const Node & node = _mesh.nodeRef(bnd_node); 71 14 : _node_id_to_mass[bnd_node] = 0.0; 72 : 73 22 : for (unsigned int i = 0; i < data[0].size(); ++i) 74 : { 75 14 : if (MooseUtils::absoluteFuzzyEqual(data[0][i], node(0), 1e-6) && 76 36 : MooseUtils::absoluteFuzzyEqual(data[1][i], node(1), 1e-6) && 77 : MooseUtils::absoluteFuzzyEqual(data[2][i], node(2), 1e-6)) 78 : { 79 14 : _node_id_to_mass[bnd_node] = data[3][i]; 80 14 : node_found += 1; 81 14 : break; 82 : } 83 : } 84 : } 85 : } 86 8 : if (node_found != data[0].size()) 87 2 : mooseError("NodalGravity: Out of ", 88 2 : data[0].size(), 89 : " nodal positions in ", 90 : getParam<FileName>("nodal_mass_file"), 91 : " only ", 92 : node_found, 93 : " nodes were found in the boundary."); 94 6 : } 95 12 : } 96 : 97 : Real 98 1600 : NodalGravity::computeQpResidual() 99 : { 100 : Real mass = 0.0; 101 1600 : if (_has_mass) 102 800 : mass = _mass; 103 : else 104 : { 105 800 : if (_node_id_to_mass.find(_current_node->id()) != _node_id_to_mass.end()) 106 800 : mass = _node_id_to_mass[_current_node->id()]; 107 : else 108 0 : mooseError("NodalGravity: Unable to find an entry for the current node in the " 109 : "_node_id_to_mass map."); 110 : } 111 1600 : Real factor = _gravity_value * _function.value(_t + _alpha * _dt, (*_current_node)); 112 1600 : return mass * -factor; 113 : }