Skip to content

Commit

Permalink
Add a test that uses setData() ref idaholab#14220
Browse files Browse the repository at this point in the history
  • Loading branch information
bwspenc committed Jan 2, 2020
1 parent f4f244c commit 30137cb
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/include/functions/HardCodedPiecewiseLinearFunction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//* 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 "PiecewiseLinearBase.h"

class HardCodedPiecewiseLinearFunction : public PiecewiseLinearBase
{
public:
static InputParameters validParams();

HardCodedPiecewiseLinearFunction(const InputParameters & parameters);
};
28 changes: 28 additions & 0 deletions test/src/functions/HardCodedPiecewiseLinearFunction.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//* 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 "HardCodedPiecewiseLinearFunction.h"

registerMooseObject("MooseTestApp", HardCodedPiecewiseLinearFunction);

InputParameters
HardCodedPiecewiseLinearFunction::validParams()
{
InputParameters params = PiecewiseLinearBase::validParams();
params.set<std::vector<Real>>("xy_data") = {}; // Avoids error in base class constructor
params.addClassDescription("Class to test using setData() to set xy data in a Piecewise function");
return params;
}

HardCodedPiecewiseLinearFunction::HardCodedPiecewiseLinearFunction(const InputParameters & parameters) : PiecewiseLinearBase(parameters)
{
const std::vector<Real> x = {0, 1, 2};
const std::vector<Real> y = {3, 1, 6};
setData(x, y);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
time,end1_pp
0.5,2
1,1
1.5,3.5
2,6
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This test ensures that hardcoded_function returns the expected
# time-dependent values. The HardCodedPiecewiseLinearFunction is
# a test object whose purpose is to ensure that the setData() method
# can be used in Piecewise functions to directly set the xy data.
[Mesh]
type = GeneratedMesh
dim = 1
xmin = 0
xmax = 1
nx = 1
[]

[Problem]
solve = false
[]

[AuxVariables]
[funcval]
[]
[]

[AuxKernels]
[funcval]
type = FunctionAux
variable = funcval
function = hardcoded_function
execute_on = 'initial timestep_end'
[]
[]


[Functions]
[hardcoded_function]
type = HardCodedPiecewiseLinearFunction
[]
[]

[Postprocessors]
[end1_pp]
type = ElementalVariableValue
variable = funcval
elementid = 0
execute_on = 'initial timestep_end'
[../]
[]

[Executioner]
type = Transient
dt = 0.5
end_time = 2
[]

[Outputs]
execute_on = 'timestep_end'
exodus = false
csv = true
[]
10 changes: 10 additions & 0 deletions test/tests/functions/hardcoded_piecewise_linear/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Tests]
design = 'PiecewiseLinear.md'
[./steady]
type = 'CSVDiff'
input = 'hardcoded_piecewise_linear.i'
exodiff = 'hardcoded_piecewise_linear_out.csv'
requirement = "The Function system shall allow for piecewise functions to directly set the xy data internally"
issues = '#14220'
[../]
[]

0 comments on commit 30137cb

Please sign in to comment.