LCOV - code coverage report
Current view: top level - src/mesh - TiledMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 58 70 82.9 %
Date: 2025-07-17 01:28:37 Functions: 3 6 50.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 "TiledMesh.h"
      11             : #include "Parser.h"
      12             : #include "InputParameters.h"
      13             : #include "MooseApp.h"
      14             : 
      15             : #include "libmesh/mesh_modification.h"
      16             : #include "libmesh/serial_mesh.h"
      17             : #include "libmesh/exodusII_io.h"
      18             : 
      19             : registerMooseObject("MooseApp", TiledMesh);
      20             : 
      21             : InputParameters
      22       14285 : TiledMesh::validParams()
      23             : {
      24       14285 :   InputParameters params = MooseMesh::validParams();
      25       14285 :   params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
      26             : 
      27       14285 :   params.addParam<Real>("x_width", 0, "The tile width in the x direction");
      28       14285 :   params.addParam<Real>("y_width", 0, "The tile width in the y direction");
      29       14285 :   params.addParam<Real>("z_width", 0, "The tile width in the z direction");
      30             : 
      31             :   // x boundary names
      32       14285 :   params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
      33       14285 :   params.addParam<BoundaryName>(
      34             :       "right_boundary", "right_boundary", "name of the right (x) boundary");
      35             : 
      36             :   // y boundary names
      37       14285 :   params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
      38       14285 :   params.addParam<BoundaryName>(
      39             :       "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
      40             : 
      41             :   // z boundary names
      42       14285 :   params.addParam<BoundaryName>(
      43             :       "front_boundary", "front_boundary", "name of the front (z) boundary");
      44       14285 :   params.addParam<BoundaryName>("back_boundary", "back_boundary", "name of the back (z) boundary");
      45             : 
      46             :   // The number of tiles is 1 in each direction unless otherwise specified.
      47             :   // An x_tiles value of 1 means do not stitch any extra meshes together in
      48             :   // the x-direction.
      49       42855 :   params.addParam<unsigned int>(
      50       28570 :       "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
      51       42855 :   params.addParam<unsigned int>(
      52       28570 :       "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
      53       42855 :   params.addParam<unsigned int>(
      54       28570 :       "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
      55             : 
      56       14285 :   params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
      57             :                              "in the x,y, and z directions.");
      58             : 
      59       14285 :   return params;
      60           0 : }
      61             : 
      62          10 : TiledMesh::TiledMesh(const InputParameters & parameters)
      63             :   : MooseMesh(parameters),
      64          10 :     _x_width(getParam<Real>("x_width")),
      65          10 :     _y_width(getParam<Real>("y_width")),
      66          20 :     _z_width(getParam<Real>("z_width"))
      67             : {
      68             :   // The TiledMesh class only works with ReplicatedMesh
      69          10 :   errorIfDistributedMesh("TiledMesh");
      70          10 : }
      71             : 
      72           0 : TiledMesh::TiledMesh(const TiledMesh & other_mesh)
      73             :   : MooseMesh(other_mesh),
      74           0 :     _x_width(other_mesh._x_width),
      75           0 :     _y_width(other_mesh._y_width),
      76           0 :     _z_width(other_mesh._z_width)
      77             : {
      78           0 : }
      79             : 
      80             : std::unique_ptr<MooseMesh>
      81           0 : TiledMesh::safeClone() const
      82             : {
      83           0 :   return _app.getFactory().copyConstruct(*this);
      84             : }
      85             : 
      86             : std::string
      87           0 : TiledMesh::getFileName() const
      88             : {
      89           0 :   return getParam<MeshFileName>("file");
      90             : }
      91             : 
      92             : void
      93          10 : TiledMesh::buildMesh()
      94             : {
      95             :   // stitch_meshes() is only implemented for ReplicatedMesh.  So make sure
      96             :   // we have one here before continuing.
      97          10 :   ReplicatedMesh * serial_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
      98             : 
      99          10 :   if (!serial_mesh)
     100           0 :     mooseError("Error, TiledMesh calls stitch_meshes() which only works on ReplicatedMesh.");
     101             :   else
     102             :   {
     103          10 :     std::string mesh_file(getParam<MeshFileName>("file"));
     104             : 
     105          10 :     if (mesh_file.rfind(".exd") < mesh_file.size() || mesh_file.rfind(".e") < mesh_file.size())
     106             :     {
     107          10 :       libMesh::ExodusII_IO ex(*this);
     108          10 :       ex.read(mesh_file);
     109          10 :       serial_mesh->prepare_for_use();
     110          10 :     }
     111             :     else
     112           0 :       serial_mesh->read(mesh_file);
     113             : 
     114          10 :     BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
     115          10 :     BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
     116          10 :     BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
     117          10 :     BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
     118          10 :     BoundaryID front = getBoundaryID(getParam<BoundaryName>("front_boundary"));
     119          10 :     BoundaryID back = getBoundaryID(getParam<BoundaryName>("back_boundary"));
     120             : 
     121             :     {
     122          10 :       std::unique_ptr<MeshBase> clone = serial_mesh->clone();
     123             : 
     124             :       // Build X Tiles
     125          20 :       for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
     126             :       {
     127          10 :         MeshTools::Modification::translate(*clone, _x_width, 0, 0);
     128          10 :         serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
     129             :                                    right,
     130             :                                    left,
     131             :                                    TOLERANCE,
     132             :                                    /*clear_stitched_boundary_ids=*/true);
     133             :       }
     134          10 :     }
     135             :     {
     136          10 :       std::unique_ptr<MeshBase> clone = serial_mesh->clone();
     137             : 
     138             :       // Build Y Tiles
     139          20 :       for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
     140             :       {
     141          10 :         MeshTools::Modification::translate(*clone, 0, _y_width, 0);
     142          10 :         serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
     143             :                                    top,
     144             :                                    bottom,
     145             :                                    TOLERANCE,
     146             :                                    /*clear_stitched_boundary_ids=*/true);
     147             :       }
     148          10 :     }
     149             :     {
     150          10 :       std::unique_ptr<MeshBase> clone = serial_mesh->clone();
     151             : 
     152             :       // Build Z Tiles
     153          20 :       for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
     154             :       {
     155          10 :         MeshTools::Modification::translate(*clone, 0, 0, _z_width);
     156          10 :         serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
     157             :                                    front,
     158             :                                    back,
     159             :                                    TOLERANCE,
     160             :                                    /*clear_stitched_boundary_ids=*/true);
     161             :       }
     162          10 :     }
     163          10 :   }
     164          10 : }

Generated by: LCOV version 1.14