Skip to content

Commit

Permalink
Use FunctionPenaltyDirichletBC in Hermite convergence tests.
Browse files Browse the repository at this point in the history
* Drop redundant periodic, FunctionNeumannBCs, and associated Functions.
* We have to use FunctionPenaltyDirichletBC with Hermites because
  MOOSE does not correctly handle the setting of DirichletBCs for
  HERMITE elements.
* Switch test to use new [Adaptivity] system. Note that this changes
  this output of the 'dofs' postprocessor since there are now
  elemental dofs for the marker variable in the system. This required
  regolding the tests, but I checked to make sure that the solutions
  were still the same.
* Drop gold files that were not used for anything.
* If you use periodic BCs, you should not apply any other kind of BC
  on that boundary.
* Reduce the order of the custom quadrature rule used. This seemed to
  make no difference in the results and might speed up the test just a
  bit.

Refs idaholab#2190.
  • Loading branch information
jwpeterson committed Nov 17, 2017
1 parent d512061 commit f599233
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 105 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -20,24 +20,6 @@
grad_x = -pi*cos(pi*x)*sin(pi*y)
grad_y = -pi*sin(pi*x)*cos(pi*y)
[../]

[./bc_fnr]
type = ParsedFunction
value = -pi*cos(pi*x)*sin(pi*y)
[../]
[./bc_fnl]
type = ParsedFunction
value = pi*cos(pi*x)*sin(pi*y)
[../]
[./bc_fnt]
type = ParsedFunction
value = -pi*sin(pi*x)*cos(pi*y)
[../]
[./bc_fnb]
type = ParsedFunction
value = pi*sin(pi*x)*cos(pi*y)
[../]

[./forcing_fn]
type = ParsedFunction
value = -2*pi*pi*sin(pi*x)*sin(pi*y)-sin(pi*x)*sin(pi*y)
Expand All @@ -52,17 +34,14 @@
[]

[Kernels]
active = 'diff forcing reaction'
[./diff]
type = Diffusion
variable = u
[../]

[./reaction]
type = Reaction
variable = u
[../]

[./forcing]
type = BodyForce
variable = u
Expand All @@ -72,53 +51,22 @@

[BCs]
[./all]
type = FunctionDirichletBC
type = FunctionPenaltyDirichletBC
variable = u
boundary = 'bottom right top left'
function = bc_fn
[../]
[./Periodic]
[./all]
variable = u
auto_direction= 'x y'
[../]
[../]
[./bc_right]
type=FunctionNeumannBC
variable = u
boundary = 'right'
function = bc_fnr
[../]
[./bc_left]
type=FunctionNeumannBC
variable = u
boundary = 'left'
function = bc_fnl
[../]
[./bc_top]
type=FunctionNeumannBC
variable = u
boundary = 'top'
function = bc_fnt
[../]
[./bc_bottom]
type=FunctionNeumannBC
variable = u
boundary = 'bottom'
function = bc_fnb
penalty = 1e10
[../]
[]

[Postprocessors]
[./dofs]
type = NumDOFs
[../]

[./h]
type = AverageElementSize
variable = u
[../]

[./L2error]
type = ElementL2Error
variable = u
Expand All @@ -138,20 +86,27 @@

[Executioner]
type = Steady

solve_type = 'NEWTON'

[./Adaptivity]
steps = 2
refine_fraction = 1
coarsen_fraction = 0
max_h_level = 10
[../]
# We use higher-order quadrature to ensure that the forcing function
# is integrated accurately.
[./Quadrature]
order=FIFTEENTH
order=ELEVENTH
[../]
[]

[Adaptivity]
steps = 2
marker = uniform
[./Markers]
[./uniform]
type = UniformMarker
mark = refine
[../]
[../]
[]


[Outputs]
execute_on = 'timestep_end'
exodus = true
Expand Down
@@ -0,0 +1,4 @@
time,H1Semierror,H1error,L2error,dofs,h
1,0.074775053298366,0.074924715366233,0.0047333262023076,116,0.70710678118655
2,0.011349257396992,0.011356952857997,0.00041801286535784,388,0.35355339059327
3,0.0015118325178008,0.0015121167524912,2.9317422887085e-05,1412,0.17677669529664
Expand Up @@ -20,15 +20,6 @@
grad_x = -pi*cos(pi*x)*sin(pi*y)
grad_y = -pi*sin(pi*x)*cos(pi*y)
[../]

