https://mooseframework.inl.gov
BackfaceCullingStudyTest.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 
11 
12 // Local includes
13 #include "TraceRay.h"
14 
15 registerMooseObject("RayTracingTestApp", BackfaceCullingStudyTest);
16 
19 {
20  auto params = LotsOfRaysRayStudy::validParams();
21  return params;
22 }
23 
25  : LotsOfRaysRayStudy(parameters)
26 {
27  // Use backface culling
28  for (const auto tid : make_range(libMesh::n_threads()))
29  traceRay(tid).setBackfaceCulling(true);
30 }
31 
32 void
34 {
37 }
38 
39 void
41 {
44 }
45 
46 void
48 {
49  _normals.clear();
50 
51  for (const Elem * elem : _mesh.getMesh().active_element_ptr_range())
52  {
53  std::vector<Point> normals(elem->n_sides());
54  for (const auto s : elem->side_index_range())
55  normals[s] = RayTracingStudy::getSideNormal(elem, s, 0);
56  _normals.emplace(elem, std::move(normals));
57  }
58 }
59 
60 const Point *
62 {
63  const auto find = _normals.find(elem);
64  if (find == _normals.end())
65  mooseError("Failed to find normal for elem ", elem->id());
66 
67  const auto & normals = find->second;
68  mooseAssert(normals.size() == elem->n_sides(), "Normals not sized properly");
69  return normals.data();
70 }
void setBackfaceCulling(const bool backface_culling)
Enable or disable the use of element normals for backface culling through the getElemNormals() method...
Definition: TraceRay.h:105
unsigned int n_threads()
virtual void initialSetup() override
MooseMesh & _mesh
The Mesh.
static InputParameters validParams()
TraceRay & traceRay(const THREAD_ID tid)
Gets the threaded TraceRay object for tid.
const Point * getElemNormals(const Elem *elem, const THREAD_ID tid) override
Gets the outward normals for a given element.
MeshBase & getMesh()
virtual void meshChanged() override
A test study that tests the use of backface culling in TraceRay.
virtual const Point & getSideNormal(const Elem *elem, const unsigned short side, const THREAD_ID tid)
Get the outward normal for a given element side.
std::unordered_map< const Elem *, std::vector< Point > > _normals
BackfaceCullingStudyTest(const InputParameters &parameters)
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
static InputParameters validParams()
registerMooseObject("RayTracingTestApp", BackfaceCullingStudyTest)
A RayTracingStudy used for generating a lot of rays for testing purposes.
unsigned int THREAD_ID