LCOV - code coverage report
Current view: top level - src/auxkernels - CartesianGrid.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 26 27 96.3 %
Date: 2025-07-15 20:50:38 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /********************************************************************/
       2             : /*                  SOFTWARE COPYRIGHT NOTIFICATION                 */
       3             : /*                             Cardinal                             */
       4             : /*                                                                  */
       5             : /*                  (c) 2021 UChicago Argonne, LLC                  */
       6             : /*                        ALL RIGHTS RESERVED                       */
       7             : /*                                                                  */
       8             : /*                 Prepared by UChicago Argonne, LLC                */
       9             : /*               Under Contract No. DE-AC02-06CH11357               */
      10             : /*                With the U. S. Department of Energy               */
      11             : /*                                                                  */
      12             : /*             Prepared by Battelle Energy Alliance, LLC            */
      13             : /*               Under Contract No. DE-AC07-05ID14517               */
      14             : /*                With the U. S. Department of Energy               */
      15             : /*                                                                  */
      16             : /*                 See LICENSE for full restrictions                */
      17             : /********************************************************************/
      18             : 
      19             : #include "CartesianGrid.h"
      20             : #include "libmesh/mesh_tools.h"
      21             : 
      22             : registerMooseObject("CardinalApp", CartesianGrid);
      23             : 
      24             : InputParameters
      25          24 : CartesianGrid::validParams()
      26             : {
      27          24 :   InputParameters params = AuxKernel::validParams();
      28          48 :   params.addRequiredRangeCheckedParam<unsigned int>("nx", "nx > 0", "Number of bins in x direction");
      29          48 :   params.addRequiredRangeCheckedParam<unsigned int>("ny", "ny > 0", "Number of bins in y direction");
      30          48 :   params.addRequiredRangeCheckedParam<unsigned int>("nz", "nz > 0", "Number of bins in z direction");
      31          48 :   params.addParam<Real>("shift", 0.0, "Optional shift to add to bin value");
      32          24 :   params.addClassDescription("Indices to divide space into 3-D Cartesian bins");
      33          24 :   return params;
      34           0 : }
      35             : 
      36          12 : CartesianGrid::CartesianGrid(const InputParameters & parameters) :
      37             :   AuxKernel(parameters),
      38          12 :   _nx(getParam<unsigned int>("nx")),
      39          24 :   _ny(getParam<unsigned int>("ny")),
      40          24 :   _nz(getParam<unsigned int>("nz")),
      41          36 :   _shift(getParam<Real>("shift"))
      42             : {
      43          12 :   BoundingBox bounding_box = MeshTools::create_bounding_box(_mesh);
      44          12 :   _min = bounding_box.min();
      45          12 :   auto max = bounding_box.max();
      46          12 :   _dx = (max(0) - _min(0)) / _nx;
      47          12 :   _dy = (max(1) - _min(1)) / _ny;
      48          12 :   _dz = (max(2) - _min(2)) / _nz;
      49          12 : }
      50             : 
      51             : Real
      52        3072 : CartesianGrid::computeValue()
      53             : {
      54        3072 :   Point pt = _current_elem->vertex_average();
      55        3072 :   int x = (pt(0) - _min(0))/ _dx;
      56        3072 :   int y = (pt(1) - _min(1))/ _dy;
      57        3072 :   int z = (pt(2) - _min(2))/ _dz;
      58        3072 :   return x + y * _nx + z * _nx * _ny + _shift;
      59             : }

Generated by: LCOV version 1.14