LCOV - code coverage report
Current view: top level - src/csg - CSGPlane.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 25 25 100.0 %
Date: 2025-10-29 16:49:47 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "CSGPlane.h"
      11             : 
      12             : namespace CSG
      13             : {
      14             : 
      15         130 : CSGPlane::CSGPlane(const std::string & name, const Point & p1, const Point & p2, const Point & p3)
      16         130 :   : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>())
      17             : {
      18         130 :   coeffsFromPoints(p1, p2, p3);
      19         130 : }
      20             : 
      21          32 : CSGPlane::CSGPlane(const std::string & name, const Real a, const Real b, const Real c, const Real d)
      22          32 :   : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>()), _a(a), _b(b), _c(c), _d(d)
      23             : {
      24          32 : }
      25             : 
      26             : std::unordered_map<std::string, Real>
      27         134 : CSGPlane::getCoeffs() const
      28             : {
      29         804 :   std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
      30         134 :   return coeffs;
      31         134 : }
      32             : 
      33             : void
      34         130 : CSGPlane::coeffsFromPoints(const Point & p1, const Point & p2, const Point & p3)
      35             : {
      36             :   // Use three points on plane to solve for the plane equation in form aX + bY +cZ = d,
      37             :   // where we are solving for a, b, c, and d.
      38         130 :   RealVectorValue v1 = p2 - p1;
      39         130 :   RealVectorValue v2 = p3 - p1;
      40         130 :   RealVectorValue cross = v2.cross(v1);
      41             : 
      42             :   // Check that provided points aren't collinear
      43         130 :   if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
      44           2 :     mooseError("Provided points to define a CSGPlane are collinear");
      45             : 
      46         128 :   _a = cross(0);
      47         128 :   _b = cross(1);
      48         128 :   _c = cross(2);
      49         128 :   _d = cross * (RealVectorValue)p1;
      50         128 : }
      51             : 
      52             : Real
      53         150 : CSGPlane::evaluateSurfaceEquationAtPoint(const Point & p) const
      54             : {
      55             :   // Compute dot product of <a, b, c> and p to determine if p lies
      56             :   // in the positive or negative halfspace of the plane
      57         150 :   const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
      58             : 
      59         150 :   return dot_prod - _d;
      60             : }
      61             : } // namespace CSG

Generated by: LCOV version 1.14