[./bc_fnr]
type = ParsedFunction
value = -pi*cos(pi*x)*sin(pi*y)
[../]
[./bc_fnl]
type = ParsedFunction
value = pi*cos(pi*x)*sin(pi*y)
[../]
[./bc_fnt]
type = ParsedFunction
value = -pi*sin(pi*x)*cos(pi*y)
Expand All @@ -37,7 +28,6 @@
type = ParsedFunction
value = pi*sin(pi*x)*cos(pi*y)
[../]

[./forcing_fn]
type = ParsedFunction
value = -2*pi*pi*sin(pi*x)*sin(pi*y)-sin(pi*x)*sin(pi*y)
Expand All @@ -57,12 +47,10 @@
type = Diffusion
variable = u
[../]

[./reaction]
type = Reaction
variable = u
[../]

[./forcing]
type = BodyForce
variable = u
Expand All @@ -71,30 +59,12 @@
[]

[BCs]
# [./all]
# type = FunctionDirichletBC
# variable = u
# boundary = 'bottom right top left'
# function = bc_fn
# [../]
[./Periodic]
[./all]
variable = u
auto_direction= 'x y'
[../]
[../]
[./bc_right]
type=FunctionNeumannBC
variable = u
boundary = 'right'
function = bc_fnr
[../]
[./bc_left]
type=FunctionNeumannBC
variable = u
boundary = 'left'
function = bc_fnl
[../]
[./bc_top]
type=FunctionNeumannBC
variable = u
Expand All @@ -113,12 +83,10 @@
[./dofs]
type = NumDOFs
[../]

[./h]
type = AverageElementSize
variable = u
[../]

[./L2error]
type = ElementL2Error
variable = u
Expand All @@ -138,17 +106,23 @@

[Executioner]
type = Steady

solve_type = 'NEWTON'

[./Adaptivity]
steps = 2
refine_fraction = 1
coarsen_fraction = 0
max_h_level = 10
[../]
# We use higher-order quadrature to ensure that the forcing function
# is integrated accurately.
[./Quadrature]
order=FIFTEENTH
order=ELEVENTH
[../]
[]

[Adaptivity]
steps = 2
marker = uniform
[./Markers]
[./uniform]
type = UniformMarker
mark = refine
[../]
[../]
[]

Expand Down
@@ -0,0 +1,4 @@
time,H1Semierror,H1error,L2error,dofs,h
1,0.074775053282849,0.074924715349675,0.0047333261853512,116,0.70710678118655
2,0.011349257394713,0.011356952855582,0.00041801286158565,388,0.35355339059327
3,0.0015118325174985,0.0015121167521718,2.9317421998023e-05,1412,0.17677669529664
35 changes: 35 additions & 0 deletions test/tests/variables/fe_hermite_convergence/plot.py
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np

"""
This script makes log-log plots of the error vs. h for the tests in this directory.
"""

filenames = ['hermite_converge_dirichlet_out.csv',
'hermite_converge_periodic_out.csv']

for filename in filenames:
fig = plt.figure()
ax1 = fig.add_subplot(111)

# passing names=True option is supposed to treat first row as column
# header names, and then everything is stored by column name in data.
data = np.genfromtxt(filename, delimiter=',', names=True)

log_h1_error = np.log10(data['H1error'])
log_l2_error = np.log10(data['L2error'])
logh = np.log10(data['h'])

h1_fit = np.polyfit(logh, log_h1_error, 1)
l2_fit = np.polyfit(logh, log_l2_error, 1)

ax1.plot(logh, log_h1_error, linewidth=2, marker='o', label=r'$H^1$ error')
ax1.text(-0.4, -2., '{:.2f}'.format(h1_fit[0]))

ax1.plot(logh, log_l2_error, linewidth=2, marker='o', label=r'$L^2$ error')
ax1.text(-0.4, -3.5, '{:.2f}'.format(l2_fit[0]))

ax1.set_xlabel('log(h)')
ax1.legend(loc='upper left')
plt.savefig(filename.rsplit( ".", 1)[0] + '.pdf')
7 changes: 4 additions & 3 deletions test/tests/variables/fe_hermite_convergence/tests
Expand Up @@ -7,10 +7,11 @@
valgrind = 'HEAVY'
[../]

[./test_hermite_converge_neumann]
[./test_hermite_converge_dirichlet]
type = 'Exodiff'
input = 'hermite_converge_neumann.i'
exodiff = 'hermite_converge_neumann_out.e-s003'
input = 'hermite_converge_dirichlet.i'
exodiff = 'hermite_converge_dirichlet_out.e-s003'
valgrind = 'HEAVY'
abs_zero = 1e-09
[../]
[]

0 comments on commit f599233

Please sign in to comment.