https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LineFunctionSampler.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 "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
64void
69
70void
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
86void
registerMooseObject("MooseApp", LineFunctionSampler)
void ErrorVector unsigned int
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
static InputParameters validParams()
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...
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.
Point _end_point
End of the line.
unsigned int _num_funcs
Number of Functions we're sampling.
Point _start_point
Beginning of the line.
std::vector< Real > _ids
The ID to use for each point (yes, this is Real on purpose)
unsigned int _num_points
Number of points along the line.
std::vector< Point > _points
The points to evaluate at.
const std::vector< FunctionName > & _function_names
Names of the Functions.
std::vector< Real > _values
So we don't have to create and destroy this vector over and over again.
static InputParameters validParams()
virtual void finalize() override
Finalize.
std::vector< const Function * > _functions
Pointers to the Functions.
LineFunctionSampler(const InputParameters &parameters)
virtual void execute() override
Execute method.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
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.
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition SamplerBase.h:38
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:91
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:69
virtual void initialize()
Initialize the datastructures.
virtual void finalize()
Finalize the values.
static InputParameters validParams()
Definition SamplerBase.C:24
processor_id_type processor_id() const