Skip to content
Permalink
Browse files

Merge pull request #13296 from joshuahansel/hansje/scalar-kernel-enab…

…le-controllable

Added control to enable/disable objects based on function
  • Loading branch information...
aeslaughter committed Apr 25, 2019
2 parents d707f25 + 70aabed commit 905386520e902fb83cf1f380d86c1683967e90f6
Showing with 525 additions and 90 deletions.
  1. +17 −0 framework/doc/content/source/controls/ConditionalEnableControl.md
  2. +14 −0 framework/doc/content/source/controls/ConditionalFunctionEnableControl.md
  3. +2 −1 framework/doc/content/source/controls/RealFunctionControl.md
  4. +6 −11 framework/doc/content/source/controls/TimePeriod.md
  5. +2 −1 framework/doc/content/source/functions/MooseParsedFunction.md
  6. +49 −0 framework/include/controls/ConditionalEnableControl.h
  7. +37 −0 framework/include/controls/ConditionalFunctionEnableControl.h
  8. +4 −14 framework/include/controls/TimePeriod.h
  9. +1 −1 framework/include/functions/MooseParsedFunctionBase.h
  10. +59 −0 framework/src/controls/ConditionalEnableControl.C
  11. +40 −0 framework/src/controls/ConditionalFunctionEnableControl.C
  12. +12 −50 framework/src/controls/TimePeriod.C
  13. +2 −0 framework/src/kernels/ScalarKernel.C
  14. +3 −3 modules/solid_mechanics/test/tests/cracking/cracking_xyz.i
  15. +3 −3 modules/tensor_mechanics/test/tests/smeared_cracking/cracking_rotation.i
  16. +3 −3 modules/tensor_mechanics/test/tests/smeared_cracking/cracking_xyz.i
  17. +1 −1 python/MooseDocs/test/gold/html/extensions/appsyntax.html
  18. +4 −0 python/MooseDocs/test/gold/latex/extensions/appsyntax.tex
  19. +1 −1 python/MooseDocs/test/gold/materialize/extensions/appsyntax.html
  20. +119 −0 test/tests/controls/conditional_functional_enable/conditional_function_enable.i
  21. +7 −0 test/tests/controls/conditional_functional_enable/gold/conditional_function_enable_out.csv
  22. +11 −0 test/tests/controls/conditional_functional_enable/tests
  23. +7 −0 test/tests/controls/time_periods/scalarkernels/gold/scalarkernels_out.csv
  24. +110 −0 test/tests/controls/time_periods/scalarkernels/scalarkernels.i
  25. +10 −0 test/tests/controls/time_periods/scalarkernels/tests
  26. +1 −1 test/tests/multiapps/initial_intactive/master.i
@@ -0,0 +1,17 @@
# ConditionalEnableControl

`Control`s deriving from `ConditionalEnableControl` allow MOOSE objects to be enabled or
disabled according to some condition. Nearly all types of MOOSE objects (`Kernel`, `BC`, etc.)
have a parameter `enable` that is controllable.

