https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "CSGEngUnit.h"
12#include "CSGUtils.h"
13
14namespace CSG
15{
16
17CSGSurface::CSGSurface(const std::string & name) : _name(name)
18{
20}
21
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))
34 else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
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
44bool
46{
47 // If both objects are engineering units, delegate to CSGEngUnit::operator== to avoid
48 // calling getCoeffs(), which is not supported on engineering unit types. The isEngUnit()
49 // check keeps the common plain-surface path free of any dynamic_cast; the casts below
50 // only run once we know the objects are engineering units.
51 if (isEngUnit())
52 {
53 if (other.isEngUnit())
54 return *dynamic_cast<const CSGEngUnit *>(this) == *dynamic_cast<const CSGEngUnit *>(&other);
55 return false; // an engineering unit cannot equal a plain surface
56 }
57
58 return (this->getName() == other.getName()) &&
59 (this->getSurfaceType() == other.getSurfaceType()) &&
60 (this->getCoeffs() == other.getCoeffs()) &&
61 (this->getTransformations() == other.getTransformations());
62}
63
64bool
66{
67 return !(*this == other);
68}
69
70} // namespace CSG
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
CSGEngUnit is the abstract base class for all "engineering unit" types in the CSG system.
Definition CSGEngUnit.h:33
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface,...
Definition CSGSurface.h:27
Halfspace
Enum for the sign of the half-space being represented by a point and surface.
Definition CSGSurface.h:31
bool operator==(const CSGSurface &other) const
Operator overload for checking if two CSGSurface objects are equal.
Definition CSGSurface.C:45
const std::string getSurfaceType() const
Get the Surface Type.
Definition CSGSurface.h:53
std::string _name
Name of surface.
Definition CSGSurface.h:122
bool operator!=(const CSGSurface &other) const
Operator overload for checking if two CSGSurface objects are not equal.
Definition CSGSurface.C:65
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
virtual bool isEngUnit() const
Whether this surface is an engineering unit.
Definition CSGSurface.h:101
CSGSurface(const std::string &name)
Default constructor.
Definition CSGSurface.C:17
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
const std::string & getName() const
Get the name of surface.
Definition CSGSurface.h:90
virtual std::unordered_map< std::string, Real > getCoeffs() const =0
Get the coefficients that define the surface.
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.
Point applyReverseTransformsToPoint(Point p) const
update the value of point p by applying the inverse of the list of transformations to the point
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition CSGUtils.C:36