www.mooseframework.org
LineValueSampler.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "LineValueSampler.h"
16 
17 template <>
20 {
22 
23  params.addRequiredParam<Point>("start_point", "The beginning of the line");
24  params.addRequiredParam<Point>("end_point", "The ending of the line");
25 
26  params.addRequiredParam<unsigned int>("num_points",
27  "The number of points to sample along the line");
28 
29  return params;
30 }
31 
33  : PointSamplerBase(parameters)
34 {
35  Point start_point = getParam<Point>("start_point");
36  Point end_point = getParam<Point>("end_point");
37 
38  unsigned int num_points = getParam<unsigned int>("num_points");
39 
40  generatePointsAndIDs(start_point, end_point, num_points, _points, _ids);
41 }
42 
43 void
44 LineValueSampler::generatePointsAndIDs(const Point & start_point,
45  const Point & end_point,
46  unsigned int num_points,
47  std::vector<Point> & points,
48  std::vector<Real> & ids)
49 {
50 
51  Point difference = end_point - start_point;
52 
53  Point delta = difference / Real(num_points - 1);
54 
55  points.resize(num_points);
56  ids.resize(num_points);
57 
58  for (unsigned int i = 0; i < num_points - 1;
59  i++) // -1 so that we can manually put in the end point to get it perfect
60  {
61  Point p = start_point + (i * delta);
62 
63  points[i] = p;
64  ids[i] = (p - start_point).norm(); // The ID is the distance along the line
65  }
66 
67  // Add the end point explicitly
68  points[num_points - 1] = end_point;
69  ids[num_points - 1] = (end_point - start_point).norm();
70 }
std::vector< Real > _ids
The ID to use for each point (yes, this is Real on purpose)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< Point > _points
The points to evaluate at.
InputParameters validParams< LineValueSampler >()
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
LineValueSampler(const InputParameters &parameters)
static void generatePointsAndIDs(const Point &start_point, const Point &end_point, unsigned int num_points, std::vector< Point > &points, std::vector< Real > &ids)
Helper function to generate the list of points along a line and a unique ID for each point...
InputParameters validParams< PointSamplerBase >()