From fc9951e76d0faf324740c00127a42f421bc45289 Mon Sep 17 00:00:00 2001 From: Jesse Carter Date: Tue, 26 Jul 2016 22:53:23 -0400 Subject: [PATCH] made MaterialDiffusion kernel simpler --- include/kernels/MaterialDiffusion.h | 23 +++++++++------- src/kernels/MaterialDiffusion.C | 41 ++++++++++++++++------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/include/kernels/MaterialDiffusion.h b/include/kernels/MaterialDiffusion.h index e24af3f422..20fc4474de 100644 --- a/include/kernels/MaterialDiffusion.h +++ b/include/kernels/MaterialDiffusion.h @@ -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(); - -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 * _diff; + /** + * This MooseArray will hold the reference we need to our + * material property from the Material class + */ + const MaterialProperty & _diffusivity; }; - #endif //MATERIALDIFFUSION_H diff --git a/src/kernels/MaterialDiffusion.C b/src/kernels/MaterialDiffusion.C index f6c5ecdfbd..b1c697ff5b 100644 --- a/src/kernels/MaterialDiffusion.C +++ b/src/kernels/MaterialDiffusion.C @@ -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() { - InputParameters params = validParams(); - params.addRequiredParam("prop_name", "the name of the material property we are going to use"); - - MooseEnum prop_state("current old older", "current"); - params.addParam("prop_state", prop_state, "Declares which property state we should retrieve"); + InputParameters params = validParams(); return params; } MaterialDiffusion::MaterialDiffusion(const InputParameters & parameters) : - Kernel(parameters) -{ - MooseEnum prop_state = getParam("prop_state"); - - if (prop_state == "current") - _diff = &getMaterialProperty("prop_name"); - else if (prop_state == "old") - _diff = &getMaterialPropertyOld("prop_name"); - else if (prop_state == "older") - _diff = &getMaterialPropertyOlder("prop_name"); -} + Diffusion(parameters), + _diffusivity(getMaterialProperty("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(); }