Skip to content

Commit 977be17

Browse files
committed
Add tests #30655
1 parent 59274aa commit 977be17

File tree

18 files changed

+532
-0
lines changed

18 files changed

+532
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosKernel.h"
13+
#include "KokkosConstantFunction.h"
14+
15+
class KokkosConstantFuncCoefDiffusion : public Moose::Kokkos::Kernel
16+
{
17+
public:
18+
static InputParameters validParams();
19+
20+
KokkosConstantFuncCoefDiffusion(const InputParameters & parameters);
21+
22+
KOKKOS_FUNCTION Real computeQpResidual(const unsigned int i,
23+
const unsigned int qp,
24+
AssemblyDatum & datum) const;
25+
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int i,
26+
const unsigned int j,
27+
const unsigned int qp,
28+
AssemblyDatum & datum) const;
29+
30+
private:
31+
Moose::Kokkos::ReferenceWrapper<const KokkosConstantFunction> _function;
32+
};
33+
34+
KOKKOS_FUNCTION inline Real
35+
KokkosConstantFuncCoefDiffusion::computeQpResidual(const unsigned int i,
36+
const unsigned int qp,
37+
AssemblyDatum & datum) const
38+
{
39+
const auto & func = static_cast<const KokkosConstantFunction &>(_function);
40+
Real k = func.value(_t, datum.q_point(qp));
41+
return k * _grad_u(datum, qp) * _grad_test(datum, i, qp);
42+
}
43+
44+
KOKKOS_FUNCTION inline Real
45+
KokkosConstantFuncCoefDiffusion::computeQpJacobian(const unsigned int i,
46+
const unsigned int j,
47+
const unsigned int qp,
48+
AssemblyDatum & datum) const
49+
{
50+
const auto & func = static_cast<const KokkosConstantFunction &>(_function);
51+
Real k = func.value(_t, datum.q_point(qp));
52+
return k * _grad_phi(datum, j, qp) * _grad_test(datum, i, qp);
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosKernel.h"
13+
#include "KokkosFunction.h"
14+
15+
class KokkosFuncCoefDiffusion : public Moose::Kokkos::Kernel
16+
{
17+
public:
18+
static InputParameters validParams();
19+
20+
KokkosFuncCoefDiffusion(const InputParameters & parameters);
21+
22+
KOKKOS_FUNCTION Real computeQpResidual(const unsigned int i,
23+
const unsigned int qp,
24+
AssemblyDatum & datum) const;
25+
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int i,
26+
const unsigned int j,
27+
const unsigned int qp,
28+
AssemblyDatum & datum) const;
29+
30+
private:
31+
const Moose::Kokkos::Function _function;
32+
};
33+
34+
KOKKOS_FUNCTION inline Real
35+
KokkosFuncCoefDiffusion::computeQpResidual(const unsigned int i,
36+
const unsigned int qp,
37+
AssemblyDatum & datum) const
38+
{
39+
Real k = _function.value(_t, datum.q_point(qp));
40+
return k * _grad_u(datum, qp) * _grad_test(datum, i, qp);
41+
}
42+
43+
KOKKOS_FUNCTION inline Real
44+
KokkosFuncCoefDiffusion::computeQpJacobian(const unsigned int i,
45+
const unsigned int j,
46+
const unsigned int qp,
47+
AssemblyDatum & datum) const
48+
{
49+
Real k = _function.value(_t, datum.q_point(qp));
50+
return k * _grad_phi(datum, j, qp) * _grad_test(datum, i, qp);
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#include "KokkosConstantFuncCoefDiffusion.h"
11+
12+
registerKokkosResidualObject("MooseTestApp", KokkosConstantFuncCoefDiffusion);
13+
14+
InputParameters
15+
KokkosConstantFuncCoefDiffusion::validParams()
16+
{
17+
InputParameters params = Kernel::validParams();
18+
params.addParam<FunctionName>("coef", "1", "The function for conductivity");
19+
return params;
20+
}
21+
22+
KokkosConstantFuncCoefDiffusion::KokkosConstantFuncCoefDiffusion(const InputParameters & parameters)
23+
: Kernel(parameters), _function(getKokkosFunction<KokkosConstantFunction>("coef"))
24+
{
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#include "KokkosFuncCoefDiffusion.h"
11+
12+
registerKokkosResidualObject("MooseTestApp", KokkosFuncCoefDiffusion);
13+
14+
InputParameters
15+
KokkosFuncCoefDiffusion::validParams()
16+
{
17+
InputParameters params = Kernel::validParams();
18+
params.addParam<FunctionName>("coef", "1", "The function for conductivity");
19+
return params;
20+
}
21+
22+
KokkosFuncCoefDiffusion::KokkosFuncCoefDiffusion(const InputParameters & parameters)
23+
: Kernel(parameters), _function(getKokkosFunction("coef"))
24+
{
25+
}
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[Mesh]
2+
type = GeneratedMesh
3+
dim = 2
4+
nx = 10
5+
ny = 10
6+
[]
7+
8+
[Variables]
9+
[u]
10+
[]
11+
[]
12+
13+
[KokkosFunctions]
14+
[constant]
15+
type = KokkosConstantFunction
16+
value = 2
17+
[]
18+
[piecewise_constant]
19+
type = KokkosPiecewiseConstant
20+
x = '0 0.5 1'
21+
y = '1 2 3'
22+
[]
23+
[]
24+
25+
[KokkosKernels]
26+
[diff]
27+
type = KokkosConstantFuncCoefDiffusion
28+
variable = u
29+
coef = constant
30+
[]
31+
[time]
32+
type = KokkosTimeDerivative
33+
variable = u
34+
[]
35+
[]
36+
37+
[KokkosBCs]
38+
[left]
39+
type = KokkosDirichletBC
40+
variable = u
41+
boundary = left
42+
value = 0
43+
[]
44+
[right]
45+
type = KokkosNeumannBC
46+
variable = u
47+
boundary = right
48+
value = 1
49+
[]
50+
[]
51+
52+
[Executioner]
53+
type = Transient
54+
num_steps = 10
55+
dt = 0.1
56+
solve_type = PJFNK
57+
petsc_options_iname = '-pc_type -pc_hypre_type'
58+
petsc_options_value = 'hypre boomeramg'
59+
[]
60+
61+
[Outputs]
62+
exodus = true
63+
[]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Tests]
2+
issues = '#30655'
3+
design = 'syntax/KokkosFunctions/index.md'
4+
[concrete_type]
5+
type = 'Exodiff'
6+
input = 'kokkos_concrete_function.i'
7+
exodiff = 'kokkos_concrete_function_out.e'
8+
requirement = 'The Kokkos function system shall include the ability to explicitly retrieve a function in a concrete type to avoid virtual function calls.'
9+
capabilities = 'kokkos'
10+
compute_devices = 'cpu cuda'
11+
[]
12+
[invalid_type]
13+
type = 'RunException'
14+
input = 'kokkos_concrete_function.i'
15+
cli_args = 'KokkosKernels/diff/coef=piecewise_constant'
16+
expect_err = 'Kokkos function \'piecewise_constant\' is not of type \'KokkosConstantFunction\''
17+
requirement = 'The Kokkos function system shall error when a provided function is not of the requested concrete type.'
18+
capabilities = 'kokkos'
19+
compute_devices = 'cpu cuda'
20+
[]
21+
[]
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[Mesh]
2+
type = GeneratedMesh
3+
dim = 2
4+
nx = 10
5+
ny = 10
6+
[]
7+
8+
[Variables]
9+
[u]
10+
[]
11+
[]
12+
13+
[KokkosFunctions]
14+
[constant]
15+
type = KokkosConstantFunction
16+
value = 2
17+
[]
18+
[]
19+
20+
[KokkosKernels]
21+
[diff]
22+
type = KokkosFuncCoefDiffusion
23+
variable = u
24+
coef = constant
25+
[]
26+
[time]
27+
type = KokkosTimeDerivative
28+
variable = u
29+
[]
30+
[]
31+
32+
[KokkosBCs]
33+
[left]
34+
type = KokkosDirichletBC
35+
variable = u
36+
boundary = left
37+
value = 0
38+
[]
39+
[right]
40+
type = KokkosNeumannBC
41+
variable = u
42+
boundary = right
43+
value = 1
44+
[]
45+
[]
46+
47+
[Executioner]
48+
type = Transient
49+
num_steps = 10
50+
dt = 0.1
51+
solve_type = PJFNK
52+
petsc_options_iname = '-pc_type -pc_hypre_type'
53+
petsc_options_value = 'hypre boomeramg'
54+
[]
55+
56+
[Outputs]
57+
exodus = true
58+
[]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Tests]
2+
issues = '#30655'
3+
design = 'KokkosConstantFunction.md'
4+
[test]
5+
type = 'Exodiff'
6+
input = 'kokkos_constant_function.i'
7+
exodiff = 'kokkos_constant_function_out.e'
8+
requirement = 'The Kokkos function system shall include a constant function.'
9+
capabilities = 'kokkos'
10+
compute_devices = 'cpu cuda'
11+
[]
12+
[]

0 commit comments

Comments
 (0)