LCOV - code coverage report
Current view: top level - src/meshgenerators - BoundingBoxNodeSetGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 38 38 100.0 %
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 "BoundingBoxNodeSetGenerator.h"
      11             : #include "MooseMeshUtils.h"
      12             : #include "CastUniquePointer.h"
      13             : #include "MooseUtils.h"
      14             : 
      15             : #include "libmesh/node.h"
      16             : 
      17             : registerMooseObject("MooseApp", BoundingBoxNodeSetGenerator);
      18             : 
      19             : InputParameters
      20       14397 : BoundingBoxNodeSetGenerator::validParams()
      21             : {
      22       14397 :   InputParameters params = MeshGenerator::validParams();
      23       14397 :   MooseEnum location("INSIDE OUTSIDE", "INSIDE");
      24             : 
      25       14397 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      26       14397 :   params.addClassDescription(
      27             :       "Assigns all of the nodes either inside or outside of a bounding box to a new nodeset.");
      28       14397 :   params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
      29             :                                                      "The name of the nodeset to create");
      30       14397 :   params.addRequiredParam<RealVectorValue>(
      31             :       "bottom_left",
      32             :       "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
      33       14397 :   params.addRequiredParam<RealVectorValue>(
      34             :       "top_right",
      35             :       "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
      36       14397 :   params.addParam<MooseEnum>("location", location, "Control of where the nodeset is to be set");
      37             : 
      38       28794 :   return params;
      39       14397 : }
      40             : 
      41          66 : BoundingBoxNodeSetGenerator::BoundingBoxNodeSetGenerator(const InputParameters & parameters)
      42             :   : MeshGenerator(parameters),
      43          66 :     _input(getMesh("input")),
      44          66 :     _location(getParam<MooseEnum>("location")),
      45          66 :     _bounding_box(MooseUtils::buildBoundingBox(getParam<RealVectorValue>("bottom_left"),
      46         198 :                                                getParam<RealVectorValue>("top_right")))
      47             : {
      48          66 : }
      49             : 
      50             : std::unique_ptr<MeshBase>
      51          65 : BoundingBoxNodeSetGenerator::generate()
      52             : {
      53          65 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      54             : 
      55             :   // Get the BoundaryIDs from the mesh
      56          65 :   std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
      57             :   std::vector<BoundaryID> boundary_ids =
      58          65 :       MooseMeshUtils::getBoundaryIDs(*mesh, boundary_names, true);
      59          65 :   if (boundary_ids.size() != 1)
      60           4 :     mooseError("Only one boundary ID can be assigned to a nodeset using a bounding box!");
      61             : 
      62             :   // Get a reference to our BoundaryInfo object
      63          61 :   BoundaryInfo & boundary_info = mesh->get_boundary_info();
      64             : 
      65          61 :   bool found_node = false;
      66          61 :   const bool inside = (_location == "INSIDE");
      67             : 
      68             :   // Loop over the elements and assign node set id to nodes within the bounding box
      69        2743 :   for (auto & node : as_range(mesh->active_nodes_begin(), mesh->active_nodes_end()))
      70        1341 :     if (_bounding_box.contains_point(*node) == inside)
      71             :     {
      72         420 :       boundary_info.add_node(node, boundary_ids[0]);
      73         420 :       found_node = true;
      74          61 :     }
      75             : 
      76             :   // Unless at least one processor found a node in the bounding box,
      77             :   // the user probably specified it incorrectly.
      78          61 :   this->comm().max(found_node);
      79             : 
      80          61 :   if (!found_node)
      81           4 :     mooseError("No nodes found within the bounding box");
      82             : 
      83          57 :   boundary_info.nodeset_name(boundary_ids[0]) = boundary_names[0];
      84             : 
      85          57 :   mesh->set_isnt_prepared();
      86         114 :   return dynamic_pointer_cast<MeshBase>(mesh);
      87          57 : }

Generated by: LCOV version 1.14