LCOV - code coverage report
Current view: top level - src/meshgenerators - OrientedSubdomainBoundingBoxGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 28 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 "OrientedSubdomainBoundingBoxGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : 
      13             : #include "libmesh/elem.h"
      14             : 
      15             : registerMooseObject("MooseApp", OrientedSubdomainBoundingBoxGenerator);
      16             : 
      17             : InputParameters
      18       14297 : OrientedSubdomainBoundingBoxGenerator::validParams()
      19             : {
      20       14297 :   InputParameters params = MeshGenerator::validParams();
      21       14297 :   params += OrientedBoxInterface::validParams();
      22             : 
      23       14297 :   MooseEnum location("INSIDE OUTSIDE", "INSIDE");
      24             : 
      25       14297 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      26       14297 :   params.addRequiredParam<subdomain_id_type>(
      27             :       "block_id", "Subdomain id to set for inside/outside the bounding box");
      28       14297 :   params.addParam<MooseEnum>(
      29             :       "location", location, "Control of where the subdomain id is to be set");
      30       14297 :   params.addClassDescription(
      31             :       "Defines a subdomain inside or outside of a bounding box with arbitrary orientation.");
      32             : 
      33       28594 :   return params;
      34       14297 : }
      35             : 
      36          16 : OrientedSubdomainBoundingBoxGenerator::OrientedSubdomainBoundingBoxGenerator(
      37          16 :     const InputParameters & parameters)
      38             :   : MeshGenerator(parameters),
      39             :     OrientedBoxInterface(parameters),
      40          16 :     _input(getMesh("input")),
      41          16 :     _location(parameters.get<MooseEnum>("location")),
      42          32 :     _block_id(parameters.get<subdomain_id_type>("block_id"))
      43             : {
      44          16 : }
      45             : 
      46             : std::unique_ptr<MeshBase>
      47          16 : OrientedSubdomainBoundingBoxGenerator::generate()
      48             : {
      49          16 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      50             : 
      51             :   // Loop over the elements
      52       46096 :   for (const auto & elem : mesh->active_element_ptr_range())
      53             :   {
      54       23040 :     bool contains = containsPoint(elem->vertex_average());
      55       23040 :     if (contains && _location == "INSIDE")
      56        1632 :       elem->subdomain_id() = _block_id;
      57       21408 :     else if (!contains && _location == "OUTSIDE")
      58        9888 :       elem->subdomain_id() = _block_id;
      59          16 :   }
      60             : 
      61          16 :   mesh->set_isnt_prepared();
      62          32 :   return dynamic_pointer_cast<MeshBase>(mesh);
      63          16 : }

Generated by: LCOV version 1.14