Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DISC
fargOCA
Commits
30790af3
Commit
30790af3
authored
Sep 22, 2021
by
Alain O' Miniussi
Browse files
move all fundamentals to constexpr
parent
c6dba421
Changes
1
Show whitespace changes
Inline
Side-by-side
include/fundamental.hpp
View file @
30790af3
...
@@ -27,9 +27,47 @@
...
@@ -27,9 +27,47 @@
#include "precision.hpp"
#include "precision.hpp"
namespace
fargOCA
{
namespace
fargOCA
{
real
constexpr
PI
=
3.14159265358979323844
;
namespace
details
{
//real const PI4 = 4*PI;
real
constexpr
cstSqrtImpl
(
real
x
,
real
l
,
real
r
)
{
real
const
epsilon
=
x
/
1e19
;
while
(
l
<=
r
)
{
real
const
mid
=
(
l
+
r
)
/
2
;
if
(
mid
*
mid
>
x
)
{
r
=
mid
;
}
else
{
if
(
x
-
mid
*
mid
<
epsilon
)
{
return
mid
;
}
l
=
mid
;
}
}
return
-
1
;
}
real
constexpr
cstSqrt
(
real
x
)
{
if
(
x
>
0
&&
x
<
1
)
{
return
1
/
cstSqrt
(
1
/
x
);
}
else
{
return
cstSqrtImpl
(
x
,
0
,
x
);
}
}
real
constexpr
cstPow
(
real
r
,
int
e
)
{
if
(
e
==
1
)
{
return
r
;
}
else
{
real
const
s
=
cstPow
(
r
,
e
/
2
);
return
e
%
2
==
0
?
s
*
s
:
r
*
s
*
s
;
}
}
}
using
details
::
cstSqrt
;
using
details
::
cstPow
;
real
constexpr
PI
=
3.14159265358979323844
;
real
constexpr
YEAR
=
365.25
*
24
*
3600
;
///< one year in s
real
constexpr
YEAR
=
365.25
*
24
*
3600
;
///< one year in s
real
constexpr
RSUN
=
6.96e+10
;
///< Sun radius in cm
real
constexpr
RSUN
=
6.96e+10
;
///< Sun radius in cm
real
constexpr
XMH
=
1.67e-24
;
///< Hydrogen mass
real
constexpr
XMH
=
1.67e-24
;
///< Hydrogen mass
...
@@ -53,14 +91,14 @@ namespace fargOCA {
...
@@ -53,14 +91,14 @@ namespace fargOCA {
/// paper : use C2^2 instead of C2
/// paper : use C2^2 instead of C2
real
constexpr
CVNR
=
1.41
;
real
constexpr
CVNR
=
1.41
;
real
const
TIME0
=
st
d
::
s
qrt
(
VOL0
/
GRAVC
/
XM0
);
// Unit of time in s
real
const
expr
TIME0
=
c
st
S
qrt
(
VOL0
/
GRAVC
/
XM0
);
// Unit of time in s
real
const
V0
=
R0
/
TIME0
;
real
const
expr
V0
=
R0
/
TIME0
;
real
const
XNU0
=
R0
*
V0
;
real
const
expr
XNU0
=
R0
*
V0
;
real
const
TEMP0
=
V0
*
V0
/
RGAS
;
real
const
expr
TEMP0
=
cstPow
(
V0
,
2
)
/
RGAS
;
real
const
RHO0
=
XM0
/
VOL0
;
real
const
expr
RHO0
=
XM0
/
VOL0
;
real
const
C0
=
CLIGHT
/
V0
;
real
const
expr
C0
=
CLIGHT
/
V0
;
real
const
A0
=
AR
*
st
d
::
p
ow
(
TEMP0
,
4
)
/
(
RHO0
*
V0
*
V0
);
real
const
expr
A0
=
AR
*
c
st
P
ow
(
TEMP0
,
4
)
/
(
RHO0
*
cstPow
(
V0
,
2
)
);
real
const
SIGMARAD
=
A0
*
C0
/
4
;
// Boltzmann constant
real
const
expr
SIGMARAD
=
A0
*
C0
/
4
;
// Boltzmann constant
real
const
E0
=
XM0
*
R0
*
R0
/
(
TIME0
*
TIME0
);
real
const
expr
E0
=
XM0
*
cstPow
(
R0
,
2
)
/
cstPow
(
TIME0
,
2
);
}
}
#endif
#endif
Alain O' Miniussi
@alainm
mentioned in commit
a3b6f126
·
Sep 22, 2021
mentioned in commit
a3b6f126
mentioned in commit a3b6f1267dfae9d73341aa377574e19599b4d8ac
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment