https://mooseframework.inl.gov
CSGSurface.C
Go to the documentation of this file.
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 "CSGSurface.h"
11 #include "CSGUtils.h"
12 
13 namespace CSG
14 {
15 
16 CSGSurface::CSGSurface(const std::string & name, const std::string & surf_type)
17  : _name(name), _surface_type(surf_type)
18 {
20 }
21 
23 CSGSurface::getHalfspaceFromPoint(const Point & p) const
24 {
25  // if transformations are present on the surface, apply them in reverse to the point and pass that
26  // new point to the evaluation to ensure transformations are considered.
27 
28  // Create a local transformed copy - the original p in the calling scope is NOT modified
29  const Point p_trans = getTransformations().size() ? applyReverseTransformsToPoint(p) : p;
30 
31  auto eval = evaluateSurfaceEquationAtPoint(p_trans);
32  if (MooseUtils::absoluteFuzzyGreaterThan(eval, 0))
33  return Halfspace::POSITIVE;
34  else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
35  return Halfspace::NEGATIVE;
36  else
37  mooseError("Point ",
38  p,
39  " used to determine halfspace evaluation lies on the surface ",
40  _name,
41  ", leading to an ambiguously defined halfspace.");
42 }
43 
44 bool
45 CSGSurface::operator==(const CSGSurface & other) const
46 {
47  return (this->getName() == other.getName()) &&
48  (this->getSurfaceType() == other.getSurfaceType()) &&
49  (this->getCoeffs() == other.getCoeffs()) &&
50  (this->getTransformations() == other.getTransformations());
51 }
52 
53 bool
54 CSGSurface::operator!=(const CSGSurface & other) const
55 {
56  return !(*this == other);
57 }
58 
59 } // namespace CSG
std::string name(const ElemQuality q)
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
Halfspace
Enum for the sign of the half-space being represented by a point and surface.
Definition: CSGSurface.h:30
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
bool operator==(const CSGSurface &other) const
Operator overload for checking if two CSGSurface objects are equal.
Definition: CSGSurface.C:45
virtual std::unordered_map< std::string, Real > getCoeffs() const =0
Get the coefficients that define the surface.
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition: CSGUtils.C:36
Point applyReverseTransformsToPoint(Point p) const
update the value of point p by applying the inverse of the list of transformations to the point ...
std::string _name
Name of surface.
Definition: CSGSurface.h:116
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
Definition: CSGSurface.h:26
CSGSurface(const std::string &name)
Default constructor.
CSGSurface::Halfspace getHalfspaceFromPoint(const Point &p) const
given a point, determine if it is in the positive or negative half-space for the surface ...
Definition: CSGSurface.C:23
bool operator!=(const CSGSurface &other) const
Operator overload for checking if two CSGSurface objects are not equal.
Definition: CSGSurface.C:54
const std::string & getSurfaceType() const
Get the Surface Type.
Definition: CSGSurface.h:61
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.