Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RandomInterface to Material #5477

Merged
merged 2 commits into from Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion framework/include/materials/Material.h
Expand Up @@ -38,6 +38,7 @@
#include "ZeroInterface.h"
#include "MeshChangedInterface.h"
#include "OutputInterface.h"
#include "RandomInterface.h"

// libMesh includes
#include "libmesh/quadrature_gauss.h"
Expand Down Expand Up @@ -81,7 +82,8 @@ class Material :
public Restartable,
public ZeroInterface,
public MeshChangedInterface,
public OutputInterface
public OutputInterface,
public RandomInterface
{
public:
Material(const InputParameters & parameters);
Expand Down
3 changes: 3 additions & 0 deletions framework/src/materials/Material.C
Expand Up @@ -25,6 +25,7 @@ InputParameters validParams<Material>()
InputParameters params = validParams<MooseObject>();
params += validParams<BlockRestrictable>();
params += validParams<BoundaryRestrictable>();
params += validParams<RandomInterface>();

params.addParam<bool>("use_displaced_mesh", false, "Whether or not this object should use the displaced mesh for computation. Note that in the case this is true but no displacements are provided in the Mesh block the undisplaced mesh will still be used.");

Expand Down Expand Up @@ -62,6 +63,7 @@ Material::Material(const InputParameters & parameters) :
// The false flag disables the automatic call buildOutputVariableHideList;
// for Material objects the hide lists are handled by MaterialOutputAction
OutputInterface(parameters, false),
RandomInterface(parameters, *parameters.get<FEProblem *>("_fe_problem"), parameters.get<THREAD_ID>("_tid"), false),
_subproblem(*parameters.get<SubProblem *>("_subproblem")),
_fe_problem(*parameters.get<FEProblem *>("_fe_problem")),
_tid(parameters.get<THREAD_ID>("_tid")),
Expand Down Expand Up @@ -252,6 +254,7 @@ Material::Material(const std::string & deprecated_name, InputParameters deprecat
// The false flag disables the automatic call buildOutputVariableHideList;
// for Material objects the hide lists are handled by MaterialOutputAction
OutputInterface(parameters(), false),
RandomInterface(parameters(), *getParam<FEProblem *>("_fe_problem"), getParam<THREAD_ID>("_tid"), false),
_subproblem(*getParam<SubProblem *>("_subproblem")),
_fe_problem(*getParam<FEProblem *>("_fe_problem")),
_tid(getParam<THREAD_ID>("_tid")),
Expand Down
22 changes: 22 additions & 0 deletions test/include/materials/RandomMaterial.h
@@ -0,0 +1,22 @@
#ifndef RANDOMMATERIAL_H
#define RANDOMMATERIAL_H

#include "Material.h"

class RandomMaterial;

template<>
InputParameters validParams<RandomMaterial>();

class RandomMaterial : public Material
{
public:
RandomMaterial(const InputParameters & parameters);
virtual void computeQpProperties();

protected:
MaterialProperty<Real> & _rand_real;
MaterialProperty<unsigned long> & _rand_long;
};

#endif //RANDOMMATERIAL_H
4 changes: 3 additions & 1 deletion test/src/base/MooseTestApp.C
Expand Up @@ -126,6 +126,7 @@
#include "DerivativeMaterialInterfaceTestProvider.h"
#include "DerivativeMaterialInterfaceTestClient.h"
#include "DefaultMatPropConsumerMaterial.h"
#include "RandomMaterial.h"

#include "DGMatDiffusion.h"
#include "DGMDDBC.h"
Expand Down Expand Up @@ -379,7 +380,8 @@ MooseTestApp::registerObjects(Factory & factory)
registerMaterial(VecRangeCheckMaterial);
registerMaterial(DerivativeMaterialInterfaceTestProvider);
registerMaterial(DerivativeMaterialInterfaceTestClient);
registerKernel(DefaultMatPropConsumerMaterial);
registerMaterial(DefaultMatPropConsumerMaterial);
registerMaterial(RandomMaterial);


registerScalarKernel(ExplicitODE);
Expand Down
23 changes: 23 additions & 0 deletions test/src/materials/RandomMaterial.C
@@ -0,0 +1,23 @@
#include "RandomMaterial.h"

template<>
InputParameters validParams<RandomMaterial>()
{
InputParameters params = validParams<Material>();
return params;
}

RandomMaterial::RandomMaterial(const InputParameters & parameters) :
Material(parameters),
_rand_real(declareProperty<Real>("rand_real")),
_rand_long(declareProperty<unsigned long>("rand_long"))
{
setRandomResetFrequency(EXEC_TIMESTEP);
}

void
RandomMaterial::computeQpProperties()
{
_rand_real[_qp] = getRandomReal();
_rand_long[_qp] = getRandomLong();
}
Binary file not shown.
65 changes: 65 additions & 0 deletions test/tests/utils/random/random_material.i
@@ -0,0 +1,65 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
distribution = SERIAL
[]

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

[Kernels]
[./diff]
type = CoefDiffusion
variable = u
coef = 1e-5
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[Materials]
[./random]
type = RandomMaterial
block = 0
outputs = exodus
output_properties = random_real
[../]
[]

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

[Executioner]
# Preconditioned JFNK (default)
type = Transient
num_steps = 5
dt = 0.1
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
output_initial = true
exodus = true
print_linear_residuals = true
print_perf_log = true
[]
17 changes: 17 additions & 0 deletions test/tests/utils/random/tests
Expand Up @@ -72,4 +72,21 @@
cli_args = 'Mesh/distribution=PARALLEL Outputs/file_base=parallel_mesh_uo_out'
prereq = 'threads_verification_uo'
[../]

# Material Tests
[./material_serial]
type = 'Exodiff'
input = 'random_material.i'
exodiff = 'random_material_out.e'
max_threads = 1
[../]

[./material_parallel]
type = 'Exodiff'
input = 'random_material.i'
exodiff = 'random_material_out.e'
prereq = 'material_serial'
min_parallel = 2
max_threads = 1
[../]
[]