Skip to content

Commit

Permalink
Pass gradients though in FunctionIC. Add tests. (idaholab#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jun 23, 2014
1 parent ae595eb commit 918adea
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 5 deletions.
6 changes: 6 additions & 0 deletions framework/include/functions/MooseParsedFunction.h
Expand Up @@ -66,6 +66,12 @@ class MooseParsedFunction :
*/
virtual Real value(Real t, const Point & pt);

/**
* Evaluate the gradient of the function. This is computed in libMesh
* through automatic symbolic differentiation.
*/
virtual RealGradient gradient(Real t, const Point & p);

/**
* Method invalid for ParsedGradFunction
* @see ParsedVectorFunction
Expand Down
6 changes: 6 additions & 0 deletions framework/src/functions/MooseParsedFunction.C
Expand Up @@ -43,6 +43,12 @@ MooseParsedFunction::value(Real t, const Point & p)
return _function_ptr->evaluate<Real>(t, p);
}

RealGradient
MooseParsedFunction::gradient(Real t, const Point & p)
{
return _function_ptr->evaluateGradient(t, p);
}

RealVectorValue
MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/)
{
Expand Down
Binary file added test/tests/ics/function_ic/gold/parsed.e
Binary file not shown.
Binary file added test/tests/ics/function_ic/gold/spline.e
Binary file not shown.
12 changes: 9 additions & 3 deletions test/tests/ics/function_ic/parsed_function.i
@@ -1,10 +1,16 @@
#
# Test the automatically generated gradients in ParsedFunction and the gradient pass-through in FunctionIC
# OLD MOOSE behavior was for parsed_function to behave the sam eas parsed_zerograd_function
# NEW MOOSE behavior is for parsed_function to behave the same as parsed_grad_function
#

[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 3.141
ymin = 3.141
ymax = 1
ymin = 0
ymax = 3.141
nx = 10
ny = 10
[]
Expand All @@ -18,7 +24,7 @@

[Functions]
[./parsed_function]
type = ParsedGradFunction
type = ParsedFunction
value = 'sin(x)-cos(y/2)'
[../]
[./parsed_grad_function]
Expand Down
62 changes: 62 additions & 0 deletions test/tests/ics/function_ic/spline_function.i
@@ -0,0 +1,62 @@
#
# Test the gradient calculation in spline function and the gradient pass-through in FunctionIC
#

[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 3
ymin = 0
ymax = 1
nx = 10
ny = 1
[]

[Variables]
[./u]
order = THIRD
family = HERMITE
[../]
[]

[Functions]
[./spline_function]
type = SplineFunction
x = '0 1 2 3'
y = '0 1 0 1'
[../]
[]

[ICs]
[./u_ic]
type = FunctionIC
variable = 'u'
function = spline_function
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[]

[Executioner]
type = Steady
[]

[Outputs]
output_initial = true
file_base = spline
[./OverSampling]
type = Exodus
refinements = 3
oversample = true
[../]
[./console]
type = Console
perf_log = false
[../]
[]
5 changes: 3 additions & 2 deletions test/tests/ics/function_ic/tests
Expand Up @@ -2,12 +2,13 @@
[./parsed_function]
type = 'Exodiff'
input = 'parsed_function.i'
exodiff = 'parsed_function.e'
exodiff = 'parsed.e'
[../]

[./spline_function]
type = 'Exodiff'
input = 'spline_function.i'
exodiff = 'spline_function.e'
exodiff = 'spline.e'
skip = 'spline gradients look iffy'
[../]
[]

0 comments on commit 918adea

Please sign in to comment.