Skip to content
Permalink
Browse files

Merge pull request #13312 from permcody/intermittent_failure

Intermittent Failure object
  • Loading branch information...
lindsayad committed May 2, 2019
2 parents eaae633 + a8c73c7 commit b2f208e11b683dd53761f909540b388a9589af45
@@ -0,0 +1,45 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "GeneralUserObject.h"
#include "MooseRandom.h"

// Forward Declarations
class IntermittentFailureUO;

template <>
InputParameters validParams<IntermittentFailureUO>();

class IntermittentFailureUO : public GeneralUserObject
{
public:
IntermittentFailureUO(const InputParameters & parameters);

virtual void initialSetup() override;
virtual void execute() override;

virtual void initialize() override {}
virtual void finalize() override {}

private:
enum class FailureType
{
RUN_SLOW
};

const FileName & _state_file;

const unsigned int _timestep_to_fail;

const FailureType _failure_type;

bool _will_fail_this_run;
};
@@ -0,0 +1,77 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

// MOOSE includes
#include "IntermittentFailureUO.h"

#include <thread>
#include <chrono>
#include <cstdlib>

registerMooseObject("MooseTestApp", IntermittentFailureUO);

template <>
InputParameters
validParams<IntermittentFailureUO>()
{
InputParameters params = validParams<GeneralUserObject>();
params.addParam<unsigned int>("timestep_to_fail", 1, "The timestep number to error out");

MooseEnum failure_type("RUN_SLOW", "RUN_SLOW");
params.addParam<MooseEnum>("failure_type", failure_type, "The type of failure to produce");

params.addParam<FileName>(
"state_file",
"_has_failed_once",
"A filename that will be \"touched\" indicating whether this is the first time this "
"simulation has run or not, triggering this Postprocessor to stall.");

return params;
}

IntermittentFailureUO::IntermittentFailureUO(const InputParameters & parameters)
: GeneralUserObject(parameters),
_state_file(getParam<FileName>("state_file")),
_timestep_to_fail(getParam<unsigned int>("timestep_to_fail")),
_failure_type(getParam<MooseEnum>("failure_type").getEnum<FailureType>()),
_will_fail_this_run(true)
{
}

void
IntermittentFailureUO::initialSetup()
{
char * intermittent_failures = std::getenv("MOOSE_ENABLE_INTERMITTENT_FAILURES");

if (!intermittent_failures || MooseUtils::checkFileReadable(_state_file, false, false))
_will_fail_this_run = false;
else
{
std::ofstream out(_state_file.c_str(), std::ofstream::out);
out.close();
mooseInfo("IntermittentFailureUO present and will trigger");
}
}

void
IntermittentFailureUO::execute()
{
// Only fail the first time (simulation)!
if (_will_fail_this_run && static_cast<unsigned int>(_t_step) >= _timestep_to_fail)
{
switch (_failure_type)
{
case FailureType::RUN_SLOW:
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
break;
default:
mooseError("Unknown failure type:");
}
}
}
@@ -0,0 +1,60 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

[Variables]
[./u]
[../]
[]

[Kernels]
[./diff]
type = CoefDiffusion
variable = u
coef = 0.1
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Executioner]
type = Transient
num_steps = 20
dt = 0.1
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

# This object will behave different on different invocations if
# MOOSE_ENABLE_INTERMITTENT_FAILURES is set
[UserObjects]
[intermittent_failure]
type = IntermittentFailureUO
timestep_to_fail = 2
[]
[]

[Outputs]
exodus = true
[]
@@ -0,0 +1,13 @@
[Tests]
[./intermittent_failure]
type = 'RunApp'
input = 'intermittent_failure.i'
max_time = 10

requirement = "The system shall support a testing mechanism that fails intermittently."
design = "TestHarness.md"
issues = "#13334"

method = '!dbg'
[../]
[]

0 comments on commit b2f208e

Please sign in to comment.
You can’t perform that action at this time.