ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
common.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_TESTS_COMMON_HPP
2#define VIENNASHE_TESTS_COMMON_HPP
3/* ============================================================================
4 Copyright (c) 2011-2022, Institute for Microelectronics,
5 Institute for Analysis and Scientific Computing,
6 TU Wien.
7
8 -----------------
9 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
10 -----------------
11
12 http://viennashe.sourceforge.net/
13
14 License: MIT (X11), see file LICENSE in the base directory
15=============================================================================== */
16
21#include "viennashe/forwards.h"
22#include "viennashe/log/log.hpp"
23
24#include <cmath>
25#include <algorithm>
26
27namespace viennashe
28{
29 namespace testing
30 {
31
39 inline bool fuzzy_equal(double is, double should, double tol = 1e-1)
40 {
41 if ( (is < should || is > should)
42 && std::fabs(is - should) / std::max(std::abs(is), std::fabs(should)) > tol)
43 {
44 viennashe::log::error() << "fuzzy_equal(): tol = " << tol << std::endl;
45 viennashe::log::error() << "fuzzy_equal(): is = " << is << std::endl;
46 viennashe::log::error() << "fuzzy_equal(): should = " << should << std::endl;
47 viennashe::log::error() << "fuzzy_equal(): diff = " << std::fabs(is - should) / std::max(std::fabs(is), std::fabs(should)) << std::endl;
48 return false;
49 }
50 return true;
51 }
52
53 } // namespace tests
54} // namespace viennashe
55
56#endif /* VIENNASHE_TESTS_COMMON_HPP */
57
Contains forward declarations and definition of small classes that must be defined at an early stage.
A logging facility providing fine-grained control over logging in ViennaSHE.
logger< true > error()
Used to log errors. The logging level is logERROR.
Definition: log.hpp:301
bool fuzzy_equal(double is, double should, double tol=1e-1)
Performs a fuzzy (up to a tolerance) equal. Returns true if is and should are equal within the tolera...
Definition: common.hpp:39
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40