www.mooseframework.org
StateProcessor.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 "StateProcessor.h"
9 #include <stdlib.h>
10 #include <string>
11 #include <cmath>
12 #include "MooseRandom.h"
13 
14 StateProcessor::StateProcessor(unsigned int max_time_step, int seed)
15  : _max_time_step(max_time_step), _ev_times()
16 {
17  MooseRandom::seed(seed);
18 
19  // add a bunch of random time items
20  unsigned int r = MooseRandom::randl() % 10;
21  for (unsigned int i = 0; i < r; i++)
22  {
23  unsigned int addI = MooseRandom::randl() % max_time_step;
24  addEv(addI);
25  }
26 }
27 
28 // Add the event in to the list in the proper order
29 void
30 StateProcessor::addEv(unsigned int time_step = 0)
31 {
32  unsigned long idx = 0;
33  while ((idx < _ev_times.size()) && (_ev_times[idx] > time_step))
34  ++idx;
35 
36  _ev_times.insert(_ev_times.begin() + idx, time_step);
37 }
38 
39 unsigned int
41 {
42  if (_ev_times.size() > 0)
43  return _ev_times.back();
44  else
45  return 0;
46 }
47 
48 unsigned int
49 StateProcessor::process(unsigned int time_step)
50 {
51  if (time_step == _ev_times.back())
52  _ev_times.pop_back();
53 
54  // todo run state processing
55 
56  if (_ev_times.size() > 0)
57  return _ev_times.back();
58  else
59  return 0;
60 }
61 
62 void
63 StateProcessor::setMaxTime(unsigned time_step)
64 {
65  _max_time_step = time_step;
66 }
unsigned int nextTime()
StateProcessor(unsigned int max_time_step, int seed=0)
unsigned int _max_time_step
std::vector< unsigned int > _ev_times
void setMaxTime(unsigned int time_step)
unsigned int process(unsigned int time_step)
void addEv(unsigned int time_step)