Skip to content

Commit

Permalink
Create transfer for controlling layered material
Browse files Browse the repository at this point in the history
  • Loading branch information
aeslaughter committed Jan 16, 2018
1 parent 7cb0e73 commit d79db77
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/controls/LayeredMaterialControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef LAYEREDMATERIALCONTROL_H
#define LAYEREDMATERIALCONTROL_H

// MOOSE includes
#include "Control.h"

// Forward Declarations
class LayeredMaterialControl;

template <>
InputParameters validParams<LayeredMaterialControl>();

/**
* A control for changing parameters associated with layer ids.
*/
class LayeredMaterialControl : public Control
{
public:
LayeredMaterialControl(const InputParameters & parameters);

protected:
virtual void execute() override;

/// The values of the parameter to control
const std::vector<Real> & _current_values;

/// The values to use from this control
const std::vector<Real> & _control_values;
};

#endif
6 changes: 6 additions & 0 deletions src/base/MastodonApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include "ResponseSpectraCalculator.h"
#include "HousnerSpectrumIntensity.h"

// Controls
#include "LayeredMaterialControl.h"

// Testing
#include "TestLayeredMaterialInterface.h"

Expand Down Expand Up @@ -123,6 +126,9 @@ MastodonApp::registerObjects(Factory & factory)
registerVectorPostprocessor(ResponseSpectraCalculator);
registerVectorPostprocessor(HousnerSpectrumIntensity);

// Controls
registerControl(LayeredMaterialControl);

// Testing
registerMaterial(TestLayeredMaterialInterfaceDocString);
registerKernel(TestLayeredMaterialInterfaceTypeError);
Expand Down
27 changes: 27 additions & 0 deletions src/controls/LayeredMaterialControl.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Mastodon includes
#include "LayeredMaterialControl.h"

template <>
InputParameters
validParams<LayeredMaterialControl>()
{
InputParameters params = validParams<Control>();
params.addRequiredParam<std::string>("parameter", "The name of the parameter to control.");
params.addRequiredParam<std::vector<Real>>("values", "The values to replace on the specified material object.");
return params;
}

LayeredMaterialControl::LayeredMaterialControl(const InputParameters & parameters)
: Control(parameters),
_current_values(getControllableValue<std::vector<Real>>("parameter")),
_control_values(getParam<std::vector<Real>>("values"))
{
if (_current_values.size() != _control_values.size())
mooseError("The layer values specified in the ", name(), " Control object and the values being controlled must be the same size.");
}

void
LayeredMaterialControl::execute()
{
setControllableValue<std::vector<Real>>("parameter", _control_values);
}
2 changes: 2 additions & 0 deletions src/materials/LinearSoilMaterial.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ validParams<LinearSoilMaterial>()
params.addClassDescription("Material for computing the shear wave speed "
"and minimum element size as a function "
"of shear modulus and density.");

params.declareControllable("shear_modulus density");
return params;
}

Expand Down
Binary file added test/tests/controls/gold/layer_control_out.e
Binary file not shown.
84 changes: 84 additions & 0 deletions test/tests/controls/layer_control.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[Mesh]
type = GeneratedMesh
dim = 1
nx = 2
[]

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

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[]

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

[AuxVariables]
[./layer]
order = CONSTANT
family = MONOMIAL
[../]
[]

[ICs]
[./layer_ic]
type = FunctionIC
function = 'if(x<0.5,1980,1949)'
variable = layer
[../]
[]

[Materials]
[./linear]
type = LinearSoilMaterial
layer_variable = layer
layer_ids = '1980 1949'
shear_modulus = '1.35e6 4.25e8'
density = '1500 1700'
outputs = exodus
[../]
[]

[Controls]
[./control_density]
type = LayeredMaterialControl
parameter = Material/linear/density
values = '1700 1500'
execute_on = 'initial'
[../]
[./control_modulus]
type = LayeredMaterialControl
parameter = Material/linear/shear_modulus
values = '4.25e8 1.35e6'
execute_on = 'initial'
[../]
[]

[Executioner]
type = Transient
num_steps = 1
[]

[Outputs]
execute_on = 'TIMESTEP_END'
hide = 'u'
exodus = true
[]
13 changes: 13 additions & 0 deletions test/tests/controls/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Tests]
[./control_layer_values]
type = Exodiff
input = layer_control.i
exodiff = layer_control_out.e
[../]
[./invalid_value_size]
type = RunException
input = layer_control.i
cli_args = Controls/control_density/values='1500'
expect_err = "The layer values specified in the control_density Control object and the values being controlled must be the same size."
[../]
[]

0 comments on commit d79db77

Please sign in to comment.