32 #ifndef OPM_MATERIAL_MATH_TOOLBOX_HPP 33 #define OPM_MATERIAL_MATH_TOOLBOX_HPP 37 #include <type_traits> 39 #include <opm/common/utility/gpuDecorators.hpp> 49 template <
class ScalarT>
52 static_assert(std::is_floating_point<ScalarT>::value,
53 "This class expects floating point scalars! (specialization missing?)");
125 if (numDerivatives != 0)
126 throw std::logic_error(
"Plain floating point objects cannot represent any derivatives");
149 {
throw std::logic_error(
"Plain floating point objects cannot represent variables"); }
160 {
throw std::logic_error(
"Plain floating point objects cannot represent variables"); }
173 template <
class LhsEval>
176 static_assert(std::is_floating_point<LhsEval>::value,
177 "The left-hand side must be a primitive floating point type!");
188 Scalar denom = std::max<Scalar>(1.0, std::abs(a + b));
190 return std::abs(valueDiff) < tolerance || std::abs(valueDiff)/denom < tolerance;
199 {
return std::max(arg1, arg2); }
203 {
return std::min(arg1, arg2); }
207 {
return std::abs(arg); }
211 {
return std::tan(arg); }
215 {
return std::atan(arg); }
219 {
return std::atan2(arg1, arg2); }
223 {
return std::sin(arg); }
227 {
return std::asin(arg); }
231 {
return std::sinh(arg); }
235 {
return std::asinh(arg); }
239 {
return std::cos(arg); }
243 {
return std::acos(arg); }
247 {
return std::cosh(arg); }
251 {
return std::acosh(arg); }
255 {
return std::sqrt(arg); }
259 {
return std::exp(arg); }
263 {
return std::log10(arg); }
267 {
return std::log(arg); }
271 {
return std::pow(base,
exp); }
275 {
return std::isfinite(arg); }
279 {
return std::isnan(arg); }
282 template <
class Eval1,
class Eval2>
285 typedef typename std::remove_const< typename std::remove_reference<Eval1>::type >::type T;
286 typedef typename std::remove_const< typename std::remove_reference<Eval2>::type >::type U;
291 typedef typename std::conditional<std::is_constructible<T, U>::value,
297 template <
class Evaluation>
298 OPM_HOST_DEVICE Evaluation blank(
const Evaluation& x)
301 template <
class Evaluation,
class Scalar>
302 OPM_HOST_DEVICE Evaluation constant(
const Scalar&
value)
305 template <
class Evaluation,
class Scalar>
306 OPM_HOST_DEVICE Evaluation constant(
unsigned numDeriv,
const Scalar&
value)
309 template <
class Evaluation,
class Scalar>
310 OPM_HOST_DEVICE Evaluation constant(
const Evaluation& x,
const Scalar&
value)
313 template <
class Evaluation,
class Scalar>
314 OPM_HOST_DEVICE Evaluation variable(
unsigned numDeriv,
const Scalar&
value,
unsigned idx)
317 template <
class Evaluation,
class Scalar>
318 OPM_HOST_DEVICE Evaluation variable(
const Evaluation& x,
const Scalar&
value,
unsigned idx)
321 template <
class Evaluation,
class Scalar>
322 OPM_HOST_DEVICE Evaluation variable(
const Scalar&
value,
unsigned idx)
325 template <
class ResultEval,
class Evaluation>
326 OPM_HOST_DEVICE
auto decay(
const Evaluation&
value)
327 -> decltype(MathToolbox<Evaluation>::template decay<ResultEval>(
value))
328 {
return MathToolbox<Evaluation>::template decay<ResultEval>(
value); }
330 template <
class Evaluation>
331 OPM_HOST_DEVICE
auto getValue(
const Evaluation& val)
335 template <
class Evaluation>
336 OPM_HOST_DEVICE
auto scalarValue(
const Evaluation& val)
340 template <
class Evaluation1,
class Evaluation2>
341 typename ReturnEval_<Evaluation1, Evaluation2>::type
342 OPM_HOST_DEVICE max(
const Evaluation1& arg1,
const Evaluation2& arg2)
343 {
return MathToolbox<typename ReturnEval_<Evaluation1, Evaluation2>::type>::max(arg1, arg2); }
345 template <
class Evaluation1,
class Evaluation2>
346 typename ReturnEval_<Evaluation1, Evaluation2>::type
347 OPM_HOST_DEVICE min(
const Evaluation1& arg1,
const Evaluation2& arg2)
348 {
return MathToolbox<typename ReturnEval_<Evaluation1, Evaluation2>::type>::min(arg1, arg2); }
350 template <
class Evaluation>
351 OPM_HOST_DEVICE Evaluation abs(
const Evaluation&
value)
354 template <
class Evaluation>
355 OPM_HOST_DEVICE Evaluation tan(
const Evaluation&
value)
358 template <
class Evaluation>
359 OPM_HOST_DEVICE Evaluation atan(
const Evaluation&
value)
362 template <
class Evaluation1,
class Evaluation2>
363 typename ReturnEval_<Evaluation1, Evaluation2>::type
364 OPM_HOST_DEVICE atan2(
const Evaluation1& value1,
const Evaluation2& value2)
365 {
return MathToolbox<typename ReturnEval_<Evaluation1, Evaluation2>::type>::atan2(value1, value2); }
367 template <
class Evaluation>
368 OPM_HOST_DEVICE Evaluation sin(
const Evaluation&
value)
371 template <
class Evaluation>
372 OPM_HOST_DEVICE Evaluation asin(
const Evaluation&
value)
375 template <
class Evaluation>
376 OPM_HOST_DEVICE Evaluation sinh(
const Evaluation&
value)
379 template <
class Evaluation>
380 OPM_HOST_DEVICE Evaluation asinh(
const Evaluation&
value)
383 template <
class Evaluation>
384 OPM_HOST_DEVICE Evaluation cos(
const Evaluation&
value)
387 template <
class Evaluation>
388 OPM_HOST_DEVICE Evaluation acos(
const Evaluation&
value)
391 template <
class Evaluation>
392 OPM_HOST_DEVICE Evaluation cosh(
const Evaluation&
value)
395 template <
class Evaluation>
396 OPM_HOST_DEVICE Evaluation acosh(
const Evaluation&
value)
399 template <
class Evaluation>
400 OPM_HOST_DEVICE Evaluation sqrt(
const Evaluation&
value)
403 template <
class Evaluation>
404 OPM_HOST_DEVICE Evaluation exp(
const Evaluation&
value)
407 template <
class Evaluation>
408 OPM_HOST_DEVICE Evaluation log(
const Evaluation&
value)
411 template <
class Evaluation>
412 OPM_HOST_DEVICE Evaluation log10(
const Evaluation&
value)
415 template <
class Evaluation1,
class Evaluation2>
416 typename ReturnEval_<Evaluation1, Evaluation2>::type
417 OPM_HOST_DEVICE pow(
const Evaluation1& base,
const Evaluation2& exp)
418 {
return MathToolbox<typename ReturnEval_<Evaluation1, Evaluation2>::type>::pow(base, exp); }
420 template <
class Evaluation>
421 OPM_HOST_DEVICE
bool isfinite(
const Evaluation&
value)
424 template <
class Evaluation>
425 OPM_HOST_DEVICE
bool isnan(
const Evaluation&
value)
Definition: MathToolbox.hpp:283
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30