Skip to content

Commit

Permalink
Merge pull request idaholab#15 from jessecarterMOOSE/simple_mat_diff_…
Browse files Browse the repository at this point in the history
…kernel_issue_14

made MaterialDiffusion kernel simpler
  • Loading branch information
jessecarterMOOSE authored Jul 27, 2016
2 parents e6cfbf9 + fc9951e commit 5957a5b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
23 changes: 14 additions & 9 deletions include/kernels/MaterialDiffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,36 @@
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef MATERIALDIFFUSION_H
#define MATERIALDIFFUSION_H

#include "Kernel.h"
#include "MaterialProperty.h"
#include "Diffusion.h"

// Forward Declaration
//Forward Declarations
class MaterialDiffusion;

/**
* validParams returns the parameters that this Kernel accepts / needs
* The actual body of the function MUST be in the .C file.
*/
template<>
InputParameters validParams<MaterialDiffusion>();


class MaterialDiffusion : public Kernel
class MaterialDiffusion : public Diffusion
{
public:

MaterialDiffusion(const InputParameters & parameters);

protected:
virtual Real computeQpResidual();

virtual Real computeQpJacobian();

std::string _prop_name;
const MaterialProperty<Real> * _diff;
/**
* This MooseArray will hold the reference we need to our
* material property from the Material class
*/
const MaterialProperty<Real> & _diffusivity;
};

#endif //MATERIALDIFFUSION_H
41 changes: 23 additions & 18 deletions src/kernels/MaterialDiffusion.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,46 @@
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "MaterialDiffusion.h"

/**
* This function defines the valid parameters for
* this Kernel and their default values
*/
template<>
InputParameters validParams<MaterialDiffusion>()
{
InputParameters params = validParams<Kernel>();
params.addRequiredParam<MaterialPropertyName>("prop_name", "the name of the material property we are going to use");

MooseEnum prop_state("current old older", "current");
params.addParam<MooseEnum>("prop_state", prop_state, "Declares which property state we should retrieve");
InputParameters params = validParams<Diffusion>();
return params;
}


MaterialDiffusion::MaterialDiffusion(const InputParameters & parameters) :
Kernel(parameters)
{
MooseEnum prop_state = getParam<MooseEnum>("prop_state");

if (prop_state == "current")
_diff = &getMaterialProperty<Real>("prop_name");
else if (prop_state == "old")
_diff = &getMaterialPropertyOld<Real>("prop_name");
else if (prop_state == "older")
_diff = &getMaterialPropertyOlder<Real>("prop_name");
}
Diffusion(parameters),
_diffusivity(getMaterialProperty<Real>("diffusivity"))
{}

Real
MaterialDiffusion::computeQpResidual()
{
return (*_diff)[_qp] * _grad_test[_i][_qp] * _grad_u[_qp];
// We're dereferencing the _diffusivity pointer to get to the
// material properties vector... which gives us one property
// value per quadrature point.

// Also... we're reusing the Diffusion Kernel's residual
// so that we don't have to recode that.
return _diffusivity[_qp]*Diffusion::computeQpResidual();
}

Real
MaterialDiffusion::computeQpJacobian()
{
return (*_diff)[_qp] * _grad_test[_i][_qp] * _grad_phi[_j][_qp];
// We're dereferencing the _diffusivity pointer to get to the
// material properties vector... which gives us one property
// value per quadrature point.

// Also... we're reusing the Diffusion Kernel's residual
// so that we don't have to recode that.
return _diffusivity[_qp]*Diffusion::computeQpJacobian();
}

0 comments on commit 5957a5b

Please sign in to comment.