https://mooseframework.inl.gov
Loading...
Searching...
No Matches
TestPICRayStudy.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 "TestPICRayStudy.h"
11
12#include "ClaimRays.h"
13#include "Function.h"
14
16
19{
20 auto params = RayTracingStudy::validParams();
21
22 params.addRequiredParam<std::vector<Point>>("start_points",
23 "The point(s) where the ray(s) start");
24 params.addRequiredParam<std::vector<Point>>(
25 "start_directions",
26 "The direction(s) that the ray(s) start in (does not need to be normalized)");
27 params.addRequiredParam<FunctionName>(
28 "velocity_function", "A function that describes the velocity field for the ray(s)");
29
30 // We're not going to use registration because we don't care to name our rays because
31 // we will have a lot of them
32 params.set<bool>("_use_ray_registration") = false;
33
34 return params;
35}
36
38 : RayTracingStudy(parameters),
39 _start_points(getParam<std::vector<Point>>("start_points")),
40 _start_directions(getParam<std::vector<Point>>("start_directions")),
41 _velocity_function(getFunction("velocity_function")),
42 _has_generated(declareRestartableData<bool>("has_generated", false)),
43 _banked_rays(
44 declareRestartableDataWithContext<std::vector<std::shared_ptr<Ray>>>("_banked_rays", this))
45{
46 if (_start_points.size() != _start_directions.size())
47 paramError("start_directions", "Must be the same size as 'start_points'");
48}
49
50void
52{
53 // We generate rays the first time only, after that we will
54 // pull from the bank and update velocities/max distances
55 if (!_has_generated)
56 {
57 // The unclaimed rays that we're going to generate
58 // Here we need to "claim" rays because in parallel, we have
59 // a list of points but do not know which processor will
60 // own the point that that ray starts in. So, we duplicate
61 // the rays on all processors and then let one processor pick them.
62 // Basically - we fill them here and then pass them to a ClaimRays
63 // object to do all of the magic. In a real PIC case, we'll just
64 // generate the rays for the local rays that we care about
65 // and the claiming probably won't be necessary
66 std::vector<std::shared_ptr<Ray>> rays(_start_points.size());
67
68 // Create a ray for each point/direction/velocity triplet
69 // Note that instead of keeping track of the velocity, we're
70 // just going to set the maximum distance that a ray can
71 // travel based on the timestep * the starting velocity.
72 for (const auto i : index_range(_start_points))
73 {
74 rays[i] = acquireReplicatedRay();
75 rays[i]->setStart(_start_points[i]);
76 rays[i]->setStartingDirection(_start_directions[i].unit());
77 rays[i]->setStartingMaxDistance(maxDistance(*rays[i]));
78 }
79
80 // Claim the rays
81 std::vector<std::shared_ptr<Ray>> claimed_rays;
82 ClaimRays claim_rays(*this, rays, claimed_rays, false);
83 claim_rays.claim();
84 // ...and then add them to be traced
85 moveRaysToBuffer(claimed_rays);
86 }
87 // Rays are in the bank: reset them and update the velocities / end distance
88 else
89 {
90 // Reset each ray
91 for (auto & ray : _banked_rays)
92 {
93 // Store off the ray's info before we reset it
94 const auto start_point = ray->currentPoint();
95 const auto direction = ray->direction();
96 const auto elem = ray->currentElem();
97
98 // Reset it (this is required to reuse a ray)
99 ray->resetCounters();
100 ray->clearStartingInfo();
101
102 // And set the new starting information
103 ray->setStart(start_point, elem);
104 ray->setStartingDirection(direction);
105 ray->setStartingMaxDistance(maxDistance(*ray));
106 }
107 // Add the rays to be traced
109 _banked_rays.clear();
110 }
111
112 _has_generated = true;
113}
114
115void
117{
118 // Copy the rays that are banked in the study into our own bank
120}
121
122Real
124{
125 // velocity * dt
127}
registerMooseObject("RayTracingTestApp", TestPICRayStudy)
Helper object for claiming Rays.
Definition ClaimRays.h:35
void claim()
Claim the Rays.
Definition ClaimRays.C:42
virtual Real & dt() const
virtual Real & time() const
virtual Real value(Real t, const Point &p) const
void paramError(const std::string &param, Args... args) const
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...
static InputParameters validParams()
std::shared_ptr< Ray > acquireReplicatedRay()
Acquire a Ray from the pool of Rays within generateRays() in a replicated fashion.
const std::vector< std::shared_ptr< Ray > > & rayBank() const
Get the Ray bank.
void moveRaysToBuffer(std::vector< std::shared_ptr< Ray > > &rays)
Moves rays to the buffer to be traced during generateRays().
Basic datastructure for a ray that will traverse the mesh.
Definition Ray.h:58
const Point & currentPoint() const
Gets the point that the Ray is currently at.
Definition Ray.h:233
Test study for generating rays for a basic particle-in-cell capability, where Rays propagate a bit ea...
bool & _has_generated
Whether or not we've generated rays yet (restartable)
const std::vector< Point > & _start_points
The starting points.
virtual void generateRays() override
Subclasses should override this to determine how to generate Rays.
virtual void postExecuteStudy() override
Entry point after study execution.
const std::vector< Point > & _start_directions
The starting directions.
TestPICRayStudy(const InputParameters &parameters)
std::vector< std::shared_ptr< Ray > > & _banked_rays
The banked rays to be used on the next timestep (restartable)
const Function & _velocity_function
The function that represents the velocity field.
Real maxDistance(const Ray &ray) const
static InputParameters validParams()
FEProblemBase & _fe_problem