https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
13registerMooseObject("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
43void
45{
47 for (dof_id_type r = _sampler.getLocalRowBegin(); r < _sampler.getLocalRowEnd(); ++r)
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
65void
67{
68 if (_parallel_type == "REPLICATED")
70}
const std::vector< double > y
const std::vector< double > x
registerMooseObject("StochasticToolsTestApp", GFunction)
virtual void execute() override
Definition GFunction.C:44
GFunction(const InputParameters &parameters)
Definition GFunction.C:28
VectorPostprocessorValue & _values
Definition GFunction.h:28
Sampler & _sampler
Definition GFunction.h:24
const bool & _classify
Definition GFunction.h:26
const Real & _limiting_value
Definition GFunction.h:27
static InputParameters validParams()
Definition GFunction.C:16
virtual void finalize() override
Definition GFunction.C:66
const std::vector< Real > & _q_vector
Definition GFunction.h:25
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
std::vector< Real > getNextLocalRow()
dof_id_type getNumberOfLocalRows() const
dof_id_type getLocalRowEnd() const
dof_id_type getLocalRowBegin() const
dof_id_type getNumberOfCols() const
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
const MooseEnum & _parallel_type
const Parallel::Communicator & _communicator