24 #if !defined(KRATOS_CHECKS_H_INCLUDED )
25 #define KRATOS_CHECKS_H_INCLUDED
31 #define KRATOS_CHECK(IsTrue) if(!(IsTrue)) KRATOS_ERROR << "Check failed because " << #IsTrue << " is not true" << std::endl;
32 #define KRATOS_CHECK_IS_FALSE(IsFalse) if(IsFalse) KRATOS_ERROR << "Check failed because " << #IsFalse << " is not false" << std::endl;
34 #define KRATOS_CHECK_EQUAL(a,b) if(!((a) == (b))) KRATOS_ERROR << "Check failed because " << #a << " is not equal to " << #b
35 #define KRATOS_CHECK_NOT_EQUAL(a,b) if((a) == (b)) KRATOS_ERROR << "Check failed because " << #a << " is equal to " << #b
37 #define KRATOS_CHECK_STRING_EQUAL(a,b) if(a.compare(b) != 0) KRATOS_ERROR << "Check failed because \"" << a << "\" is not equal to \"" << b << "\"" << std::endl;
38 #define KRATOS_CHECK_STRING_NOT_EQUAL(a,b) if(a.compare(b) == 0) KRATOS_ERROR << "Check failed because \"" << a << "\" is equal to \"" << b << "\"" << std::endl;
40 #define KRATOS_CHECK_C_STRING_EQUAL(a,b) if((strcmp(a,b) != 0)) KRATOS_ERROR << "Check failed because \"" << a << "\" is not equal to \"" << b << "\"" << std::endl;
41 #define KRATOS_CHECK_C_STRING_NOT_EQUAL(a,b) if((strcmp(a,b) == 0)) KRATOS_ERROR << "Check failed because \"" << a << "\" is equal to \"" << b << "\"" << std::endl;
43 #define KRATOS_CHECK_LESS(a,b) if(!(a < b)) KRATOS_ERROR << "Check failed because " << #a << " is greater than or equal to " << #b << std::endl;
44 #define KRATOS_CHECK_LESS_EQUAL(a,b) if(!(a <= b)) KRATOS_ERROR << "Check failed because " << #a << " is greater than " << #b << std::endl;
46 #define KRATOS_CHECK_GREATER(a,b) if(!(a > b)) KRATOS_ERROR << "Check failed because " << #a << " is less than or equal to " << #b
47 #define KRATOS_CHECK_GREATER_EQUAL(a,b) if(!(a >= b)) KRATOS_ERROR << "Check failed because " << #a << " is less than " << #b
49 #define KRATOS_CHECK_STRING_CONTAIN_SUB_STRING(TheString, SubString) if (TheString.find(SubString) == std::string::npos ) \
50 KRATOS_ERROR << "The string \"" << SubString << "\" was not found in the given string" << std::endl;
52 #define KRATOS_CHECK_NEAR(a,b, tolerance) if(!(std::abs(a - b) <= tolerance)) KRATOS_ERROR << "Check failed because " << #a << " = " << a << \
53 " is not near to " << #b << " = " << b << " within the tolerance " << tolerance
54 #define KRATOS_CHECK_RELATIVE_NEAR(a,b, tolerance) if(!(std::abs(b) <= std::numeric_limits<double>::epsilon())) { KRATOS_ERROR_IF(!(std::abs((a - b)/b) <= tolerance)) << "Check failed because " << #a << " = " << a << \
55 " is not near to " << #b << " = " << b << " within the relative tolerance " << tolerance << std::endl; } else {KRATOS_CHECK_NEAR(a,b,tolerance);}
56 #define KRATOS_CHECK_DOUBLE_EQUAL(a,b) KRATOS_CHECK_NEAR(a,b,std::numeric_limits<double>::epsilon())
58 #define KRATOS_CHECK_VECTOR_NEAR(a, b, tolerance) { \
59 KRATOS_ERROR_IF_NOT(a.size() == b.size()) \
60 << "Check failed because vector arguments do not have the same size:" \
62 << "First argument has size " << a.size() << ", " \
63 << "second argument has size " << b.size() << "." << std::endl; \
64 for (std::size_t _i = 0; _i < a.size(); _i++) { \
65 KRATOS_ERROR_IF( !(std::abs(a[_i] - b[_i]) <= tolerance) ) \
66 << "Check failed because vector " << #a << " with values" << std::endl \
68 << "Is not near vector " << #b << " with values" << std::endl \
70 << "Mismatch found in component " << _i << ":" << std::endl \
71 << a[_i] << " not near " << b[_i] \
72 << " within tolerance " << tolerance << "." << std::endl; \
75 #define KRATOS_CHECK_VECTOR_RELATIVE_NEAR(a, b, tolerance) { \
76 KRATOS_ERROR_IF_NOT(a.size() == b.size()) \
77 << "Check failed because vector arguments do not have the same size:" \
79 << "First argument has size " << a.size() << ", " \
80 << "second argument has size " << b.size() << "." << std::endl; \
81 for (std::size_t _i = 0; _i < a.size(); _i++) { \
82 if (std::abs(b[_i]) > std::numeric_limits<double>::epsilon()) { \
83 KRATOS_ERROR_IF( !(std::abs((a[_i] - b[_i])/b[_i]) <= tolerance) ) \
84 << "Check failed because vector " << #a << " with values" << std::endl \
86 << "Is not near vector " << #b << " with values" << std::endl \
88 << "Mismatch found in component " << _i << ":" << std::endl \
89 << a[_i] << " not near " << b[_i] \
90 << " within relative tolerance " << tolerance << "." << std::endl; \
92 KRATOS_ERROR_IF( !(std::abs(a[_i] - b[_i]) <= tolerance) ) \
93 << "Check failed because vector " << #a << " with values" << std::endl \
95 << "Is not near vector " << #b << " with values" << std::endl \
97 << "Mismatch found in component " << _i << ":" << std::endl \
98 << a[_i] << " not near " << b[_i] \
99 << " within tolerance " << tolerance << "." << std::endl; \
103 #define KRATOS_CHECK_VECTOR_EQUAL(a, b) KRATOS_CHECK_VECTOR_NEAR(a,b,std::numeric_limits<double>::epsilon())
105 #define KRATOS_CHECK_MATRIX_NEAR(a, b, tolerance) { \
106 KRATOS_ERROR_IF_NOT((a.size1() == b.size1()) && (a.size2() == b.size2())) \
107 << "Check failed because matrix arguments do not have the same dimensions:" \
109 << "First argument has dimensions (" << a.size1() << "," << a.size2() << "), " \
110 << "second argument has dimensions (" << b.size1() << "," << b.size2() << ")." \
112 for (std::size_t _i = 0; _i < a.size1(); _i++) { \
113 for (std::size_t _j = 0; _j < a.size2(); _j++) { \
114 KRATOS_ERROR_IF( !(std::abs(a(_i,_j) - b(_i,_j)) <= tolerance) ) \
115 << "Check failed because matrix " << #a << " with values" << std::endl \
117 << "Is not near matrix " << #b << " with values" << std::endl \
119 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
120 << a(_i,_j) << " not near " << b(_i,_j) \
121 << " within tolerance " << tolerance << "." << std::endl; \
125 #define KRATOS_CHECK_MATRIX_RELATIVE_NEAR(a, b, tolerance) { \
126 KRATOS_ERROR_IF_NOT((a.size1() == b.size1()) && (a.size2() == b.size2())) \
127 << "Check failed because matrix arguments do not have the same dimensions:" \
129 << "First argument has dimensions (" << a.size1() << "," << a.size2() << "), " \
130 << "second argument has dimensions (" << b.size1() << "," << b.size2() << ")." \
132 for (std::size_t _i = 0; _i < a.size1(); _i++) { \
133 for (std::size_t _j = 0; _j < a.size2(); _j++) { \
134 if (std::abs(b(_i,_j)) > std::numeric_limits<double>::epsilon()) { \
135 KRATOS_ERROR_IF( !(std::abs((a(_i,_j) - b(_i,_j))/b(_i,_j)) <= tolerance) ) \
136 << "Check failed because matrix " << #a << " with values" << std::endl \
138 << "Is not near matrix " << #b << " with values" << std::endl \
140 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
141 << a(_i,_j) << " not near " << b(_i,_j) \
142 << " within relative tolerance " << tolerance << "." << std::endl; \
144 KRATOS_ERROR_IF( !(std::abs(a(_i,_j) - b(_i,_j)) <= tolerance) ) \
145 << "Check failed because matrix " << #a << " with values" << std::endl \
147 << "Is not near matrix " << #b << " with values" << std::endl \
149 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
150 << a(_i,_j) << " not near " << b(_i,_j) \
151 << " within tolerance " << tolerance << "." << std::endl; \
156 #define KRATOS_CHECK_MATRIX_EQUAL(a, b) KRATOS_CHECK_MATRIX_NEAR(a,b,std::numeric_limits<double>::epsilon())
158 #define KRATOS_CHECK_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) \
161 KRATOS_ERROR << #TheStatement << " exited without throwing an error." << std::endl; \
162 } catch (Kratos::Exception& e) { \
163 if ( std::string(e.what()).find( TheErrorMessage ) == std::string::npos ) \
165 << "Test Failed: " << #TheStatement \
166 << " did not throw the expected error." << std::endl \
167 << "Expected:" << std::endl << TheErrorMessage << std::endl \
168 << "Got:" << std::endl << e.what() << std::endl; \
171 #define KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode) \
172 KRATOS_ERROR_IF_NOT(TheNode.SolutionStepsDataHas(TheVariable)) \
173 << "Missing " << TheVariable.Name() << " variable in solution step data for node " \
174 << TheNode.Id() << "." << std::endl;
176 #define KRATOS_CHECK_DOF_IN_NODE(TheVariable, TheNode) \
177 KRATOS_ERROR_IF_NOT(TheNode.HasDofFor(TheVariable)) \
178 << "Missing Degree of Freedom for " << TheVariable.Name() \
179 << " in node " << TheNode.Id() << "." << std::endl;
182 #define KRATOS_DEBUG_CHECK(IsTrue) KRATOS_CHECK(IsTrue)
183 #define KRATOS_DEBUG_CHECK_IS_FALSE(IsFalse) KRATOS_CHECK_IS_FALSE(IsFalse)
185 #define KRATOS_DEBUG_CHECK_EQUAL(a,b) KRATOS_CHECK_EQUAL(a,b)
186 #define KRATOS_DEBUG_CHECK_NOT_EQUAL(a,b) KRATOS_CHECK_NOT_EQUAL(a,b)
188 #define KRATOS_DEBUG_CHECK_C_STRING_EQUAL(a,b) KRATOS_CHECK_C_STRING_EQUAL(a,b)
189 #define KRATOS_DEBUG_CHECK_C_STRING_NOT_EQUAL(a,b) KRATOS_CHECK_C_STRING_NOT_EQUAL(a,b)
191 #define KRATOS_DEBUG_CHECK_LESS(a,b) KRATOS_CHECK_LESS(a,b)
192 #define KRATOS_DEBUG_CHECK_LESS_EQUAL(a,b) KRATOS_CHECK_LESS_EQUAL(a,b)
194 #define KRATOS_DEBUG_CHECK_GREATER(a,b) KRATOS_CHECK_GREATER(a,b)
195 #define KRATOS_DEBUG_CHECK_GREATER_EQUAL(a,b) KRATOS_CHECK_GREATER_EQUAL(a,b)
197 #define KRATOS_DEBUG_CHECK_STRING_CONTAIN_SUB_STRING(TheString, SubString) KRATOS_CHECK_STRING_CONTAIN_SUB_STRING(TheString, SubString)
199 #define KRATOS_DEBUG_CHECK_NEAR(a,b, tolerance) KRATOS_CHECK_NEAR(a,b, tolerance)
200 #define KRATOS_DEBUG_CHECK_DOUBLE_EQUAL(a,b) KRATOS_CHECK_DOUBLE_EQUAL(a,b)
202 #define KRATOS_DEBUG_CHECK_VECTOR_NEAR(a, b, tolerance) KRATOS_CHECK_VECTOR_NEAR(a, b, tolerance)
203 #define KRATOS_DEBUG_CHECK_VECTOR_EQUAL(a, b) KRATOS_CHECK_VECTOR_EQUAL(a, b)
205 #define KRATOS_DEBUG_CHECK_MATRIX_NEAR(a, b, tolerance) KRATOS_CHECK_MATRIX_NEAR(a, b, tolerance)
206 #define KRATOS_DEBUG_CHECK_MATRIX_EQUAL(a, b) KRATOS_CHECK_MATRIX_EQUAL(a, b)
208 #define KRATOS_DEBUG_CHECK_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) KRATOS_CHECK_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage)
210 #define KRATOS_DEBUG_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode) KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode)
211 #define KRATOS_DEBUG_CHECK_DOF_IN_NODE(TheVariable, TheNode) KRATOS_CHECK_DOF_IN_NODE(TheVariable, TheNode)
214 #define KRATOS_DEBUG_CHECK(IsTrue) if(false) KRATOS_CHECK(IsTrue)
215 #define KRATOS_DEBUG_CHECK_IS_FALSE(IsFalse) if(false) KRATOS_CHECK_IS_FALSE(IsFalse)
217 #define KRATOS_DEBUG_CHECK_EQUAL(a,b) if(false) KRATOS_CHECK_EQUAL(a,b)
218 #define KRATOS_DEBUG_CHECK_NOT_EQUAL(a,b) if(false) KRATOS_CHECK_NOT_EQUAL(a,b)
220 #define KRATOS_DEBUG_CHECK_C_STRING_EQUAL(a,b) if(false) KRATOS_CHECK_C_STRING_EQUAL(a,b)
221 #define KRATOS_DEBUG_CHECK_C_STRING_NOT_EQUAL(a,b) if(false) KRATOS_CHECK_C_STRING_NOT_EQUAL(a,b)
223 #define KRATOS_DEBUG_CHECK_LESS(a,b) if(false) KRATOS_CHECK_LESS(a,b)
224 #define KRATOS_DEBUG_CHECK_LESS_EQUAL(a,b) if(false) KRATOS_CHECK_LESS_EQUAL(a,b)
226 #define KRATOS_DEBUG_CHECK_GREATER(a,b) if(false) KRATOS_CHECK_GREATER(a,b)
227 #define KRATOS_DEBUG_CHECK_GREATER_EQUAL(a,b) if(false) KRATOS_CHECK_GREATER_EQUAL(a,b)
229 #define KRATOS_DEBUG_CHECK_STRING_CONTAIN_SUB_STRING(TheString, SubString) if(false) KRATOS_CHECK_STRING_CONTAIN_SUB_STRING(TheString, SubString)
231 #define KRATOS_DEBUG_CHECK_NEAR(a,b, tolerance) if(false) KRATOS_CHECK_NEAR(a,b, tolerance)
232 #define KRATOS_DEBUG_CHECK_DOUBLE_EQUAL(a,b) if(false) KRATOS_CHECK_DOUBLE_EQUAL(a,b)
234 #define KRATOS_DEBUG_CHECK_VECTOR_NEAR(a, b, tolerance) if (false) KRATOS_CHECK_VECTOR_NEAR(a, b, tolerance)
235 #define KRATOS_DEBUG_CHECK_VECTOR_EQUAL(a, b) if (false) KRATOS_CHECK_VECTOR_EQUAL(a, b)
237 #define KRATOS_DEBUG_CHECK_MATRIX_NEAR(a, b, tolerance) if (false) KRATOS_CHECK_MATRIX_NEAR(a, b, tolerance)
238 #define KRATOS_DEBUG_CHECK_MATRIX_EQUAL(a, b) if (false) KRATOS_CHECK_MATRIX_EQUAL(a, b)
240 #define KRATOS_DEBUG_CHECK_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) if(false) KRATOS_CHECK_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage)
242 #define KRATOS_DEBUG_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode) if(false) KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode)
243 #define KRATOS_DEBUG_CHECK_DOF_IN_NODE(TheVariable, TheNode) if(false) KRATOS_CHECK_DOF_IN_NODE(TheVariable, TheNode)