www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TestSampler Class Reference

UserObject for testing Sampler object threaded and parallel behavior, it should be used for anything else. More...

#include <TestSampler.h>

Inheritance diagram for TestSampler:
[legend]

Public Member Functions

 TestSampler (const InputParameters &parameters)
 

Protected Member Functions

virtual void execute () final
 
virtual void initialize () final
 
virtual void finalize () final
 
virtual void threadJoin (const UserObject &uo) final
 

Protected Attributes

Sampler & _sampler
 
const MooseEnum & _test_type
 

Detailed Description

UserObject for testing Sampler object threaded and parallel behavior, it should be used for anything else.

Definition at line 27 of file TestSampler.h.

Constructor & Destructor Documentation

◆ TestSampler()

TestSampler::TestSampler ( const InputParameters &  parameters)

Definition at line 26 of file TestSampler.C.

27  : ElementUserObject(parameters),
28  SamplerInterface(this),
29  _sampler(getSampler("sampler")),
30  _test_type(getParam<MooseEnum>("test_type"))
31 {
32 }
const MooseEnum & _test_type
Definition: TestSampler.h:38
Sampler & _sampler
Definition: TestSampler.h:37

Member Function Documentation

◆ execute()

virtual void TestSampler::execute ( )
inlinefinalprotectedvirtual

Definition at line 33 of file TestSampler.h.

33 {}

◆ finalize()

void TestSampler::finalize ( )
finalprotectedvirtual

Definition at line 35 of file TestSampler.C.

36 {
37  if (_communicator.size() > 1 && _test_type == "mpi")
38  {
39  std::size_t vec_size;
40  std::vector<Real> samples;
41  if (_communicator.rank() == 0)
42  {
43  samples = _sampler.getSamples()[0].get_values();
44  vec_size = samples.size();
45  }
46 
47  _communicator.broadcast(vec_size);
48  samples.resize(vec_size);
49  _communicator.broadcast(samples);
50 
51  if (_sampler.getSamples()[0].get_values() != samples)
52  mooseError("The sample generation is not working correctly with MPI.");
53  }
54 }
const MooseEnum & _test_type
Definition: TestSampler.h:38
Sampler & _sampler
Definition: TestSampler.h:37

◆ initialize()

virtual void TestSampler::initialize ( )
inlinefinalprotectedvirtual

Definition at line 34 of file TestSampler.h.

34 {}

◆ threadJoin()

void TestSampler::threadJoin ( const UserObject &  uo)
finalprotectedvirtual

Definition at line 57 of file TestSampler.C.

58 {
59  if (_test_type == "thread")
60  {
61  const TestSampler & other = static_cast<const TestSampler &>(uo);
62  if (_sampler.getSamples() != other._sampler.getSamples())
63  mooseError("The sample generation is not working correctly with threads.");
64  }
65 }
const MooseEnum & _test_type
Definition: TestSampler.h:38
UserObject for testing Sampler object threaded and parallel behavior, it should be used for anything ...
Definition: TestSampler.h:27
Sampler & _sampler
Definition: TestSampler.h:37

Member Data Documentation

◆ _sampler

Sampler& TestSampler::_sampler
protected

Definition at line 37 of file TestSampler.h.

Referenced by finalize(), and threadJoin().

◆ _test_type

const MooseEnum& TestSampler::_test_type
protected

Definition at line 38 of file TestSampler.h.

Referenced by finalize(), and threadJoin().


The documentation for this class was generated from the following files: