https://mooseframework.inl.gov
SolidPropertiesTestUtils.h
Go to the documentation of this file.
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 // Relative tolerance to be used when comparing to a value from external fluid
13 // property packages, which might be using different underlying models
14 #define REL_TOL_EXTERNAL_VALUE 1e-3
15 
16 // Relative tolerance to be used when comparing to a value computed directly
17 // from the code at an earlier date, to ensure that implementations are not
18 // inadvertently changed
19 #define REL_TOL_SAVED_VALUE 1e-12
20 
21 // Relative tolerance to be used for consistency checks - computing properties
22 // in different ways at the same state
23 #define REL_TOL_CONSISTENCY 1e-10
24 
25 // Relative tolerance to be used when comparing a derivative value to a finite
26 // difference approximation
27 #define REL_TOL_DERIVATIVE 1e-6
28 
29 // Relative perturbation for derivative tests
30 #define REL_PERTURBATION 1e-6
31 
32 // Macro for computing relative error
33 #define REL_TEST(value, ref_value, tol) \
34  if (std::abs(ref_value) < 1e-15) \
35  ABS_TEST(value, ref_value, tol); \
36  else \
37  EXPECT_LE(std::abs(((value) - (ref_value)) / (ref_value)), tol);
38 
39 // Macro for computing absolute error
40 #define ABS_TEST(value, ref_value, tol) EXPECT_LE(std::abs(((value) - (ref_value))), (tol))
41 
42 // Macro for performing a derivative test with a custom perturbation for 1 parameter
43 #define DERIV_TEST_CUSTOM_PERTURBATION(f, a, tol, rel_pert) \
44  { \
45  const Real da = rel_pert * a; \
46  const Real df_da_fd = (f(a + da) - f(a - da)) / (2 * da); \
47  Real f_value, df_da; \
48  f(a, f_value, df_da); \
49  REL_TEST(f(a), f_value, REL_TOL_CONSISTENCY); \
50  REL_TEST(df_da, df_da_fd, tol); \
51  }
52 
53 // Macro for performing a derivative test with 1 parameter
54 #define DERIV_TEST(f, a, tol) \
55  { \
56  DERIV_TEST_CUSTOM_PERTURBATION(f, a, tol, REL_PERTURBATION); \
57  }
58 
59 // Macro for testing that the definition of the derivative of specific internal energy is
60 // consistent with the definition of the isobaric specific heat capacity
61 #define SPECIFIC_INTERNAL_ENERGY_TESTS(sp, T, dT, rel_tol) \
62  { \
63  const Real de_dT_fd = (sp->e_from_T(T + dT) - sp->e_from_T(T - dT)) / (2 * dT); \
64  Real e, de_dT; \
65  sp->e_from_T(T, e, de_dT); \
66  REL_TEST(e, sp->e_from_T(T), REL_TOL_CONSISTENCY); \
67  REL_TEST(de_dT, de_dT_fd, rel_tol); \
68  REL_TEST(sp->cp_from_T(T), de_dT, rel_tol); \
69  }