LCOV - code coverage report
Current view: top level - src/interfaces - OrientedBoxInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 31 35 88.6 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.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 "OrientedBoxInterface.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "InputParameters.h"
      14             : #include "MooseError.h"
      15             : 
      16             : #include <memory>
      17             : 
      18             : InputParameters
      19       28587 : OrientedBoxInterface::validParams()
      20             : {
      21             : 
      22       28587 :   InputParameters params = emptyInputParameters();
      23       28587 :   params.addRequiredParam<Point>("center",
      24             :                                  "The center (many people spell this 'center') of the box.");
      25       28587 :   params.addRequiredParam<Real>("width", "The width of the box");
      26       28587 :   params.addRequiredParam<Real>("length", "The length of the box");
      27       28587 :   params.addRequiredParam<Real>("height", "The height of the box");
      28       28587 :   params.addRequiredParam<RealVectorValue>("width_direction",
      29             :                                            "The direction along which the width is oriented.");
      30       28587 :   params.addRequiredParam<RealVectorValue>("length_direction",
      31             :                                            "The direction along which the length is oriented (must "
      32             :                                            "be perpendicular to width_direction).");
      33       28587 :   return params;
      34           0 : }
      35             : 
      36          29 : OrientedBoxInterface::OrientedBoxInterface(const InputParameters & parameters)
      37          29 :   : _center(parameters.get<Point>("center"))
      38             : {
      39          29 :   const std::string & name = parameters.get<std::string>("_object_name");
      40             : 
      41             :   // Define the bounding box
      42          29 :   Real xmax = 0.5 * parameters.get<Real>("width");
      43          29 :   Real ymax = 0.5 * parameters.get<Real>("length");
      44          29 :   Real zmax = 0.5 * parameters.get<Real>("height");
      45             : 
      46          29 :   Point bottom_left(-xmax, -ymax, -zmax);
      47          29 :   Point top_right(xmax, ymax, zmax);
      48             : 
      49          29 :   _bounding_box = std::make_unique<libMesh::BoundingBox>(bottom_left, top_right);
      50             : 
      51             :   /*
      52             :    * now create the rotation matrix that rotates the oriented
      53             :    * box's width direction to "x", its length direction to "y"
      54             :    * and its height direction to "z"
      55             :    */
      56          29 :   RealVectorValue w = parameters.get<RealVectorValue>("width_direction");
      57          29 :   RealVectorValue l = parameters.get<RealVectorValue>("length_direction");
      58             : 
      59             :   /*
      60             :    * Normalize the width and length directions in readiness for
      61             :    * insertion into the rotation matrix
      62             :    */
      63          29 :   Real len = w.norm();
      64          29 :   if (len == 0.0)
      65           0 :     mooseError("Length of width_direction vector is zero in ", name);
      66          29 :   w /= len;
      67             : 
      68          29 :   len = l.norm();
      69          29 :   if (len == 0.0)
      70           0 :     mooseError("Length of length_direction vector is zero in ", name);
      71          29 :   l /= len;
      72             : 
      73          29 :   if (w * l > 1E-10)
      74           0 :     mooseError("width_direction and length_direction are not perpendicular in ", name);
      75             : 
      76             :   // The rotation matrix!
      77          29 :   _rot_matrix = std::make_unique<RealTensorValue>(w, l, w.cross(l));
      78          29 : }
      79             : 
      80             : bool
      81       34560 : OrientedBoxInterface::containsPoint(const Point & point)
      82             : {
      83             :   // Translate the point to the origin, and then rotate
      84       34560 :   return _bounding_box->contains_point((*_rot_matrix) * (point - _center));
      85             : }

Generated by: LCOV version 1.14