LCOV - code coverage report
Current view: top level - src/state_sim - StateProcessor.C (source / functions) Hit Total Coverage
Test: stochastic_tools Test Coverage Lines: 21 23 91.3 %
Date: 2017-11-18 13:35:36 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11