Two list parameters exist: `enable_objects` and `disable_objects`. The former
is used to specify which objects should be enabled when the specified condition
is met, and the latter is used to specify which objects should be disabled when
the specified condition is met. See the
[Object and Parameter Names](syntax/Controls/index.md#object-and-parameter-names)
section for the syntax of describing object names.

If the parameter `reverse_on_false` is set to true (as it is by default),
the objects in the `enable_objects` list are disabled when the condition is
false, and the objects in the `disable_objects` list are enabled when the
condition is false.
@@ -0,0 +1,14 @@
# ConditionalFunctionEnableControl

!syntax description /Controls/ConditionalFunctionEnableControl

`ConditionalFunctionEnableControl` objects derive from [ConditionalEnableControl](/ConditionalEnableControl.md).

`ConditionalFunctionEnableControl` objects allow MOOSE objects to be enabled or
disabled according to the value of a [Function](syntax/Functions/index.md).

!syntax parameters /Controls/ConditionalFunctionEnableControl

!syntax inputs /Controls/ConditionalFunctionEnableControl

!syntax children /Controls/ConditionalFunctionEnableControl
@@ -18,7 +18,8 @@ The `RealFunctionControl` object is designed for this purpose as shown in [real_
Notice that the "parameter" input parameter is expecting a parameter name which can be defined
in various forms.

!include /TimePeriod.md re=For a dis(.*?)section\.
For a discussion on the naming of objects and parameters see
[Object and Parameter Names](syntax/Controls/index.md#object-and-parameter-names) section.

!syntax parameters /Controls/RealFunctionControl

@@ -1,21 +1,16 @@
# TimePeriod

The `TimePeriod` object is designed to control the active state of an object as a function
of time. Nearly all objects (e.g., [Kernels],
[BCs], etc.) may be enabled/disabled according to the simulation time using
the `TimePeriod` control.
The `TimePeriod` class derives from [ConditionalEnableControl](/ConditionalEnableControl.md).

`TimePeriod` objects are designed to control the active state of a MOOSE object,
based on whether the time value is in some range.

For example, consider a simulation that contains two [Kernels] "diff0" and "diff1". Initially,
"diff0" is active and after time 0.49 "diff1" becomes active and "diff0" is disable. The following
code snippet demonstrates how this switching of kernels is achieve with the `TimePeriod` object.
"diff0" is active and after time 0.49 "diff1" becomes active and "diff0" is disabled. The following
code snippet demonstrates how this switching of kernels is achieved with the `TimePeriod` object.

!listing test/tests/controls/time_periods/kernels/kernels.i block=Controls

Notice that the object names---the "enable_objects" and "disable_objects" parameters---expect a
list of object names, which are defined in two different ways. For a discussion on the naming
of objects and parameters see
[Object and Parameter Names](syntax/Controls/index.md#object-and-parameter-names) section.

!syntax parameters /Controls/TimePeriod

!syntax inputs /Controls/TimePeriod
@@ -14,8 +14,9 @@ corresponding `vals` parameter vector should list the items these variables are
bound to. Variables can be bound to:

- Constant number literals (for example `vars = kB` and `vals = 8.61733e-5`)
- A PostProcessor name (providing the value form the PP's last execution)
- A PostProcessor name (providing the value from the PP's last execution)
- A Function name (providing an immediate evaluation of the specified function)
- A scalar variable name

Further information can be found at the
[function parser site](http://warp.povusers.org/FunctionParser/).
@@ -0,0 +1,49 @@
//* 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

#ifndef CONDITIONALENABLECONTROL_H
#define CONDITIONALENABLECONTROL_H

#include "Control.h"

class ConditionalEnableControl;

template <>
InputParameters validParams<ConditionalEnableControl>();

/**
* Base class for controls that enable/disable object(s) based on some condition
*/
class ConditionalEnableControl : public Control
{
public:
ConditionalEnableControl(const InputParameters & parameters);

virtual void execute() override;

protected:
/**
* Condition that must be true for an entry of the "enable" list to be enabled
* and/or an entry of the "disable" list to be disabled
*
* @param[in] i Index of entry within enable and/or disable list for which the condition applies
*/
virtual bool conditionMet(const unsigned int & i) = 0;

/// List of objects to enable if condition is met
const std::vector<std::string> & _enable;

/// List of objects to disable if condition is met
const std::vector<std::string> & _disable;

/// When true, the disable/enable lists are set to opposite values when the specified condition is false
const bool & _reverse_on_false;
};

#endif // CONDITIONALENABLECONTROL_H
@@ -0,0 +1,37 @@
//* 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

#ifndef CONDITIONALFUNCTIONENABLECONTROL_H
#define CONDITIONALFUNCTIONENABLECONTROL_H

#include "ConditionalEnableControl.h"

class ConditionalFunctionEnableControl;
class Function;

template <>
InputParameters validParams<ConditionalFunctionEnableControl>();

/**
* Control for enabling/disabling objects when a function value is true
*/
class ConditionalFunctionEnableControl : public ConditionalEnableControl
{
public:
ConditionalFunctionEnableControl(const InputParameters & parameters);

protected:
virtual bool conditionMet(const unsigned int & i) override;

private:
/// The function to give a true or false value
Function & _function;
};

#endif // CONDITIONALFUNCTIONENABLECONTROL_H
@@ -11,19 +11,18 @@
#define TIMEPERIOD_H

// MOOSE includes
#include "Control.h"
#include "ConditionalEnableControl.h"

// Forward declarations
class TimePeriod;
class Function;

template <>
InputParameters validParams<TimePeriod>();

/**
* A basic control for disabling objects for a portion of the simulation.
*/
class TimePeriod : public Control
class TimePeriod : public ConditionalEnableControl
{
public:
/**
@@ -32,29 +31,20 @@ class TimePeriod : public Control
*/
TimePeriod(const InputParameters & parameters);

virtual void execute() override;

protected:
/**
* If enabled, this injects the start/end times into the TimeStepper sync times.
*/
void initialSetup() override;

private:
/// List of objects to enable
const std::vector<std::string> & _enable;

/// List of objects to disable
const std::vector<std::string> & _disable;
virtual bool conditionMet(const unsigned int & i) override;

private:
/// The time to begin enabling the supplied object tags (defaults to the simulation start time)
std::vector<Real> _start_time;

/// The time to stop enabling the supplied object tags (defaults to the end of the simulation)
std::vector<Real> _end_time;

/// Flag for setting value outside of time range
bool _set_outside_of_range;
};

#endif // TIMEPERIOD_H
@@ -28,7 +28,7 @@ InputParameters validParams();

/**
* Creates the 'vars' and 'vals' parameters used by all ParsedFunctions, the
* parameters provided from this function should be appeneded to the parameters
* parameters provided from this function should be appended to the parameters
* for the class using the += operator.
* @see MooseParsedFunction, MooseParsedGradFunction, MooseParsedVectorFunction
*/
@@ -0,0 +1,59 @@
//* 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

#include "ConditionalEnableControl.h"

template <>
InputParameters
validParams<ConditionalEnableControl>()
{
InputParameters params = validParams<Control>();

params.addParam<std::vector<std::string>>(
"disable_objects", std::vector<std::string>(), "A list of object tags to disable.");
params.addParam<std::vector<std::string>>(
"enable_objects", std::vector<std::string>(), "A list of object tags to enable.");

params.addParam<bool>("reverse_on_false",
true,
"When true, the disable/enable lists are set to opposite values when the "
"specified condition is false.");

return params;
}

ConditionalEnableControl::ConditionalEnableControl(const InputParameters & parameters)
: Control(parameters),
_enable(getParam<std::vector<std::string>>("enable_objects")),
_disable(getParam<std::vector<std::string>>("disable_objects")),
_reverse_on_false(getParam<bool>("reverse_on_false"))
{
// Error if enable and disable lists are both empty
if (_enable.empty() && _disable.empty())
mooseError(
"Either or both of the 'enable_objects' and 'disable_objects' parameters must be set.");
}

void
ConditionalEnableControl::execute()
{
// ENABLE
for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i)
if (conditionMet(i))
setControllableValueByName<bool>(_enable[i], std::string("enable"), true);
else if (_reverse_on_false)
setControllableValueByName<bool>(_enable[i], std::string("enable"), false);

// DISABLE
for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i)
if (conditionMet(i))
setControllableValueByName<bool>(_disable[i], std::string("enable"), false);
else if (_reverse_on_false)
setControllableValueByName<bool>(_disable[i], std::string("enable"), true);
}
@@ -0,0 +1,40 @@
//* 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

#include "ConditionalFunctionEnableControl.h"
#include "Function.h"

registerMooseObject("MooseApp", ConditionalFunctionEnableControl);

template <>
InputParameters
validParams<ConditionalFunctionEnableControl>()
{
InputParameters params = validParams<ConditionalEnableControl>();

params.addRequiredParam<FunctionName>("conditional_function",
"The function to give a true or false value");

params.addClassDescription(
"Control for enabling/disabling objects when a function value is true");

return params;
}

ConditionalFunctionEnableControl::ConditionalFunctionEnableControl(
const InputParameters & parameters)
: ConditionalEnableControl(parameters), _function(getFunction("conditional_function"))
{
}

bool
ConditionalFunctionEnableControl::conditionMet(const unsigned int & /*i*/)
{
return _function.value(_t, Point());
}
Oops, something went wrong.

0 comments on commit 9053865

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