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 "OverlayMeshGenerator.h" 11 : #include "CastUniquePointer.h" 12 : #include "DistributedRectilinearMeshGenerator.h" 13 : #include "InputParameters.h" 14 : 15 : // libMesh includes 16 : #include "libmesh/mesh_modification.h" 17 : #include "libmesh/mesh_tools.h" 18 : 19 : registerMooseObject("MooseApp", OverlayMeshGenerator); 20 : 21 : InputParameters 22 14281 : OverlayMeshGenerator::validParams() 23 : { 24 14281 : InputParameters params = MeshGenerator::validParams(); 25 : 26 14281 : params += DistributedRectilinearMeshGenerator::validParams(); 27 14281 : params.addRequiredParam<MeshGeneratorName>("input", "The base mesh we want to overlay"); 28 : 29 14281 : params.addClassDescription("Creates a Cartesian mesh overlaying " 30 : "the input mesh region."); 31 : 32 14281 : return params; 33 0 : } 34 : 35 8 : OverlayMeshGenerator::OverlayMeshGenerator(const InputParameters & parameters) 36 : : MeshGenerator(parameters), 37 8 : _dim(getParam<MooseEnum>("dim")), 38 16 : _mesh_name(getParam<MeshGeneratorName>("input")) 39 : { 40 : // Declare that all of the meshes in the "inputs" parameter are to be used by 41 : // a sub mesh generator 42 8 : declareMeshForSub("input"); 43 : 44 8 : _input_mesh = &getMeshByName(_mesh_name); 45 : 46 8 : auto input_params = _app.getFactory().getValidParams("DistributedRectilinearMeshGenerator"); 47 : 48 144 : input_params.applySpecificParameters(parameters, 49 : {"dim", 50 : "nx", 51 : "ny", 52 : "nz", 53 : "xmin", 54 : "ymin", 55 : "zmin", 56 : "xmax", 57 : "ymax", 58 : "zmax", 59 : "bias_x", 60 : "bias_y", 61 : "bias_z", 62 : "num_side_layers", 63 : "num_cores_for_partition", 64 : "partition", 65 : "elem_type"}); 66 : 67 8 : addMeshSubgenerator("DistributedRectilinearMeshGenerator", 68 16 : _mesh_name + "_distributedrectilinearmeshgenerator", 69 : input_params); 70 8 : _build_mesh = &getMeshByName(_mesh_name + "_distributedrectilinearmeshgenerator"); 71 24 : } 72 : std::unique_ptr<MeshBase> 73 8 : OverlayMeshGenerator::generate() 74 : { 75 8 : std::unique_ptr<MeshBase> input_mesh = std::move(*_input_mesh); 76 8 : std::unique_ptr<MeshBase> build_mesh = std::move(*_build_mesh); 77 : 78 : // find the boundary of the input mesh box 79 8 : auto bbox_input = MeshTools::create_bounding_box(*input_mesh); 80 : 81 : // Transform the generated DistributedRectilinearMesh to overlay with the input mesh 82 8 : RealVectorValue scale_factor; 83 8 : scale_factor = bbox_input.max() - bbox_input.min(); 84 : 85 : // scale 86 8 : if (scale_factor(0) != 1 || scale_factor(1) != 1 || scale_factor(2) != 1) 87 8 : MeshTools::Modification::scale(*build_mesh, scale_factor(0), scale_factor(1), scale_factor(2)); 88 : 89 8 : RealVectorValue translation_vector; 90 8 : translation_vector = bbox_input.min(); 91 : 92 : // translate 93 8 : if (translation_vector(0) != 0 || translation_vector(1) != 0 || translation_vector(2) != 0) 94 8 : MeshTools::Modification::translate( 95 8 : *build_mesh, translation_vector(0), translation_vector(1), translation_vector(2)); 96 : 97 16 : return dynamic_pointer_cast<MeshBase>(build_mesh); 98 8 : }