Example 09 : Stateful Materials Properties
Results

Beginning

End
Complete Source Files
(examples/ex09_stateful_materials/ex09.i)
[Mesh]
file = square.e
uniform_refine = 4
[]
[Variables]
[./convected]
order = FIRST
family = LAGRANGE
[../]
[./diffused]
order = FIRST
family = LAGRANGE
[../]
[]
[Kernels]
[./convected_ie]
type = TimeDerivative
variable = convected
[../]
[./example_diff]
# This Kernel uses "diffusivity" from the active material
type = ExampleDiffusion
variable = convected
[../]
[./conv]
type = ExampleConvection
variable = convected
some_variable = diffused
[../]
[./diffused_ie]
type = TimeDerivative
variable = diffused
[../]
[./diff]
type = Diffusion
variable = diffused
[../]
[]
[BCs]
[./left_convected]
type = DirichletBC
variable = convected
boundary = 'left'
value = 0
[../]
[./right_convected]
type = DirichletBC
variable = convected
boundary = 'right'
value = 1
[../]
[./left_diffused]
type = DirichletBC
variable = diffused
boundary = 'left'
value = 0
[../]
[./right_diffused]
type = DirichletBC
variable = diffused
boundary = 'right'
value = 1
[../]
[]
[Materials]
[./example_material]
type = ExampleMaterial
block = 1
initial_diffusivity = 0.05
[../]
[]
[Executioner]
type = Transient
solve_type = 'PJFNK'
num_steps = 10
dt = 1.0
[]
[Outputs]
execute_on = 'timestep_end'
exodus = true
[]
(examples/ex09_stateful_materials/include/materials/ExampleMaterial.h)
// 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 "Material.h"
/**
* Example material class that defines a few properties.
*/
class ExampleMaterial : public Material
{
public:
ExampleMaterial(const InputParameters & parameters);
static InputParameters validParams();
protected:
virtual void initQpStatefulProperties() override;
virtual void computeQpProperties() override;
private:
Real _initial_diffusivity;
/**
* Create two MooseArray Refs to hold the current
* and previous material properties respectively
*/
MaterialProperty<Real> & _diffusivity;
const MaterialProperty<Real> & _diffusivity_old;
};
(examples/ex09_stateful_materials/src/materials/ExampleMaterial.C)
// 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 "ExampleMaterial.h"
registerMooseObject("ExampleApp", ExampleMaterial);
InputParameters
ExampleMaterial::validParams()
{
InputParameters params = Material::validParams();
params.addParam<Real>("initial_diffusivity", 1.0, "The Initial Diffusivity");
return params;
}
ExampleMaterial::ExampleMaterial(const InputParameters & parameters)
: Material(parameters),
// Get a parameter value for the diffusivity
_initial_diffusivity(getParam<Real>("initial_diffusivity")),
// Declare that this material is going to have a Real
// valued property named "diffusivity" that Kernels can use.
_diffusivity(declareProperty<Real>("diffusivity")),
// Retrieve/use an old value of diffusivity.
// Note: this is _expensive_ as we have to store values for each
// qp throughout the mesh. Only do this if you REALLY need it!
_diffusivity_old(getMaterialPropertyOld<Real>("diffusivity"))
{
}
void
ExampleMaterial::initQpStatefulProperties()
{
// init the diffusivity property (this will become
// _diffusivity_old in the first call of computeProperties)
_diffusivity[_qp] = _initial_diffusivity;
}
void
ExampleMaterial::computeQpProperties()
{
_diffusivity[_qp] = _diffusivity_old[_qp] * 2;
}