Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_REAL.H
Go to the documentation of this file.
1#ifndef AMREX_REAL_H_
2#define AMREX_REAL_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Extension.H>
6
7#ifdef BL_USE_FLOAT
8# undef BL_USE_DOUBLE
9# undef BL_USE_FLOAT
10/*
11 The macro BL_USE_FLOAT indicates that C++ floating-point calculations should
12 use "float" variables and Fortran floating-point calculations should use
13 "real*4" variables. One of BL_USE_FLOAT or BL_USE_DOUBLE must always be
14 defined when compiling and using AMReX.
15*/
16# define BL_USE_FLOAT 1
17#else
18# undef BL_USE_FLOAT
19# undef BL_USE_DOUBLE
20/*
21 The macro BL_USE_DOUBLE indicates that C++ floating-point calculations
22 should use "double" variables and Fortran floating-point calculations
23 should use "real*8" variables. One of BL_USE_FLOAT or BL_USE_DOUBLE must
24 always be defined when compiling and using AMReX.
25*/
26# define BL_USE_DOUBLE 1
27#endif
28
29#if !defined(BL_LANG_FORT)
30#ifdef __cplusplus
31#include <cfloat>
32#include <type_traits>
33#else
34#include <float.h>
35#endif
36
37/*
38 Real is a typedef specifying the precision of the floating-point
39 calculations in C++ code. It will be either float or double
40 depending upon which of the macros BL_USE_FLOAT or
41 BL_USE_DOUBLE, respectively, is defined during compilations. For
42 portability, you should write floating-point code in terms of this
43 typedef, instead of using float or double directly.
44
45 Note that exactly one of these macros must be defined
46 when compiling any module that uses floating-point.
47*/
48
49#ifdef BL_USE_FLOAT
50typedef float amrex_real; // NOLINT(modernize-use-using)
51// We need to define these to get around a CUDA 9.2 bug that breaks std::numeric_limits
52#define AMREX_REAL_MIN FLT_MIN
53#define AMREX_REAL_MAX FLT_MAX
54#define AMREX_REAL_LOWEST (-FLT_MAX)
55#else
56typedef double amrex_real; // NOLINT(modernize-use-using)
57#define AMREX_REAL_MIN DBL_MIN
58#define AMREX_REAL_MAX DBL_MAX
59#define AMREX_REAL_LOWEST (-DBL_MAX)
60#endif
61
62#ifdef AMREX_SINGLE_PRECISION_PARTICLES
63typedef float amrex_particle_real; // NOLINT(modernize-use-using)
64#else
65typedef double amrex_particle_real; // NOLINT(modernize-use-using)
66#endif
67
68#ifdef __cplusplus
69namespace amrex {
70
81
92
102 using ParticleMeshReal = std::common_type_t<Real, ParticleReal>;
103
108inline namespace literals {
109
119 constexpr Real
120 operator""_rt( long double x )
121 {
122 return Real( x );
123 }
124
125 constexpr Real
126 operator""_rt( unsigned long long int x )
127 {
128 return Real( x );
129 }
130
131 constexpr ParticleReal
132 operator""_prt( long double x )
133 {
134 return ParticleReal( x );
135 }
136
137 constexpr ParticleReal
138 operator""_prt( unsigned long long int x )
139 {
140 return ParticleReal( x );
141 }
143} // namespace literals
144} // namespace amrex
145#endif
146
147#endif /* !BL_LANG_FORT */
148
149#endif /*BL_REAL_H*/
Compiler- and backend-specific extension macros (e.g., restrict, SIMD, inline).
double amrex_real
Definition AMReX_REAL.H:56
double amrex_particle_real
Definition AMReX_REAL.H:65
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_particle_real ParticleReal
Floating Point Type for Particles.
Definition AMReX_REAL.H:91
std::common_type_t< Real, ParticleReal > ParticleMeshReal
Floating Point Type for Particle-Mesh Operations.
Definition AMReX_REAL.H:102
Definition AMReX_Amr.cpp:50