https://mooseframework.inl.gov
TestTransientRaysStudy.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 #include "TestTransientRaysStudy.h"
11 
12 #include "Function.h"
13 
14 registerMooseObject("RayTracingTestApp", TestTransientRaysStudy);
15 
18 {
19  auto params = RayTracingStudy::validParams();
20  params.addRequiredParam<FunctionName>("distance_function",
21  "The function to sample for the ray distances");
22  params.addRequiredParam<BoundaryName>("boundary", "The boundary to spawn rays from");
23  params.set<bool>("_use_ray_registration") = false;
24  return params;
25 }
26 
28  : RayTracingStudy(parameters),
29  _distance_function(getFunction("distance_function")),
30  _boundary_id(_mesh.getBoundaryID(getParam<BoundaryName>("boundary"))),
31  _generated_rays(declareRestartableData<bool>("generated_rays", false)),
32  _banked_rays(
33  declareRestartableDataWithContext<std::vector<std::shared_ptr<Ray>>>("banked_rays", this))
34 {
35 }
36 
37 void
39 {
40  if (!_generated_rays)
41  {
42  for (const auto bnd_elem : *_mesh.getBoundaryElementRange())
43  if (bnd_elem->_elem->processor_id() == processor_id() && bnd_elem->_bnd_id == _boundary_id)
44  {
45  const auto elem = bnd_elem->_elem;
46  const auto side = elem->build_side_ptr(bnd_elem->_side);
47  const auto start_point = side->vertex_average();
48 
49  auto ray = acquireRay();
50  ray->setStart(start_point, elem, bnd_elem->_side);
51  ray->setStartingDirection(elem->vertex_average() - start_point);
52  ray->setStartingMaxDistance(_distance_function.value(_fe_problem.time(), start_point));
53  moveRayToBuffer(ray);
54  }
55 
56  _generated_rays = true;
57  }
58  else
59  {
60  for (auto & ray : _banked_rays)
61  {
62  const auto start_point = ray->currentPoint();
63  const auto direction = ray->direction();
64  const auto elem = ray->currentElem();
65 
66  ray->resetCounters();
67  ray->clearStartingInfo();
68  ray->setStart(start_point, elem);
69  ray->setStartingDirection(direction);
70  ray->setStartingMaxDistance(_distance_function.value(_fe_problem.time(), start_point));
71  }
73  _banked_rays.clear();
74  }
75 }
76 
77 void
79 {
81 }
TestTransientRaysStudy(const InputParameters &parameters)
const std::vector< std::shared_ptr< Ray > > & rayBank() const
Get the Ray bank.
virtual Real & time() const
MooseMesh & _mesh
The Mesh.
const Function & _distance_function
std::shared_ptr< Ray > acquireRay()
User APIs for constructing Rays within the RayTracingStudy.
registerMooseObject("RayTracingTestApp", TestTransientRaysStudy)
std::vector< std::shared_ptr< Ray > > & _banked_rays
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
static InputParameters validParams()
Basic datastructure for a ray that will traverse the mesh.
Definition: Ray.h:56
virtual void postExecuteStudy() override
Entry point after study execution.
FEProblemBase & _fe_problem
Tests transient rays.
static InputParameters validParams()
void moveRayToBuffer(std::shared_ptr< Ray > &ray)
Moves a ray to the buffer to be traced during generateRays().
virtual void generateRays() override
Subclasses should override this to determine how to generate Rays.
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement *> * getBoundaryElementRange()
virtual Real value(Real t, const Point &p) const
void moveRaysToBuffer(std::vector< std::shared_ptr< Ray >> &rays)
Moves rays to the buffer to be traced during generateRays().
processor_id_type processor_id() const
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...