www.mooseframework.org
LineFunctionSampler.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 "LineFunctionSampler.h"
16 
17 // MOOSE includes
18 #include "Function.h"
19 #include "LineValueSampler.h"
20 
21 template <>
24 {
26 
27  params += validParams<SamplerBase>();
28 
29  params.addRequiredParam<Point>("start_point", "The beginning of the line");
30  params.addRequiredParam<Point>("end_point", "The ending of the line");
31 
32  params.addRequiredParam<unsigned int>("num_points",
33  "The number of points to sample along the line");
34 
35  params.addRequiredParam<std::vector<FunctionName>>("functions",
36  "The Functions to sample along the line");
37 
38  return params;
39 }
40 
42  : GeneralVectorPostprocessor(parameters),
43  SamplerBase(parameters, this, _communicator),
44  _start_point(getParam<Point>("start_point")),
45  _end_point(getParam<Point>("end_point")),
46  _num_points(getParam<unsigned int>("num_points")),
47  _function_names(getParam<std::vector<FunctionName>>("functions")),
48  _num_funcs(_function_names.size()),
49  _functions(_num_funcs),
50  _values(_num_funcs)
51 {
52  // Get the Functions
53  for (unsigned int i = 0; i < _num_funcs; i++)
55 
56  // Unfortunately, std::vector<FunctionName> can't be cast to std::vector<std::string>...
57  std::vector<std::string> function_name_strings(_num_funcs);
58  for (unsigned int i = 0; i < _num_funcs; i++)
59  function_name_strings[i] = _function_names[i];
60 
61  // Initialize the datastructions in SamplerBase
62  SamplerBase::setupVariables(function_name_strings);
63 
64  // Generate points along the line
66 }
67 
68 void
70 {
72 }
73 
74 void
76 {
77  if (processor_id() == 0) // Only sample on processor zero for now
78  {
79  // TODO: Thread this when we finally move to C++11
80  for (unsigned int p = 0; p < _num_points; p++)
81  {
82  for (unsigned int i = 0; i < _num_funcs; i++)
83  _values[i] = _functions[i]->value(_t, _points[p]);
84 
86  }
87  }
88 }
89 
90 void
92 {
94 }
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition: SamplerBase.h:46
virtual void initialize()
Initialize the datastructures.
Definition: SamplerBase.C:75
Point _start_point
Beginning of the line.
LineFunctionSampler(const InputParameters &parameters)
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< LineFunctionSampler >()
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...
virtual void finalize() override
Finalize.
void setupVariables(const std::vector< std::string > &variable_names)
You MUST call this in the constructor of the child class and pass down the name of the variables...
Definition: SamplerBase.C:51
std::vector< Point > _points
The points to evaluate at.
InputParameters validParams< GeneralVectorPostprocessor >()
Point _end_point
End of the line.
virtual void finalize()
Finalize the values.
Definition: SamplerBase.C:87
virtual void execute() override
Execute method.
virtual void addSample(const Point &p, const Real &id, const std::vector< Real > &values)
Call this with the value of every variable at each point you want to sample at.
Definition: SamplerBase.C:61
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...
Function & getFunctionByName(const FunctionName &name)
Get a function with a given name.
InputParameters validParams< SamplerBase >()
Definition: SamplerBase.C:26
unsigned int _num_funcs
Number of Functions we&#39;re sampling.
std::vector< Real > _ids
The ID to use for each point (yes, this is Real on purpose)
std::vector< Function * > _functions
Pointers to the Functions.
const std::vector< FunctionName > & _function_names
Names of the Functions.
unsigned int _num_points
Number of points along the line.
virtual void initialize() override
Initialize the datastructures.
std::vector< Real > _values
So we don&#39;t have to create and destroy this vector over and over again.