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 : #pragma once 11 : 12 : #ifdef MOOSE_UNIT_TEST 13 : #include "gtest/gtest.h" 14 : #endif 15 : 16 : #include "MooseApp.h" 17 : #include "MooseEnum.h" 18 : 19 : namespace CSG 20 : { 21 : 22 : /** 23 : * CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) 24 : * surface, represented as some polynomial in x, y, and z 25 : */ 26 : class CSGSurface 27 : { 28 : public: 29 : /// Enum for the sign of the half-space being represented by a point and surface 30 : enum class Halfspace 31 : { 32 : POSITIVE, 33 : NEGATIVE 34 : }; 35 : 36 : /** 37 : * Default constructor 38 : * 39 : * @param name unique name of surface 40 : */ 41 : CSGSurface(const std::string & name); 42 : 43 : /** 44 : * @brief Construct a new CSGSurface 45 : * 46 : * @param name unique name of surface 47 : * @param surf_type surface type 48 : */ 49 : CSGSurface(const std::string & name, const std::string & surf_type); 50 : 51 : /** 52 : * Destructor 53 : */ 54 252 : virtual ~CSGSurface() = default; 55 : 56 : /** 57 : * @brief Get the Surface Type 58 : * 59 : * @return type of surface 60 : */ 61 328 : const std::string & getSurfaceType() const { return _surface_type; } 62 : 63 : /** 64 : * @brief Get the coefficients that define the surface 65 : * 66 : * @return map of coefficients and their values 67 : */ 68 : virtual std::unordered_map<std::string, Real> getCoeffs() const = 0; // Pure virtual function 69 : 70 : /** 71 : * @brief given a point, determine its evaluation based on the surface equation. A positive value 72 : * indicates a point that lies in the positive half-space with regards to the surface, a negative 73 : * value indicates a point that lies in the negative side of the surface, and a value of 0 74 : * indicates that the point lies on the surface. 75 : * 76 : * @param p point 77 : * @return evaluation of point based on surface equation 78 : */ 79 : virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const = 0; // Pure virtual function 80 : 81 : /** 82 : * @brief given a point, determine if it is in the positive or negative 83 : * half-space for the surface 84 : * 85 : * @param p point 86 : * @return sign of the half-space 87 : */ 88 : CSGSurface::Halfspace getHalfspaceFromPoint(const Point & p) const; 89 : 90 : /** 91 : * @brief Get the name of surface 92 : * 93 : * @return std::string name of surface 94 : */ 95 1376 : const std::string & getName() const { return _name; } 96 : 97 : /// Operator overload for checking if two CSGSurface objects are equal 98 : bool operator==(const CSGSurface & other) const; 99 : 100 : /// Operator overload for checking if two CSGSurface objects are not equal 101 : bool operator!=(const CSGSurface & other) const; 102 : 103 : protected: 104 : // set the name of the surface - intentionally not public because 105 : // name needs to be managed at the CSGSurfaceList level 106 24 : void setName(const std::string & name) { _name = name; } 107 : 108 : /// Name of surface 109 : std::string _name; 110 : 111 : /// Type of surface that is being represented 112 : /// string is taken directly from the surface class name 113 : const std::string _surface_type; 114 : 115 : // CSGSurfaceList needs to be friend to access setName() 116 : friend class CSGSurfaceList; 117 : 118 : #ifdef MOOSE_UNIT_TEST 119 : /// Friends for unit testing 120 : ///@{ 121 : FRIEND_TEST(CSGSurfaceTest, testSetName); 122 : ///@} 123 : #endif 124 : }; 125 : } // namespace CSG