LCOV - code coverage report
Current view: top level - src/meshgenerators - MoveNodeGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 39 41 95.1 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 "MoveNodeGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : #include "libmesh/node.h"
      13             : 
      14             : registerMooseObject("MooseApp", MoveNodeGenerator);
      15             : 
      16             : InputParameters
      17       14337 : MoveNodeGenerator::validParams()
      18             : {
      19       14337 :   InputParameters params = MeshGenerator::validParams();
      20             : 
      21       14337 :   params.addRequiredParam<MeshGeneratorName>("input", "Input mesh to Move");
      22             : 
      23       14337 :   params.addRequiredParam<std::vector<dof_id_type>>("node_id", "Id of modified node");
      24             : 
      25       14337 :   params.addParam<std::vector<Point>>("new_position", "New position in vector space");
      26       14337 :   params.addParam<std::vector<Point>>("shift_position",
      27             :                                       "Shifts to apply to the position in vector space");
      28             : 
      29       14337 :   params.addClassDescription("Modifies the position of one or more nodes");
      30             : 
      31       14337 :   return params;
      32           0 : }
      33             : 
      34          40 : MoveNodeGenerator::MoveNodeGenerator(const InputParameters & parameters)
      35             :   : MeshGenerator(parameters),
      36          40 :     _input(getMesh("input")),
      37          40 :     _node_id(getParam<std::vector<dof_id_type>>("node_id")),
      38          40 :     _new_position(nullptr),
      39          40 :     _shift_position(nullptr)
      40             : {
      41          40 :   if (isParamValid("shift_position") == isParamValid("new_position"))
      42           4 :     mooseError("You must specify either 'shift_position' or 'new_position'! "
      43             :                "You have specified either both or none");
      44             : 
      45          36 :   if (isParamValid("new_position"))
      46             :   {
      47          28 :     _new_position = &getParam<std::vector<Point>>("new_position");
      48             : 
      49          28 :     if (_node_id.size() != _new_position->size())
      50           4 :       paramError("node_id", "Must be the same length as 'new_position'.");
      51             :   }
      52             : 
      53          32 :   if (isParamValid("shift_position"))
      54             :   {
      55           8 :     _shift_position = &getParam<std::vector<Point>>("shift_position");
      56             : 
      57           8 :     if (_node_id.size() != _shift_position->size())
      58           0 :       paramError("node_id", "Must be the same length as 'shift_position'.");
      59             :   }
      60          32 : }
      61             : 
      62             : std::unique_ptr<MeshBase>
      63          31 : MoveNodeGenerator::generate()
      64             : {
      65          31 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      66             : 
      67             :   // get the node
      68         112 :   for (MooseIndex(_node_id.size()) i = 0; i < _node_id.size(); i++)
      69             :   {
      70          85 :     std::size_t num_found = 0;
      71          85 :     auto * node = mesh->query_node_ptr(_node_id[i]);
      72             : 
      73             :     // change the position of the acquired node
      74          85 :     if (node)
      75             :     {
      76          80 :       if (_new_position)
      77          56 :         node->assign((*_new_position)[i]);
      78             :       else
      79             :       {
      80          24 :         Point pt((*node)(0), (*node)(1), (*node)(2));
      81          24 :         node->assign(pt + (*_shift_position)[i]);
      82             :       }
      83             : 
      84          80 :       ++num_found;
      85             :     }
      86             : 
      87             :     // Make sure we found the node
      88          85 :     mesh->comm().sum(num_found);
      89          85 :     if (!num_found)
      90           4 :       mooseError("A node with the ID ", _node_id[i], " was not found.");
      91             :   }
      92          54 :   return dynamic_pointer_cast<MeshBase>(mesh);
      93          27 : }

Generated by: LCOV version 1.14