https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NodalGravity.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
10#include "NodalGravity.h"
11#include "MooseUtils.h"
12#include "DelimitedFileReader.h"
13#include "Function.h"
14
15registerMooseObject("SolidMechanicsApp", NodalGravity);
16
19{
21 params.addClassDescription("Computes the gravitational force for a given nodal mass.");
22 params.addRangeCheckedParam<Real>("alpha",
23 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 params.addParam<Real>("mass", "Mass associated with the node");
28 params.addParam<FileName>(
29 "nodal_mass_file",
30 "The file containing the nodal positions and the corresponding nodal masses.");
31 params.addParam<Real>("gravity_value", 0.0, "Acceleration due to gravity.");
32 // A ConstantFunction of "1" is supplied as the default
33 params.addParam<FunctionName>(
34 "function", "1", "A function that describes the gravitational force");
35 return params;
36}
37
39 : NodalKernel(parameters),
40 _has_mass(isParamValid("mass")),
41 _has_nodal_mass_file(isParamValid("nodal_mass_file")),
42 _mass(_has_mass ? getParam<Real>("mass") : 0.0),
43 _alpha(getParam<Real>("alpha")),
44 _gravity_value(getParam<Real>("gravity_value")),
45 _function(getFunction("function"))
46{
48 mooseError("NodalGravity: Please provide either mass or nodal_mass_file as input.");
50 mooseError("NodalGravity: Please provide either mass or nodal_mass_file as input, not both.");
51
53 {
54 MooseUtils::DelimitedFileReader nodal_mass_file(getParam<FileName>("nodal_mass_file"));
55 nodal_mass_file.setHeaderFlag(MooseUtils::DelimitedFileReader::HeaderFlag::OFF);
56 nodal_mass_file.read();
57 std::vector<std::vector<Real>> data = nodal_mass_file.getData();
58 if (data.size() != 4)
59 mooseError("NodalGravity: The number of columns in ",
60 getParam<FileName>("nodal_mass_file"),
61 " should be 4.");
62
63 unsigned int node_found = 0;
64 const std::set<BoundaryID> bnd_ids = BoundaryRestrictable::boundaryIDs();
65 for (auto & bnd_id : bnd_ids)
66 {
67 const std::vector<dof_id_type> & bnd_node_set = _mesh.getNodeList(bnd_id);
68 for (auto & bnd_node : bnd_node_set)
69 {
70 const Node & node = _mesh.nodeRef(bnd_node);
71 _node_id_to_mass[bnd_node] = 0.0;
72
73 for (unsigned int i = 0; i < data[0].size(); ++i)
74 {
75 if (MooseUtils::absoluteFuzzyEqual(data[0][i], node(0), 1e-6) &&
76 MooseUtils::absoluteFuzzyEqual(data[1][i], node(1), 1e-6) &&
77 MooseUtils::absoluteFuzzyEqual(data[2][i], node(2), 1e-6))
78 {
79 _node_id_to_mass[bnd_node] = data[3][i];
80 node_found += 1;
81 break;
82 }
83 }
84 }
85 }
86 if (node_found != data[0].size())
87 mooseError("NodalGravity: Out of ",
88 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 }
95}
96
97Real
99{
100 Real mass = 0.0;
101 if (_has_mass)
102 mass = _mass;
103 else
104 {
105 if (_node_id_to_mass.find(_current_node->id()) != _node_id_to_mass.end())
106 mass = _node_id_to_mass[_current_node->id()];
107 else
108 mooseError("NodalGravity: Unable to find an entry for the current node in the "
109 "_node_id_to_mass map.");
110 }
111 Real factor = _gravity_value * _function.value(_t + _alpha * _dt, (*_current_node));
112 return mass * -factor;
113}
registerMooseObject("SolidMechanicsApp", NodalGravity)
virtual const std::set< BoundaryID > & boundaryIDs() const
virtual Real value(Real t, const Point &p) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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)
void mooseError(Args &&... args) const
virtual const Node & nodeRef(const dof_id_type i) const
const std::vector< dof_id_type > & getNodeList(boundary_id_type nodeset_id) const
const std::vector< std::vector< T > > & getData() const
void setHeaderFlag(HeaderFlag value)
Calculates the gravitational force proportional to nodal mass.
virtual Real computeQpResidual() override
NodalGravity(const InputParameters &parameters)
std::map< dof_id_type, Real > _node_id_to_mass
Map between boundary nodes and nodal mass.
const bool _has_mass
Booleans for validity of params.
static InputParameters validParams()
const Real _mass
Mass associated with the node.
const Real _alpha
HHT time integration parameter.
const bool _has_nodal_mass_file
const Real _gravity_value
Acceleration due to gravity.
const Function & _function
Time and space dependent factor multiplying acceleration due to gravity.
const Node *const & _current_node
static InputParameters validParams()
MooseMesh & _mesh