https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MoveNodeGenerator.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 "MoveNodeGenerator.h"
11#include "CastUniquePointer.h"
12#include "libmesh/node.h"
13
15
18{
20
21 params.addRequiredParam<MeshGeneratorName>("input", "Input mesh to Move");
22
23 params.addRequiredParam<std::vector<dof_id_type>>("node_id", "Id of modified node");
24
25 params.addParam<std::vector<Point>>("new_position", "New position in vector space");
26 params.addParam<std::vector<Point>>("shift_position",
27 "Shifts to apply to the position in vector space");
28
29 params.addClassDescription("Modifies the position of one or more nodes");
30
31 return params;
32}
33
35 : MeshGenerator(parameters),
36 _input(getMesh("input")),
37 _node_id(getParam<std::vector<dof_id_type>>("node_id")),
38 _new_position(nullptr),
39 _shift_position(nullptr)
40{
41 if (isParamValid("shift_position") == isParamValid("new_position"))
42 mooseError("You must specify either 'shift_position' or 'new_position'! "
43 "You have specified either both or none");
44
45 if (isParamValid("new_position"))
46 {
47 _new_position = &getParam<std::vector<Point>>("new_position");
48
49 if (_node_id.size() != _new_position->size())
50 paramError("node_id", "Must be the same length as 'new_position'.");
51 }
52
53 if (isParamValid("shift_position"))
54 {
55 _shift_position = &getParam<std::vector<Point>>("shift_position");
56
57 if (_node_id.size() != _shift_position->size())
58 paramError("node_id", "Must be the same length as 'shift_position'.");
59 }
60}
61
62std::unique_ptr<MeshBase>
64{
65 std::unique_ptr<MeshBase> mesh = std::move(_input);
66
67 // get the node
68 for (MooseIndex(_node_id.size()) i = 0; i < _node_id.size(); i++)
69 {
70 std::size_t num_found = 0;
71 auto * node = mesh->query_node_ptr(_node_id[i]);
72
73 // change the position of the acquired node
74 if (node)
75 {
76 if (_new_position)
77 node->assign((*_new_position)[i]);
78 else
79 {
80 Point pt((*node)(0), (*node)(1), (*node)(2));
81 node->assign(pt + (*_shift_position)[i]);
82 }
83
84 ++num_found;
85 }
86
87 // Make sure we found the node
88 mesh->comm().sum(num_found);
89 if (!num_found)
90 mooseError("A node with the ID ", _node_id[i], " was not found.");
91 }
92 return dynamic_pointer_cast<MeshBase>(mesh);
93}
registerMooseObject("MooseApp", MoveNodeGenerator)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Modifies the position of one or more node(s)
static InputParameters validParams()
const std::vector< Point > * _shift_position
The shift(s) to apply to each node.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
const std::vector< dof_id_type > _node_id
The id(s) of the node(s) to be moved.
MoveNodeGenerator(const InputParameters &parameters)
const std::vector< Point > * _new_position
The new position(s) of the node.
MeshBase & mesh