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 14301 : OrientedSubdomainBoundingBoxGenerator::validParams() 19 : { 20 14301 : InputParameters params = MeshGenerator::validParams(); 21 14301 : params += OrientedBoxInterface::validParams(); 22 : 23 14301 : MooseEnum location("INSIDE OUTSIDE", "INSIDE"); 24 : 25 14301 : params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify"); 26 14301 : params.addRequiredParam<subdomain_id_type>( 27 : "block_id", "Subdomain id to set for inside/outside the bounding box"); 28 14301 : params.addParam<MooseEnum>( 29 : "location", location, "Control of where the subdomain id is to be set"); 30 14301 : params.addClassDescription( 31 : "Defines a subdomain inside or outside of a bounding box with arbitrary orientation."); 32 : 33 28602 : return params; 34 14301 : } 35 : 36 18 : OrientedSubdomainBoundingBoxGenerator::OrientedSubdomainBoundingBoxGenerator( 37 18 : const InputParameters & parameters) 38 : : MeshGenerator(parameters), 39 : OrientedBoxInterface(parameters), 40 18 : _input(getMesh("input")), 41 18 : _location(parameters.get<MooseEnum>("location")), 42 36 : _block_id(parameters.get<subdomain_id_type>("block_id")) 43 : { 44 18 : } 45 : 46 : std::unique_ptr<MeshBase> 47 18 : OrientedSubdomainBoundingBoxGenerator::generate() 48 : { 49 18 : std::unique_ptr<MeshBase> mesh = std::move(_input); 50 : 51 : // Loop over the elements 52 51858 : for (const auto & elem : mesh->active_element_ptr_range()) 53 : { 54 25920 : bool contains = containsPoint(elem->vertex_average()); 55 25920 : if (contains && _location == "INSIDE") 56 1836 : elem->subdomain_id() = _block_id; 57 24084 : else if (!contains && _location == "OUTSIDE") 58 11124 : elem->subdomain_id() = _block_id; 59 18 : } 60 : 61 18 : mesh->set_isnt_prepared(); 62 36 : return dynamic_pointer_cast<MeshBase>(mesh); 63 18 : }