https://mooseframework.inl.gov
GFunction.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 "GFunction.h"
11 #include "Sampler.h"
12 
13 registerMooseObject("StochasticToolsTestApp", GFunction);
14 
17 {
19 
20  params.addRequiredParam<std::vector<Real>>("q_vector", "q values for g-function");
21  params.addRequiredParam<SamplerName>(
22  "sampler", "The Sampler object to use to perform g-function evaluations.");
23  params.addParam<bool>("classify", false, "Flag to turn return binary values.");
24  params.addParam<Real>("limiting_value", 0.0, "True if value exceeds limiting value.");
25  return params;
26 }
27 
29  : GeneralVectorPostprocessor(parameters),
30  _sampler(getSampler("sampler")),
31  _q_vector(getParam<std::vector<Real>>("q_vector")),
32  _classify(getParam<bool>("classify")),
33  _limiting_value(getParam<Real>("limiting_value")),
34  _values(declareVector("g_values"))
35 {
36  if (_q_vector.size() != _sampler.getNumberOfCols())
37  paramError("q_vector", "The 'q_vector' size must match the number of columns in the Sampler.");
38  for (const auto & q : _q_vector)
39  if (q < 0)
40  paramError("q_vector", "The 'q_vector' entries must be zero or positive.");
41 }
42 
43 void
45 {
48  {
49  std::vector<Real> x = _sampler.getNextLocalRow();
50  Real y = 1;
51  for (std::size_t i = 0; i < _q_vector.size(); ++i)
52  y *= (std::abs(4 * x[i] - 2) + _q_vector[i]) / (1 + _q_vector[i]);
53  if (!_classify)
54  _values.push_back(y);
55  else
56  {
57  if (y > _limiting_value)
58  _values.push_back(1.0);
59  else
60  _values.push_back(0.0);
61  }
62  }
63 }
64 
65 void
67 {
68  if (_parallel_type == "REPLICATED")
70 }
const std::vector< Real > & _q_vector
Definition: GFunction.h:25
void paramError(const std::string &param, Args... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const bool & _classify
Definition: GFunction.h:26
const MooseEnum & _parallel_type
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
std::vector< Real > getNextLocalRow()
dof_id_type getLocalRowBegin() const
const std::vector< double > y
const Parallel::Communicator & _communicator
dof_id_type getNumberOfLocalRows() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
const std::vector< double > x
virtual void finalize() override
Definition: GFunction.C:66
VectorPostprocessorValue & _values
Definition: GFunction.h:28
dof_id_type getLocalRowEnd() const
GFunction(const InputParameters &parameters)
Definition: GFunction.C:28
virtual void execute() override
Definition: GFunction.C:44
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
Definition: GFunction.C:16
registerMooseObject("StochasticToolsTestApp", GFunction)
Sampler & _sampler
Definition: GFunction.h:24
const Real & _limiting_value
Definition: GFunction.h:27
dof_id_type getNumberOfCols() const
uint8_t dof_id_type