www.mooseframework.org
LineFunctionSampler.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "LineFunctionSampler.h"
11 
12 // MOOSE includes
13 #include "Function.h"
14 #include "LineValueSampler.h"
15 
17 
20 {
22  params.addClassDescription("Sample one or more functions along a line.");
23  params += SamplerBase::validParams();
24 
25  params.addRequiredParam<Point>("start_point", "The beginning of the line");
26  params.addRequiredParam<Point>("end_point", "The ending of the line");
27 
28  params.addRequiredParam<unsigned int>("num_points",
29  "The number of points to sample along the line");
30 
31  params.addRequiredParam<std::vector<FunctionName>>("functions",
32  "The Functions to sample along the line");
33 
34  return params;
35 }
36 
38  : GeneralVectorPostprocessor(parameters),
39  SamplerBase(parameters, this, _communicator),
40  _start_point(getParam<Point>("start_point")),
41  _end_point(getParam<Point>("end_point")),
42  _num_points(getParam<unsigned int>("num_points")),
43  _function_names(getParam<std::vector<FunctionName>>("functions")),
44  _num_funcs(_function_names.size()),
45  _functions(_num_funcs),
46  _values(_num_funcs)
47 {
48  // Get the Functions
49  for (unsigned int i = 0; i < _num_funcs; i++)
51 
52  // Unfortunately, std::vector<FunctionName> can't be cast to std::vector<std::string>...
53  std::vector<std::string> function_name_strings(_num_funcs);
54  for (unsigned int i = 0; i < _num_funcs; i++)
55  function_name_strings[i] = _function_names[i];
56 
57  // Initialize the datastructions in SamplerBase
58  SamplerBase::setupVariables(function_name_strings);
59 
60  // Generate points along the line
62 }
63 
64 void
66 {
68 }
69 
70 void
72 {
73  if (processor_id() == 0) // Only sample on processor zero for now
74  {
75  // TODO: Thread this when we finally move to C++11
76  for (unsigned int p = 0; p < _num_points; p++)
77  {
78  for (unsigned int i = 0; i < _num_funcs; i++)
79  _values[i] = _functions[i]->value(_t, _points[p]);
80 
82  }
83  }
84 }
85 
86 void
88 {
90 }
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition: SamplerBase.h:36
virtual void initialize()
Initialize the datastructures.
Definition: SamplerBase.C:75
std::vector< const Function * > _functions
Pointers to the Functions.
Point _start_point
Beginning of the line.
registerMooseObject("MooseApp", LineFunctionSampler)
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...
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
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
std::vector< Point > _points
The points to evaluate at.
static InputParameters validParams()
Definition: SamplerBase.C:22
Point _end_point
End of the line.
virtual void finalize()
Finalize the values.
Definition: SamplerBase.C:91
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
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
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...
unsigned int _num_funcs
Number of Functions we&#39;re sampling.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::vector< Real > _ids
The ID to use for each point (yes, this is Real on purpose)
const std::vector< FunctionName > & _function_names
Names of the Functions.
static InputParameters validParams()
unsigned int _num_points
Number of points along the line.
processor_id_type processor_id() const
virtual void initialize() override
Initialize the datastructures.
void ErrorVector unsigned int
std::vector< Real > _values
So we don&#39;t have to create and destroy this vector over and over again.