Skip to content

Commit

Permalink
Add tests for newmark beta and central difference (idaholab#18178)
Browse files Browse the repository at this point in the history
  • Loading branch information
cticenhour authored and jbadger95 committed Aug 9, 2021
1 parent 289fc83 commit fdc65c1
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 4 deletions.
29 changes: 29 additions & 0 deletions test/include/postprocessors/ADElementAverageSecondTimeDerivative.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "ElementAverageValue.h"

/**
* This postprocessor computes a volume integral of the second time derivative of a given AD variable.
*/
class ADElementAverageSecondTimeDerivative : public ElementAverageValue
{
public:
static InputParameters validParams();

ADElementAverageSecondTimeDerivative(const InputParameters & parameters);

protected:
virtual Real computeQpIntegral() override;

/// Holds the solution second derivative wrt time at the current quadrature points
const ADVariableValue & _u_dotdot;
};
32 changes: 32 additions & 0 deletions test/src/postprocessors/ADElementAverageSecondTimeDerivative.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ADElementAverageSecondTimeDerivative.h"

registerMooseObject("MooseTestApp", ADElementAverageSecondTimeDerivative);

InputParameters
ADElementAverageSecondTimeDerivative::validParams()
{
InputParameters params = ElementAverageValue::validParams();
params.addClassDescription("Computes the element averaged second derivative of variable");
return params;
}

ADElementAverageSecondTimeDerivative::ADElementAverageSecondTimeDerivative(
const InputParameters & parameters)
: ElementAverageValue(parameters), _u_dotdot(_is_transient ? adCoupledDotDot("variable") : _ad_zero)
{
}

Real
ADElementAverageSecondTimeDerivative::computeQpIntegral()
{
return MetaPhysicL::raw_value(_u_dotdot[_qp]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
###########################################################
# This is a simple test with a time-dependent problem
# demonstrating the use of the TimeIntegrator system.
#
# Testing that the second time derivative is calculated
# correctly using the Central Difference method for an AD
# variable.
#
# @Requirement F1.30
###########################################################

[Mesh]
type = GeneratedMesh
dim = 2
xmin = -1
xmax = 1
ymin = -1
ymax = 1
nx = 1
ny = 1
[]

[Variables]
[./u]
[../]
[]

[Functions]
[./forcing_fn]
type = PiecewiseLinear
x = '0.0 0.1 0.2 0.3 0.4 0.5 0.6'
y = '0.0 0.0 0.0025 0.01 0.0175 0.02 0.02'
[../]
[]

[Kernels]
[./ie]
type = ADTimeDerivative
variable = u
[../]

[./diff]
type = ADDiffusion
variable = u
[../]
[]

[BCs]
[./left]
type = ADFunctionDirichletBC
variable = u
boundary = 'left'
function = forcing_fn
preset = false
[../]
[./right]
type = ADFunctionDirichletBC
variable = u
boundary = 'right'
function = forcing_fn
preset = false
[../]
[]

[Executioner]
type = Transient

[./TimeIntegrator]
type = CentralDifference
[]

start_time = 0.0
num_steps = 6
dt = 0.1
[]

[Postprocessors]
[./udotdot]
type = ElementAverageSecondTimeDerivative
variable = u
[../]
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# demonstrating the use of the TimeIntegrator system.
#
# Testing that the first and second time derivatives
# are calculated correctly using the Newmark-Beta method
# are calculated correctly using the Central Difference
# method
#
# @Requirement F1.30
###########################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
time,udotdot
0,0
0.1,0
0.2,0
0.3,0.25
0.4,0.5
0.5,1.3010426069826e-16
0.6,-0.5
11 changes: 9 additions & 2 deletions test/tests/time_integrators/central-difference/tests
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Tests]
design = "CentralDifference.md"
issues = '#13964 #9726'

issues = '#13964 #9726 #18178'
[./central_difference]
type = 'CSVDiff'
input = 'central_difference.i'
Expand All @@ -10,4 +9,12 @@
requirement = "The CentralDifference time integrator shall correctly compute the first"
" and second time derivatives."
[../]
[./ad_central_difference_dotdot]
type = 'CSVDiff'
input = 'ad_central_difference_dotdot.i'
csvdiff = 'ad_central_difference_dotdot_out.csv'

requirement = "The CentralDifference time integrator shall correctly compute the second"
" time derivative of an AD variable."
[../]
[]
84 changes: 84 additions & 0 deletions test/tests/time_integrators/newmark-beta/ad_newmark_beta_dotdot.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
###########################################################
# This is a simple test with a time-dependent problem
# demonstrating the use of the TimeIntegrator system.
#
# Testing that the second time derivative is calculated
# correctly using the Newmark-Beta method for an AD variable
#
# @Requirement F1.30
###########################################################

[Mesh]
type = GeneratedMesh
dim = 2
xmin = -1
xmax = 1
ymin = -1
ymax = 1
nx = 1
ny = 1
[]

[Variables]
[./u]
[../]
[]

[Functions]
[./forcing_fn]
type = PiecewiseLinear
x = '0.0 0.1 0.2 0.3 0.4 0.5 0.6'
y = '0.0 0.0 0.0025 0.01 0.0175 0.02 0.02'
[../]
[]

[Kernels]
[./ie]
type = ADTimeDerivative
variable = u
[../]

[./diff]
type = ADDiffusion
variable = u
[../]
[]

[BCs]
[./left]
type = ADFunctionDirichletBC
variable = u
preset = false
boundary = 'left'
function = forcing_fn
[../]
[./right]
type = ADFunctionDirichletBC
variable = u
preset = false
boundary = 'right'
function = forcing_fn
[../]
[]

[Executioner]
type = Transient

# Time integrator scheme
scheme = "newmark-beta"

start_time = 0.0
num_steps = 6
dt = 0.1
[]

[Postprocessors]
[./udotdot]
type = ADElementAverageSecondTimeDerivative
variable = u
[../]
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
time,udotdot
0,0
0.1,0
0.2,1
0.3,-5.7732263414323e-11
0.4,-1.0000000000423
0.5,6.8312333567633e-10
0.6,-1.7013536690591e-09
11 changes: 10 additions & 1 deletion test/tests/time_integrators/newmark-beta/tests
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Tests]
design = "NewmarkBeta.md"
issues = "#12185 #18233"
issues = "#12185 #18178 #18233"
[./newmark_beta_default]
type = 'CSVDiff'
input = 'newmark_beta_default_parameters.i'
Expand Down Expand Up @@ -29,4 +29,13 @@
requirement = "The NewmarkBeta time integrator shall correctly use the inactive_tsteps"
" parameter."
[../]
[./ad_newmark_beta_dotdot]
type = 'CSVDiff'
input = 'ad_newmark_beta_dotdot.i'
csvdiff = 'ad_newmark_beta_dotdot_out.csv'

requirement = "The NewmarkBeta time integrator shall correctly compute the second"
" time derivative of an AD variable using the default beta"
" and gamma parameters."
[../]
[]

0 comments on commit fdc65c1

Please sign in to comment.