Skip to content

Commit

Permalink
Add test for function loading data from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud committed Sep 25, 2023
1 parent 11e380b commit 062c464
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
time,from_json
0,1
1,1
2,1
3,1
4,1
5,1
6,-1
7,-1
8,10
9,10
10,10
68 changes: 34 additions & 34 deletions test/tests/functions/piecewise_constant/piecewise_constant.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This tests the PiecewiseConstant function.
# There are four variables and four functions: a,b,c, and d. The diffusion equation is "solved"
# for each of these variables with a boundary condition of type FunctionDirchletBC applied to a boundary
# for each of these variables with a boundary condition of type FunctionDirichletBC applied to a boundary
# (i.e. node set) that includes every node in the element, so the solution is the boundary condition defined by the function.
# Each boundary condition uses a function of type PiecewiseConstant.
# Each boundary condition uses a function of type PiecewiseConstant.
#
# The value of the variables should correspond to the function.

Expand All @@ -16,100 +16,100 @@

[Variables]

[./aVar]
[aVar]
order = FIRST
family = LAGRANGE
initial_condition = 0.1
[../]
[./bVar]
[]
[bVar]
order = FIRST
family = LAGRANGE
initial_condition = 0.1
[../]
[./cVar]
[]
[cVar]
order = FIRST
family = LAGRANGE
initial_condition = 0.1
[../]
[./dVar]
[]
[dVar]
order = FIRST
family = LAGRANGE
initial_condition = 0.1
[../]
[]
[]

[Functions]
[./a]
[a]
type = PiecewiseConstant
xy_data = '0.5 0.1
1.0 0.2
1.5 0.1'
direction = left
[../]
[./b]
[]
[b]
type = PiecewiseConstant
x = '0.5 1.0 1.5'
y = '0.1 0.2 0.1'
direction = right
[../]
[./c]
[]
[c]
type = PiecewiseConstant
data_file = pc.csv
direction = left
format = columns
[../]
[./d]
[]
[d]
type = PiecewiseConstant
data_file = pc.csv
direction = right
format = columns
[../]
[]
[]

[Kernels]
[./diffa]
[diffa]
type = Diffusion
variable = aVar
[../]
[./diffb]
[]
[diffb]
type = Diffusion
variable = bVar
[../]
[./diffc]
[]
[diffc]
type = Diffusion
variable = cVar
[../]
[./diffd]
[]
[diffd]
type = Diffusion
variable = dVar
[../]
[]
[]

[BCs]
[./a]
[a]
type = FunctionDirichletBC
variable = aVar
boundary = '1'
function = a
[../]
[./b]
[]
[b]
type = FunctionDirichletBC
variable = bVar
boundary = '1'
function = b
[../]
[./c]
[]
[c]
type = FunctionDirichletBC
variable = cVar
boundary = '1'
function = c
[../]
[./d]
[]
[d]
type = FunctionDirichletBC
variable = dVar
boundary = '1'
function = d
[../]
[]
[]

[Executioner]
Expand Down
43 changes: 43 additions & 0 deletions test/tests/functions/piecewise_constant/piecewise_constant_json.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[Mesh]
type = GeneratedMesh
dim = 1
[]

[Problem]
solve = false
[]

[UserObjects]
[json]
type = JSONFileReader
filename = 'function_values.json'
[]
[]

[Functions]
[from_json]
type = PiecewiseConstant
json_uo = 'json'
x_keys = "los_datos some_key some_other_key"
y_keys = "los_datos second_key some_other_key"
[]
[]

[Postprocessors]
[from_json]
type = FunctionValuePostprocessor
function = from_json
execute_on = 'TIMESTEP_END INITIAL'
[]
[]

[Executioner]
type = Transient
dt = 1
start_time = 0
end_time = 10
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[]

[Functions]
[./left]
[left]
type = PiecewiseConstant
xy_data = '-8 4
-7 3
Expand All @@ -20,28 +20,28 @@
8 4'
direction = left
scale_factor = 2
[../]
[./right]
[]
[right]
type = PiecewiseConstant
x = '-8 -7 -5.5 -2 2 5.5 7 8'
y = ' 4 3 2 1 1 2 3 4'
direction = right
scale_factor = 2
[../]
[./left_inclusive]
[]
[left_inclusive]
type = PiecewiseConstant
x = '-8 -7 -5.5 -2 2 5.5 7 8'
y = ' 4 3 2 1 1 2 3 4'
direction = left_inclusive
scale_factor = 2
[../]
[./right_inclusive]
[]
[right_inclusive]
type = PiecewiseConstant
x = '-8 -7 -5.5 -2 2 5.5 7 8'
y = ' 4 3 2 1 1 2 3 4'
direction = right_inclusive
scale_factor = 2
[../]
[]
[]

[Postprocessors]
Expand Down
26 changes: 19 additions & 7 deletions test/tests/functions/piecewise_constant/tests
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
[Tests]
issues = '#2272'
issues = '#2272 #xxx'
design = 'source/functions/PiecewiseConstant.md'
[./piecewise_constant]
[piecewise_constant]
type = 'Exodiff'
input = 'piecewise_constant.i'
exodiff = 'piecewise_constant_out.e'
requirement = "The Function system shall include an object that creates a function based on x- and y-data pairs and returns an explicit value from the supplied data when queried (i.e., linear interpolation is not performed)."
[../]
[./piecewise_constant_simple]
requirement = "The system shall include an object that creates a function based on x- and y-data "
"pairs and returns an explicit value from the supplied data when queried (i.e., "
"linear interpolation is not performed)."
[]
[piecewise_constant_simple]
type = 'CSVDiff'
input = 'piecewise_constant_simple.i'
csvdiff = 'piecewise_constant_simple_out.csv'
requirement = "The Function system shall include an object that creates a function based on x- and y-data pairs and returns an explicit value from the supplied data when queried (i.e., linear interpolation is not performed) in a simple simulation, with both negative and positive values."
[../]
requirement = "The system shall include an object that creates a function based on x- and y-data "
"pairs and returns an explicit value from the supplied data when queried (i.e., "
"linear interpolation is not performed) in a simple simulation, with both negative "
"and positive values."
[]
[piecewise_constant_from_json]
type = CSVDiff
input = 'piecewise_constant_json.i'
csvdiff = 'piecewise_constant_json_out.csv'
requirement = "The system shall be able to compute a piecewise constant function based on x- and "
"y-data loaded from a JSON file."
[]
[]

0 comments on commit 062c464

Please sign in to comment.