www.mooseframework.org
TestSampler.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "TestSampler.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<ElementUserObject>();
15  params.addRequiredParam<SamplerName>("sampler", "The sampler to test.");
16 
17  MooseEnum test_type("mpi thread");
18  params.addParam<MooseEnum>("test_type", test_type, "The type of test to perform.");
19  return params;
20 }
21 
22 TestSampler::TestSampler(const InputParameters & parameters)
23  : ElementUserObject(parameters),
24  SamplerInterface(this),
25  _sampler(getSampler("sampler")),
26  _test_type(getParam<MooseEnum>("test_type"))
27 {
28 }
29 
30 void
32 {
33  if (_communicator.size() > 1 && _test_type == "mpi")
34  {
35  std::size_t vec_size;
36  std::vector<Real> samples;
37  if (_communicator.rank() == 0)
38  {
39  samples = _sampler.getSamples()[0].get_values();
40  vec_size = samples.size();
41  }
42 
43  _communicator.broadcast(vec_size);
44  samples.resize(vec_size);
45  _communicator.broadcast(samples);
46 
47  if (_sampler.getSamples()[0].get_values() != samples)
48  mooseError("The sample generation is not working correctly with MPI.");
49  }
50 }
51 
52 void
53 TestSampler::threadJoin(const UserObject & uo)
54 {
55  if (_test_type == "thread")
56  {
57  const TestSampler & other = static_cast<const TestSampler &>(uo);
58  if (_sampler.getSamples() != other._sampler.getSamples())
59  mooseError("The sample generation is not working correctly with threads.");
60  }
61 }
TestSampler(const InputParameters &parameters)
Definition: TestSampler.C:22
const MooseEnum & _test_type
Definition: TestSampler.h:36
UserObject for testing Sampler object threaded and parallel behavior, it should be used for anything ...
Definition: TestSampler.h:25
Sampler & _sampler
Definition: TestSampler.h:35
virtual void finalize() final
Definition: TestSampler.C:31
virtual void threadJoin(const UserObject &uo) final
Definition: TestSampler.C:53
InputParameters validParams< TestSampler >()
Definition: TestSampler.C:12