https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGUtils.C
Go to the documentation of this file.
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// MOOSE includes
11#include "CSGUtils.h"
12
13using namespace CSG;
14
15namespace CSGUtils
16{
17
19getInnerRegion(const std::vector<std::reference_wrapper<const CSGSurface>> & surfaces,
20 const libMesh::Point & origin)
21{
22 CSGRegion inner_region;
23 for (const auto & surf_ref : surfaces)
24 {
25 const auto & surf = surf_ref.get();
26 const auto direction = surf.getHalfspaceFromPoint(origin);
27 auto halfspace = (direction == CSGSurface::Halfspace::POSITIVE) ? +surf : -surf;
28 inner_region = (inner_region.getRegionType() == CSGRegion::RegionType::EMPTY)
29 ? halfspace
30 : inner_region & halfspace;
31 }
32 return inner_region;
33}
34
35void
36checkValidCSGName(const std::string & name)
37{
38 // Check if invalid symbol is present in the name. These include whitespaces and symbols
39 // for halfspaces and region operators
40 const std::regex invalid_symbols(R"([\+\-~|& ])");
41 std::smatch matches;
42
43 if (std::regex_search(name, matches, invalid_symbols))
44 {
45 char matched_char = name[matches.position(0)];
46 if (matched_char == ' ')
47 mooseError("Detected whitespace in CSG component with name ", name, ". This is not allowed.");
48 else
49 mooseError("Invalid symbol in CSG component with name ", name, ": ", matched_char);
50 }
51}
52}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection,...
Definition CSGRegion.h:23
RegionType getRegionType() const
Get the region type.
Definition CSGRegion.h:123
CSG::CSGRegion getInnerRegion(const std::vector< std::reference_wrapper< const CSG::CSGSurface > > &surfaces, const libMesh::Point &origin)
Get inner region of given surfaces, defined as the intersection of halfspaces of each surface.
Definition CSGUtils.C:19
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition CSGUtils.C:36