LCOV - code coverage report
Current view: top level - src/userobjects - LayeredGapBin.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 50 52 96.2 %
Date: 2025-07-15 20:50:38 Functions: 7 8 87.5 %
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 "LayeredGapBin.h"
      20             : 
      21             : registerMooseObject("CardinalApp", LayeredGapBin);
      22             : 
      23             : InputParameters
      24         120 : LayeredGapBin::validParams()
      25             : {
      26         120 :   InputParameters params = PlaneSpatialBinUserObject::validParams();
      27         240 :   MooseEnum directions("x y z");
      28             : 
      29         240 :   params.addRequiredParam<MooseEnum>(
      30             :       "direction", directions, "The direction of the layers (x, y, or z)");
      31         240 :   params.addRequiredRangeCheckedParam<unsigned int>(
      32             :       "num_layers",
      33             :       "num_layers > 0",
      34             :       "The number of layers between the bounding box of the domain; this will "
      35             :       "create num_layers + 1 side bins");
      36         120 :   params.addClassDescription("Creates a unique spatial bin for layers in a specified direction");
      37         120 :   return params;
      38         120 : }
      39             : 
      40          60 : LayeredGapBin::LayeredGapBin(const InputParameters & parameters)
      41             :   : PlaneSpatialBinUserObject(parameters),
      42          60 :     _direction(parameters.get<MooseEnum>("direction")),
      43         120 :     _num_layers(getParam<unsigned int>("num_layers")),
      44          60 :     _layered_subproblem(parameters.getCheckedPointerParam<SubProblem *>("_subproblem")),
      45         120 :     _num_faces(_num_layers + 1)
      46             : {
      47          60 :   BoundingBox bounding_box = MeshTools::create_bounding_box(_layered_subproblem->mesh());
      48          60 :   _direction_min = bounding_box.min()(_direction);
      49          60 :   _direction_max = bounding_box.max()(_direction);
      50             : 
      51          60 :   _directions = {_direction};
      52             : 
      53          60 :   _layer_pts.resize(_num_faces);
      54          60 :   _layer_pts[0] = _direction_min;
      55          60 :   Real dx = (_direction_max - _direction_min) / _num_layers;
      56         324 :   for (unsigned int i = 1; i < _num_faces; ++i)
      57         264 :     _layer_pts[i] = _layer_pts[i - 1] + dx;
      58             : 
      59          60 :   _bin_centers.resize(_num_faces);
      60          60 :   _unit_normals.resize(_num_faces);
      61         384 :   for (unsigned int i = 0; i < _num_faces; ++i)
      62             :   {
      63         324 :     _bin_centers[i] = Point(0.0, 0.0, 0.0);
      64         324 :     _bin_centers[i](_direction) = _layer_pts[i];
      65             : 
      66         324 :     _unit_normals[i] = Point(0.0, 0.0, 0.0);
      67         324 :     _unit_normals[i](_direction) = 1.0;
      68             :   }
      69             : 
      70          60 :   _effective_layer_pts.resize(_num_layers + 2);
      71          60 :   _effective_layer_pts[0] = _direction_min - dx;
      72          60 :   _effective_layer_pts[_num_layers + 1] = _direction_max + dx;
      73         324 :   for (unsigned int i = 1; i < _num_layers + 1; ++i)
      74         264 :     _effective_layer_pts[i] = 0.5 * (_layer_pts[i] + _layer_pts[i - 1]);
      75          60 : }
      76             : 
      77             : unsigned int
      78    60727670 : LayeredGapBin::bin(const Point & p) const
      79             : {
      80    60727670 :   Real direction_x = p(_direction);
      81    60727670 :   return binFromBounds(direction_x, _effective_layer_pts);
      82             : }
      83             : 
      84             : unsigned int
      85    26465244 : LayeredGapBin::num_bins() const
      86             : {
      87    26465244 :   return _num_faces;
      88             : }
      89             : 
      90             : unsigned int
      91           0 : LayeredGapBin::gapIndex(const Point & p) const
      92             : {
      93           0 :   return bin(p);
      94             : }
      95             : 
      96             : Real
      97    34191360 : LayeredGapBin::distanceFromGap(const Point & point, const unsigned int & gap_index) const
      98             : {
      99    34191360 :   const auto & layer_pt = _layer_pts[gap_index];
     100    34191360 :   return std::abs(point(_direction) - layer_pt);
     101             : }
     102             : 
     103             : void
     104    34191360 : LayeredGapBin::gapIndexAndDistance(const Point & point, unsigned int & index, Real & distance) const
     105             : {
     106    34191360 :   index = bin(point);
     107    34191360 :   distance = distanceFromGap(point, index);
     108    34191360 : }
     109             : 
     110             : Real
     111        4064 : LayeredGapBin::adjustBinValue(const unsigned int & i) const
     112             : {
     113             :   // This bin object gets _direction_min and _direction_max from a bounding box over the
     114             :   // mesh. This means that the first and last planes are on the boundary of the domain,
     115             :   // so the integrating volume is actually only half of _gap_thickness in
     116             :   // NekBinnedPlaneIntegral/NekBinnedPlaneAverage. Therefore, to get correct area integrals,
     117             :   // we divide each integral by _gap_thickness (in NekSideBinnedIntegral) except for the
     118             :   // first and last bins, which we only divide by _gap_thickness / 2.0
     119             : 
     120        4064 :   if (i == 0 || i == (num_bins() - 1))
     121        1168 :     return 2.0;
     122             : 
     123             :   return 1.0;
     124             : }

Generated by: LCOV version 1.14