Skip to content

Commit

Permalink
Beginning construction of shape_side_uo test. (Issue idaholab#7980)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lindsay committed Nov 1, 2016
1 parent a21fc47 commit bca59ed
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/include/kernels/PotentialAdvection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef POTENTIALADVECTION_H_
#define POTENTIALADVECTION_H_

#include "Kernel.h"

class PotentialAdvection;

template<>
InputParameters validParams<PotentialAdvection>();

class PotentialAdvection : public Kernel
{
public:
PotentialAdvection(const InputParameters & parameters);

protected:
virtual Real computeQpResidual();
virtual Real computeQpJacobian();
virtual Real computeQpOffDiagJacobian(unsigned int jvar);

private:
const VariableGradient & _grad_potential;
unsigned int _potential_id;
Real _sgn;
};

#endif //POTENTIALADVECTION_H
52 changes: 52 additions & 0 deletions test/src/kernels/PotentialAdvection.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "PotentialAdvection.h"

template<>
InputParameters validParams<PotentialAdvection>()
{
InputParameters params = validParams<Kernel>();
params.addCoupledVar("potential", "The potential responsible for charge advection");
params.addParam<bool>("positive_charge", true, "Whether the potential is advecting positive charges. Should be set to false if charges are negative.");
return params;
}

PotentialAdvection::PotentialAdvection(const InputParameters & parameters) :
Kernel(parameters),
_grad_potential(isCoupled("potential") ? coupledGradient("potential") : RealGradient(0.)),
_potential_id(coupled("potential")),
_sgn(getParam<bool>("positive_charge") ? 1 : -1)
{}

Real
PotentialAdvection::computeQpResidual()
{
return -_grad_test[_i][_qp] * _sgn * -_grad_potential[_qp] * _u[_qp];
}

Real
PotentialAdvection::computeQpJacobian()
{
return -_grad_test[_i][_qp] * _sgn * -_grad_potential[_qp] * _phi[_j][_qp];
}

Real
PotentialAdvection::computeQpOffDiagJacobian(unsigned int jvar)
{
if (jvar == _potential_id)
return -_grad_test[_i][_qp] * _sgn * -_grad_phi[_j][_qp] * _u[_qp];

else
return 0;
}
97 changes: 97 additions & 0 deletions test/tests/userobjects/shape_element_user_object/shape_side_uo.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[Mesh]
type = GeneratedMesh
dim = 1
nx = 2
[]

[Variables]
[./u]
order = FIRST
family = LAGRANGE
[./InitialCondition]
type = FunctionIC
function = (x-0.5)^2
[../]
[../]
[./v]
order = FIRST
family = LAGRANGE
[./InitialCondition]
type = FunctionIC
function = (x-0.5)^2
[../]
[../]
[./w]
order = FIRST
family = LAGRANGE
[./InitialCondition]
type = FunctionIC
function = (x-0.5)^2
[../]
[../]
[]

[Kernels]
[./diff_u]
type = Diffusion
variable = u
[../]
[./diff_v]
type = Diffusion
variable = v
[../]
[./shape_w]
type = ExampleShapeElementKernel2
user_object = example_uo
v = v
u = u
variable = w
[../]
[./time_w]
type = TimeDerivative
variable = w
[../]
[./time_u]
type = TimeDerivative
variable = u
[../]
[./time_v]
type = TimeDerivative
variable = v
[../]
[]

[UserObjects]
[./example_uo]
type = ExampleShapeElementUserObject
u = u
v = v
# as this userobject computes quantities for both the residual AND the jacobian
# it needs to have these execute_on flags set.
execute_on = 'linear nonlinear'
[../]
[]

[Preconditioning]
[./smp]
type = SMP
full = true
#off_diag_row = 'w w'
#off_diag_column = 'v u'
[../]
[]

[Executioner]
type = Transient
solve_type = NEWTON
petsc_options = '-snes_test_display'
petsc_options_iname = '-snes_type'
petsc_options_value = 'test'
dt = 0.1
num_steps = 2
[]

[Outputs]
exodus = true
print_perf_log = true
[]

0 comments on commit bca59ed

Please sign in to comment.